forked from dvopsway/datasploit
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathdomain_pastes.py
executable file
·108 lines (87 loc) · 3.35 KB
/
domain_pastes.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
#!/usr/bin/env python
import base
import config as cfg
import requests
import json
import sys
import re
from termcolor import colored
ENABLED = True
class style:
BOLD = '\033[1m'
END = '\033[0m'
def colorize(string):
colourFormat = '\033[{0}m'
colourStr = colourFormat.format(32)
resetStr = colourFormat.format(0)
lastMatch = 0
formattedText = ''
for match in re.finditer(
r'([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,4})|/(?:http:\/\/)?(?:([^.]+)\.)?datasploit\.info/|/(?:http:\/\/)?(?:([^.]+)\.)?(?:([^.]+)\.)?datasploit\.info/)',
string):
start, end = match.span()
formattedText += string[lastMatch: start]
formattedText += colourStr
formattedText += string[start: end]
formattedText += resetStr
lastMatch = end
formattedText += string[lastMatch:]
return formattedText
#test
def google_search(domain):
url = "https://www.googleapis.com/customsearch/v1?key=%s&cx=%s&q=\"%s\"&start=1" % (
cfg.google_cse_key, cfg.google_cse_cx, domain)
all_results = []
r = requests.get(url, headers={'referer': 'www.datasploit.info/hello'})
data = json.loads(r.content)
if 'error' in data:
return False, data
if int(data['searchInformation']['totalResults']) > 0:
all_results += data['items']
while "nextPage" in data['queries']:
next_index = data['queries']['nextPage'][0]['startIndex']
url = "https://www.googleapis.com/customsearch/v1?key=%s&cx=%s&q=\"%s\"&start=%s" % (
cfg.google_cse_key, cfg.google_cse_cx, domain, next_index)
data = json.loads(requests.get(url).content)
if 'error' in data:
return True, all_results
else:
all_results += data['items']
return True, all_results
def banner():
print colored(style.BOLD + '\n---> Finding Paste(s)..\n' + style.END, 'blue')
def main(domain):
if cfg.google_cse_key != "" and cfg.google_cse_key != "XYZ" and cfg.google_cse_cx != "" and cfg.google_cse_cx != "XYZ":
status, data = google_search(domain)
return [status, data]
else:
return [False, "INVALID_API"]
def output(data, domain=""):
if not data[0]:
if type(data) == list and data[1] == "INVALID_API":
print colored(
style.BOLD + '\n[-] google_cse_key and google_cse_cx not configured. Skipping paste(s) search.\nPlease refer to https://datasploit.readthedocs.io/en/latest/apiGeneration/.\n' + style.END, 'red')
else:
print "Error Message: %s" % data[1]['error']['message']
print "Error Code: %s" % data[1]['error']['code']
print "Error Description: %s" % data[1]['error']['errors'][0]['reason']
else:
print "[+] %s results found\n" % len(data[1])
for x in data[1]:
print "Title: %s\nURL: %s\nSnippet: %s\n" % (x['title'].encode('utf-8'), colorize(x['link'].encode('utf-8')), colorize(x['snippet'].encode('utf-8')))
if __name__ == "__main__":
domain = sys.argv[1]
banner()
result = main(domain)
if result:
output(result, domain)
'''
if __name__ == "__main__":
domain = sys.argv[1]
banner()
result = main(domain)
output(result, domain)
except Exception as e:
print e
print "Please provide a domain name as argument"
'''