# -*-coding:utf-8-*-
import hashlib,os,winreg,wmi
# 获取文件md5
def CalcMD5(path):
with open(path, 'rb') as f:
md5obj = hashlib.md5()
md5obj.update(f.read())
hash = md5obj.hexdigest()
return hash
if __name__ == '__main__':
# 程序启动目录
startup_path = r"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp"
# 程序启动目录 列表
startup_path_list = os.listdir(startup_path)
# 删除 desktop.ini
startup_path_list.remove("desktop.ini")
if len(startup_path_list) > 0:
print "-" * 70 + "\n" + "检测:C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp"
for file in startup_path_list:
file_md5 = CalcMD5(os.path.join(startup_path,file))
print {"md5":file_md5,"name":file}
print "-" * 70
else:
print "-" * 70 + "\n" + "检测:C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp - 未发现可疑文件。"
print "-" * 70
# 注册表启动项 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
location = r"Software\Microsoft\Windows\CurrentVersion\Run"
# 获取注册表该位置的所有键值
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, location)
print "\n" + "-"*70 + "\n" + "检测:" + location
i = 0
while True:
try:
# 获取注册表对应位置的键和值
print(winreg.EnumValue(key, i))
i += 1
except OSError as error:
# 一定要关闭这个键
winreg.CloseKey(key)
break
print "-"*70
# 获取正在运行的系统启动服务
print "\n" + "-" * 70 + "\n" + "检测:" + "系统启动服务"
c = wmi.WMI()
for service in c.Win32_Service():
# 状态为 Running 的服务
if str(service.State) == "Running":
print {"name":service.Name,"path":service.PathName}
print "-" * 70
输入内容:
----------------------------------------------------------------------
检测:C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
{'name': 'calc.exe', 'md5': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
----------------------------------------------------------------------
----------------------------------------------------------------------
检测:Software\Microsoft\Windows\CurrentVersion\Run
('ctfmon', u'C:\\WINDOWS\\system32\\ctfmon.exe', 1)
----------------------------------------------------------------------
----------------------------------------------------------------------
检测:系统启动服务
{'path': u'C:\\WINDOWS\\system32\\svchost.exe -k apphost', 'name': u'AppHostSvc'}
{'path': u'C:\\WINDOWS\\system32\\svchost.exe -k netsvcs -p', 'name': u'Appinfo'}
----------------------------------------------------------------------