-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict_sql_queries.py
More file actions
74 lines (58 loc) · 2 KB
/
Copy pathpredict_sql_queries.py
File metadata and controls
74 lines (58 loc) · 2 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
import pandas as pd
import nltk
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from nltk.stem import WordNetLemmatizer
def build_model():
text = pd.read_csv("datasets/plain.txt", sep='\n', skiprows=2, header=None)
text.head()
text.rename(columns={0: 'txt'}, inplace=True)
text2 = pd.read_csv("datasets/sql_querys.txt", sep='\n', header=None)
s1 = list(text['txt'])
s2 = list(text2[0])
s1 = [i.lower() for i in s1]
s2 = [i.lower() for i in s2]
y1 = [0 for i in range(len(s1))]
y2 = [1 for i in range(len(s2))]
y = y1 + y2
word_lem = WordNetLemmatizer()
new_s1 = []
stopwords = nltk.corpus.stopwords.words("english")
for i in s1:
temp = i.split(' ')
temp1 = []
for j in temp:
j = j.strip(',').strip(r'["]').strip(';').strip('“').strip('”').strip(r'[.]+')
j = j.replace("’", '')
if j not in stopwords and j.isalpha():
j = word_lem.lemmatize(j)
temp1.append(j)
new_s1.append(' '.join(temp1))
new_s2 = []
for i in s2:
temp = i.split(' ')
temp1 = []
for j in temp:
if j not in stopwords:
j = word_lem.lemmatize(j)
temp1.append(j)
new_s2.append(' '.join(temp1))
new_s = new_s1 + new_s2
tokenizer1 = Tokenizer(num_words=100000, oov_token="<OOV>")
tokenizer1.fit_on_texts(new_s)
model = load_model("model/model.h5")
return model, tokenizer1
"""
entry = input("Please enter sql query for check: ")
entry = entry.lower()
temp = []
temp.append(entry)
token = tokenizer1.texts_to_sequences(temp)
pad = pad_sequences(token, maxlen=150, padding="post")
decision = model.predict_proba(pad)[0][0]
if decision < 0.6:
print(f"{entry} - is not identified as a malicious query")
else:
print(f"{entry} - is identified as a malicious query !!!")
"""