-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdector.py
43 lines (33 loc) · 1.18 KB
/
dector.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
import json
import re
import argparse
import base64
def detect(path):
print("Checking model", path)
with open(path, "rb") as f:
content = f.read().decode("latin-1")
body = re.search("{(.*)}", content).group()
model = json.loads(body)
found = 0
for layer in model["config"]["layers"]:
if layer['class_name'] != "Lambda":
continue
print("\nFound Lambda layer with name \"" + layer["config"]["name"] + "\"")
func = layer["config"]["function"]
print("With body function:")
print("Raw base64:")
print(func[0])
decoded = base64.b64decode(func[0]).decode("latin-1")
print("Decoded:")
print(decoded)
found += 1
print("\nFound {} Lambda functions".format(found))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Detect malicious Tensorflow model")
parser.add_argument("path", type=str, help="Path of the Tensorflow model")
args = parser.parse_args()
try:
detect(args.path)
except Exception as e:
print("Failed to analyse for Lambda layers, don't give up!")
print(e)