为了账号安全,请及时绑定邮箱和手机立即绑定

python漏洞检测代码怎么编写?

python漏洞检测代码怎么编写?

心有法竹 2018-12-19 19:11:00
python漏洞检测代码怎么编写
查看完整描述

1 回答

?
Cats萌萌

TA贡献1805条经验 获得超9个赞

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()



查看完整回答
反对 回复 2019-01-10
  • 1 回答
  • 0 关注
  • 886 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信