-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathpentesting-tool.py
471 lines (410 loc) · 16.5 KB
/
pentesting-tool.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# -*- encoding: utf-8 -*-
'''
Author:Jose Manuel Ortega
email:jmoc25@gmnail.com
'''
import sys
import os
import nmap
import socket
import getopt, sys
import platform
import urllib, urllib2, json
import ftplib
import time
import utils
import re
import argparse
try:
from bs4 import BeautifulSoup
except Exception as e:
print("pip install beautifulsoup4")
exit(1)
try:
import requests
except:
print "Request library not found, please install it before proceeding\n"
sys.exit()
#datetime
from datetime import datetime
from pywebfuzz import fuzzdb
#for request password
import getpass
from Log import Log
from NexposeFrameWork import NexposeFrameWork
from MetaSploitFrameWork import MetaSploitFrameWork
from UtilDNS import UtilDNS
from ShodanSearch import ShodanSearch
from SSHConnection import SSHConnection
from FTPConnection import FTPConnection
from Checker import Checker
from Scraping import Scraping
from InfoLocation import InfoLocation
from ScanningNMAP import ScanningNMAP
from HTTPScan import HTTPScan
from CheckOpenSslVulnerable import CheckOpenSslVulnerable
from CheckFTPVulnerable import CheckFTPVulnerable
from NmapScanner import NmapScanner
from ExtractMails import ExtractMails
from Search import Search
from CheckVuln_SQL_XSS_LFI import CheckVuln_SQL_XSS_LFI
from IdentifyServer import IdentifyServer
from CheckHeadersXSS import CheckHeadersXSS
from CheckCookies import CheckCookies
#from ScannerScapy import ScannerScapy
#nexpose
import pynexposeHttps
import builtwith
def author():
return """
+---------------------------------------------------------+
|Author: Jose Manuel Ortega - @jmortegac |
|Web site: http://about.me/jmortegac |
|Project: https://github.com/jmortega/python-pentesting |
+---------------------------------------------------------+
"""
def showMenu():
print "[0]-->EXIT"
print "[1]-->Check Open Ports[80,8080 by default]"
print "[2]-->Port Scanning[It will scan over ports parameter,by default it will scan 80 and 8080]"
print "[3]-->Nmap Scanning Advanced"
print "[4]-->Check Option methods"
print "[5]-->Check DNS Servers info"
print "[6]-->Check Host info from Shodan Service"
print "[7]-->NMAP Port Scanning"
print "[8]-->Host Info by Socket Call"
print "[9]-->GeoLocation Host Info"
print "[10]-->Scraping for images and pdf & obtain metadata"
print "[11]-->Get Headers info"
print "[12]-->Get SSH user/password Brute Force[Requires port 22 opened]"
print "[13]-->Get FTP Anonymous access[Requires port 21 opened]"
print "[14]-->MetaSploitFrameWork"
print "[15]-->NexposeFramework"
print "[16]-->HTTP SCAN[Requires port 80 opened]"
print "[17]-->Check HeartBleed OpenSSL vulnerability[Requires port 443 opened]"
print "[18]-->Check FTP Server Buffer Overflow Vulnerability[Requires port 21 opened]"
print "[19]-->Check Vulnerabilities SQL,XSS,LFI in domain"
print "[20]-->Check Domains and obtain metadata[mails, hosts, servers,urls]"
print "[21]-->Check open ports with scapy"
print "[22]-->Check website libraries"
print "[23]-->Identify web server"
print "[24]-->Check headers & Clickjacking"
print "[25]-->Check Cookies from website"
option = raw_input ("Choose an option:")
return option
if __name__ == "__main__":
print(author())
parser = argparse.ArgumentParser(description='Pentesting-tool')
# Main arguments
parser.add_argument("-target", dest="target", help="target IP / domain", required=None)
parser.add_argument("-ports", dest="ports", help="Please, specify the target port(s) separated by comma[80,8080 by default]", default = "80,8080")
parser.add_argument("-proxy", dest="proxy", help="Proxy[IP:PORT]", required=None)
parsed_args = parser.parse_args()
shodanSearch = ShodanSearch()
dnsResolver = UtilDNS()
sshConnection = SSHConnection()
checker = Checker()
scraping = Scraping()
scanningNMAP = ScanningNMAP()
infoLocation = InfoLocation()
httpScan = HTTPScan()
checkOpenSslVulnerable = CheckOpenSslVulnerable()
checkFtpVulnerable = CheckFTPVulnerable()
extractMails = ExtractMails()
checkVuln_SQL_XSS_LFI = CheckVuln_SQL_XSS_LFI()
#scannerScapy = ScannerScapy()
#default port list
ip = ""
hostname = ""
option = ""
ip_server_metasploit = ""
port_server_metasploit = ""
user_metasploit = ""
password_metasploit = ""
shodan_results = []
shodan_visited = []
pyconnect = 0
if parsed_args.target == None:
while (hostname ==""):
hostname = raw_input ("[*] Introduce IP or name domain:")
else:
hostname = parsed_args.target
print("\n [*] Obtain Ip address from host name")
print "-----------------------------------"
ip = socket.gethostbyname(hostname)
print '[*] The IP address of ', hostname, 'is', ip
while option != 0:
print "\n [*] IP/Hostname: "+ ip + " / " + hostname
option = showMenu()
if option == "0":
sys.exit(1);
if option == "1":
f = open('logOpenPorts.txt', 'a')
sys.stdout = Log(sys.stdout, f)
portlist = parsed_args.ports.split(',')
checker.checkOpenPorts(ip,hostname,portlist)
if option == "2":
f = open('logPortScanning.txt', 'a')
sys.stdout = Log(sys.stdout, f)
print "[*] Scanning ports "+ parsed_args.ports + "..."
portlist = parsed_args.ports.split(',')
for port in portlist:
NmapScanner().nmapScan(ip, port)
NmapScanner().nmapScanJSONGenerate(ip, parsed_args.ports)
if option == "3":
f = open('logNmapScanningAdvanced.txt', 'a')
sys.stdout = Log(sys.stdout, f)
checker.checkNmapOptions(ip)
if option == "4":
f = open('logOptionMethods.txt', 'a')
sys.stdout = Log(sys.stdout, f)
checker.checkOptionMethods(hostname)
if option == "5":
f = open('logDnsInfo.txt', 'a')
sys.stdout = Log(sys.stdout, f)
dnsResolver.checkDNSInfo(ip,hostname)
if option == "6":
f = open('logHostInfo.txt', 'a')
sys.stdout = Log(sys.stdout, f)
shodanSearch.obtain_host_info2(ip)
shodanSearch.obtain_host_info2(hostname)
if option == "7":
f = open('logNScanningNmap.txt', 'a')
sys.stdout = Log(sys.stdout, f)
portlist = parsed_args.ports
scanningNMAP.scanNMAP(ip,portlist)
if platform.system() == "Linux":
scanningNMAP.scanningNmapUnix(ip,hostname,portlist)
if platform.system() == "Windows":
scanningNMAP.scanningNmapWindows(ip,hostname,portlist)
if option == "8":
f = open('logHostByName.txt', 'a')
sys.stdout = Log(sys.stdout, f)
print socket.gethostbyname(hostname)
if option == "9":
f = open('logGeoLocationInfo.txt', 'a')
sys.stdout = Log(sys.stdout, f)
infoLocation.printRecord(ip)
infoLocation.printRecord(hostname)
infoLocation.geoInfo(hostname,ip)
if option == "10":
f = open('logScraping.txt', 'a')
sys.stdout = Log(sys.stdout, f)
print '\njpg images'
print '--------------'
scraping.getImgFromUrl(hostname, 'jpg')
print '\npng images'
print '--------------'
scraping.getImgFromUrl(hostname, 'png')
print '\ngif images'
print '--------------'
scraping.getImgFromUrl(hostname, 'gif')
scraping.scrapingImagesPdf(hostname)
scraping.scrapingImagesPdf(ip)
scraping.scrapingBeautifulSoup(hostname)
scraping.scrapingBeautifulSoup(ip)
if option == "11":
f = open('logCheckHeaders.txt', 'a')
sys.stdout = Log(sys.stdout, f)
checker.checkHeadersInfoByIp(ip)
checker.checkHeadersInfoByHostName(hostname)
if option == "12":
f = open('logSSHBruteForce.txt', 'a')
sys.stdout = Log(sys.stdout, f)
sshConnection.SSHBruteForce(hostname)
if option == "13":
f = open('logFTP.txt', 'a')
sys.stdout = Log(sys.stdout, f)
ftpConnection = FTPConnection(hostname)
ftpConnection.ftpConnectionAnonymous()
if option == "14":
while (ip_server_metasploit == ""):
ip_server_metasploit = raw_input ("[*] Introduce IP server where MetaSploit is running:")
while (port_server_metasploit == ""):
port_server_metasploit = raw_input ("[*] Introduce Port server where MetaSploit is running:")
while (user_metasploit == ""):
user_metasploit = raw_input ("[*] Introduce user for MetaSploit:")
while (password_metasploit == ""):
password_metasploit = getpass.getpass ("[*] Introduce password for MetaSploit:")
try:
f = open('metaSploit_log.txt', 'w')
sys.stdout = Log(sys.stdout, f)
metaSploitFrameWork = MetaSploitFrameWork(port_server_metasploit,ip_server_metasploit,ip,user_metasploit,password_metasploit)
metaSploitFrameWork.scanMetaSploitFrameWork()
except Exception,e:
print "Error to connecting with MetaSploit Server"
print e
pass
if option == "15":
if pyconnect == 0:
serveraddr_nexpose = ""
port_server_nexpose = ""
user_nexpose = ""
password_nexpose = ""
while (serveraddr_nexpose == ""):
serveraddr_nexpose = raw_input ("[*] Introduce IP server where Nexpose is running:")
while (port_server_nexpose == ""):
port_server_nexpose = raw_input ("[*] Introduce Port server where Nexpose is running:")
while (user_nexpose == ""):
user_nexpose = raw_input ("[*] Introduce user for Nexpose:")
while (password_nexpose == ""):
password_nexpose = getpass.getpass ("[*] Introduce password for Nexpose:")
try:
if pyconnect == 0:
pynexposeHttps = pynexposeHttps.NeXposeServer(serveraddr_nexpose, port_server_nexpose, user_nexpose, password_nexpose)
pyconnect = 1
except Exception,e:
pyconnect = 0
print e.message
print "Error to connecting with NeXposeServer"
pass
try:
f = open('nexpose_log.txt', 'w')
sys.stdout = Log(sys.stdout, f)
nexposeFrameWork = NexposeFrameWork(pynexposeHttps)
nexposeFrameWork.siteListing()
nexposeFrameWork.vulnerabilityListing()
pynexposeHttps.logout()
except Exception,e:
print "Error to connecting with NeXposeServer for listing vulnerabilities"
print e
pass
if option == "16":
f = open('logHTTPScan.txt', 'a')
sys.stdout = Log(sys.stdout, f)
httpScan.startHTTPScanBruteForce(hostname,ip,parsed_args.proxy)
if option == "17":
f = open('logCheckHeartbleed.txt', 'a')
sys.stdout = Log(sys.stdout, f)
checkOpenSslVulnerable.startCheckVulnerability(ip,hostname)
if option == "18":
f = open('logCheckFTPvulnerable.txt', 'a')
sys.stdout = Log(sys.stdout, f)
checkFtpVulnerable.startCheckVulnerability(ip,hostname)
if option == "19":
f = open('logCheckvuln_SQL_XSS_LFI.txt', 'a')
sys.stdout = Log(sys.stdout, f)
checkVuln_SQL_XSS_LFI.startCheckVulnerability(ip,hostname)
if option == "21":
f = open('logCheckOpenPortsScapy.txt', 'a')
sys.stdout = Log(sys.stdout, f)
#scannerScapy.scan_ports_multithread(hostname,parsed_args.ports)
if option == "22":
f = open('logCheckLibrariesWebsite.txt', 'a')
sys.stdout = Log(sys.stdout, f)
url = utils.verify_url(hostname)
print 'Obtaining libraries from website ' + url
print builtwith.parse(str(url))
if option == "23":
f = open('logIdentifyWebServer.txt', 'a')
sys.stdout = Log(sys.stdout, f)
url = utils.verify_url(hostname)
print 'Identify Server from ' + url
identifyServer = IdentifyServer()
identifyServer.test(url)
identifyServer.test(hostname)
identifyServer.test(ip)
if option == "24":
f = open('logCheckHeadersXSS.txt', 'a')
sys.stdout = Log(sys.stdout, f)
url = utils.verify_url(hostname)
print 'Checking headers from ' + url
headersXSS = CheckHeadersXSS()
headersXSS.test(url)
if option == "25":
f = open('logCheckCookies.txt', 'a')
sys.stdout = Log(sys.stdout, f)
url = utils.verify_url(hostname)
print 'Checking cookies from ' + url
checkCookies = CheckCookies()
checkCookies.test(url)
if option == "20":
try:
f = open('logCheckDomains.txt', 'a')
sys.stdout = Log(sys.stdout, f)
html = utils.HtmlExtractor(hostname)
#url always starts with http:// or https://
print "[+] Searching urls, emails and domains......"
url = html.get_url()
print url
data_extractor = utils.DataExtractor(html.get_body(), url, only_href = True)
logins = fuzzdb.Discovery.PredictableRes.Logins
httpMethods= fuzzdb.attack_payloads.http_protocol.http_protocol_methods
data_extractor.get_predictable_urls(url,logins)
data_extractor.get_http_methods(url,httpMethods)
urls = data_extractor.get_urls()
if len(urls)>0:
print "[+] URLS:"
for url in urls:
print url
extractMails.obtain_mails(url)
else:
print "[-] No URL found"
domains = data_extractor.get_domains(urls)
if len(domains)>0:
print "[+] Domains:"
for domain in domains:
print domain
extractMails.obtain_mails(domain)
else:
print "[-] No Domains found"
ips = data_extractor.get_ips_for_domains(domains)
for key in ips.iterkeys():
print key, ": ", " ".join(ips[key])
extractMails.obtain_mails(hostname)
except Exception,e:
pass
host=''
if hostname.startswith("www") == True:
parts = hostname.split(".")
for part in parts:
if part !='www':
host+=part+'.'
host = host[:-1]
else:
host = hostname
search = Search(host)
search.process()
emails = search.get_emails()
hosts = search.get_hostnames()
full = []
print "\n\n[+] Emails:"
print "------------------"
if emails == []:
print "No emails found"
else:
for email in emails:
print email
print "\n[+] Hosts:"
print "------------------------------------"
if hosts == []:
print "No hosts found"
else:
print "[+] Resolving hostnames and IPs... "
host = utils.Checker(hosts)
full = host.check()
for host in full:
print host
print "\n[+] Shodan Database search:"
print "------------------------------------"
for host in full:
try:
ip = host.split(":")[0]
if not shodan_visited.count(ip):
print "\tSearching Shodan info for: " + host
shodan_visited.append(ip)
results = shodanSearch.execute(ip)
for res in results:
#print str(res['_shodan'])
shodan_results.append(host + "SHODAN" + str(res['_shodan']) + "SHODAN" + str(res['port']))
except Exception,e:
continue
#print shodan_results
print "\n[+] Shodan results:"
print "------------------------------------"
for result in shodan_results:
print result.split("SHODAN")[0] + ":" + result.split("SHODAN")[1]+ ":" + result.split("SHODAN")[2]
response = requests.get('http://sameip.org/'+ip)
bs = BeautifulSoup(response.text, 'lxml')
for site in bs.find_all(attrs={'class': 's-title'}):
print site.text.encode('utf-8')