diff options
Diffstat (limited to 'toys/brhute.py')
-rw-r--r-- | toys/brhute.py | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/toys/brhute.py b/toys/brhute.py index c69d411..851d742 100644 --- a/toys/brhute.py +++ b/toys/brhute.py @@ -1,7 +1,8 @@ from collections import deque import time -from asynhttp import http_evented import asyncore +from asynhttp import http_evented # in brhute repository +import asyncdns # sudo pip install asyncdns import warnings # grbrute - asynchronous URL fetcher based on asyhttp @@ -15,26 +16,52 @@ import warnings # https://gist.github.com/ibrahima/3153647 - request_queue.py # http://rubydoc.info/github/typhoeus/typhoeus/frames/Typhoeus - Ruby Typhoeus -# XXX handle multiple connections # XXX multiple processes, autodetect and repartir connections +# DNS resolving with asyncdns class Brhute_connection: - def __init__(self, ip, port=80, cb_response=None): - self.cb_response = cb_response + def __init__(self, url_iter, ip, port, req_per_connection, cb_response, + interval=0, verbose=False): + self.url_iter = url_iter + self.ip = ip + self.port = port + self.req_per_connection = req_per_connection + self.cb_response_user = cb_response + self.interval = interval + self.verbose = verbose self.ongoing = 0 self.hev = http_evented.http_evented((ip, port), onConnected=self._connected) - def get(self, url): + def get(self, host, url): + if self.verbose: + print "XXX Brhute_connection.get" headers = {'Host': host} body = None - self.hev[0].make_HTTP_request("GET", url, body, headers, - self._cb_response_connection) + self.hev.make_HTTP_request("GET", url, body, headers, + self._cb_response) self.ongoing += 1 - def _cb_response_connection(self, response): + def _connected(self): + self._send() + + def _send(self): + while self.ongoing < self.req_per_connection: + # get an URL to send + try: + (host, url) = next(self.url_iter) + except StopIteration, e: + return + if self.verbose: + print "[-] %s" % url + # send the url + self.get(host, url) + + def _cb_response(self, response): self.ongoing -= 1 - if self.cb_response: - self.cb_response(response) + if self.cb_response_user: + self.cb_response_user(response) + self._send() + time.sleep(self.interval) class Brhute_ip: """ Fetch URLs from one IP @@ -43,49 +70,27 @@ class Brhute_ip: to terminate. If you want to integrate it in a gevent driven program, use block=False""" def __init__(self, url_iter, ip, port=80, cb_response=None, - nb_connections=1, req_per_connection=10, sleep=0, + nb_connections=3, req_per_connection=10, interval=0, verbose=False, block=True): warnings.warn("XXX WARNING: WORK IN PROGRESS") - warnings.warn("XXX WARNING: Don't excpect this to work") + warnings.warn("XXX WARNING: Don't expect this to work") self.url_iter = url_iter self.ip = ip self.port = port self.cb_response_user = cb_response self.nb_connections = nb_connections self.req_per_connection = req_per_connection - self.sleep = sleep + self.interval = interval self.verbose = verbose - self.ongoing_total = 0 self.conns = deque() for i in range(nb_connections): - self.conns.append(Brhute_conn(cb_response)) + self.conns.append(Brhute_connection(url_iter, ip, port, + req_per_connection, cb_response, interval, + verbose)) if block: asyncore.loop() - def send(self): - while self.ongoing_total < self.nb_connections * self.req_per_connection: - # get an URL to send - try: - (host, url) = next(self.url_iter) - except StopIteration, e: - return - if self.verbose: - print "[-] %s" % url - # send the url - self.conn[0].get(url) - self.ongoing_total += 1 - - def _connected(self): - self.send() - - def _cb_response(self, response): - self.ongoing_total -= 1 - if self.cb_response_user: - self.cb_response_user(response) - self.send() - time.sleep(self.sleep) - class Brhute_multi_ip: """Fetch URLs from multiple IPs pointing to the same content""" def __init__(self): |