-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (41 loc) · 1.55 KB
/
main.py
File metadata and controls
53 lines (41 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/python3
# Dont want to use too many external libs if I can help it
import lsusbParser
import datetime as dt
import time as t
def compareKnown(devices):
print("[*] Comparing to known devices\n")
# Import list of known "safe" device fingerprints
with open('knownDevices.ids') as f:
knownFingerprints = f.read()
# For each devices, compare its vendorID ([2]) + productID([3]) to a list of known "safe" devices
allKnown = True
for d in devices:
fingerprint = d[2]+":"+d[3]
if(fingerprint not in knownFingerprints):
allKnown = False
print("[!] Unknown device detected")
deviceInformation = lsusbParser.getDeviceInfo(d[0], d[1])
print(" [-] Device: %s" % deviceInformation)
print(" [-] Fingerprint: %s" % fingerprint)
if(allKnown):
print("[*] All devices are known\n")
def main():
# Begin script
time = dt.datetime.fromtimestamp(t.time()).strftime('%H:%M:%S %Y-%m-%d')
print("[!] Starting USB bus scan %s\n" % time)
# Get all devices using lsbusbParser class
print("[*] Getting connected devices\n")
devices, formatDevices = lsusbParser.getDevices()
# Print some information
numConnectedDevices = len(devices)
count = 1
print("[*] Devices connected: %d" % numConnectedDevices)
for d in formatDevices:
print(" [#%d] - %s"% (count, d.decode()))
count+=1
print()
# Compare returned devices to a list of known or "safe" devices
compareKnown(devices)
if __name__ == "__main__":
main()