Phishing-Detect / app.py
Rahmat's picture
Upload 8 files
f5cf9ac
raw
history blame contribute delete
No virus
7.58 kB
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import base64
import seaborn as sns
import matplotlib.pyplot as plt
import symbol
st.write("""
# WebPhishing Detection App
WebPhishing Detection App adalah sebuah aplikasi untuk mendeteksi sebuah Phishing pada situs web.
Aplikasi ini menggunakan berbagai macam paramater untuk menujukan bahwa situs Phishing atau Normal
""")
url_dataset = f'<a href="phishing.csv">Download Dataset CSV File</a>'
st.markdown(url_dataset, unsafe_allow_html=True)
def user_input_features() :
UsingIP = st.sidebar.selectbox('UsingIP', ('YA', 'Tidak'))
LongURL = st.sidebar.selectbox('LongURL', ('YA', 'Tidak'))
ShortURL = st.sidebar.selectbox('Short URL', ('YA', 'Tidak'))
Symbol = st.sidebar.selectbox('Symbol', ('YA', 'Tidak'))
Redirecting = st.sidebar.selectbox('Redirecting', ('YA', 'Tidak'))
PrefixSuffix = st.sidebar.selectbox('PrefixSuffix', ('YA', 'Tidak'))
SubDomains = st.sidebar.selectbox('SubDomains', ('YA', 'Tidak'))
HTTPS = st.sidebar.selectbox('HTTPS', ('YA', 'Tidak'))
DomainRegLen = st.sidebar.selectbox('DomainRegLen', ('YA', 'Tidak'))
Favicon = st.sidebar.selectbox('Favicon', ('YA', 'Tidak'))
NonStdPort = st.sidebar.selectbox('NonStdPort', ('YA', 'Tidak'))
HTTPSDomainURL = st.sidebar.selectbox('HTTPSDomainURL', ('YA', 'Tidak'))
RequestURL = st.sidebar.selectbox('RequestURL', ('YA', 'Tidak'))
AnchorURL = st.sidebar.selectbox('AnchorURL', ('YA', 'Tidak'))
LinksInScriptTags = st.sidebar.selectbox('LinksInScriptTags', ('YA', 'Tidak'))
ServerFormHandler = st.sidebar.selectbox('ServerFormHandler', ('YA', 'Tidak'))
InfoEmail = st.sidebar.selectbox('InfoEmail', ('YA', 'Tidak'))
AbnormalURL = st.sidebar.selectbox('AbnormalURL', ('YA', 'Tidak'))
WebsiteForwarding = st.sidebar.selectbox('WebsiteForwarding', ('YA', 'Tidak'))
StatusBarCust = st.sidebar.selectbox('StatusBarCust', ('YA', 'Tidak'))
DisableRightClick = st.sidebar.selectbox('DisableRightClick', ('YA', 'Tidak'))
UsingPopupWindow = st.sidebar.selectbox('UsingPopupWindow', ('YA', 'Tidak'))
IframeRedirection = st.sidebar.selectbox('IframeRedirection', ('YA', 'Tidak'))
AgeofDomain = st.sidebar.selectbox('AgeofDomain', ('YA', 'Tidak'))
DNSRecording = st.sidebar.selectbox('DNSRecording', ('YA', 'Tidak'))
WebsiteTraffic = st.sidebar.selectbox('WebsiteTraffic', ('YA', 'Tidak'))
PageRank = st.sidebar.selectbox('PageRank', ('YA', 'Tidak'))
GoogleIndex = st.sidebar.selectbox('GoogleIndex', ('YA', 'Tidak'))
LinksPointingToPage = st.sidebar.selectbox('LinksPointingToPage', ('YA', 'Tidak'))
StatsReport = st.sidebar.selectbox('StatsReport', ('YA', 'Tidak'))
# phishingYT01 = 1
#if(phishingYT == 'Left') :
#phishingYT01 = 0
usingip = -1
if(UsingIP == 'YA') :
usingip = 1
longurl = -1
if(LongURL == 'YA') :
longurl =1
shorturl = -1
if(ShortURL == 'YA') :
shorturl =1
symbol = -1
if(Symbol == 'YA') :
symbol =1
redirecting = -1
if(Redirecting == 'YA') :
redirecting =1
subdomains = -1
if(SubDomains == 'YA') :
subdomains =1
prefixsuffix = -1
if(PrefixSuffix == 'YA') :
prefixsuffix =1
https = -1
if(HTTPS == 'YA') :
https =1
domainreglen = -1
if(DomainRegLen == 'YA') :
domainreglen =1
favicon = -1
if(Favicon == 'YA') :
favicon =1
nonstdport = -1
if(NonStdPort == 'YA') :
nonstdport =1
httpsdomainurl = -1
if(HTTPSDomainURL == 'YA') :
httpsdomainurl =1
requesturl = -1
if(RequestURL == 'YA') :
requesturl =1
anchorurl = -1
if(AnchorURL == 'YA') :
anchorurl =1
linksinscripttags = -1
if(LinksInScriptTags == 'YA') :
linksinscripttags =1
serverformhandler = -1
if(ServerFormHandler == 'YA') :
serverformhandler =1
infoemail = -1
if(InfoEmail == 'YA') :
infoemail =1
abnormalurl = -1
if(AbnormalURL == 'YA') :
abnormalurl =1
websiteforwarding = 0
if(WebsiteForwarding == 'Tidak') :
websiteforwarding = 0
statusbarcust = -1
if(StatusBarCust == 'YA') :
statusbarcust =1
disablerightclick = -1
if(DisableRightClick == 'YA') :
disablerightclick =1
usingpopupwindow = -1
if(UsingPopupWindow == 'YA') :
usingpopupwindow =1
iframeredirection = -1
if(IframeRedirection == 'YA') :
iframeredirection =1
ageofdomain = -1
if(AgeofDomain == 'YA') :
ageofdomain =1
dnsrecording = -1
if(DNSRecording == 'YA') :
dnsrecording =1
websitetraffic = -1
if(WebsiteTraffic == 'YA') :
websitetraffic =1
pagerank= -1
if(PageRank== 'YA') :
pagerank =1
googleindex = -1
if(GoogleIndex == 'YA') :
googleindex =1
linkspointingtopage= -1
if(LinksPointingToPage== 'YA') :
linkspointingtopage =1
statsreport= -1
if(StatsReport== 'YA') :
statsreport =1
#data = {'phishingYT':[phishingYT01],
data = {
'UsingIP':[usingip],
'LongURL':[longurl],
'ShortURL':[shorturl],
'Symbol@':[symbol],
'Redirecting//':[redirecting],
'SubDomains':[subdomains],
'PrefixSuffix-':[prefixsuffix],
'HTTPS':[https],
'DomainRegLen':[domainreglen],
'Favicon':[favicon],
'NonStdPort':[nonstdport],
'HTTPSDomainURL':[httpsdomainurl],
'RequestURL':[requesturl],
'AnchorURL':[anchorurl],
'LinksInScriptTags':[linksinscripttags],
'ServerFormHandler':[serverformhandler ],
'InfoEmail':[infoemail],
'AbnormalURL':[abnormalurl],
'WebsiteForwarding':[websiteforwarding],
'StatusBarCust':[statusbarcust],
'DisableRightClick':[disablerightclick],
'UsingPopupWindow':[usingpopupwindow],
'IframeRedirection':[iframeredirection],
'AgeofDomain':[ageofdomain],
'DNSRecording':[dnsrecording],
'WebsiteTraffic':[websitetraffic],
'PageRank':[pagerank],
'GoogleIndex':[googleindex],
'LinksPointingToPage':[linkspointingtopage],
'StatsReport':[statsreport]}
features = pd.DataFrame(data)
return features
input_df = user_input_features()
phishing_raw = pd.read_csv('phishing.csv')
phishing_raw.fillna(0, inplace=True)
phishing = phishing_raw.drop(columns=['class'])
df = pd.concat([input_df, phishing],axis=0)
df = df[:1] # Selects only the first row (the user input data)
df.fillna(0, inplace=True)
features = ['UsingIP', 'LongURL', 'ShortURL', 'Symbol@', 'Redirecting//',
'PrefixSuffix-', 'SubDomains', 'HTTPS', 'DomainRegLen', 'Favicon',
'NonStdPort', 'HTTPSDomainURL', 'RequestURL', 'AnchorURL',
'LinksInScriptTags', 'ServerFormHandler', 'InfoEmail', 'AbnormalURL',
'WebsiteForwarding', 'StatusBarCust', 'DisableRightClick',
'UsingPopupWindow', 'IframeRedirection', 'AgeofDomain', 'DNSRecording',
'WebsiteTraffic', 'PageRank', 'GoogleIndex', 'LinksPointingToPage',
'StatsReport']
df = df[features]
st.subheader('User Input features')
st.write(df)
load_clf = pickle.load(open('PhishingDETECT_clf.pkl', 'rb'))
detection = load_clf.predict(df)
if(detection < 0) :
detection = 0
detection_proba = load_clf.predict_proba(df)
phishing_labels = np.array(['Normal', 'Phishing'])
st.subheader('Detection')
st.write(phishing_labels[detection])
st.subheader('Detection Probability')
df_prob = pd.DataFrame(data=detection_proba, index=['Probability'], columns=phishing_labels)
st.write(df_prob)