aboutsummaryrefslogtreecommitdiffstats
path: root/toys
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-04-17 06:47:45 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-04-17 06:47:45 +0200
commit7bc3eba021a8628c37a04bde60265f6cb2ba46ae (patch)
treeb31fe25fdeac7aa59485b4ebcaf55d6bf935e67a /toys
parentpphidden_async: use grbrute (diff)
downloadlaurent-tools-7bc3eba021a8628c37a04bde60265f6cb2ba46ae.tar.xz
laurent-tools-7bc3eba021a8628c37a04bde60265f6cb2ba46ae.zip
grbrute: fix event processing interuption by user
now when the user callback return False it stops grbrute
Diffstat (limited to 'toys')
-rw-r--r--toys/grbrute.py11
-rw-r--r--toys/pphidden_async.py16
2 files changed, 19 insertions, 8 deletions
diff --git a/toys/grbrute.py b/toys/grbrute.py
index 5dfa48e..414fd53 100644
--- a/toys/grbrute.py
+++ b/toys/grbrute.py
@@ -30,9 +30,10 @@ class SessionQueue:
grequests.send(req, self.pool, exception_handler=self._cb_exception)
self.ongoing += 1
- def _cb_response_session(self, res):
+ def _cb_response_session(self, res, verify=None, cert=None, proxies=None, timeout=None, stream=None):
self.ongoing -= 1
- self.cb_response(res)
+ if self.cb_response(res) is False:
+ self.pool.kill()
def _cb_exception(self, req, e):
print "ERROR: sending of %s failed, retrying :\n%s" % (req.url, e)
@@ -40,6 +41,8 @@ class SessionQueue:
class Grbrute:
""" url_iter is the iterator that provides the URLs.
+ cb_response should return True for the processing to continue, and False
+ to terminate.
If you want to integrate it in a gevent driven program, use block=False"""
def __init__(self, url_iter, cb_response=None,
nb_sessions=3, req_per_session=10, sleep=0,
@@ -78,7 +81,9 @@ class Grbrute:
def _cb_response(self, res):
self.ongoing_total -= 1
+ cont = True
if self.cb_response_user:
- self.cb_response_user(res)
+ cont = self.cb_response_user(res)
self._send()
time.sleep(self.sleep)
+ return cont
diff --git a/toys/pphidden_async.py b/toys/pphidden_async.py
index 229a181..1b6a576 100644
--- a/toys/pphidden_async.py
+++ b/toys/pphidden_async.py
@@ -27,10 +27,13 @@ class Pp_url:
return res
def cb_response(res):
- print "[-] %s : %d" % (res.url, res.status_code)
+ global found
+ if not found:
+ print "[-] %s : %d" % (res.url, res.status_code)
if res.status_code != 404:
- print "[*] found: %s" % res.url
- sys.exit(0)
+ found = res.url
+ return False
+ return True
parser = argparse.ArgumentParser(description='pphidden_async',
epilog="Example: %s 73 0 0" % sys.argv[0])
@@ -44,7 +47,10 @@ parser.add_argument('-v', action="store_true", dest="verbose", default=False,
help="verbose")
args = parser.parse_args()
+found = None
url_iter = Pp_url(args.image, args.start_x, args.start_y)
grbrute.Grbrute(url_iter, cb_response, verbose=args.verbose)
-print "[*] not found"
-sys.exit(1)
+if found is False:
+ print "[*] not found"
+ sys.exit(1)
+print "[*] found: %s" % found