简体   繁体   English

使用 Python CGI 时,有没有办法 output bash 命令导致与默认格式不同的格式

[英]Is there a way to output bash command results in a different format from default when using Python CGI

When running bash commands from Python to a webpage, succesful output to the webpage occurs when no output options are set. When running bash commands from Python to a webpage, succesful output to the webpage occurs when no output options are set. However, i'd like to save the output to an xml file and display the output to the webpage.但是,我想将 output 保存到 xml 文件并将 output 显示到网页。 I get an error when attempting to do this:尝试执行此操作时出现错误:

在此处输入图像描述

Code:代码:

#!/usr/bin/python
import subprocess
import os
# Import modules for CGI handling
import cgi, cgitb; cgitb.enable()
import time

# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
niktoValue = form.getvalue('niktoInput')


# Get data from fields
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "</head>"
print "<body>"
print "<h2>Nikto Scan Information for %s </h2>" % (niktoValue)


def bash(command):
    return subprocess.check_output(['bash', '-c', command])

def niktoScan():
    res = bash("nikto -h %s -output xml" % niktoValue).splitlines()
    print(res)



niktoScan()

print "</body>"
print "</html>"

Error 13 is normally "Permission denied" .错误 13 通常是"Permission denied"

I suspect your CGI script is running as the _www user rather than as your regular user when you are logged in at your desktop.当您在桌面登录时,我怀疑您的 CGI 脚本是以_www用户而不是以普通用户身份运行的。 You can test by running id in the bash script under the http server or looking in your http server config file - maybe /etc/apache2/httpd.conf for the part that looks like this:您可以通过在 http 服务器下的bash脚本中运行id进行测试,或者查看您的 http 服务器配置文件 - 可能类似于 /etc/apache2/ /etc/apache2/httpd.conf的部分。

User/Group: The name (or #number) of the user/group to run httpd as.用户/组:运行 httpd 的用户/组的名称(或#number)。 It is usually good practice to create a dedicated user and group for running httpd, as with most system services.与大多数系统服务一样,创建一个专门的用户和组来运行 httpd 通常是一种很好的做法。

User _www Group _www用户_www 组_www

I am unfamiliar with the nikto program, so you will need to find out from its author how to allow the www user to run it - maybe by adding that user to a Unix group, maybe via sudo , maybe something else.我不熟悉nikto程序,因此您需要从其作者那里了解如何允许www用户运行它 - 可能通过将该用户添加到 Unix 组,可能通过sudo ,也可能是其他方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM