我正在尝试创建一个脚本来强制SSH(和其他协议)作为项目的一部分,从我学到的东西。这只是代码的一部分:
import optparse, sys, os
def main():
parser = optparse.OptionParser()
parser.add_option('-v', '--verbose', dest='verbose', help='Show output of program executing')
parser.add_option('-u', '--username', dest='username', help='Provide a valid username for service/protocol being executed.')
parser.add_option('-s', '--service', dest='service', help="Provide a service being attacked. Several protocols and services are supported.")
parser.add_option('-p', '--password', dest='password', help='Provide a wordlist or directory to a wordlist')
parser.add_option('-a', '--address', dest='address', help='Provide host address for specified service')
(options, args) = parser.parse_args()
man_options = ['username', 'password']
for m in man_options:
if not options.__dict__[m]:
print R + "You have to specify a username AND a wordlist!" + W
sys.exit()
我希望允许用户按照协议(例如-s
,ssh
等)使用ftp
标记传递他们想要攻击的协议。
这是我后续的初始代码:
if (options.service == 'ssh' or 'SSH') and (options.address is None):
print R + "Please specify a host for SSH" + W
sys.exit()
#else:
# do the actual dictionary attack
虽然最初有效:
$ python script.py -u test -p test.txt -s ssh
Please specify a host for SSH
$ python script.py -u test -p test.txt -s ssh -a 123
$
为FTP添加这些代码行会导致问题:
if (options.service == 'ftp' or 'FTP') and (options.address is None):
print R + "Please specify a host for FTP" + W
sys.exit()
运行脚本会导致:
$ python script.py -u test -p test.txt -s ftp
Please specify a host for SSH
我该如何解决这个问题?我对optparse
做了很多研究,并没有多少帮助我解决这个问题。谢谢!