Skip to content

Commit 38b53e6

Browse files
committed
Merge branch 'dev'
2 parents 171ef20 + 223ceba commit 38b53e6

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

httpgrep.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
################################################################################
2020

2121

22+
import re
2223
import sys
2324
import os
2425
import socket
@@ -30,7 +31,7 @@
3031

3132

3233
__author__ = 'noptrix'
33-
__version__ = '2.0'
34+
__version__ = '2.1'
3435
__copyright__ = 'santa clause'
3536
__license__ = 'MIT'
3637

@@ -103,7 +104,7 @@
103104
'searchstr': '',
104105
'method': 'get',
105106
'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'),
107108
'bytes': 64,
108109
'threads': 80,
109110
'timeout': 3.0,
@@ -170,29 +171,32 @@ def get_strings(strings):
170171
return
171172

172173

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+
173182
def scan(url):
174183
if opts['verbose']:
175184
log(f'scanning {url}', 'verbose')
176185

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)
180187

181188
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'])
188191
res = repr(r.text[idx:idx+opts['bytes']])
189192
log(f'{url} => body => {res}', 'good')
190193
if opts['logfile']:
191194
log(f'{url} => body => {res}', 'file')
192195

193196
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']):
196200
log(f"{url} => header => {k}: {v}", 'good')
197201
if opts['logfile']:
198202
log(f"{url} => header => {k}: {v}", 'file')
@@ -300,7 +304,7 @@ def parse_cmdline(cmdline):
300304
if o == '-c':
301305
opts['timeout'] = float(a)
302306
if o == '-i':
303-
opts['case_in'] = True
307+
opts['case_in'] = re.IGNORECASE
304308
if o == '-r':
305309
opts['rptr'] = True
306310
if o == '-l':

0 commit comments

Comments
 (0)