|
19 | 19 | ################################################################################ |
20 | 20 |
|
21 | 21 |
|
| 22 | +import re |
22 | 23 | import sys |
23 | 24 | import os |
24 | 25 | import socket |
|
30 | 31 |
|
31 | 32 |
|
32 | 33 | __author__ = 'noptrix' |
33 | | -__version__ = '2.0' |
| 34 | +__version__ = '2.1' |
34 | 35 | __copyright__ = 'santa clause' |
35 | 36 | __license__ = 'MIT' |
36 | 37 |
|
|
103 | 104 | 'searchstr': '', |
104 | 105 | 'method': 'get', |
105 | 106 | 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0', |
106 | | - 'where': ['headers', 'body'], |
| 107 | + 'where': ('headers', 'body'), |
107 | 108 | 'bytes': 64, |
108 | 109 | 'threads': 80, |
109 | 110 | 'timeout': 3.0, |
@@ -170,29 +171,32 @@ def get_strings(strings): |
170 | 171 | return |
171 | 172 |
|
172 | 173 |
|
| 174 | +def http_req(url): |
| 175 | + m = getattr(requests, opts['method']) |
| 176 | + r = m(url, timeout=opts['timeout'], headers={'User-Agent': opts['ua']}, |
| 177 | + verify=False) |
| 178 | + |
| 179 | + return r |
| 180 | + |
| 181 | + |
173 | 182 | def scan(url): |
174 | 183 | if opts['verbose']: |
175 | 184 | log(f'scanning {url}', 'verbose') |
176 | 185 |
|
177 | | - m = getattr(requests, opts['method']) |
178 | | - r = m(url, timeout=opts['timeout'], headers={'User-Agent': opts['ua']}, |
179 | | - verify=False) |
| 186 | + r = http_req(url) |
180 | 187 |
|
181 | 188 | if 'body' in opts['where']: |
182 | | - res = r.text |
183 | | - if opts['case_in']: |
184 | | - searchstr = opts['searchstr'].lower() |
185 | | - res = r.text.lower() |
186 | | - if searchstr in r.text: |
187 | | - idx = r.text.index(searchstr) |
| 189 | + if re.search(opts['searchstr'], r.text, opts['case_in']): |
| 190 | + idx = r.text.index(opts['searchstr']) |
188 | 191 | res = repr(r.text[idx:idx+opts['bytes']]) |
189 | 192 | log(f'{url} => body => {res}', 'good') |
190 | 193 | if opts['logfile']: |
191 | 194 | log(f'{url} => body => {res}', 'file') |
192 | 195 |
|
193 | 196 | if 'headers' in opts['where']: |
194 | | - for k,v in r.headers.items(): |
195 | | - if searchstr in k or searchstr in v: |
| 197 | + for k, v in r.headers.items(): |
| 198 | + if re.search(opts['searchstr'], k, opts['case_in']) or \ |
| 199 | + re.search(opts['searchstr'], v, opts['case_in']): |
196 | 200 | log(f"{url} => header => {k}: {v}", 'good') |
197 | 201 | if opts['logfile']: |
198 | 202 | log(f"{url} => header => {k}: {v}", 'file') |
@@ -300,7 +304,7 @@ def parse_cmdline(cmdline): |
300 | 304 | if o == '-c': |
301 | 305 | opts['timeout'] = float(a) |
302 | 306 | if o == '-i': |
303 | | - opts['case_in'] = True |
| 307 | + opts['case_in'] = re.IGNORECASE |
304 | 308 | if o == '-r': |
305 | 309 | opts['rptr'] = True |
306 | 310 | if o == '-l': |
|
0 commit comments