Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
cs2modrewrite — 将 Cobalt Strike 配置文件转换为 modrewrite 脚本 | Kitploit
工具/GitHubGitHub/threatexpress/cs2modrewrite
Web代理与拦截IDS/IPS规避网络安全渗透测试命令与控制红队
GitHubthreatexpress/cs2modrewrite

cs2modrewrite

将 Cobalt Strike 配置文件转换为 modrewrite 脚本

查看仓库
60811653年前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

为 Apache mod_rewrite 或 Nginx 自动生成规则集,实现智能 HTTP C2 重定向

Python application 该项目将 Cobalt Strike profile 转换为功能可用的 mod_rewrite .htaccess 或 Nginx 配置文件,以支持向 Cobalt Strike teamserver 进行 HTTP 反向代理重定向。使用反向代理可为后端 C2 服务器提供保护,使其免受探测分析、调查以及一般互联网背景辐射的影响。

注意:在部署之前,您应根据需要测试和调整输出结果,但这些脚本应该能处理大部分繁重工作。

功能特性

  • 现在要求 Python 3.0+
  • 支持 CS 4.0 中引入的 Cobalt Strike 自定义 URI 功能
  • 基于有效 C2 URI(HTTP GET、POST 和 Stager)以及指定的 User-Agent 字符串生成重写规则。
    • 结果:默认情况下,只有指向有效 C2 端点且携带指定 UA 字符串的请求才会被代理到 teamserver。
  • 使用自定义 Malleable C2 profile 构建包含相应 mod_rewrite 规则的 .htaccess 文件
  • 使用自定义 Malleable C2 profile 构建包含相应 proxy_pass 规则的 Nginx 配置
  • 支持通过 HTTP 或 HTTPS 代理到 Cobalt Strike teamserver
  • 将不匹配的请求通过 HTTP 302 重定向到合法站点

快速开始

为便于快速测试,项目中已包含 havex.profile 示例。

  1. 针对某个 profile 运行脚本
  2. 将输出保存到重定向服务器上的 .htaccess 或 /etc/nginx/nginx.conf
  3. 根据需要修改
  4. 重新加载\重启 Web 服务器

使用远程包含文件的 Apache mod_rewrite 示例用法

root@kitploit:~
python3 cs2modrewrite.py -i havex.profile -c https://TEAMSERVER -r https://GOHERE -o /etc/apache2/redirect.rules

Apache 配置示例

root@kitploit:~
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    RemoteIPHeader X-Forwarded-For

    ErrorLog /var/log/apache2/redirector_error.log
    CustomLog /var/log/apache2/redirector_access.log combined
    ErrorDocument 401 " "
    ErrorDocument 403 " "
    ErrorDocument 404 " "
    ErrorDocument 500 " "
    ErrorDocument 503 " "

    # Include redirect.rules
    Include /etc/apache2/redirect.rules
</VirtualHost>

建议使用类似如下方式更新 Apache 的 Server Header、ServerTokens 及日志记录。

root@kitploit:~
## Update Apached Server Header, ServerTokens, and logging
echo "Update Update Apached Server Header, ServerTokens, and logging"
sed -i -e 's/\(ServerTokens\s\+\)OS/\1Prod/g' /etc/apache2/conf-enabled/security.conf
sed -i -e 's/\(ServerSignature\s\+\)On/\1Off/g' /etc/apache2/conf-enabled/security.conf
echo "SecServerSignature Server" >> /etc/apache2/conf-enabled/security.conf
echo "LogLevel alert rewrite:trace2" >> /etc/apache2/conf-enabled/security.conf

## Update Apached remoteip.conf
echo "Update Apached remoteip.conf"
echo "RemoteIPHeader X-Forwarded-For" >> /etc/apache2/conf-enabled/remoteip.conf

## Restart apache server
echo "Restart apache server"
systemctl restart apache2

使用 .htaccess 文件的 Apache mod_rewrite 示例用法

root@kitploit:~
python3 cs2modrewrite.py -i havex.profile -c https://TEAMSERVER -r https://GOHERE -o /var/www/html/.htaccess

Apache 重写设置与提示

启用 Rewrite 和 Proxy

root@kitploit:~
apt-get install apache2
a2enmod rewrite headers proxy proxy_http ssl cache
a2dismod -f deflate
service apache2 reload

注意: https://bluescreenofjeff.com/2016-06-28-cobalt-strike-http-c2-redirectors-with-apache-mod_rewrite/ "e0x70i 在下方评论中指出,如果您的 Cobalt Strike Malleable C2 profile 包含 gzip 的 Accept-Encoding 头,您的 Apache 安装可能会默认压缩该流量,从而导致您的 Beacon 无响应或功能异常。要解决此问题,请禁用 mod_deflate(通过 a2dismod deflate,并在您的重写规则中添加 No Encode([NE])标志)。(感谢 e0x70i!)"

启用 SSL 支持

确保站点配置(即 /etc/apache2/available-sites/*.conf)中包含以下条目

root@kitploit:~
# Enable SSL
SSLEngine On
# Enable SSL Proxy
SSLProxyEngine On
# Trust Self-Signed Certificates generated by CobaltStrike
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off

.HTACCESS

如果您计划在 .htaccess 文件中使用 mod_rewrite(而不是在站点配置文件中使用),您还需要通过将 AllowOverride None 更改为 AllowOverride All 来启用 .htaccess 文件的使用。对于所有网站,请编辑 /etc/apache2/apache.conf

root@kitploit:~
<Directory /var/www/>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

最后,为确保万无一失,请再次重启 Apache。

service apache2 restart

故障排查

如果您需要对重定向规则行为进行故障排查,请在站点配置文件中添加以下行,以启用详细的错误跟踪。

LogLevel alert rewrite:trace5

接下来,重新加载 Apache,并监控 /var/log/access.log 和 /var/log/error.log,以查看哪些规则正在匹配。


Nginx 示例用法

安装 Nginx

root@kitploit:~
apt-get install nginx nginx-extras

注意: 自定义服务器头需要 nginx-extras。如果您无法获取此软件包,请注释掉生成的配置文件中的服务器头行。

创建重定向规则

将 cs2nginx.py 的输出保存到 /etc/nginx/nginx.conf,并根据需要修改(SSL 参数)。

python3 ./cs2nginx.py -i havex.profile -c https://127.0.0.1 -r https://www.google.com -H mydomain.local >/etc/nginx/nginx.conf

最后,在修改服务器配置文件后,重启 nginx。

service nginx restart

结语

配置好重定向并使其正常运行后,请确保您的 C2 服务器仅允许来自重定向服务器以及您可信 IP(VPN、办公网段等)的入站流量。

建议通过 GeoIP 限制(mod_maxmind)以及恶意 User-Agent 和 IP 网段黑名单,为重定向服务器增加额外的防护。感谢 @curi0usJack 提供的思路。

参考资料

  • Joe Vest 与 Andrew Chiles - cs2modrewrite.py 博客文章

  • @bluescreenofjeff - 使用 Apache mod_rewrite 配置 Cobalt Strike HTTP C2 重定向器

  • Adam Brown - 使用 Nginx 实现具有弹性的红队 HTTPS 重定向

  • Apache - Apache mod_rewrite 文档

下载工具