python漏洞检测代码怎么编写
1个回答
2017-06-19
展开全部
import socket
import os
import sys
port = 21
banner = "FreeFloat FTP Server"
portList = [21,22,80,110]
portOpen = True
services = {'ftp':21, 'ssh':22, 'smtp':25, 'http':80}
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,filename):
f = open(filename,'r')
for line in f.readlines():
if line.strip('\n') in banner:
print '[+] Server is vulnerable: ' + banner.strip('\n')
def main():
if len(sys.argv) == 2:
filename = sys.argv[1]
if not os.path.isfile(filename):
print '[-] ' +filename + ' does not exist.'
exit(0)
if not os.access(filename, os.R_OK):
print '[-] ' +filename + ' access denied.'
exit(0)
else:
print '[-] Usage: ' + str(sys.argv[0]) + ' <vuln filename>'
exit(0)
portList = [21,22,25,80,110,443]
for x in range(147,150):
ip = '192.168.95.' + str(x)
for port in portList:
banner = retBanner(ip,port)
if banner:
print '[+] ' + ip + ': ' + banner
checkVulns(banner, filename)
if __name__ == '__main__':
main()
复制代码
import os
import sys
port = 21
banner = "FreeFloat FTP Server"
portList = [21,22,80,110]
portOpen = True
services = {'ftp':21, 'ssh':22, 'smtp':25, 'http':80}
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,filename):
f = open(filename,'r')
for line in f.readlines():
if line.strip('\n') in banner:
print '[+] Server is vulnerable: ' + banner.strip('\n')
def main():
if len(sys.argv) == 2:
filename = sys.argv[1]
if not os.path.isfile(filename):
print '[-] ' +filename + ' does not exist.'
exit(0)
if not os.access(filename, os.R_OK):
print '[-] ' +filename + ' access denied.'
exit(0)
else:
print '[-] Usage: ' + str(sys.argv[0]) + ' <vuln filename>'
exit(0)
portList = [21,22,25,80,110,443]
for x in range(147,150):
ip = '192.168.95.' + str(x)
for port in portList:
banner = retBanner(ip,port)
if banner:
print '[+] ' + ip + ': ' + banner
checkVulns(banner, filename)
if __name__ == '__main__':
main()
复制代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询