本文最后更新于:2019 , 八月 19日 星期一, 4:54 下午
声明
仿照即刻安全-九世的文章
参考链接:https://www.cnblogs.com/haq5201314/p/9161618.html
识别windows的未打补丁
Code
思路
- 在cmd中输入
systeminfo
,并自动写入为txt文件 - 判断系统补丁信息文件和危害补丁文件是否存在
- 两个文件进行对比,没有的则打出来
code
#coding:utf-8
import os
import re
import optparse
def main():
parser = optparse.OptionParser()
parser.add_option('-w', dest='windows', help='-w [filename] View windows')
(options,args) = parser.parse_args()
if options.windows:
win()
filename = options.windows
windows(filename)
else:
parser.print_help()
exit()
# 将win系统补丁信息进行提取
def win():
info = os.popen("systeminfo")
win_info = info.read()
res = re.compile('KB\d+')
result = res.findall(win_info)
f = open('win_info.txt','w')
for i in result:
f.write(i+'\n')
f.close()
# 判断文件是否存在
def exists(filename):
File_exists = os.path.exists(filename)
info_exists = os.path.exists('win_info.txt')
if File_exists == True and info_exists == True:
exists = 'success'
return exists
else:
exists = 'failure'
return exists
# 将文本中的内容存入字典中
def win_re(filename):
lists = []
win = open(filename,'r')
res = re.compile('KB\d+')
for i in win:
result = res.findall(i)
for k in result:
lists.append(k)
win.close()
list = []
info = open('win_info.txt', 'r')
for i in info:
list.append(i.strip('\n'))
info.close()
return lists, list
def windows(filename):
file_exists = exists(filename)
if file_exists == 'success':
print('[+] {} exists'.format(filename))
else:
print('[-] {} Not exists'.format(filename))
exit()
x = win_re(filename)
for v in x[0]:
if v in x[1]:
pass
else:
print("[*] " + v)
if __name__ == '__main__':
main()