Updated diags.py

This commit is contained in:
2Shirt 2018-12-27 19:52:18 -07:00
parent 10e978d4c5
commit 0a899539c9
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -6,184 +6,186 @@ from functions.common import *
# STATIC VARIABLES # STATIC VARIABLES
AUTORUNS_SETTINGS = { AUTORUNS_SETTINGS = {
r'Software\Sysinternals\AutoRuns': { r'Software\Sysinternals\AutoRuns': {
'checkvirustotal': 1, 'checkvirustotal': 1,
'EulaAccepted': 1, 'EulaAccepted': 1,
'shownomicrosoft': 1, 'shownomicrosoft': 1,
'shownowindows': 1, 'shownowindows': 1,
'showonlyvirustotal': 1, 'showonlyvirustotal': 1,
'submitvirustotal': 0, 'submitvirustotal': 0,
'verifysignatures': 1, 'verifysignatures': 1,
}, },
r'Software\Sysinternals\AutoRuns\SigCheck': { r'Software\Sysinternals\AutoRuns\SigCheck': {
'EulaAccepted': 1, 'EulaAccepted': 1,
}, },
r'Software\Sysinternals\AutoRuns\Streams': { r'Software\Sysinternals\AutoRuns\Streams': {
'EulaAccepted': 1, 'EulaAccepted': 1,
}, },
r'Software\Sysinternals\AutoRuns\VirusTotal': { r'Software\Sysinternals\AutoRuns\VirusTotal': {
'VirusTotalTermsAccepted': 1, 'VirusTotalTermsAccepted': 1,
}, },
} }
def check_connection(): def check_connection():
"""Check if the system is online and optionally abort the script.""" """Check if the system is online and optionally abort the script."""
while True: while True:
result = try_and_print(message='Ping test...', function=ping, cs='OK') result = try_and_print(message='Ping test...', function=ping, cs='OK')
if result['CS']: if result['CS']:
break break
if not ask('ERROR: System appears offline, try again?'): if not ask('ERROR: System appears offline, try again?'):
if ask('Continue anyway?'): if ask('Continue anyway?'):
break break
else: else:
abort() abort()
def check_secure_boot_status(show_alert=False): def check_secure_boot_status(show_alert=False):
"""Checks UEFI Secure Boot status via PowerShell.""" """Checks UEFI Secure Boot status via PowerShell."""
boot_mode = get_boot_mode() boot_mode = get_boot_mode()
cmd = ['PowerShell', '-Command', 'Confirm-SecureBootUEFI'] cmd = ['PowerShell', '-Command', 'Confirm-SecureBootUEFI']
result = run_program(cmd, check=False) result = run_program(cmd, check=False)
# Check results # Check results
if result.returncode == 0: if result.returncode == 0:
out = result.stdout.decode() out = result.stdout.decode()
if 'True' in out: if 'True' in out:
# It's on, do nothing # It's on, do nothing
return return
elif 'False' in out: elif 'False' in out:
if show_alert: if show_alert:
show_alert_box('Secure Boot DISABLED') show_alert_box('Secure Boot DISABLED')
raise SecureBootDisabledError raise SecureBootDisabledError
else:
if show_alert:
show_alert_box('Secure Boot status UNKNOWN')
raise SecureBootUnknownError
else: else:
if boot_mode != 'UEFI': if show_alert:
if (show_alert and show_alert_box('Secure Boot status UNKNOWN')
global_vars['OS']['Version'] in ('8', '8.1', '10')): raise SecureBootUnknownError
# OS supports Secure Boot else:
show_alert_box('Secure Boot DISABLED\n\nOS installed LEGACY') if boot_mode != 'UEFI':
raise OSInstalledLegacyError if (show_alert and
else: global_vars['OS']['Version'] in ('8', '8.1', '10')):
# Check error message # OS supports Secure Boot
err = result.stderr.decode() show_alert_box('Secure Boot DISABLED\n\nOS installed LEGACY')
if 'Cmdlet not supported' in err: raise OSInstalledLegacyError
if show_alert: else:
show_alert_box('Secure Boot UNAVAILABLE?') # Check error message
raise SecureBootNotAvailError err = result.stderr.decode()
else: if 'Cmdlet not supported' in err:
if show_alert: if show_alert:
show_alert_box('Secure Boot ERROR') show_alert_box('Secure Boot UNAVAILABLE?')
raise GenericError raise SecureBootNotAvailError
else:
if show_alert:
show_alert_box('Secure Boot ERROR')
raise GenericError
def get_boot_mode(): def get_boot_mode():
"""Check if Windows is booted in UEFI or Legacy mode, returns str.""" """Check if Windows is booted in UEFI or Legacy mode, returns str."""
kernel = ctypes.windll.kernel32 kernel = ctypes.windll.kernel32
firmware_type = ctypes.c_uint() firmware_type = ctypes.c_uint()
# Get value from kernel32 API # Get value from kernel32 API
try: try:
kernel.GetFirmwareType(ctypes.byref(firmware_type)) kernel.GetFirmwareType(ctypes.byref(firmware_type))
except: except:
# Just set to zero # Just set to zero
firmware_type = ctypes.c_uint(0) firmware_type = ctypes.c_uint(0)
# Set return value # Set return value
type_str = 'Unknown' type_str = 'Unknown'
if firmware_type.value == 1: if firmware_type.value == 1:
type_str = 'Legacy' type_str = 'Legacy'
elif firmware_type.value == 2: elif firmware_type.value == 2:
type_str = 'UEFI' type_str = 'UEFI'
return type_str return type_str
def run_autoruns(): def run_autoruns():
"""Run AutoRuns in the background with VirusTotal checks enabled.""" """Run AutoRuns in the background with VirusTotal checks enabled."""
extract_item('Autoruns', filter='autoruns*', silent=True) extract_item('Autoruns', filter='autoruns*', silent=True)
# Update AutoRuns settings before running # Update AutoRuns settings before running
for path, settings in AUTORUNS_SETTINGS.items(): for path, settings in AUTORUNS_SETTINGS.items():
winreg.CreateKey(HKCU, path) winreg.CreateKey(HKCU, path)
with winreg.OpenKey(HKCU, path, access=winreg.KEY_WRITE) as key: with winreg.OpenKey(HKCU, path, access=winreg.KEY_WRITE) as key:
for name, value in settings.items(): for name, value in settings.items():
winreg.SetValueEx(key, name, 0, winreg.REG_DWORD, value) winreg.SetValueEx(key, name, 0, winreg.REG_DWORD, value)
popen_program(global_vars['Tools']['AutoRuns'], minimized=True) popen_program(global_vars['Tools']['AutoRuns'], minimized=True)
def run_hwinfo_sensors(): def run_hwinfo_sensors():
"""Run HWiNFO sensors.""" """Run HWiNFO sensors."""
path = r'{BinDir}\HWiNFO'.format(**global_vars) path = r'{BinDir}\HWiNFO'.format(**global_vars)
for bit in [32, 64]: for bit in [32, 64]:
# Configure # Configure
source = r'{}\general.ini'.format(path) source = r'{}\general.ini'.format(path)
dest = r'{}\HWiNFO{}.ini'.format(path, bit) dest = r'{}\HWiNFO{}.ini'.format(path, bit)
shutil.copy(source, dest) shutil.copy(source, dest)
with open(dest, 'a') as f: with open(dest, 'a') as f:
f.write('SensorsOnly=1\n') f.write('SensorsOnly=1\n')
f.write('SummaryOnly=0\n') f.write('SummaryOnly=0\n')
popen_program(global_vars['Tools']['HWiNFO']) popen_program(global_vars['Tools']['HWiNFO'])
def run_nircmd(*cmd): def run_nircmd(*cmd):
"""Run custom NirCmd.""" """Run custom NirCmd."""
extract_item('NirCmd', silent=True) extract_item('NirCmd', silent=True)
cmd = [global_vars['Tools']['NirCmd'], *cmd] cmd = [global_vars['Tools']['NirCmd'], *cmd]
run_program(cmd, check=False) run_program(cmd, check=False)
def run_xmplay(): def run_xmplay():
"""Run XMPlay to test audio.""" """Run XMPlay to test audio."""
extract_item('XMPlay', silent=True) extract_item('XMPlay', silent=True)
cmd = [global_vars['Tools']['XMPlay'], cmd = [global_vars['Tools']['XMPlay'],
r'{BinDir}\XMPlay\music.7z'.format(**global_vars)] r'{BinDir}\XMPlay\music.7z'.format(**global_vars)]
# Unmute audio first # Unmute audio first
extract_item('NirCmd', silent=True) extract_item('NirCmd', silent=True)
run_nircmd('mutesysvolume', '0') run_nircmd('mutesysvolume', '0')
# Open XMPlay # Open XMPlay
popen_program(cmd) popen_program(cmd)
def run_hitmanpro(): def run_hitmanpro():
"""Run HitmanPro in the background.""" """Run HitmanPro in the background."""
extract_item('HitmanPro', silent=True) extract_item('HitmanPro', silent=True)
cmd = [ cmd = [
global_vars['Tools']['HitmanPro'], global_vars['Tools']['HitmanPro'],
'/quiet', '/noinstall', '/noupload', '/quiet', '/noinstall', '/noupload',
r'/log={LogDir}\Tools\HitmanPro.txt'.format(**global_vars)] r'/log={LogDir}\Tools\HitmanPro.txt'.format(**global_vars)]
popen_program(cmd) popen_program(cmd)
def run_process_killer(): def run_process_killer():
"""Kill most running processes skipping those in the whitelist.txt.""" """Kill most running processes skipping those in the whitelist.txt."""
# borrowed from TronScript (reddit.com/r/TronScript) # borrowed from TronScript (reddit.com/r/TronScript)
# credit to /u/cuddlychops06 # credit to /u/cuddlychops06
prev_dir = os.getcwd() prev_dir = os.getcwd()
extract_item('ProcessKiller', silent=True) extract_item('ProcessKiller', silent=True)
os.chdir(r'{BinDir}\ProcessKiller'.format(**global_vars)) os.chdir(r'{BinDir}\ProcessKiller'.format(**global_vars))
run_program(['ProcessKiller.exe', '/silent'], check=False) run_program(['ProcessKiller.exe', '/silent'], check=False)
os.chdir(prev_dir) os.chdir(prev_dir)
def run_rkill(): def run_rkill():
"""Run RKill and cleanup afterwards.""" """Run RKill and cleanup afterwards."""
extract_item('RKill', silent=True) extract_item('RKill', silent=True)
cmd = [ cmd = [
global_vars['Tools']['RKill'], global_vars['Tools']['RKill'],
'-s', '-l', r'{LogDir}\Tools\RKill.log'.format(**global_vars), '-s', '-l', r'{LogDir}\Tools\RKill.log'.format(**global_vars),
'-new_console:n', '-new_console:s33V'] '-new_console:n', '-new_console:s33V']
run_program(cmd, check=False) run_program(cmd, check=False)
wait_for_process('RKill') wait_for_process('RKill')
# RKill cleanup # RKill cleanup
desktop_path = r'{USERPROFILE}\Desktop'.format(**global_vars['Env']) desktop_path = r'{USERPROFILE}\Desktop'.format(**global_vars['Env'])
if os.path.exists(desktop_path): if os.path.exists(desktop_path):
for item in os.scandir(desktop_path): for item in os.scandir(desktop_path):
if re.search(r'^RKill', item.name, re.IGNORECASE): if re.search(r'^RKill', item.name, re.IGNORECASE):
dest = r'{LogDir}\Tools\{name}'.format( dest = r'{LogDir}\Tools\{name}'.format(
name=dest, **global_vars) name=dest, **global_vars)
dest = non_clobber_rename(dest) dest = non_clobber_rename(dest)
shutil.move(item.path, dest) shutil.move(item.path, dest)
def show_alert_box(message, title='Wizard Kit Warning'): def show_alert_box(message, title='Wizard Kit Warning'):
"""Show Windows alert box with message.""" """Show Windows alert box with message."""
message_box = ctypes.windll.user32.MessageBoxW message_box = ctypes.windll.user32.MessageBoxW
message_box(None, message, title, 0x00001030) message_box(None, message, title, 0x00001030)
if __name__ == '__main__': if __name__ == '__main__':
print("This file is not meant to be called directly.") print("This file is not meant to be called directly.")
# vim: sts=2 sw=2 ts=2