aboutsummaryrefslogtreecommitdiffstats
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/brhute.py81
-rw-r--r--toys/pphidden_async.py29
2 files changed, 64 insertions, 46 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):
diff --git a/toys/pphidden_async.py b/toys/pphidden_async.py
index 6dd1b86..7df3ad1 100644
--- a/toys/pphidden_async.py
+++ b/toys/pphidden_async.py
@@ -6,8 +6,9 @@ import brhute
# http://www.pointerpointer.com/gridPositions.json
class Pp_url:
- def __init__(self, image, x, y, max_x=2000, max_y=2000):
- self.base_url = "http://www.pointerpointer.com/images"
+ def __init__(self, image, x, y, max_x=100, max_y=100):
+ self.host = "www.pointerpointer.com"
+ self.base_url = "/images"
self.image = image
self.x = x
self.y = y
@@ -18,14 +19,14 @@ class Pp_url:
def __iter__(self):
return self
def next(self):
- res = "%s/N%04d_%d_%d.jpg" % (self.base_url, self.image, self.x, self.y)
+ url = "%s/N%04d_%d_%d.jpg" % (self.base_url, self.image, self.x, self.y)
self.y += 1
if self.y > self.max_y:
self.x += 1
self.y = 0
if self.x > self.max_x:
raise StopIteration
- return res
+ return (self.host, url)
def cb_response_grbrute(res):
global found
@@ -36,6 +37,15 @@ def cb_response_grbrute(res):
return False
return True
+def cb_response_brhute(res):
+ global found
+ if not found:
+ print "res: %s" % res
+ #if res.status_code != 404:
+ # found = res.url
+ # return False
+ #return True
+
parser = argparse.ArgumentParser(description='pphidden_async',
epilog="Example: %s 73 0 0" % sys.argv[0])
parser.add_argument('image', action="store", type=int,
@@ -44,20 +54,23 @@ parser.add_argument('start_x', action="store", type=int,
help="Start at coordinate X=")
parser.add_argument('start_y', action="store", type=int,
help="Start at coordinate Y=")
-parser.add_argument('-b', action="store_true", dest="backend", default="gbrute",
+parser.add_argument('-b', action="store", dest="backend", default="gbrute",
help="Backend, can be gbrute (default) or brhute (work in progress)")
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)
if args.backend == "gbrute":
+ url_iter = Pp_url(args.image, args.start_x, args.start_y)
grbrute.Grbrute(url_iter, cb_response_grbrute, verbose=args.verbose)
elif args.backend == "brhute":
- brhute.Brhute_ip(url_iter, ip,
- cb_response=cb_response_brute, verbose=args.verbose)
+ url_iter = Pp_url(args.image, args.start_x, args.start_y)
+ brhute.Brhute_ip(url_iter, "207.171.163.203", # Amazon
+ cb_response=cb_response_brhute, verbose=args.verbose)
+ #brhute.Brhute_ip(url_iter, "173.194.34.14", # Google
+ # cb_response=cb_response_brhute, verbose=args.verbose)
else:
print "Error: Unknown backend specified"
sys.exit(1)