-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginBack.py
More file actions
160 lines (147 loc) · 6.1 KB
/
PluginBack.py
File metadata and controls
160 lines (147 loc) · 6.1 KB
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
import re
import asyncio
import websockets
import mysql.connector
from mysql.connector import errorcode
def ConectarBaseDeDatos():
cnx = ""
curs = ""
try:
cnx = mysql.connector.connect(user='pluggin', password='', host='',
database='Validator')
curs = cnx.cursor()
print("Conectado a la BD")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
cnx.close()
return cnx, curs
def get_cantidadBlackList(fromm, curs):
query = f"SELECT cantidad FROM blacklist WHERE FROMM = \"{fromm}\""
curs.execute(query)
cantidad = curs.fetchall()
if cantidad:
return int(cantidad[0][0])
else:
return 0
async def BackEnd(websocket, path):
separador = " # "
cnx, curs = ConectarBaseDeDatos()
score = 0
primerreceived = await websocket.recv()
penreceived = await websocket.recv()
fromm = await websocket.recv()
msgid = await websocket.recv()
auth = await websocket.recv()
fromm = fromm.split("<")
if len(fromm) > 1:
fromm = fromm[1].replace(">", "")
else:
fromm =fromm[0].replace(">", "")
msgid = msgid.replace("<", "").replace(">", "")
query = f"SELECT * FROM Correo WHERE FROMM = \"{fromm}\""
curs.execute(query)
res = curs.fetchall()
cantidad = get_cantidadBlackList(fromm, curs)
if res and cantidad < 5:
if primerreceived != penreceived:
for i,line in enumerate(res[0]):
if i == 0:
msgidsbd = res[0][i].split(separador)
for msgidbd in msgidsbd:
if re.match(msgidbd, msgid.replace("[","").replace("]","")):
score += 1
break
elif i == 2:
primerosBD = res[0][i].split(separador)
for primeroBD in primerosBD:
if re.findall(primeroBD, primerreceived):
score += 0.75
break
elif i == 3:
pensbd = res[0][i].split(separador)
for penbd in pensbd:
if re.findall(penbd, penreceived):
score += 0.75
break
elif i == 4:
utcsbd = res[0][i]
if utcsbd:
utcsbd = res[0][i].split(separador)
for utcbd in utcsbd:
pattern = "([\-|\+]\d\d\d\d|(\(\w\w\w\)))"
if re.findall(pattern, primerreceived):
try:
utcbd = "[" + utcbd + "]"
if re.findall(utcbd, primerreceived):
score += 1
break
except:
utcbd = "(" + utcbd + ")"
if re.findall(utcbd, primerreceived):
score += 1
break
else:
score += 1
else:
score += 1
elif i == 5:
authsbd = res[0][i].split(separador)
maxi = int(authsbd[0])
mini = int(authsbd[1])
pattern = "(pass)"
a = re.findall(pattern, auth)
if int(len(a)) in range(mini, maxi+1):
score += 1.5
elif primerreceived == penreceived:
for i,line in enumerate(res[0]):
if i == 0:
msgidsbd = res[0][i].split(separador)
for msgidbd in msgidsbd:
if re.match(msgidbd, msgid.replace("[","").replace("]","")):
score += 1
break
elif i == 2:
primerosBD = res[0][i].split(separador)
for primeroBD in primerosBD:
if re.findall(primeroBD, primerreceived):
score += 1.5
break
elif i == 4:
utcsbd = res[0][i].split(separador)
for utcbd in utcsbd:
pattern = "([\-|\+]\d\d\d\d|(\(\w\w\w\)))"
if re.findall(pattern, primerreceived):
try:
utcbd = "[" + utcbd + "]"
if re.findall(utcbd, primerreceived):
score += 1
break
except:
utcbd = "(" + utcbd + ")"
if re.findall(utcbd, primerreceived):
score += 1
break
else:
score += 1
elif i == 5:
authsbd = res[0][i].split(separador)
maxi = int(authsbd[0])
mini = int(authsbd[1])
pattern = "(pass)"
a = re.findall(pattern, auth)
if int(len(a)) in range(mini, maxi+1):
score += 1.5
else:
if cantidad > 0:
score = 1
else:
score = 6
await websocket.send(str(score-cantidad))
start_server = websockets.serve(BackEnd, "", 10000)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()