-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawlFinal.py
310 lines (258 loc) · 10.3 KB
/
crawlFinal.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
import time
import requests
from stem import Signal
from stem.control import Controller
from bs4 import BeautifulSoup
import os
import csv
import pandas as pd
import docx
import subprocess
import spacy
import sqlite3
con = sqlite3.connect("Classification.db")
cur = con.cursor()
def addDB():
url = input("Enter url of classified website")
classno = int(input("Enter the class number:\n1 - drugs\n2 - weapons\n3- trafficking/fraud"))
cur.execute("""
INSERT INTO types(link, classification)
VALUES (?,?)
""", (url, classno))
con.commit ()
print("Successfully added")
keywords_for_drugs = ['alcohol','drug'
'Ayahuasca',
'Cannabis', 'Marijuana','Pot','Weed','Central Nervous System Depressants', 'Benzos',
'Cocaine','Coke','Crack',
'GHB',
'Hallucinogens',
'Heroin',
'Inhalants',
'Ketamine',
'Khat','Kratom',
'LSD', 'Acid',
'MDMA','Ecstas','Molly',
'Mescaline', 'Peyote',
'Methamphetamine', 'Crystal','Meth',
'PCP', 'Angel', 'Dust',
'Prescription' ,'Opioids', 'Oxy','Percs',
'Stimulants' ,'Speed',
'Psilocybin' ,'Magic Mushrooms','Shrooms',
'Rohypnol' ,'Flunitrazepam','Roofies',
'Salvia',
'Steroids', 'Anabolic',
'Synthetic', 'Cannabinoids', 'K2','Spice',
'Synthetic', 'Cathinones' ,'Bath', 'Salts','Flakka',
'Tobacco','Nicotine' ,'Vaping']
# keywords_for_fraud = ['credit cards','credit card','stolen accounts','stolen account','passport','fake identity','drivers license','bank','account','accounts','paypal','visa','mastercard',]
keywords_for_guns = ['guns','weapons','gun','weapon','ammo','glock','pistol','sniper','assualt','rifle','EuroGuns','Kal','Eagle','Desert']
keywords_for_traffiking = ['chat','room','traffiking','fourm','credit cards','credit card','stolen accounts','stolen account','passport','fake identity','drivers license','bank','account','accounts','paypal','visa','mastercard','Fourm']
def detect(title):
print(list(title.split(' ')))
# if list(title.split(' ')) in keywords_for_drugs:
# return 1
# 1 is for drugs; 2 is for guns; 3 is for human traffiking
for i in list(title.split( )):
if i in keywords_for_drugs:
return 1
elif i in keywords_for_guns:
return 2
elif i in keywords_for_traffiking:
return 3
# else:
# return 4
# elif list(title.split(' ')) in keywords_for_guns:
# return 2
# elif list(title.split(' ')) in keywords_for_fraud:
# return 3
# else:
# return 4
def drugs(link,title):
filename = list(title.split(' '))
filename = filename[0]
mydoc = docx.Document()
# if the website has drugs then we print the drugs and details in form of table and write it in word doc
url=link
dfs = pd.read_html(url)
mydoc.add_paragraph('The website belongs to drugs category. The title(of website) and the items sold are: ')
mydoc.add_paragraph(title)
for df in dfs:
# Converting dataframe to list
li = df.values.tolist()
# Printing list
print(li)
for i in li:
mydoc.add_paragraph(str(i))
mydoc.save('/home/user/Desktop/Crawler/drugs' + filename+'classified_.docx')
print("Created Word File Successfully")
def weapons(link,title):
filename = list(title.split(' '))
filename = filename[0]
mydoc = docx.Document()
# if the website has drugs then we print the drugs and details in form of table and write it in word doc
url=link
dfs = pd.read_html(url)
mydoc.add_paragraph('The website belongs to category weapons, the title(of website) and the details of weapons sold are: ')
mydoc.add_paragraph(title)
for df in dfs:
# Converting dataframe to list
li = df.values.tolist()
# Printing list
print(li)
for i in li:
mydoc.add_paragraph(str(i))
mydoc.save('/home/user/Desktop/Crawler/weapons' + filename+'classified_.docx')
def traffiking(link,title,name):
filename = list(title.split(' '))
filename = filename[0]
mydoc = docx.Document()
# we are checking for any potential human names, and if found we then grab that html element and show it to user
response = requests.get(link,headers = headers)
soup = BeautifulSoup(response.text,'html.parser')
sentence = soup.get_text()
nlp = spacy.load('en_core_web_sm')
doc = nlp(sentence)
if sentence.find(name)!=-1:
print("Name found! Extra details of the name are:")
res_index = sentence.find(name,1)
start_index = res_index-50
end_index = res_index+50
print(sentence[start_index:end_index])
mydoc.add_paragraph(sentence[start_index:end_index])
mydoc.save('/home/user/Desktop/Crawler/traffiking' + filename+'classified_.docx')
# break
else:
print("No specific names found, printing all detected names by NLP")
for ent in doc.ents:
if ent.label == 'PERSON':
print(ent.text,ent.label)
def enumerate(link):
# any potential .onion link can be enumerated using nikto
output = subprocess.run(["nikto", "-h", link])
print(output)
choice = input("Do you want the above data in excel format?")
if choice == "yes":
filename = link+"_enumeration"
mydoc = docx.Document()
mydoc.add_paragraph(output)
mydoc.save('/home/user/Desktop/Crawler/' + filename+'classified_.docx')
def get_title(link):
l1=[]
response = requests.get(link, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
title=''
print("The title of "+link+" is: ")
for data in soup.find_all('title'):
l1.append(data.get_text().strip())
print(data.get_text().strip())
data = data.get_text().strip()
print('\n\n')
# return l1
return data
def crawl():
with Controller.from_port(port=9051) as controller:
# Set the controller password
keywords = input("Enter any specific keyword to search: ")
controller.authenticate(password='CristianoRonaldoCR7')
num_links_to_crawl = int(input("Enter number of links to crawl: "))
count = 0
# starting url: http://jgwe5cjqdbyvudjqskaajbfibfewew4pndx52dye7ug3mt3jimmktkid.onion.ly/
url = input("Enter the url: ")
visited = set()
queue = [url]
while True:
# Get the next link in the queue
link = queue.pop(0)
# Skip the link if it has already been visited
if link in visited:
continue
# Set the new IP address
controller.signal(Signal.NEWNYM)
try:
# Send the request to the URL
response = requests.get(link, headers=headers)
# Parse the response
soup = BeautifulSoup(response.text, 'html.parser')
# Find all links on the page
links = soup.find_all('a')
# Add any links that contain the keywords to the queue
for a in links:
href = a.get('href')
# if any(keyword in href for keyword in keywords):
if 'http' in href:
queue.append(href)
else:
queue.append(link + href)
if(href==None):
continue
elif('http' in href or 'https' in href):
queue.append(href)
visited.add(link)
count+=1
title = get_title(link)
classify = detect(title)
print("Classification is ", classify)
# classify=3
if classify == 1:
drugs(url,title)
elif classify == 2:
weapons(url,title)
elif classify == 3:
name = input("Its a potential Trafficking website, Enter name to find: ")
traffiking(url,title,name)
if len(visited)==num_links_to_crawl:
print("Visited Links: ")
for i in visited:
print(i)
if len(visited)> num_links_to_crawl:
break
if count>num_links_to_crawl:
break
except(EOFError):
print("Exception occured at link: ",link)
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36'
headers = {'User-Agent': user_agent}
print("Select your option: \n1 - To crawl a website till a limit is achieved and collect all the links related to that specific keyword\n2 - To classify the given website\n3 - To check for child details in a given website\n4 - To enumerate a given .onion link \n5 - To add a link to database\n\nSelect your option:")
option = int(input())
# To crawl a website till a limit is achieved and collect all the links related to that specific keyword
if option == 1:
crawl()
# To classify the given website
elif option == 2:
url = input("Enter URL to be detected: ")
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
for data in soup.find_all('title'):
data = data.get_text().strip()
classify = detect(data)
print("1 - Drugs\n2 - Weapons\n3 - Human Traffiking/Fraud: ")
print(classify)
if classify == 1 or classify == 2:
drugs(url,data)
elif classify == 3:
name = input("Enter child name: ")
traffiking(url,data,name)
# To check for child details
elif option == 3:
url = input("Enter link: ")
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
# title=''
for data in soup.find_all('title'):
data = data.get_text().strip()
# weapons(url,data)
name = input("Enter the baby name to be searched: ")
traffiking(url,data,name)
# to enumerate a given link
elif option == 4:
url = input("Enter URL: ")
enumerate(url)
# adding a link and its classification to sqlite db
elif option == 5:
addDB()
# Drug link : http://6hzbfxpnsdo4bkplp5uojidkibswevsz3cfpdynih3qvfr24t5qlkcyd.onion/
# Weapon link :
# baby link : https://nameberry.com/
# 4th your choice
# adding to database