From fe8596fcf180a041fb5209ad483b1e45be5c2150 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Wed, 17 Apr 2013 00:44:36 +0200 Subject: add pphidden_async.py, WIP implementation of optimised parrallel HTTP queries engine using multiple sessions (HTTP/1.1) and multiple requests per connections using grequests --- toys/pphidden_async.py | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 toys/pphidden_async.py (limited to 'toys') diff --git a/toys/pphidden_async.py b/toys/pphidden_async.py new file mode 100644 index 0000000..24dec8d --- /dev/null +++ b/toys/pphidden_async.py @@ -0,0 +1,100 @@ +import requests +import grequests +from collections import deque +import time +import sys +import warnings +warnings.warn("XXX WORK IN PROGRESS") +warnings.warn("XXX don't excpect this to work !") + +# http://www.pointerpointer.com/gridPositions.json + +# Python grequests ressources : +# https://gist.github.com/ibrahima/3153647 - request_queue.py +# http://rubydoc.info/github/typhoeus/typhoeus/frames/Typhoeus - Ruby Typhoeus + +class SessionQueue: + def __init__(self): + self.session = requests.Session() + self.ongoing = deque() + + def add(self, url): + req = grequests.get(url, session=self.sessions) + grequests.send(req) + self.ongoing.append(req) + +class Brute: + """ Find existence of URLs provided by url_iter based on HTTP error code. + Uses multiple simultaneous connections (HTTP/1.1) and multiple parralel + requests per connection. + If you want to integrate""" + def __init__(self, url_iter, nb_sessions=3, req_per_session=10, sleep=0, + debug=False, block=True): + self.url_iter = url_iter + self.nb_sessions = nb_sessions + self.req_per_session = req_per_session + self.sleep = sleep + self.debug = debug + self.ips = ips # XXX TODO + self.sessions = deque() + self.ongoing = 0 + for i in range(nb_sessions) + self.sessions.append(SessionQueue()) + self._send() + + def _send(self) + while self.ongoing < self.nb_sessions * self.req_per_session: + try: + url = self.url_iter.next() + except StopIteration, e: + return + if len(s.ongoing) < self.req_per_session: + print "[-] %s" % url + s.add(url) + self.ongoing += 1 + + def _add_url(self, url) + self. + + def _cb_response(self, res): + print "response: %s" % res + self.ongoing -= 1 + self._send() + time.sleep(self.sleep) + +class Pp_url: + def __init__(self, image, x, y, max_x=2000, max_y=2000): + self.base_url = "http://www.pointerpointer.com/images" + self.image = image + self.x = x + self.y = y + self.max_x = max_x + self.max_y = max_y + print ">>> Looking for image %d <<<" % image + print ">>>> starting x=%d y=%d <<<<" % (x, y) + def __iter__(self): + return self + def __next__(self): + res = "%s/N%04d_%d_%d.jpg" % (self.base_url, self.image, self.x, self.y) + self.index += 1 + if self.y > self.max_y: + self.x += 1 + self.y = 0 + if self.x > self.max_x: + raise StopIteration + return res + +image = int(sys.argv[1]) +x = int(sys.argv[2]) +y = int(sys.argv[3]) + +url_iter = Pp_url(image, x, y) +b = Brute(ips=None, conn_per_ip=3, url_iter) + +if b.found: + print "[*] found: %s" % b.url +else: + print "[*] not found" + +sys.exit(0 if b.found else 1) + -- cgit v1.2.3-59-g8ed1b