├── Images ├── g.png ├── bing.png ├── cosmo.png ├── image.png ├── yahoo.png └── favicon.ico ├── Tools.docx ├── Snapshots ├── Email.PNG ├── Files.PNG ├── BlackEye.PNG ├── Phishing.PNG ├── Search.PNG ├── HackedInfo.PNG ├── Legitimate.PNG ├── Suspicious.PNG ├── WebBrowser.PNG ├── ErrorMessage.PNG ├── ErrorMessage2.PNG ├── FakeWebsite.PNG └── CertificateDetails.PNG ├── LICENSE ├── Mail Info Extracter ├── Main.py ├── extractInfo.py └── detectPhishing.py ├── README.md ├── .gitignore └── shield.py /Images/g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Images/g.png -------------------------------------------------------------------------------- /Tools.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Tools.docx -------------------------------------------------------------------------------- /Images/bing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Images/bing.png -------------------------------------------------------------------------------- /Images/cosmo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Images/cosmo.png -------------------------------------------------------------------------------- /Images/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Images/image.png -------------------------------------------------------------------------------- /Images/yahoo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Images/yahoo.png -------------------------------------------------------------------------------- /Images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Images/favicon.ico -------------------------------------------------------------------------------- /Snapshots/Email.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/Email.PNG -------------------------------------------------------------------------------- /Snapshots/Files.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/Files.PNG -------------------------------------------------------------------------------- /Snapshots/BlackEye.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/BlackEye.PNG -------------------------------------------------------------------------------- /Snapshots/Phishing.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/Phishing.PNG -------------------------------------------------------------------------------- /Snapshots/Search.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/Search.PNG -------------------------------------------------------------------------------- /Snapshots/HackedInfo.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/HackedInfo.PNG -------------------------------------------------------------------------------- /Snapshots/Legitimate.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/Legitimate.PNG -------------------------------------------------------------------------------- /Snapshots/Suspicious.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/Suspicious.PNG -------------------------------------------------------------------------------- /Snapshots/WebBrowser.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/WebBrowser.PNG -------------------------------------------------------------------------------- /Snapshots/ErrorMessage.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/ErrorMessage.PNG -------------------------------------------------------------------------------- /Snapshots/ErrorMessage2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/ErrorMessage2.PNG -------------------------------------------------------------------------------- /Snapshots/FakeWebsite.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/FakeWebsite.PNG -------------------------------------------------------------------------------- /Snapshots/CertificateDetails.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nishakm1234/Phishing_Detection_Using_Python/HEAD/Snapshots/CertificateDetails.PNG -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Nishakm1234 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Mail Info Extracter/Main.py: -------------------------------------------------------------------------------- 1 | import extractInfo 2 | import detectPhishing 3 | import csv 4 | import tkinter as tk 5 | 6 | def handleClick(username,password): 7 | Status=[] 8 | #Files=extractInfo.extractFromEmail('networkteam2019@gmail.com','cdnn@1997') 9 | Files=extractInfo.extractFromEmail(username,password) 10 | extractInfo.extract_URL_From_Sub(Files) 11 | if Files: 12 | with open('Data/mailout.txt', mode='r') as infile: 13 | reader = csv.reader(infile) 14 | for row in reader: 15 | print(row) 16 | with open("Data/Status.txt", "a+") as fh_out: 17 | res=detectPhishing.validateURL(row) 18 | Status.append(res) 19 | fh_out.write(res+'\n') 20 | fh_out.close() 21 | 22 | 23 | window=tk.Tk() 24 | 25 | l1=tk.Label(window,text='Email-Id:') 26 | l2=tk.Label(window,text='Password') 27 | 28 | t1=tk.Entry(window,textvariable=tk.StringVar()) 29 | t2=tk.Entry(window,show="*",textvariable=tk.StringVar()) 30 | print('$$$$$$$$$$$$$$$$$$$$$$$$$$'+t1.get()) 31 | b1=tk.Button(window,text="Check",command=lambda: handleClick(t1.get(),t2.get())) 32 | 33 | l1.grid(row=0,column=0) 34 | t1.grid(row=0,column=1) 35 | l2.grid(row=1,column=0) 36 | t2.grid(row=1,column=1) 37 | b1.grid(row=2,column=1) 38 | 39 | window.mainloop() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Phishing_Detection_Using_Python 2 | ## Web Browser Code 3 | The proposed project tries to detect 4 | and prevent the URL phishing attack. The project will be preventive as it takes any url as 5 | input, classifies the url to any one of the category i.e., phishing, suspicious and legitimate thus 6 | preventing the user from unknowingly getting directed to the fake websites, and losing 7 | personal credentials to the attacker. 8 | * The python file "shield" contains the code. 9 | * The csv file "train1" contains the dataset. 10 | * The Images folder contains all the required images. 11 | ### Note 12 | * The code runs only in Python 3 version. 13 | * The links to download the tools is provided in the "Tools" document. 14 | 15 | ## Mail Information Extractor 16 | The "Mail Info Extracter" folder contains the code to extract the the essential information from an unread email. 17 | ### Note: 18 | This particular folder contains three codes.It should be made sure that all the three codes should be contained in a single folder along with the csv file "train1". Also a folder named "Data" should be created within the existing folder. On running the "Main.py" the files are created within Data folder with all the extracted mail information. Among these "Status" contains the status of the URLs present in the mail. 19 | 20 | ## License 21 | This project is licensed under the MIT License - see the LICENSE file for details. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /Mail Info Extracter/extractInfo.py: -------------------------------------------------------------------------------- 1 | #following class is used to extract the information from email and get the rquired data 2 | import re 3 | import datetime 4 | import email 5 | import imaplib 6 | 7 | #following method is used to extract the information from mail service 8 | def extractFromEmail(EMAIL_ACCOUNT,PASSWORD): 9 | 10 | #EMAIL_ACCOUNT = "networkteam2019@gmail.com" 11 | #PASSWORD = "cdnn@1997" 12 | Files=[] 13 | mail = imaplib.IMAP4_SSL('imap.gmail.com') 14 | mail.login(EMAIL_ACCOUNT, PASSWORD) 15 | mail.list() 16 | mail.select('inbox') 17 | result, data = mail.uid('search', None, "UNSEEN") # (ALL/UNSEEN) 18 | i = len(data[0].split()) 19 | 20 | for x in range(i): 21 | latest_email_uid = data[0].split()[x] 22 | result, email_data = mail.uid('fetch', latest_email_uid, '(RFC822)') 23 | # result, email_data = conn.store(num,'-FLAGS','\\Seen') 24 | # this might work to set flag to seen, if it doesn't already 25 | raw_email = email_data[0][1] 26 | raw_email_string = raw_email.decode('utf-8') 27 | email_message = email.message_from_string(raw_email_string) 28 | 29 | # Header Details 30 | date_tuple = email.utils.parsedate_tz(email_message['Date']) 31 | if date_tuple: 32 | local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple)) 33 | local_message_date = "%s" %(str(local_date.strftime("%a, %d %b %Y %H:%M:%S"))) 34 | email_from = str(email.header.make_header(email.header.decode_header(email_message['From']))) 35 | email_to = str(email.header.make_header(email.header.decode_header(email_message['To']))) 36 | subject = str(email.header.make_header(email.header.decode_header(email_message['Subject']))) 37 | 38 | # Body details 39 | for part in email_message.walk(): 40 | if part.get_content_type() == "text/plain": 41 | body = part.get_payload(decode=True) 42 | file_name = "Data/email_" + str(x) + ".txt" 43 | Files.append(file_name) 44 | output_file = open(file_name, 'w') 45 | output_file.write("From: %s\nTo: %s\nDate: %s\nSubject: %s\n\nBody: \n\n%s" %(email_from, email_to,local_message_date, subject, body.decode('utf-8'))) 46 | output_file.close() 47 | else: 48 | continue 49 | return Files 50 | 51 | #the following method is used to extrct the required information from text file storing the extracted email 52 | def extract_URL_From_Sub(Files): 53 | url_pattern = re.compile('((http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?)') 54 | From_pattern = re.compile('^(From:\s)(.*)') 55 | Sub_pattern = re.compile('^(Subject:\s)(.*)') 56 | for inputfile in Files: 57 | with open(inputfile) as fh_in: 58 | for line in fh_in: 59 | match_list = url_pattern.findall(line) 60 | From = From_pattern.findall(line) 61 | Subj= Sub_pattern.findall(line) 62 | if match_list: 63 | with open("Data/mailout.txt", "a+") as fh_out: 64 | fh_out.write(match_list[0][0]+'\n') 65 | fh_out.close() 66 | if From: 67 | with open("Data/From.txt", "a+") as fh_out: 68 | fh_out.write(From[0][1]+'\n') 69 | fh_out.close() 70 | if Subj: 71 | with open("Data/Sub.txt", "a+") as fh_out: 72 | fh_out.write(Subj[0][1]+'\n') 73 | fh_out.close() -------------------------------------------------------------------------------- /Mail Info Extracter/detectPhishing.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | def long_url(l): 4 | """This function is defined in order to differntiate website based on the length of the URL""" 5 | l= str(l) 6 | if len(l) < 53: 7 | return 0 8 | elif len(l)>=53 and len(l)<75: 9 | return 2 10 | else: 11 | return 1 12 | 13 | def have_at_symbol(l): 14 | """This function is used to check whether the URL contains @ symbol or not""" 15 | if "@" in str(l): 16 | return 1 17 | else: 18 | return 0 19 | 20 | def redirection(l): 21 | """If the url has symbol(//) after protocol then such URL is to be classified as phishing """ 22 | l= str(l) 23 | if l.count('//')>1: 24 | return 1 25 | else: 26 | return 0 27 | 28 | def prefix_suffix_seperation(l): 29 | """seprate prefix and suffix""" 30 | l= str(l) 31 | if l.count('-')<=3: 32 | return 0 33 | elif l.count('-')>3 and l.count('-')<=5: 34 | return 2 35 | else: 36 | return 1 37 | 38 | def sub_domains(l): 39 | """check the subdomains""" 40 | l= str(l) 41 | if l.count('.') <= 3: 42 | return 0 43 | else: 44 | return 1 45 | 46 | def slash_count(l): 47 | """Check the slash count""" 48 | l= str(l) 49 | if l.count('/')<5: 50 | return 0 51 | elif l.count('/')>=5 and l.count('/')<=7: 52 | return 2 53 | else: 54 | return 1 55 | 56 | def have_mod_symbol(l): 57 | """Check if modulus is present""" 58 | if "%" in str(l): 59 | return 1 60 | else: 61 | return 0 62 | 63 | def have_dollar_symbol(l): 64 | """Check dollar is present""" 65 | if "$" in str(l): 66 | return 1 67 | else: 68 | return 0 69 | 70 | def have_anchor_symbol(l): 71 | """Check if anchor symbol is present""" 72 | if "<" in str(l) or ">" in str(l): 73 | return 1 74 | else: 75 | return 0 76 | def have_question_symbol(l): 77 | """Check if question mark is present""" 78 | if "?" in str(l): 79 | return 1 80 | else: 81 | return 0 82 | def have_underscore_symbol(l): 83 | """Check if underscore is present""" 84 | if "_" in str(l): 85 | return 1 86 | else: 87 | return 0 88 | 89 | def have_equal_symbol(l): 90 | """Check if equal symbol is present""" 91 | if "=" in str(l): 92 | return 1 93 | else: 94 | return 0 95 | 96 | def have_hash_symbol(l): 97 | """Check if hash symbol is present""" 98 | if "#" in str(l): 99 | return 1 100 | else: 101 | return 0 102 | 103 | def have_space_symbol(l): 104 | """Check if space is present""" 105 | if " " in str(l): 106 | return 1 107 | else: 108 | return 0 109 | 110 | def have_asp_extension(l): 111 | """Check if .asp extension is present""" 112 | if ".asp" in str(l): 113 | return 1 114 | else: 115 | return 0 116 | 117 | def have_doc_extension(l): 118 | """Check if .doc extension is present""" 119 | if ".doc" in str(l): 120 | return 1 121 | else: 122 | return 0 123 | 124 | def have_htm_extension(l): 125 | """Check if .htm extension is present""" 126 | if ".htm" in str(l): 127 | return 1 128 | else: 129 | return 0 130 | 131 | def have_html_extension(l): 132 | """Check if .html extension is present""" 133 | if ".html" in str(l): 134 | return 1 135 | else: 136 | return 0 137 | 138 | def have_mp3_extension(l): 139 | """Check if .mp3 extension is present""" 140 | if ".mp3" in str(l): 141 | return 1 142 | else: 143 | return 0 144 | 145 | def have_mpeg_extension(l): 146 | """Check if .mpeg extension is present""" 147 | if ".mpeg" in str(l): 148 | return 1 149 | else: 150 | return 0 151 | 152 | def have_pdf_extension(l): 153 | """Check if .pdf extension is present""" 154 | if ".pdf" in str(l): 155 | return 1 156 | else: 157 | return 0 158 | 159 | def have_php_extension(l): 160 | """Check if .php extension is present""" 161 | if ".php" in str(l): 162 | return 1 163 | else: 164 | return 0 165 | 166 | def have_txt_extension(l): 167 | """Check if .txt extension is present""" 168 | if ".txt" in str(l): 169 | return 1 170 | else: 171 | return 0 172 | 173 | def have_ampersand_symbol(l): 174 | """Check if ampersand symbol is present""" 175 | if "&" in str(l): 176 | return 1 177 | else: 178 | return 0 179 | 180 | def have_xyz_extension(l): 181 | """Check if .xyz extension is present""" 182 | if ".xyz" in str(l): 183 | return 1 184 | else: 185 | return 0 186 | def blacklist_function(l): 187 | with open('train1.csv', mode='r') as infile: 188 | reader = csv.reader(infile) 189 | for row in reader: 190 | if row==[l]: 191 | return 0 192 | return 1 193 | 194 | def validateURL(url): 195 | status='' 196 | a=long_url(url) 197 | b=have_at_symbol(url) 198 | c=redirection(url) 199 | d=prefix_suffix_seperation(url) 200 | e=sub_domains(url) 201 | f=slash_count(url) 202 | g=have_mod_symbol(url) 203 | i=have_dollar_symbol(url) 204 | j=have_anchor_symbol(url) 205 | k=have_question_symbol(url) 206 | m=have_underscore_symbol(url) 207 | n=have_equal_symbol(url) 208 | o=have_hash_symbol(url) 209 | p=have_space_symbol(url) 210 | q=have_asp_extension(url) 211 | r=have_doc_extension(url) 212 | s=have_htm_extension(url) 213 | t=have_html_extension(url) 214 | u=have_mp3_extension(url) 215 | v=have_mpeg_extension(url) 216 | w=have_pdf_extension(url) 217 | x=have_php_extension(url) 218 | y=have_txt_extension(url) 219 | z=have_ampersand_symbol(url) 220 | a1=have_xyz_extension(url) 221 | bl1=blacklist_function(url) 222 | 223 | if bl1==0: 224 | """To check if the phished url is present in the dataset and display a warning if present""" 225 | status='Already BlackListed' 226 | elif a==1 or b==1 or c==1 or d==1 or e==1 or f==1 or g==1 or i==1 or j==1 or k==1 or m==1 or n==1 or o==1 or p==1 or q==1 or r==1 or s==1 or t==1 or u==1 or v==1 or w==1 or x==1 or y==1 or z==1 or a1==1: 227 | """To check if the phished url is present in the dataset. If it is not present it is added to the dataset""" 228 | if(bl1==1): 229 | with open('train1.csv', 'a') as newFile: 230 | newFileWriter = csv.writer(newFile) 231 | newFileWriter.writerow([url]) 232 | 233 | status='Phishing detected,Added to Blacklist' 234 | 235 | elif a==2 or d==2 or f==2: 236 | """To check for a suspicious website""" 237 | status='suspicious' 238 | 239 | elif a==0 or b==0 or c==0 or d==0 or e==0 or f==0 or g==0 or i==0 or j==0 or k==0 or m==0 or n==0 or o==0 or p==0 or q==0 or r==0 or s==0 or t==0 or u==0 or v==0 or w==0 or x==0 or y==0 or z==0 or a1==0: 240 | """To check for a legitimate website""" 241 | status='No threat detected' 242 | return status -------------------------------------------------------------------------------- /shield.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import webbrowser 3 | import tempfile 4 | import urllib.request 5 | import urllib.parse 6 | import re 7 | from tkinter import Tk, Text, TOP, Label, Menu, Entry, Button, RAISED, END 8 | from tkinter import * 9 | from tkinter.colorchooser import * 10 | from tkinter import ttk 11 | from tkinter.filedialog import askopenfilename 12 | from tkinter import messagebox 13 | import ssl, socket 14 | import csv 15 | # Run main application 16 | class Browser: 17 | """This creates a relay that allows a user to directly view data sent from a web server.""" 18 | def __init__(self, master): 19 | """Sets up a browsing session.""" 20 | # Explicit global declarations are used to allow certain variable to be used in all methods. 21 | global e1,e2,e3,e4,t1 22 | # Here we create some temporary settings that allow us to create a client that ignores proxy settings. 23 | self.proxy_handler = urllib.request.ProxyHandler(proxies=None) 24 | self.opener = urllib.request.build_opener(self.proxy_handler) 25 | # This sets up components for the GUI. 26 | menu=Menu(root) 27 | menu.configure(background='white') 28 | root.config(menu=menu) 29 | subMenu=Menu(menu) 30 | menu.add_cascade(label="Apps",menu=subMenu) 31 | subMenu.add_command(label="Gmail", command=lambda aurl=url1:OpenUrl(aurl)) 32 | subMenu.add_command(label="Y! Mail", command=lambda aurl=url2:OpenUrl(aurl)) 33 | subMenu.add_command(label="Youtube", command=lambda aurl=url3:OpenUrl(aurl)) 34 | subMenu.add_command(label="Facebook", command=lambda aurl=url4:OpenUrl(aurl)) 35 | subMenu.add_command(label="Github", command=lambda aurl=url5:OpenUrl(aurl)) 36 | subMenu.add_command(label="LinkedIn", command=lambda aurl=url6:OpenUrl(aurl)) 37 | subMenu.add_separator() 38 | editMenu=Menu(menu) 39 | menu.add_cascade(label="Settings",menu=editMenu) 40 | editMenu.add_command(label="Themes and Colors", command=getColor) 41 | editMenu.add_command(label="History") 42 | editMenu.add_command(label="Connect account...") 43 | editMenu.add_command(label="Exit", command=root.quit) 44 | editMenu=Menu(menu) 45 | menu.add_cascade(label="Bookmarks",menu=editMenu) 46 | editMenu.add_command(label="View") 47 | editMenu.add_command(label="Add bookmark") 48 | editMenu=Menu(menu) 49 | menu.add_cascade(label="Tools",menu=editMenu) 50 | editMenu.add_command(label="Inspect Element") 51 | editMenu.add_command(label="Manage Extensions") 52 | editMenu.add_command(label="Developer Tools") 53 | editMenu=Menu(menu) 54 | menu.add_cascade(label="Downloads",menu=editMenu) 55 | editMenu.add_command(label="Open Downloads Folder", command=callback) 56 | 57 | """Label widget""" 58 | Label(root, text='Enter the search item',bg="lightblue",font=("Times New Roman",18)).pack(side=TOP) 59 | """Entry widget""" 60 | e1 = Entry(root,width=80) 61 | e1.pack(side=TOP) 62 | """Button widget""" 63 | Button(root, text='Browse', width=10, relief=RAISED,bg="white", font=("Times New Roman",14), command=self.ButtonClick).pack(side=TOP) 64 | 65 | """Label widget""" 66 | Label(root, text='To display URLs of legitimate websites',bg="lightblue",font=("Times New Roman",18)).pack(side=TOP) 67 | """Entry widget""" 68 | e3 = Entry(root,width=80) 69 | e3.pack(side=TOP) 70 | """Button widget""" 71 | Button(root, text='Search', width=10, relief=RAISED,bg="white", font=("Times New Roman",14),command=self.buttonClick).pack(side=TOP) 72 | """Text widget""" 73 | t1 = Text(root, height=5, width=80) 74 | t1.pack() 75 | """Button widget""" 76 | Button(root, text='Clear', width=10, relief=RAISED,bg="white", font=("Times New Roman",14),command=lambda: t1.delete(1.0,END)).pack(side=TOP) 77 | 78 | """Label widget""" 79 | Label(root, text='Enter URL to be checked',bg="lightblue",font=("Times New Roman",18)).pack(side=TOP) 80 | """Entry widget""" 81 | e2 = Entry(root,width=80) 82 | e2.pack(side=TOP) 83 | """Button widget""" 84 | Button(root, text='Check', width=10, relief=RAISED,bg="white", font=("Times New Roman",14), command=self.buttonOnClick).pack(side=TOP) 85 | 86 | """Label widget""" 87 | Label(root, text='To fetch Certificate Details',bg="lightblue",font=("Times New Roman",18)).pack(side=TOP) 88 | """Entry widget""" 89 | e4 = Entry(root,width=80) 90 | e4.pack(side=TOP) 91 | """Button widget""" 92 | Button(root, text='Details', width=10, relief=RAISED,bg="white", font=("Times New Roman",14), command=self.Certificate_details).pack(side=TOP) 93 | 94 | """This function is to display the top 10 legitimate URLs of the given item in the entry field""" 95 | def buttonClick(self): 96 | try: 97 | from googlesearch import search 98 | except ImportError: 99 | print("No module named 'google' found") 100 | 101 | """Iterate 10 times to fetch the top 10 legitimate URLs""" 102 | for j in search(e3.get(), tld="co.in", num=10, stop=10, pause=2): 103 | """To display the results to the text widget""" 104 | t1.insert(END,j) 105 | t1.insert(END,'\n') 106 | """To delete or clear the entry item""" 107 | e3.delete(0, END) 108 | e3.insert(0, "") 109 | 110 | """This function is to browse the given search item""" 111 | def ButtonClick(self): 112 | """It will open webbrowser with the given url pattern""" 113 | webbrowser.open_new_tab('http://www.google.com/search?btnG=1&q=%s' % e1.get()) 114 | """To delete or clear the entry item""" 115 | e1.delete(0, END) 116 | e1.insert(0, "") 117 | 118 | """This function is to fetch the certificate details""" 119 | def Certificate_details(self): 120 | """Fetch the hostname""" 121 | hostname = e4.get() 122 | ctx = ssl.create_default_context() 123 | s = ctx.wrap_socket(socket.socket(), server_hostname=hostname) 124 | """To check if the connection is established correctly""" 125 | try: 126 | s.connect((hostname, 443)) 127 | cert = s.getpeercert() 128 | subject = dict(x[0] for x in cert['subject']) 129 | issued_to = subject['commonName'] 130 | issuer = dict(x[0] for x in cert['issuer']) 131 | issued_by = issuer['commonName'] 132 | """To display the message box with the fetched certificate details""" 133 | messagebox.showinfo("Certificate Details","Issued To:%s\nIssued By:%s"%(issued_to,issued_by)) 134 | except Exception as e: 135 | #To display the exception message 136 | messagebox.showinfo("Information","Give a valid hostname \n or \n Could not fetch the certificate details") 137 | """To delete or clear the entry item""" 138 | e4.delete(0, END) 139 | e4.insert(0, "") 140 | 141 | """This function is to check the url features to predict whether it is legitimate,phishing or suspicious""" 142 | def buttonOnClick(self): 143 | u1=valid_url(e2.get()) 144 | a=long_url(e2.get()) 145 | b=have_at_symbol(e2.get()) 146 | c=redirection(e2.get()) 147 | d=prefix_suffix_seperation(e2.get()) 148 | e=sub_domains(e2.get()) 149 | f=slash_count(e2.get()) 150 | g=have_mod_symbol(e2.get()) 151 | i=have_dollar_symbol(e2.get()) 152 | j=have_anchor_symbol(e2.get()) 153 | k=have_question_symbol(e2.get()) 154 | m=have_underscore_symbol(e2.get()) 155 | n=have_equal_symbol(e2.get()) 156 | o=have_hash_symbol(e2.get()) 157 | p=have_space_symbol(e2.get()) 158 | q=have_asp_extension(e2.get()) 159 | r=have_doc_extension(e2.get()) 160 | s=have_htm_extension(e2.get()) 161 | t=have_html_extension(e2.get()) 162 | u=have_mp3_extension(e2.get()) 163 | v=have_mpeg_extension(e2.get()) 164 | w=have_pdf_extension(e2.get()) 165 | x=have_php_extension(e2.get()) 166 | y=have_txt_extension(e2.get()) 167 | z=have_ampersand_symbol(e2.get()) 168 | a1=have_xyz_extension(e2.get()) 169 | bl1=blacklist_function(e2.get()) 170 | if u1==4: 171 | #Error message 172 | messagebox.showerror("Error", "Enter a valid url which begins from http:// or https://") 173 | e2.delete(0, END) 174 | e2.insert(0, "") 175 | elif bl1==0: 176 | """To check if the phished url is present in the dataset and display a warning if present""" 177 | messagebox.showwarning("Warning","This is a phishing website.") 178 | 179 | #To clear the entry field 180 | e2.delete(0, END) 181 | e2.insert(0, "") 182 | elif a==1 or b==1 or c==1 or d==1 or e==1 or f==1 or g==1 or i==1 or j==1 or k==1 or m==1 or n==1 or o==1 or p==1 or q==1 or r==1 or s==1 or t==1 or u==1 or v==1 or w==1 or x==1 or y==1 or z==1 or a1==1: 183 | """To check if the phished url is present in the dataset. If it is not present it is added to the dataset""" 184 | if(bl1==1): 185 | with open('train1.csv', 'a') as newFile: 186 | newFileWriter = csv.writer(newFile) 187 | newFileWriter.writerow([e2.get()]) 188 | #Warning is displayed 189 | messagebox.showwarning("Warning","This is a phishing website.") 190 | 191 | #To clear the entry field 192 | e2.delete(0, END) 193 | e2.insert(0, "") 194 | 195 | elif a==2 or d==2 or f==2: 196 | """To check for a suspicious website""" 197 | #Ok or cancel message 198 | mbox=messagebox.askokcancel("Question","This is a suspicious website.\n Do you want to continue?") 199 | if mbox ==1: 200 | #Redirect to the requested URL 201 | webbrowser.open_new_tab('%s' % e2.get()) 202 | e2.delete(0, END) 203 | e2.insert(0, "") 204 | 205 | elif a==0 or b==0 or c==0 or d==0 or e==0 or f==0 or g==0 or i==0 or j==0 or k==0 or m==0 or n==0 or o==0 or p==0 or q==0 or r==0 or s==0 or t==0 or u==0 or v==0 or w==0 or x==0 or y==0 or z==0 or a1==0: 206 | """To check for a legitimate website""" 207 | #Display information message 208 | messagebox.showinfo("Information","This is a legitimate website \n It is safe to use") 209 | webbrowser.open_new_tab('%s' % e2.get()) 210 | """To delete or clear the entry item""" 211 | e2.delete(0, END) 212 | e2.insert(0, "") 213 | 214 | # Creates a Tk() window that is always in front of all other windows. 215 | root = Tk() 216 | #The total size of the window 217 | root.geometry("1366x768+0+0") 218 | C = Canvas(root, bg="blue", height=250, width=300) 219 | #To set the background image 220 | filename = PhotoImage(file ="image.png") 221 | background_label = Label(root, image=filename) 222 | background_label.place(x=0, y=0, relwidth=1, relheight=1) 223 | #The title of the application window 224 | root.wm_title("Web Browser ") 225 | url1='http://www.gmail.com' 226 | url2='http://www.yahoomail.com' 227 | url3='http://www.youtube.com' 228 | url4='http://www.facebook.com' 229 | url5='http://www.github.com' 230 | url6='http://www.linkedin.com' 231 | url7='http://www.firefox.com' 232 | url8='http://www.bing.com' 233 | url9='http://www.yahoo.com' 234 | url10='http://www.google.com' 235 | """scrollbar = Scrollbar(root) 236 | scrollbar.configure(background='grey') 237 | scrollbar.pack(side=RIGHT, fill=Y)""" 238 | 239 | def OpenUrl(url): 240 | webbrowser.open_new(url) 241 | 242 | from tkinter.colorchooser import * 243 | def getColor(): 244 | color = askcolor() 245 | 246 | def callback(): 247 | name= askopenfilename() 248 | 249 | def valid_url(l): 250 | l=str(l) 251 | if "http" in str(l) or "https" in str(l): 252 | return 3 253 | else: 254 | return 4 255 | def long_url(l): 256 | """This function is defined in order to differntiate website based on the length of the URL""" 257 | l= str(l) 258 | if len(l) < 53: 259 | return 0 260 | elif len(l)>=53 and len(l)<75: 261 | return 2 262 | else: 263 | return 1 264 | 265 | def have_at_symbol(l): 266 | """This function is used to check whether the URL contains @ symbol or not""" 267 | if "@" in str(l): 268 | return 1 269 | else: 270 | return 0 271 | 272 | def redirection(l): 273 | """If the url has symbol(//) after protocol then such URL is to be classified as phishing """ 274 | l= str(l) 275 | if l.count('//')>1: 276 | return 1 277 | else: 278 | return 0 279 | 280 | def prefix_suffix_seperation(l): 281 | """seprate prefix and suffix""" 282 | l= str(l) 283 | if l.count('-')<=3: 284 | return 0 285 | elif l.count('-')>3 and l.count('-')<=5: 286 | return 2 287 | else: 288 | return 1 289 | 290 | def sub_domains(l): 291 | """check the subdomains""" 292 | l= str(l) 293 | if l.count('.') <= 3: 294 | return 0 295 | else: 296 | return 1 297 | 298 | def slash_count(l): 299 | """Check the slash count""" 300 | l= str(l) 301 | if l.count('/')<5: 302 | return 0 303 | elif l.count('/')>=5 and l.count('/')<=7: 304 | return 2 305 | else: 306 | return 1 307 | 308 | def have_mod_symbol(l): 309 | """Check if modulus is present""" 310 | if "%" in str(l): 311 | return 1 312 | else: 313 | return 0 314 | 315 | def have_dollar_symbol(l): 316 | """Check dollar is present""" 317 | if "$" in str(l): 318 | return 1 319 | else: 320 | return 0 321 | 322 | def have_anchor_symbol(l): 323 | """Check if anchor symbol is present""" 324 | if "<" in str(l) or ">" in str(l): 325 | return 1 326 | else: 327 | return 0 328 | def have_question_symbol(l): 329 | """Check if question mark is present""" 330 | if "?" in str(l): 331 | return 1 332 | else: 333 | return 0 334 | def have_underscore_symbol(l): 335 | """Check if underscore is present""" 336 | if "_" in str(l): 337 | return 1 338 | else: 339 | return 0 340 | 341 | def have_equal_symbol(l): 342 | """Check if equal symbol is present""" 343 | if "=" in str(l): 344 | return 1 345 | else: 346 | return 0 347 | 348 | def have_hash_symbol(l): 349 | """Check if hash symbol is present""" 350 | if "#" in str(l): 351 | return 1 352 | else: 353 | return 0 354 | 355 | def have_space_symbol(l): 356 | """Check if space is present""" 357 | if " " in str(l): 358 | return 1 359 | else: 360 | return 0 361 | 362 | def have_asp_extension(l): 363 | """Check if .asp extension is present""" 364 | if ".asp" in str(l): 365 | return 1 366 | else: 367 | return 0 368 | 369 | def have_doc_extension(l): 370 | """Check if .doc extension is present""" 371 | if ".doc" in str(l): 372 | return 1 373 | else: 374 | return 0 375 | 376 | def have_htm_extension(l): 377 | """Check if .htm extension is present""" 378 | if ".htm" in str(l): 379 | return 1 380 | else: 381 | return 0 382 | 383 | def have_html_extension(l): 384 | """Check if .html extension is present""" 385 | if ".html" in str(l): 386 | return 1 387 | else: 388 | return 0 389 | 390 | def have_mp3_extension(l): 391 | """Check if .mp3 extension is present""" 392 | if ".mp3" in str(l): 393 | return 1 394 | else: 395 | return 0 396 | 397 | def have_mpeg_extension(l): 398 | """Check if .mpeg extension is present""" 399 | if ".mpeg" in str(l): 400 | return 1 401 | else: 402 | return 0 403 | 404 | def have_pdf_extension(l): 405 | """Check if .pdf extension is present""" 406 | if ".pdf" in str(l): 407 | return 1 408 | else: 409 | return 0 410 | 411 | def have_php_extension(l): 412 | """Check if .php extension is present""" 413 | if ".php" in str(l): 414 | return 1 415 | else: 416 | return 0 417 | 418 | def have_txt_extension(l): 419 | """Check if .txt extension is present""" 420 | if ".txt" in str(l): 421 | return 1 422 | else: 423 | return 0 424 | 425 | def have_ampersand_symbol(l): 426 | """Check if ampersand symbol is present""" 427 | if "&" in str(l): 428 | return 1 429 | else: 430 | return 0 431 | 432 | def have_xyz_extension(l): 433 | """Check if .xyz extension is present""" 434 | if ".xyz" in str(l): 435 | return 1 436 | else: 437 | return 0 438 | def blacklist_function(l): 439 | with open('train1.csv', mode='r') as infile: 440 | reader = csv.reader(infile) 441 | for row in reader: 442 | if row==[l]: 443 | return 0 444 | return 1 445 | 446 | Label(root, text='Direct Links',bg="lightblue",font=("Times New Roman",18)).pack(side=TOP) 447 | frame=Frame(root) 448 | frame.pack(side=TOP) 449 | 450 | b1=ttk.Button(frame, command=lambda aurl=url10:OpenUrl(aurl)) 451 | b1.pack(side=LEFT) 452 | m1=PhotoImage(file="g.png") 453 | b1.config(image=m1) 454 | tm1=m1.subsample(7,7) 455 | b1.config(image=tm1) 456 | b2=ttk.Button(frame, command=lambda aurl=url8:OpenUrl(aurl)) 457 | b2.pack(side=LEFT) 458 | m2=PhotoImage(file="bing.png") 459 | b2.config(image=m2) 460 | tm2=m2.subsample(6,6) 461 | b2.config(image=tm2) 462 | b3=ttk.Button(frame, command=lambda aurl=url9:OpenUrl(aurl)) 463 | b3.pack(side=LEFT) 464 | m3=PhotoImage(file="yahoo.png") 465 | b3.config(image=m3) 466 | tm3=m3.subsample(6,6) 467 | b3.config(image=tm3) 468 | # Starts the program by initializing the Browser object and main-looping the Tk() window. 469 | info_from_server = Browser(root) 470 | root.mainloop() 471 | 472 | 473 | --------------------------------------------------------------------------------