-
Notifications
You must be signed in to change notification settings - Fork 6
/
r_q.py
99 lines (98 loc) · 5.23 KB
/
r_q.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
import ssl,urllib2
from r_p import f_p
from StringIO import StringIO
import gzip
import zlib
import socket
import os,inspect
import sys
class rqs:
global file_parsing
file_parsing = f_p()
global path
path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
def ch_en(self,response):
if response.info().get('Content-Encoding') == 'gzip' or response.info().get('Content-Encoding') == 'x-gzip':
buf = StringIO(response.read())
f = gzip.GzipFile(fileobj=buf)
data = f.read()
elif response.info().get('Content-Encoding') == 'deflate':
f = StringIO.StringIO(zlib.decompress(response.read()))
data = f.read()
else:
data = response.read()
return data
def send_req(self,postdata,ssla,tm,ref):
if ssla == True:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
header,body,method,url = file_parsing.f_par(postdata,'Https')
if method.upper() == 'GET':
req = urllib2.Request(url,headers=header)
try:
response = urllib2.urlopen(req, context=ctx,timeout=tm)
except socket.timeout, e:
print "\n---------------------------------------------------------------\n---------------------------------------------------------------\nThe connection has timed out. Please check the network connectivity or increase the connection timeout using option --contimeout."
print "Scan result observed till now is stored in reflected.txt file\n"
sys.exit(0)
except urllib2.HTTPError, response:
pass
except urllib2.URLError,response:
print "\n---------------------------------------------------------------\nError occured.\nError Message:",response.args[0]
sys.exit(0)
data = self.ch_en(response)
return data,response.code,url,response.url
elif method.upper() == 'POST':
req = urllib2.Request(url,body,header)
try:
response = urllib2.urlopen(req, context=ctx,timeout=tm)
except socket.timeout, e:
print "\n---------------------------------------------------------------\nThe connection has timed out. Please check the network connectivity or increase the connection timeout using option --contimeout"
print "Scan result observed till now is stored in reflected.txt file\n"
sys.exit(0)
except urllib2.HTTPError, response:
pass
except urllib2.URLError,response:
print "\n---------------------------------------------------------------\nError occured.\nError Message:",response.args[0]
sys.exit(0)
data = self.ch_en(response)
return data,response.code,url,response.url
else:
print "Method not supported:", method
sys.exit(0)
else:
header,body,method,url = file_parsing.f_par(postdata,'Http')
if method.upper() == 'GET':
req = urllib2.Request(url,headers=header)
try:
response = urllib2.urlopen(req,timeout=tm)
except socket.timeout, e:
print "\n---------------------------------------------------------------\nThe connection has timed out. Please check the network connectivity or increase the connection timeout using option --contimeout"
print "Scan result observed till now is stored in reflected.txt file\n"
sys.exit(0)
except urllib2.HTTPError, response:
pass
except urllib2.URLError,response:
print "\n---------------------------------------------------------------\nError occured.\nError Message:",response.args[0]
sys.exit(0)
data = self.ch_en(response)
return data,response.code,url,response.url
elif method.upper() == 'POST':
req = urllib2.Request(url,body,header)
try:
response = urllib2.urlopen(req,timeout=tm)
except socket.timeout, e:
print "\n---------------------------------------------------------------\nThe connection has timed out. Please check the network connectivity or increase the connection timeout using option --contimeout"
print "Scan result observed till now is stored in reflected.txt file\n"
sys.exit(0)
except urllib2.HTTPError, response:
pass
except urllib2.URLError,response:
print "\n---------------------------------------------------------------\nError occured.\nError Message:",response.args[0]
sys.exit(0)
data = self.ch_en(response)
return data,response.code,url,response.url
else:
print "Method not supported:", method
sys.exit(0)