
Cobalt Strike 프로필을 modrewrite 스크립트로 변환합니다
이 프로젝트는 Cobalt Strike 프로파일을 기능적인 mod_rewrite
.htaccess 또는 Nginx 구성 파일로 변환하여 HTTP 역방향 프록시 리디렉션을 Cobalt Strike 팀서버로 지원합니다. 역방향 프록시를 사용하면 프로파일링, 조사 및 일반적인 인터넷 배경 방사선으로부터 백엔드 C2 서버를 보호할 수 있습니다.
참고: 배포 전에 필요에 따라 출력을 테스트하고 조정해야 하지만, 이 스크립트들이 대부분의 작업을 처리할 것입니다.
빠른 테스트를 위해 havex.profile 예제가 포함되어 있습니다.
.htaccess 또는 /etc/nginx/nginx.conf에 저장python3 cs2modrewrite.py -i havex.profile -c https://TEAMSERVER -r https://GOHERE -o /etc/apache2/redirect.rules
예제 Apache 구성
<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 및 로깅을 업데이트하는 것을 고려하세요.
## 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
python3 cs2modrewrite.py -i havex.profile -c https://TEAMSERVER -r https://GOHERE -o /var/www/html/.htaccess
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 프로파일에 gzip에 대한 Accept-Encoding 헤더가 포함되어 있으면 Apache 설치 시 기본적으로 해당 트래픽을 압축하여 Beacon이 응답하지 않거나 오작동할 수 있습니다. 이를 해결하려면 mod_deflate를 비활성화하고(a2dismod deflate 사용) 재작성 규칙에 No Encode ([NE]) 플래그를 추가하세요. (감사합니다, e0x70i!)"
다음 항목이 사이트 구성(예: /etc/apache2/available-sites/*.conf)에 있는지 확인하세요.
# 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 파일에서 mod_rewrite를 사용하려면(사이트 구성 파일 대신) AllowOverride None을 AllowOverride All로 변경하여 .htaccess 파일 사용을 활성화해야 합니다. 모든 웹사이트에 대해 /etc/apache2/apache.conf를 편집하세요.
<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를 모니터링하여 어떤 규칙이 일치하는지 확인하세요.
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) 및 불량 사용자 에이전트와 IP 범위의 블랙리스트를 사용하여 추가 리디렉터 보호를 고려하세요. 아이디어를 주신 @curi0usJack님께 감사드립니다.