forked from 5l1v3r1/-penetrator-sql-injection-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
penetrator.py
90 lines (77 loc) · 2.36 KB
/
penetrator.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
#!/usr/bin/python
from __future__ import print_function
import os
import sys
import requests
import optparse
import urllib
import urllib2
import urllib3
import httplib
import socket
import httplib2
import thread
import threading
def main():
# Get Options
parser = optparse.OptionParser()
parser.add_option('-r', '--redir',
dest="redir",
default=False,
action="store_true",
help='Allow HTTP redirects',
)
parser.add_option('-s', '--save',
dest="save",
default=False,
action="store_true",
help='Save HTTP response content to files',
)
parser.add_option('-o', '--out',
dest="out",
default=os.getcwd(),
help='Directory to save HTTP responses',
)
parser.set_usage("""Usage: ./penetrator.py [options] <base url> <payload list>
(Use '$' as variable in url that will be swapped out with each payload)
Example: penetrator.py http://www.example.com/file/$.pdf payloads.txt
""")
options, remainder = parser.parse_args()
redir = options.redir
save_responses = options.save
output_dir = options.out
if output_dir.endswith('/'):
output_dir = output_dir[:-1]
### Assign arguments to variables
if len(remainder) == 2:
baseurl = remainder[0]
if '$' not in baseurl:
print("Error: Please include variable character ('$') in URL")
sys.exit()
payloadfile = remainder[1]
else:
print("Invalid number of arguments: use -h option for usage")
sys.exit()
### Try reading payloads into variable
try:
with open(payloadfile) as f:
payloaddata = f.readlines()
except:
print("Error: cannot read file '%s'" % payloadfile)
sys.exit()
### Attempt connection to each URL and print stats
print("Status\tLength\tTime\t Host")
print("---------------------------------")
for payload in payloaddata:
payload = payload.strip('\n')
url = baseurl.replace('$', payload)
r = requests.get(url, allow_redirects=redir)
print("%s\t%s\t%s\t %s" % (r.status_code, len(r.content), r.elapsed.total_seconds()*1000, url))
if save_responses and len(r.content) != 0:
try:
with open('%s/%s' % (output_dir, payload), 'wb') as f:
f.write(r.content)
except:
print("Error: could not write file '%s/%s'" % (output_dir, payload))
if __name__ == '__main__':
main()