-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHome.py
346 lines (306 loc) · 12.8 KB
/
Home.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# import streamlit as st
# import machine_learning as ml
# import feature_extraction as fe
# from bs4 import BeautifulSoup
# import requests as re
# import matplotlib.pyplot as plt
#
# # col1, col2 = st.columns([1, 3])
#
# st.title('Phishing Website Detection using Machine Learning')
# st.write('This ML-based app is developed for educational purposes. Objective of the app is detecting phishing websites only using content data. Not URL!'
# ' You can see the details of approach, data set, and feature set if you click on _"See The Details"_. ')
#
#
# with st.expander("PROJECT DETAILS"):
# st.subheader('Approach')
# st.write('We used _supervised learning_ to classify phishing and legitimate websites. '
# 'We benefit from content-based approach and focus on html of the websites. '
# 'Also, We used scikit-learn for the ML models.'
# )
# st.write('For this educational project, '
# 'We created my own data set and defined features, some from the literature and some based on manual analysis. '
# 'We used requests library to collect data, BeautifulSoup module to parse and extract features. ')
# st.write('The source code and data sets are available in the below Github link:')
# st.write('_https://github.com/AdarshVajpayee19/Phishing-Website-Detection-ML_')
#
# st.subheader('Data set')
# st.write('We used _"phishtank.org"_ & _"tranco-list.eu"_ as data sources.')
# st.write('Totally 26584 websites ==> **_16060_ legitimate** websites | **_10524_ phishing** websites')
#
# # ----- FOR THE PIE CHART ----- #
# labels = 'phishing', 'legitimate'
# phishing_rate = int(ml.phishing_df.shape[0] / (ml.phishing_df.shape[0] + ml.legitimate_df.shape[0]) * 100)
# legitimate_rate = 100 - phishing_rate
# sizes = [phishing_rate, legitimate_rate]
# explode = (0.1, 0)
# fig, ax = plt.subplots()
# ax.pie(sizes, explode=explode, labels=labels, shadow=True, startangle=90, autopct='%1.1f%%')
# ax.axis('equal')
# st.pyplot(fig)
# # ----- !!!!! ----- #
#
# st.write('Features + URL + Label ==> Dataframe')
# st.markdown('label is 1 for phishing, 0 for legitimate')
# number = st.slider("Select row number to display", 0, 100)
# st.dataframe(ml.legitimate_df.head(number))
#
#
# @st.cache
# def convert_df(df):
# # IMPORTANT: Cache the conversion to prevent computation on every rerun
# return df.to_csv().encode('utf-8')
#
# csv = convert_df(ml.df)
#
# st.download_button(
# label="Download data as CSV",
# data=csv,
# file_name='phishing_legitimate_structured_data.csv',
# mime='text/csv',
# )
#
# st.subheader('Features')
# st.write('We used only content-based features. I didn\'t use url-based faetures like length of url etc.'
# 'Most of the features extracted using find_all() method of BeautifulSoup module after parsing html.')
#
# st.subheader('Results')
# st.write('We used 7 different ML classifiers of scikit-learn and tested them implementing k-fold cross validation.'
# 'Firstly obtained their confusion matrices, then calculated their accuracy, precision and recall scores.'
# 'Comparison table is below:')
# st.table(ml.df_results)
# st.write('NB --> Gaussian Naive Bayes')
# st.write('SVM --> Support Vector Machine')
# st.write('DT --> Decision Tree')
# st.write('RF --> Random Forest')
# st.write('AB --> AdaBoost')
# st.write('NN --> Neural Network')
# st.write('KN --> K-Neighbours')
#
# with st.expander('EXAMPLE PHISHING URLs:'):
# st.write('_https://rtyu38.godaddysites.com/_')
# st.write('_https://karafuru.invite-mint.com/_')
# st.write('_https://defi-ned.top/h5/#/_')
# st.caption('REMEMBER, PHISHING WEB PAGES HAVE SHORT LIFECYCLE! SO, THE EXAMPLES SHOULD BE UPDATED!')
#
# choice = st.selectbox("Please select your machine learning model",
# [
# 'Gaussian Naive Bayes', 'Support Vector Machine', 'Decision Tree', 'Random Forest',
# 'AdaBoost', 'Neural Network', 'K-Neighbours'
# ]
# )
#
# model = ml.nb_model
#
# if choice == 'Gaussian Naive Bayes':
# model = ml.nb_model
# st.write('GNB model is selected!')
# elif choice == 'Support Vector Machine':
# model = ml.svm_model
# st.write('SVM model is selected!')
# elif choice == 'Decision Tree':
# model = ml.dt_model
# st.write('DT model is selected!')
# elif choice == 'Random Forest':
# model = ml.rf_model
# st.write('RF model is selected!')
# elif choice == 'AdaBoost':
# model = ml.ab_model
# st.write('AB model is selected!')
# elif choice == 'Neural Network':
# model = ml.nn_model
# st.write('NN model is selected!')
# else:
# model = ml.kn_model
# st.write('KN model is selected!')
#
#
# url = st.text_input('Enter the URL')
# # check the url is valid or not
# if st.button('Check!'):
# try:
# response = re.get(url, verify=False, timeout=4)
# if response.status_code != 200:
# print(". HTTP connection was not successful for the URL: ", url)
# else:
# soup = BeautifulSoup(response.content, "html.parser")
# vector = [fe.create_vector(soup)] # it should be 2d array, so I added []
# result = model.predict(vector)
# if result[0] == 0:
# st.success("This web page seems a legitimate!")
# st.balloons()
# else:
# st.warning("Attention! This web page is a potential PHISHING!")
# st.snow()
#
# except re.exceptions.RequestException as e:
# print("--> ", e)
#
#
#
#
#
import streamlit as st
import machine_learning as ml
import feature_extraction as fe
from bs4 import BeautifulSoup
import requests as re
import matplotlib.pyplot as plt
from pathlib import Path
from PIL import Image
from streamlit_option_menu import option_menu
st.set_page_config(page_title='Phishing Website Detection Using Machine Learning', page_icon='./static/favicon.png')
# Add the CSS rule using st.markdown
st.markdown(
"""
<style>
.css-wjbhl0.e1fqkh3o9 {
display: none;
}
</style>
""",
unsafe_allow_html=True
)
# --- PATH SETTINGS ---
current_dir = Path(__file__).parent if "__file__" in locals() else Path.cwd()
css_file = current_dir / "styles" / "main.css"
phishing_account_pic = current_dir / "static" / "Phishing-account.gif"
def applicationRun():
# Add content for the Home page here
# Set page title and description
st.markdown("<h1 style='color:#c8a808'>Phishr</h1>", unsafe_allow_html=True)
st.markdown("<h3 style='color:#4d6cc1'>Phish the Phisher before they phish you!!!</h3>", unsafe_allow_html=True)
# Add a horizontal line
st.markdown("<hr>", unsafe_allow_html=True)
st.markdown("<h4 style='color:#4d6cc1'>Understanding Phishing Attack</4>", unsafe_allow_html=True)
st.write('Phishing attacks are a common type of cyber attack where malicious actors attempt to deceive individuals or organizations into revealing '
'sensitive information such as usernames, passwords, credit card numbers, or other personal or financial data. These attacks typically '
'involve impersonating a trusted entity, such as a bank, a government agency, a company, or even a colleague or friend.')
# st.image("static\Phishing-account.gif", use_column_width=True)
# st.markdown(
# '<img src="phishing_account_pic">',
# unsafe_allow_html=True,
# )
#
# # --- LOAD CSS, PDF & PROFIL PIC ---
# with open(css_file) as f:
# st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
# phishing_account_pic = Image.open(phishing_account_pic)
# # --- HERO SECTION ---
# col1, col2 = st.columns(2, gap="small")
# with col1:
# st.image(phishing_account_pic)
# Load the GIF
phishing_acc = "static/Phishing-account.gif"
# Display the GIF
st.image(phishing_acc, caption='PHISHr', use_column_width=True)
st.markdown("<hr>", unsafe_allow_html=True)
with st.expander('EXAMPLE PHISHING URLs:'):
st.write('_https://rtyu38.godaddysites.com/_')
st.write('_https://karafuru.invite-mint.com/_')
st.write('_https://defi-ned.top/h5/#/_')
st.caption('REMEMBER, PHISHING WEB PAGES HAVE SHORT LIFECYCLE! SO, THE EXAMPLES SHOULD BE UPDATED!')
# Add a horizontal line
st.markdown("<hr>", unsafe_allow_html=True)
choice = st.selectbox("Please select your machine learning model",
[
'Gaussian Naive Bayes', 'Support Vector Machine', 'Decision Tree', 'Random Forest',
'AdaBoost', 'Neural Network', 'K-Neighbours'
]
)
model = ml.nb_model
if choice == 'Gaussian Naive Bayes':
model = ml.nb_model
st.write('GNB model is selected!')
elif choice == 'Support Vector Machine':
model = ml.svm_model
st.write('SVM model is selected!')
elif choice == 'Decision Tree':
model = ml.dt_model
st.write('DT model is selected!')
elif choice == 'Random Forest':
model = ml.rf_model
st.write('RF model is selected!')
elif choice == 'AdaBoost':
model = ml.ab_model
st.write('AB model is selected!')
elif choice == 'Neural Network':
model = ml.nn_model
st.write('NN model is selected!')
else:
model = ml.kn_model
st.write('KN model is selected!')
url = st.text_input('Enter the URL')
# check the url is valid or not
if st.button('Check!'):
try:
response = re.get(url, verify=False, timeout=4)
if response.status_code != 200:
print(". HTTP connection was not successful for the URL: ", url)
else:
soup = BeautifulSoup(response.content, "html.parser")
vector = [fe.create_vector(soup)] # it should be 2d array, so I added []
result = model.predict(vector)
if result[0] == 0:
st.success("This web page seems legitimate!")
# st.image("static\Safe.gif", use_column_width=True)
# st.markdown(
# '<img src="./app/static/Safe.gif">',
# unsafe_allow_html=True,
# )
# Load the GIF
Safe = "static/Safe.gif"
# Display the GIF
st.image(Safe, caption='Safe', use_column_width=True)
st.balloons()
else:
st.warning("Attention! This web page is a potential phishing!")
# st.image("static\Warning.gif", use_column_width=True)
# st.markdown(
# '<img src="./app/static/Warning.gif">',
# unsafe_allow_html=True,
# )
# Load the GIF
warning = "static/Warning.gif"
# Display the GIF
st.image(warning, caption='Warning', use_column_width=True)
st.snow()
except re.exceptions.RequestException as e:
print("--> ", e)
st.markdown("<hr>", unsafe_allow_html=True)
st.markdown("<h4 style='color:#4d6cc1'>Mitigating Phishing Risks</h4>", unsafe_allow_html=True)
st.write(
'Phishing attacks pose significant risks to individuals, businesses, and organizations. They can lead to identity theft, financial loss, data breaches, '
'and reputational damage. To protect against phishing attacks, it\'s essential to stay vigilant, be cautious of unsolicited emails or messages, '
'verify the authenticity of websites and communications, and regularly update security measures such as antivirus software and firewalls. '
'Additionally, education and awareness training for employees and users are crucial in preventing successful phishing attacks.')
# Add a horizontal line
st.markdown("<hr>", unsafe_allow_html=True)
# # Add Navigation Bar Styling
# st.markdown(
# """
# <style>
# .sidebar .sidebar-content {
# background-color: #f0f2f6;
# }
# .css-1aumxhk {
# color: #000000;
# background-color: #4CAF50;
# }
# </style>
# """,
# unsafe_allow_html=True
# )
from menu import streamlit_menu
from pages import Blog, Project_Description, Contact_Us,FAQ
selected = streamlit_menu()
if selected == "Home":
applicationRun()
if selected == "Project_Description":
Project_Description.show()
elif selected == "Contact_Us":
Contact_Us.show()
elif selected == "FAQ":
FAQ.show()
elif selected == "Blog":
Blog.show()