CoolFace
Apppublic

Rahmat/Phishing-Detect

sourceHugging Facebigscience-openrail-mupdated 4y agoView on Hugging Face
1likes
app.py221 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3import numpy as np4import pickle5import base646import seaborn as sns7import matplotlib.pyplot as plt8 9import symbol10 11st.write("""12# WebPhishing Detection App13 14WebPhishing Detection App adalah sebuah aplikasi untuk mendeteksi sebuah Phishing pada situs web. 15Aplikasi ini menggunakan berbagai macam paramater untuk menujukan bahwa situs Phishing atau Normal16 17 18""")19 20 21url_dataset = f'<a href="phishing.csv">Download Dataset CSV File</a>'22st.markdown(url_dataset, unsafe_allow_html=True)23 24def user_input_features() :25    UsingIP = st.sidebar.selectbox('UsingIP', ('YA', 'Tidak'))26    LongURL = st.sidebar.selectbox('LongURL', ('YA', 'Tidak'))27    ShortURL = st.sidebar.selectbox('Short URL', ('YA', 'Tidak'))28    Symbol = st.sidebar.selectbox('Symbol', ('YA', 'Tidak'))29    Redirecting = st.sidebar.selectbox('Redirecting', ('YA', 'Tidak'))30    PrefixSuffix = st.sidebar.selectbox('PrefixSuffix', ('YA', 'Tidak'))31    SubDomains = st.sidebar.selectbox('SubDomains', ('YA', 'Tidak'))32    HTTPS = st.sidebar.selectbox('HTTPS', ('YA', 'Tidak'))33    DomainRegLen = st.sidebar.selectbox('DomainRegLen', ('YA', 'Tidak'))34    Favicon = st.sidebar.selectbox('Favicon', ('YA', 'Tidak'))35    NonStdPort = st.sidebar.selectbox('NonStdPort', ('YA', 'Tidak'))36    HTTPSDomainURL = st.sidebar.selectbox('HTTPSDomainURL', ('YA', 'Tidak'))37    RequestURL = st.sidebar.selectbox('RequestURL', ('YA', 'Tidak'))38    AnchorURL = st.sidebar.selectbox('AnchorURL', ('YA', 'Tidak'))39    LinksInScriptTags = st.sidebar.selectbox('LinksInScriptTags', ('YA', 'Tidak'))40    ServerFormHandler = st.sidebar.selectbox('ServerFormHandler', ('YA', 'Tidak'))41    InfoEmail = st.sidebar.selectbox('InfoEmail', ('YA', 'Tidak'))42    AbnormalURL = st.sidebar.selectbox('AbnormalURL', ('YA', 'Tidak'))43    WebsiteForwarding = st.sidebar.selectbox('WebsiteForwarding', ('YA', 'Tidak'))44    StatusBarCust = st.sidebar.selectbox('StatusBarCust', ('YA', 'Tidak'))45    DisableRightClick = st.sidebar.selectbox('DisableRightClick', ('YA', 'Tidak'))46    UsingPopupWindow = st.sidebar.selectbox('UsingPopupWindow', ('YA', 'Tidak'))47    IframeRedirection = st.sidebar.selectbox('IframeRedirection', ('YA', 'Tidak'))48    AgeofDomain = st.sidebar.selectbox('AgeofDomain', ('YA', 'Tidak'))49    DNSRecording = st.sidebar.selectbox('DNSRecording', ('YA', 'Tidak'))50    WebsiteTraffic = st.sidebar.selectbox('WebsiteTraffic', ('YA', 'Tidak'))51    PageRank = st.sidebar.selectbox('PageRank', ('YA', 'Tidak'))52    GoogleIndex = st.sidebar.selectbox('GoogleIndex', ('YA', 'Tidak'))53    LinksPointingToPage = st.sidebar.selectbox('LinksPointingToPage', ('YA', 'Tidak'))54    StatsReport = st.sidebar.selectbox('StatsReport', ('YA', 'Tidak'))55  56   # phishingYT01 = 157    #if(phishingYT == 'Left') :58        #phishingYT01 = 059   60    usingip = -161    if(UsingIP == 'YA') :62        usingip = 163    longurl = -164    if(LongURL == 'YA') :65        longurl =166    shorturl = -167    if(ShortURL == 'YA') :68        shorturl =169    symbol = -170    if(Symbol == 'YA') :71        symbol =172    redirecting = -173    if(Redirecting == 'YA') :74        redirecting =175    subdomains = -176    if(SubDomains == 'YA') :77        subdomains =178    prefixsuffix = -179    if(PrefixSuffix == 'YA') :80        prefixsuffix =181    https = -182    if(HTTPS == 'YA') :83        https =184    domainreglen = -185    if(DomainRegLen == 'YA') :86        domainreglen =187    favicon = -188    if(Favicon == 'YA') :89        favicon =190    nonstdport = -191    if(NonStdPort == 'YA') :92        nonstdport =193    httpsdomainurl = -194    if(HTTPSDomainURL == 'YA') :95        httpsdomainurl =196    requesturl = -197    if(RequestURL == 'YA') :98        requesturl =199    anchorurl = -1100    if(AnchorURL == 'YA') :101        anchorurl =1102    linksinscripttags = -1103    if(LinksInScriptTags == 'YA') :104        linksinscripttags =1105    serverformhandler = -1106    if(ServerFormHandler == 'YA') :107        serverformhandler =1108    infoemail = -1109    if(InfoEmail == 'YA') :110        infoemail  =1111    abnormalurl = -1112    if(AbnormalURL == 'YA') :113        abnormalurl =1114    websiteforwarding = 0115    if(WebsiteForwarding == 'Tidak') :116        websiteforwarding = 0117    statusbarcust = -1118    if(StatusBarCust == 'YA') :119        statusbarcust  =1120    disablerightclick = -1121    if(DisableRightClick == 'YA') :122        disablerightclick  =1123    usingpopupwindow = -1124    if(UsingPopupWindow == 'YA') :125        usingpopupwindow  =1126    iframeredirection = -1127    if(IframeRedirection == 'YA') :128        iframeredirection  =1129    ageofdomain = -1130    if(AgeofDomain == 'YA') :131        ageofdomain  =1132    dnsrecording = -1133    if(DNSRecording == 'YA') :134        dnsrecording  =1135    websitetraffic = -1136    if(WebsiteTraffic == 'YA') :137        websitetraffic  =1138    pagerank= -1139    if(PageRank== 'YA') :140        pagerank  =1141    googleindex = -1142    if(GoogleIndex == 'YA') :143        googleindex  =1144    linkspointingtopage= -1145    if(LinksPointingToPage== 'YA') :146        linkspointingtopage  =1147    statsreport= -1148    if(StatsReport== 'YA') :149        statsreport  =1150   151   #data = {'phishingYT':[phishingYT01], 152 153    data = { 154    'UsingIP':[usingip],155    'LongURL':[longurl],156    'ShortURL':[shorturl],157    'Symbol@':[symbol],158    'Redirecting//':[redirecting],159    'SubDomains':[subdomains],160    'PrefixSuffix-':[prefixsuffix],161    'HTTPS':[https],162    'DomainRegLen':[domainreglen],163    'Favicon':[favicon],164    'NonStdPort':[nonstdport],165    'HTTPSDomainURL':[httpsdomainurl],166    'RequestURL':[requesturl],167    'AnchorURL':[anchorurl],168    'LinksInScriptTags':[linksinscripttags],169    'ServerFormHandler':[serverformhandler ],170    'InfoEmail':[infoemail],171    'AbnormalURL':[abnormalurl],172    'WebsiteForwarding':[websiteforwarding],173    'StatusBarCust':[statusbarcust],174    'DisableRightClick':[disablerightclick],175    'UsingPopupWindow':[usingpopupwindow],176    'IframeRedirection':[iframeredirection],177    'AgeofDomain':[ageofdomain],178    'DNSRecording':[dnsrecording],179    'WebsiteTraffic':[websitetraffic],180    'PageRank':[pagerank],181    'GoogleIndex':[googleindex],182    'LinksPointingToPage':[linkspointingtopage],183    'StatsReport':[statsreport]}184 185    features = pd.DataFrame(data)186    return features187 188input_df = user_input_features()189 190phishing_raw = pd.read_csv('phishing.csv')191phishing_raw.fillna(0, inplace=True)192phishing = phishing_raw.drop(columns=['class'])193df = pd.concat([input_df, phishing],axis=0)194 195df = df[:1] # Selects only the first row (the user input data)196df.fillna(0, inplace=True)197 198features = ['UsingIP', 'LongURL', 'ShortURL', 'Symbol@', 'Redirecting//',199       'PrefixSuffix-', 'SubDomains', 'HTTPS', 'DomainRegLen', 'Favicon',200       'NonStdPort', 'HTTPSDomainURL', 'RequestURL', 'AnchorURL',201       'LinksInScriptTags', 'ServerFormHandler', 'InfoEmail', 'AbnormalURL',202       'WebsiteForwarding', 'StatusBarCust', 'DisableRightClick',203       'UsingPopupWindow', 'IframeRedirection', 'AgeofDomain', 'DNSRecording',204       'WebsiteTraffic', 'PageRank', 'GoogleIndex', 'LinksPointingToPage',205       'StatsReport']206 207df = df[features]208 209st.subheader('User Input features')210st.write(df)211load_clf = pickle.load(open('PhishingDETECT_clf.pkl', 'rb'))212detection = load_clf.predict(df)213if(detection < 0) :214    detection = 0215detection_proba = load_clf.predict_proba(df)216phishing_labels = np.array(['Normal', 'Phishing'])217st.subheader('Detection')218st.write(phishing_labels[detection])219st.subheader('Detection Probability')220df_prob = pd.DataFrame(data=detection_proba, index=['Probability'], columns=phishing_labels)221st.write(df_prob)