rss
twitter
12/07/2009 10:50:52

SPyShell.py

#!/usr/bin/env python
# Simple python shell by Pham Duc Hai (duchaikhtn@gmail.com)
# http://guru.net.vn
import socket
import os
import commands

host = ''
port = 2009
password = 'secretcode'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(1)

print "Server is running on port %d; press Ctrl-C to terminate." % port

clientsock, clientaddr = s.accept()
clientfile = clientsock.makefile('rw', 0)
clientfile.write("SPyShell by Pham Duc Hai\n")
clientfile.write("Welcome, " + str(clientaddr) + "\n")

while 1:
    clientfile.write("Please enter password: ")
    line = clientfile.readline().strip()
    if line == password:
        clientfile.write('\n\r# ')
        while 1:
            line = clientfile.readline().strip()
            if line == "exit":
                clientfile.close()
                clientsock.close()
            output = commands.getoutput(line)   
            clientfile.write(output)
            clientfile.write('\n\r# ')
    else:
        clientfile.write('Wrong password!\n\r')
1.61821699142