-
Notifications
You must be signed in to change notification settings - Fork 34
/
qianxin_skyeye.py
49 lines (40 loc) · 1.48 KB
/
qianxin_skyeye.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
import json
import ipaddress
import socketserver
from SecAutoBan import SecAutoBan
def is_lan(ip: str) -> bool:
if bypass_lan:
return ipaddress.ip_address(ip).is_private
return False
class SyslogUDPHandler(socketserver.BaseRequestHandler):
def __init__(self, request, client_address, server, ws_client):
self.ws_client = ws_client
super().__init__(request, client_address, server)
def handle(self):
data = self.request[0]
if len(data) == 0:
return
message = data.decode('utf-8')
msg = json.loads(message.split("|!alarm|!")[1])
sip = msg["attack_sip"]
if sip == "":
return
if is_lan(sip):
return
origin = "攻击" + msg["alarm_sip"] + ": [" + msg["type"] + "]" + msg["vuln_type"]
self.ws_client.send_alarm(sip, origin)
def alarm_analysis(ws_client):
with socketserver.ThreadingUDPServer(("0.0.0.0", listen_syslog_udp_port), lambda *args: SyslogUDPHandler(*args, ws_client=ws_client)) as server:
sec_auto_ban.print("[+] 监听SysLog端口: " + str(listen_syslog_udp_port) + "/UDP")
server.serve_forever()
if __name__ == "__main__":
listen_syslog_udp_port = 567
bypass_lan = True # 过滤内网攻击,True 开启 | False 关闭
sec_auto_ban = SecAutoBan(
server_ip="127.0.0.1",
server_port=80,
sk="sk-*****",
client_type="alarm",
alarm_analysis = alarm_analysis
)
sec_auto_ban.run()