我已经在 Python 上断断续续有一段时间了(断断续续比断断续续多),但又开始使用“暴力 Python”。我想修改 vuln 扫描器以从端口列表中读取,而不仅仅是使用硬编码列表(此时更多的是出于我自己的理解而非实用性)。
#!/usr/bin/python
# Use banner list
# Scan popular ports on a range of hosts
import socket
import sys
if len(sys.argv)==3:
filename = sys.argv[1]
print "[+] Reading Vulnerabilities From: "+filename
filename2 = sys.argv[2]
print "[+] Reading Ports From: "+filename2
def retBanner(ip, port):
try:
socket.setdefaulttimeout(2)
s = socket.socket()
s.connect((ip, port))
banner = s.recv(1024)
return banner
except:
return
def checkVulns(banner):
f = open(filename,'r')
for line in f.readlines():
if line.strip('\n') in banner:
print "[+] Server is vulnerable: "+banner.strip('\n')
def main():
f2 = open(filename2,'r')
for x in range(1,254):
ip = '192.168.140.' + str(x)
for port in f2.readlines():
banner = retBanner(ip, port)
if banner:
print "[+] "+ip+": "+banner
checkVulns(banner)
if __name__ == '__main__':
main()
这打印,但没有任何反应:
root@kali:~/programming/python# ./vuln-scanner-3.py vuln_banners.txt portlist.txt
[+] Reading Vulnerabilities From: vuln_banners.txt
[+] Reading Ports From: portlist.txt
在单独的屏幕会话中,我正在运行 tcpdump,没有结果(界面正确)
root@kali:~/programming/python# tcpdump -s0 -vvnn -i eth0 net 192.168.140.0 mask 255.255.255.0 and not 192.168.140.1 and port 22
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
关于为什么这不能正常运行的任何想法?提前致谢。