看到现有帖子的建议并做了:
(1)照顾" SyntaxError: EOF while scanning triple-quoted string literal
"通过推荐
(2)据说用" print "Content-type: text/html\n\n"
"
但是仍然。
[Tue Jul 12 14:55:59 2016] [error] [client 172.16.1.18] malformed header from script. Bad header=172.16.1.18 [has executed] d: reset.py, referer: http://172.16.1.18/cgi-bin/index.cgi?message=
任何建议都将受到赞赏。
感谢。
[index.cgi的一部分]
<form name="input" action="/cgi-bin/reset.py" method="get">
<input type="submit" value="Reset">
[reset.py]
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable() # for troubleshooting
import os
import subprocess
form = cgi.FieldStorage()
from subprocess import *
message = form.getvalue("message", "(no message)")
print os.environ["REMOTE_ADDR"]+ " [has executed] " + Popen('ls', shell=True, stdin=PIPE, stdout=PIPE).communicate()[0]
print "Content-type: text/html\n\n"
print """
<html>
<h2><title>Resetting</title>
<body>
<h3> Resetting </h3>
<p>Done</p>
</body>
</html"
print """
print cgi.escape(message)
答案 0 :(得分:0)
感谢“丹尼尔罗斯曼” 在标题下面移动了一个命令。 我认为不直接html的骨干代码不属于下面。
import subprocess
form = cgi.FieldStorage()
from subprocess import *
message = form.getvalue("message", "(no message)")
print "Content-type: text/html\n\n"
print os.environ["REMOTE_ADDR"]+ " [has executed] " + Popen('df -h', shell=True, stdin=PIPE, stdout=PIPE).communicate()[0]
print """