#NEWLINE# def get_settings( args = None , override_defaults = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# 'Parse args and set other settings based on them\n\n    Default settings can be overriden by passing in a dictionary\n    \n    Return a new dictionary containing all args and settings\n    ' #NEWLINE# parser = argparser ( ) #NEWLINE# args = parser . parse_args ( args ) #NEWLINE# settings = { #NEWLINE# #INDENT# 'args' : args , #NEWLINE# 'receive_postbacks' : True , #NEWLINE# 'shell_command' : 'bash' , #NEWLINE# 'http_fetcher' : 'curl -LSs' , #NEWLINE# 'mime_type' : args . mime_type , #NEWLINE# 'require_hostname_header' : False , #NEWLINE# 'log_post_backs' : args . log_post_backs , #NEWLINE# 'ssl' : args . ssl , #NEWLINE# 'ssl_context' : None , #NEWLINE# 'pin' : ( args . pin or ( args . ssl is None ) ) , #NEWLINE# 'num_gets' : args . num_gets , #NEWLINE# 'require_knock' : ( not args . disable_knock ) , #NEWLINE# 'knock' : args . knock , #NEWLINE# 'verbose' : args . verbose , #NEWLINE# 'survey' : args . survey , #NEWLINE# 'ssh' : args . ssh , #NEWLINE# 'quiet' : ( args . quiet and ( not args . verbose ) ) , #NEWLINE# 'client_logging' : args . client_logging , #NEWLINE# 'client_quiet' : args . client_quiet , #NEWLINE# 'log_process' : None , #NEWLINE# 'log_file' : None , #NEWLINE# 'require_knock_from_environment' : True , #NEWLINE# 'wget' : args . wget , #NEWLINE# 'unwrapped' : args . unwrapped , #NEWLINE# 'stdin' : sys . stdin , #NEWLINE# 'stdout' : sys . stdout , #NEWLINE# 'time_command' : False , #NEWLINE# 'get_curlbomb_command' : get_curlbomb_command , #NEWLINE# #UNINDENT# } #NEWLINE# settings . update ( override_defaults ) #NEWLINE# if args . verbose : #NEWLINE# #INDENT# logging . getLogger ( 'curlbomb' ) . setLevel ( level = logging . INFO ) #NEWLINE# settings [ 'log_post_backs' ] = True #NEWLINE# logging . getLogger ( 'tornado.access' ) . setLevel ( level = logging . INFO ) #NEWLINE# #UNINDENT# if args . debug : #NEWLINE# #INDENT# settings [ 'verbose' ] = True #NEWLINE# logging . getLogger ( 'curlbomb' ) . setLevel ( level = logging . DEBUG ) #NEWLINE# settings [ 'log_post_backs' ] = True #NEWLINE# logging . getLogger ( 'tornado.access' ) . setLevel ( level = logging . DEBUG ) #NEWLINE# #UNINDENT# if ( settings [ 'require_knock' ] and ( not settings [ 'knock' ] ) ) : #NEWLINE# #INDENT# settings [ 'knock' ] = base64 . b64encode ( bytes ( random . sample ( range ( 256 ) , 12 ) ) , altchars = b'_.' ) . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# if settings [ 'survey' ] : #NEWLINE# #INDENT# settings [ 'receive_postbacks' ] = False #NEWLINE# settings [ 'client_logging' ] = False #NEWLINE# #UNINDENT# if args . disable_postback : #NEWLINE# #INDENT# settings [ 'receive_postbacks' ] = False #NEWLINE# #UNINDENT# if settings [ 'unwrapped' ] : #NEWLINE# #INDENT# settings [ 'require_knock_from_environment' ] = False #NEWLINE# #UNINDENT# if ( args . pin and ( args . ssl is False ) ) : #NEWLINE# #INDENT# print ( '--pin requires --ssl' ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# if args . wget : #NEWLINE# #INDENT# settings [ 'http_fetcher' ] = 'wget -q -O -' #NEWLINE# if args . log_post_backs : #NEWLINE# #INDENT# print ( "wget can't stream the client output, so --log-posts is not supported in wget mode" ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# if args . pin : #NEWLINE# #INDENT# print ( 'SSL certificate pinning only works in curl mode' ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# #UNINDENT# if ( args . port == 'random' ) : #NEWLINE# #INDENT# s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) #NEWLINE# s . bind ( ( '' , 0 ) ) #NEWLINE# settings [ 'port' ] = s . getsockname ( ) [ 1 ] #NEWLINE# s . close ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# settings [ 'port' ] = int ( args . port ) #NEWLINE# #UNINDENT# settings [ 'display_host' ] = socket . gethostbyname ( socket . gethostname ( ) ) #NEWLINE# settings [ 'display_port' ] = settings [ 'port' ] #NEWLINE# if settings [ 'ssh' ] : #NEWLINE# #INDENT# ssh_parts = settings [ 'ssh' ] . split ( ':' ) #NEWLINE# ssh_host = ssh_parts [ 0 ] #NEWLINE# ssh_port = 22 #NEWLINE# http_port = settings [ 'port' ] #NEWLINE# if ( len ( ssh_parts ) == 3 ) : #NEWLINE# #INDENT# ssh_port = ssh_parts [ 1 ] #NEWLINE# http_port = ssh_parts [ 2 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( ssh_parts ) == 2 ) : #NEWLINE# #INDENT# http_port = ssh_parts [ 1 ] #NEWLINE# #UNINDENT# #UNINDENT# settings [ 'ssh_forward' ] = '0.0.0.0:{http_port}:localhost:{port}' . format ( port = settings [ 'port' ] , http_port = http_port ) #NEWLINE# settings [ 'ssh_host' ] = ssh_host #NEWLINE# settings [ 'ssh_port' ] = ssh_port #NEWLINE# settings [ 'display_port' ] = http_port #NEWLINE# if ( '@' in ssh_host ) : #NEWLINE# #INDENT# ( settings [ 'ssh_user' ] , settings [ 'display_host' ] ) = ssh_host . split ( '@' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# settings [ 'display_host' ] = ssh_host #NEWLINE# #UNINDENT# #UNINDENT# if args . domain : #NEWLINE# #INDENT# parts = args . domain . split ( ':' ) #NEWLINE# settings [ 'display_host' ] = parts [ 0 ] #NEWLINE# if ( len ( parts ) > 1 ) : #NEWLINE# #INDENT# settings [ 'display_port' ] = parts [ 1 ] #NEWLINE# #UNINDENT# #UNINDENT# if ( settings [ 'ssl' ] is not False ) : #NEWLINE# #INDENT# settings [ 'ssl_context' ] = tls . get_ssl_context_from_settings ( settings ) #NEWLINE# #UNINDENT# if ( ( not settings [ 'stdout' ] . isatty ( ) ) and ( not settings [ 'quiet' ] ) ) : #NEWLINE# #INDENT# settings [ 'log_post_backs' ] = True #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# prepare_cmd = args . prepare_command #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# args . command = None #NEWLINE# args . script_hash = None #NEWLINE# args . signature = None #NEWLINE# args . resource = settings [ 'stdin' ] #NEWLINE# prepare_cmd = run . prepare #NEWLINE# #UNINDENT# prepare_cmd ( args , settings , parser ) #NEWLINE# return settings