0%

ctfbot搭建指南

QQbot搭建记录

简单记录一下搭一个没有带脑子的qqbot的过程。

无脑版(裸go-cqhttp)

从接口和go-cqhttp

先去release上下载,wget就行。

直接走一波./go-cqhttp,然后会出config.yml,如下配置。

反向代理加上脑子才需要,但是先挂出来吧。

1
2
3
4
5
6
7
8
9
10
11
12
- ws-reverse:
## 反向WS Universal 地址
## 注意 设置了此项地址后下面两项将会被忽
universal: ws://127.0.0.1:8080/cqhttp/ws
## 反向WS API 地址
api: ws://127.0.0.1:8080/cqhttp/api
## 反向WS Event 地址
event: ws://127.0.0.1:8080/cqhttp/event
## 重连间隔 单位毫秒
reconnect-interval: 3000
middlewares:
<<: *default # 引用默认中间件

然后不行试试127.0.0.10.0.0.0

还有什么

1
sudo chmod 777 ./go-cqhttp

接着执行

1
sudo ./go-cqhttp

然后建议扫码登录。可以先测试下

测试成功后使用这个命令

1
sudo nohup ./go-cqhttp > go.log 2>&1 &

到浏览器中输入

1
http://127.0.0.1:5700/send_private_msg?user_id=xxxxx&message=aaaa

看看能不能收到消息,收到就成功了。

接着改CTFd/CTFd/api/v1/challenges.py

加上这两部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# TODO: Convert this into a re-useable decorator
if config.is_teams_mode() and team is None:
abort(403)

fails = Fails.query.filter_by(
account_id=user.account_id, challenge_id=challenge_id
).count()

challenge = Challenges.query.filter_by(id=challenge_id).first_or_404()
#从这开始
challenge_name=challenge.name
challenge_category=challenge.category
user_name=user.name #这里结束
if challenge.state == "hidden":
abort(404)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
if status:  # The challenge plugin says the input is right
if ctftime() or current_user.is_admin():
chal_class.solve(
user=user, team=team, challenge=challenge, request=request
)
clear_standings()

log(
"submissions",
"[{date}] {name} submitted {submission} on {challenge_id} with kpm {kpm} [CORRECT]",
submission=request_data["submission"].encode("utf-8"),
challenge_id=challenge_id,
kpm=kpm,
)
#从这里开始加
# auto-broadcast

solve_count = Solves.query.filter_by(challenge_id=challenge_id).count()
blood_number = ""
if solve_count == 1:
blood_number = "一血"
elif solve_count == 2:
blood_number = "二血"
elif solve_count == 3:
blood_number = "三血"
else:
pass
if blood_number:
print("是三血")
print(challenge_category) # 题目分类
print(challenge_name) # 题目名称
print(user_name)
print(blood_number)
import requests
url = "http://127.0.0.1:5700/send_group_msg?group_id=xxxxx&message="
msg="恭喜<{}>获得[{}]类型题目《{}》 {}! Tql".format(user_name,challenge_category, challenge_name,blood_number)
url=url+msg
try:
requests.get(url=url)
except:
pass
else:
print("不是三血")
import requests
url = "http://127.0.0.1:5700/send_group_msg?group_id=xxxxx&message="


msg="恭喜<{}>解出[{}]类型题目《{}》Tql".format(user_name,challenge_category, challenge_name)
url=url+msg
try:
print('不是三血开始推送')
requests.get(url=url)
print('不是三血推送成功')
except:
print('不是三血推送失败')
pass
#到这结束
return {
"success": True,
"data": {"status": "correct", "message": message},
}
else: # The challenge plugin says the input is wrong
-------------本文结束感谢您的阅读-------------