<s> """<STR_LIT>""" <EOL> import argparse <EOL> import imp <EOL> import re <EOL> import subprocess <EOL> import time <EOL> import socket <EOL> import pyrax <EOL> import tasa <EOL> from tasa . store import Queue , PickleQueue <EOL> from tasa . utils import iterit <EOL> from tasa . worker import BaseWorker <EOL> pyrax . set_setting ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> pyrax . set_setting ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class MasscanWorker ( BaseWorker ) : <EOL> qinput = Queue ( '<STR_LIT>' ) <EOL> qoutput = Queue ( '<STR_LIT>' ) <EOL> chunk_size = <NUM_LIT> <EOL> def run ( self , job ) : <EOL> """<STR_LIT>""" <EOL> command = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , str ( job [ <NUM_LIT:0> ] ) , <EOL> '<STR_LIT>' , str ( job [ <NUM_LIT:1> ] ) , <EOL> '<STR_LIT>' , str ( job [ <NUM_LIT:2> ] ) , <EOL> ] <EOL> proc = subprocess . Popen ( command , <EOL> stdout = subprocess . PIPE ) <EOL> for line in proc . stdout : <EOL> match = re . match ( <EOL> '<STR_LIT>' , <EOL> line . strip ( ) ) <EOL> if match : <EOL> yield match . groups ( ) <EOL> proc . wait ( ) <EOL> class RFBFingerprinter ( BaseWorker ) : <EOL> qinput = Queue ( '<STR_LIT>' ) <EOL> qoutput = PickleQueue ( '<STR_LIT>' ) <EOL> def run ( self , job ) : <EOL> port , proto , ip = job <EOL> s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> s . settimeout ( <NUM_LIT:1> ) <EOL> output = [ ] <EOL> try : <EOL> s . connect ( ( ip , int ( port ) ) ) <EOL> rfb_proto = s . recv ( <NUM_LIT> ) <EOL> output . append ( rfb_proto ) <EOL> s . sendall ( rfb_proto ) <EOL> security_proto = s . recv ( <NUM_LIT> ) <EOL> output . append ( security_proto ) <EOL> if rfb_proto != '<STR_LIT>' : <EOL> s . sendall ( '<STR_LIT>' ) <EOL> follow_data = s . recv ( <NUM_LIT> ) <EOL> output . append ( follow_data ) <EOL> s . close ( ) <EOL> except Exception : <EOL> pass <EOL> if output : <EOL> yield [ ip , port ] + output <EOL> class ScreenshotWorker ( BaseWorker ) : <EOL> qinput = PickleQueue ( '<STR_LIT>' ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ScreenshotWorker , self ) . __init__ ( * args , ** kwargs ) <EOL> pyrax . set_credentials ( tasa . conf . rax_username , <EOL> tasa . conf . rax_password ) <EOL> def run ( self , job ) : <EOL> ip = job [ <NUM_LIT:0> ] <EOL> port = job [ <NUM_LIT:1> ] <EOL> screen = str ( int ( port ) - <NUM_LIT> ) <EOL> try : <EOL> security_protos = job [ <NUM_LIT:3> ] [ <NUM_LIT:1> : ] <EOL> except IndexError : <EOL> return <EOL> if '<STR_LIT>' in security_protos : <EOL> command = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT::>' . join ( [ ip , screen ] ) , <EOL> '<STR_LIT:->' , <EOL> ] <EOL> proc = subprocess . Popen ( command , <EOL> stdout = subprocess . PIPE ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> if stdout : <EOL> container = ip . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> file_name = ip + '<STR_LIT:_>' + port + '<STR_LIT>' <EOL> pyrax . cloudfiles . store_object ( container , <EOL> file_name , <EOL> stdout , <EOL> content_type = "<STR_LIT>" ) <EOL> connection = tasa . store . connection <EOL> connection . hset ( '<STR_LIT>' + container , file_name , stderr ) <EOL> def insert_job ( ) : <EOL> """<STR_LIT>""" <EOL> seed = str ( int ( time . time ( ) ) ) <EOL> total_shards = tasa . conf . shards <EOL> jobs = [ ] <EOL> for shard in range ( <NUM_LIT:1> , total_shards + <NUM_LIT:1> ) : <EOL> jobs . append ( <EOL> [ seed , '<STR_LIT>' % ( shard , total_shards ) , tasa . conf . ports ] ) <EOL> MasscanWorker . qinput . send ( * jobs ) <EOL> def create_containers ( ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> pyrax . set_credentials ( tasa . conf . rax_username , <EOL> tasa . conf . rax_password ) <EOL> connection = tasa . store . connection <EOL> for subnet in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> cont_name = str ( subnet ) <EOL> container = pyrax . cloudfiles . create_container ( cont_name ) <EOL> pyrax . cloudfiles . make_container_public ( container ) <EOL> connection . hset ( '<STR_LIT>' , cont_name , container . cdn_uri ) <EOL> print "<STR_LIT>" , subnet <EOL> print "<STR_LIT>" <EOL> def render_output_website ( ) : <EOL> """<STR_LIT>""" <EOL> from jinja2 import Environment , PackageLoader <EOL> env = Environment ( loader = PackageLoader ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> connection = tasa . store . connection <EOL> containers = { } <EOL> uris = connection . hgetall ( '<STR_LIT>' ) <EOL> for key , value in uris . items ( ) : <EOL> containers [ key ] = { '<STR_LIT>' : value } <EOL> pipe = connection . pipeline ( ) <EOL> queue_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for name in queue_names : <EOL> pipe . llen ( name ) <EOL> queue_lengths = pipe . execute ( ) <EOL> queues = zip ( queue_names , queue_lengths ) <EOL> for key in uris . keys ( ) : <EOL> pipe . hgetall ( '<STR_LIT>' + key ) <EOL> for key , value in zip ( uris . keys ( ) , pipe . execute ( ) ) : <EOL> containers [ key ] [ '<STR_LIT>' ] = value <EOL> template = env . get_template ( '<STR_LIT>' ) <EOL> rendered = template . render ( containers = containers , queues = queues ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> f . write ( rendered ) <EOL> template = env . get_template ( '<STR_LIT>' ) <EOL> for key in containers . keys ( ) : <EOL> rendered = template . render ( base_uri = containers [ key ] [ '<STR_LIT>' ] , <EOL> files = containers [ key ] [ '<STR_LIT>' ] ) <EOL> with open ( '<STR_LIT>' % key , '<STR_LIT:w>' ) as f : <EOL> f . write ( rendered ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = argparse . ArgumentParser ( ) <EOL> subparsers = parser . add_subparsers ( help = "<STR_LIT>" ) <EOL> parser_insert = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> parser_insert . set_defaults ( func = insert_job ) <EOL> parser_insert . add_argument ( '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_insert . add_argument ( '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_insert . add_argument ( '<STR_LIT>' , default = '<STR_LIT:100>' , type = int , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_job = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_job . set_defaults ( func = create_containers ) <EOL> parser_job = subparsers . add_parser ( '<STR_LIT>' ) <EOL> parser_job . set_defaults ( func = render_output_website ) <EOL> parser . parse_args ( namespace = tasa . conf ) <EOL> tasa . conf . func ( ) </s>
