aboutsummaryrefslogtreecommitdiffstats
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/brhute.py70
1 files changed, 34 insertions, 36 deletions
diff --git a/toys/brhute.py b/toys/brhute.py
index a301713..c69d411 100644
--- a/toys/brhute.py
+++ b/toys/brhute.py
@@ -1,6 +1,7 @@
from collections import deque
import time
from asynhttp import http_evented
+import asyncore
import warnings
# grbrute - asynchronous URL fetcher based on asyhttp
@@ -14,27 +15,26 @@ import warnings
# https://gist.github.com/ibrahima/3153647 - request_queue.py
# http://rubydoc.info/github/typhoeus/typhoeus/frames/Typhoeus - Ruby Typhoeus
-class SessionQueue:
- def __init__(self, pool, cb_response):
- self.pool = pool
+# XXX handle multiple connections
+# XXX multiple processes, autodetect and repartir connections
+
+class Brhute_connection:
+ def __init__(self, ip, port=80, cb_response=None):
self.cb_response = cb_response
- self.session = requests.Session()
self.ongoing = 0
+ self.hev = http_evented.http_evented((ip, port), onConnected=self._connected)
- def add(self, url):
- req = grequests.get(url, session=self.session,
- hooks = {'response' : self._cb_response_session})
- grequests.send(req, self.pool, exception_handler=self._cb_exception)
+ def get(self, url):
+ headers = {'Host': host}
+ body = None
+ self.hev[0].make_HTTP_request("GET", url, body, headers,
+ self._cb_response_connection)
self.ongoing += 1
- def _cb_response_session(self, res, verify=None, cert=None, proxies=None, timeout=None, stream=None):
+ def _cb_response_connection(self, response):
self.ongoing -= 1
- 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)
- grequests.send(req, self.pool, exception_handler=self._cb_exception)
+ if self.cb_response:
+ self.cb_response(response)
class Brhute_ip:
""" Fetch URLs from one IP
@@ -43,50 +43,48 @@ 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=3, sleep=0, verbose=False, block=True):
+ nb_connections=1, req_per_connection=10, sleep=0,
+ verbose=False, block=True):
warnings.warn("XXX WARNING: WORK IN PROGRESS")
warnings.warn("XXX WARNING: Don't excpect this to work")
self.url_iter = url_iter
self.ip = ip
self.port = port
self.cb_response_user = cb_response
- self.nb_sessions = nb_sessions
+ self.nb_connections = nb_connections
+ self.req_per_connection = req_per_connection
self.sleep = sleep
self.verbose = verbose
- self.pool = grequests.Pool()
- self.sessions = deque()
self.ongoing_total = 0
- hev = http_evented.http_evented((ip, port))
- self._send()
+ self.conns = deque()
+ for i in range(nb_connections):
+ self.conns.append(Brhute_conn(cb_response))
if block:
- self.pool.join()
+ asyncore.loop()
- def _send(self):
- while self.ongoing_total < self.nb_sessions * self.req_per_session:
+ def send(self):
+ while self.ongoing_total < self.nb_connections * self.req_per_connection:
# get an URL to send
try:
- url = next(self.url_iter)
+ (host, url) = next(self.url_iter)
except StopIteration, e:
return
if self.verbose:
print "[-] %s" % url
- # select a session that has room to send
- while self.sessions[0].ongoing == self.req_per_session:
- self.sessions.rotate(1)
- # send URL using selected sessions
- self.sessions[0].add(url)
+ # send the url
+ self.conn[0].get(url)
self.ongoing_total += 1
- self.sessions.rotate(1)
- def _cb_response(self, res):
+ def _connected(self):
+ self.send()
+
+ def _cb_response(self, response):
self.ongoing_total -= 1
- cont = True
if self.cb_response_user:
- cont = self.cb_response_user(res)
- self._send()
+ self.cb_response_user(response)
+ self.send()
time.sleep(self.sleep)
- return cont
class Brhute_multi_ip:
"""Fetch URLs from multiple IPs pointing to the same content"""