-
Notifications
You must be signed in to change notification settings - Fork 44
/
print_signature.py
46 lines (43 loc) · 1.73 KB
/
print_signature.py
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
import lief
import argparse
import os
import sys
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Process some PE Files')
parser.add_argument('FILE', help='PE File')
parser.add_argument('--verbose', '-v', action="store_true", help='PE File')
args = parser.parse_args()
if os.path.isdir(args.FILE):
# Directory, check all
for f in os.listdir():
if os.path.isfile(os.path.join(args.FILE, f)):
binary = lief.parse(os.path.join(args.FILE, f))
if binary:
if binary.has_signature:
print("{} - SIGNED".format(f))
else:
if args.verbose:
print("{} - NOT SIGNED".format(f))
else:
if args.verbose:
print("{} - NOT A PE FILE".format(f))
elif os.path.isdir(os.path.join(args.FILE, f)):
if args.verbose:
print("{} - Directory".format(f))
elif os.path.isfile(args.FILE):
binary = lief.parse(args.FILE)
if binary.has_signature:
if args.verbose:
for c in binary.signature.certificates:
print(c)
print("")
else:
issuer_serial = ":".join(map(lambda e : "{:02x}".format(e), binary.signature.signer_info.issuer[1]))
for c in binary.signature.certificates:
serial = ":".join(map(lambda e : "{:02x}".format(e), c.serial_number))
if serial == issuer_serial:
print(c)
else:
print("This binary is not signed")
else:
print("Invalid file path")