Skip to content

Instantly share code, notes, and snippets.

@HackingLZ
Created April 19, 2023 13:29
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HackingLZ/b7e5ef65524bb986c16882ef534715c4 to your computer and use it in GitHub Desktop.
Save HackingLZ/b7e5ef65524bb986c16882ef534715c4 to your computer and use it in GitHub Desktop.
altitude alert
import csv
import requests
import argparse
from bs4 import BeautifulSoup
from colorama import Fore, Style, init
init(autoreset=True)
known_security_vendors = [
'symantec', 'mcafee', 'trendmicro', 'kaspersky', 'bitdefender',
'sophos', 'avast', 'avg', 'avira', 'comodo', 'eset', 'f-secure',
'fortinet', 'bit9', 'malwarebytes', 'panda security', 'webroot',
'sentinelone', 'fireeye', 'crowdstrike', 'trendmicro'
]
def download_altitudes(url, output_filename):
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
table_rows = soup.select('table tbody tr')
data = []
for row in table_rows:
cells = row.find_all('td')
minifilter = cells[0].get_text(strip=True)
altitude = cells[1].get_text(strip=True)
company = cells[2].get_text(strip=True)
data.append([minifilter, altitude, company])
with open(output_filename, 'w', newline='', encoding='utf-8') as csvfile:
csv_writer = csv.writer(csvfile)
csv_writer.writerow(['Minifilter', 'Altitude', 'Company'])
csv_writer.writerows(data)
print(f"Data has been written to {output_filename}")
def parse_vendors(altitudes_csv, min_altitude, max_altitude):
vendors = []
with open(altitudes_csv, 'r', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
try:
altitude = float(row['Altitude'])
if min_altitude <= altitude <= max_altitude:
vendors.append(row['Company'])
except ValueError:
# Skip the row if the altitude value cannot be converted to a float
pass
return list(set(vendors))
def lookup_drivers(input_filename, altitudes_csv):
drivers = []
with open(input_filename, 'r', encoding='utf-8') as file:
drivers = [line.strip() for line in file]
found_drivers = []
with open(altitudes_csv, 'r', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['Minifilter'] in drivers:
found_drivers.append(row)
vendors_320000_329998 = parse_vendors(altitudes_csv, 320000, 329998)
for driver in found_drivers:
if any([vendor.lower() in driver['Company'].lower() for vendor in known_security_vendors]):
print(Fore.RED + f"{driver['Minifilter']}, {driver['Altitude']}, {driver['Company']}")
elif driver['Company'] in vendors_320000_329998:
print(Fore.RED + f"{driver['Minifilter']}, {driver['Altitude']}, {driver['Company']}")
else:
print(f"{driver['Minifilter']}, {driver['Altitude']}, {driver['Company']}")
def main():
parser = argparse.ArgumentParser(description='Download and lookup driver altitudes.')
parser.add_argument('-d', '--download', action='store_true', help='Download altitudes data and save it to a CSV file')
parser.add_argument('-l', '--lookup', metavar='FILE', help='Lookup drivers from a file and display their altitudes and companies')
args = parser.parse_args()
url = 'https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/allocated-altitudes'
output_filename = 'allocated_altitudes.csv'
if args.download:
download_altitudes(url, output_filename)
if args.lookup:
lookup_drivers(args.lookup, output_filename)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment