3
3
import importlib
4
4
import io
5
5
import os
6
+ import runpy
6
7
import pickle
7
8
import pytest
8
9
import requests
@@ -83,6 +84,11 @@ def __reduce__(self):
83
84
return pickle .loads , (b"I12345\n ." ,) # Loads the value 12345
84
85
85
86
87
+ class Malicious14 :
88
+ def __reduce__ (self ):
89
+ return runpy ._run_code , ("print('456')" ,)
90
+
91
+
86
92
class HTTPResponse :
87
93
def __init__ (self , status , data = None ):
88
94
self .status = status
@@ -336,6 +342,9 @@ def initialize_pickle_files():
336
342
initialize_pickle_file (
337
343
f"{ _root_path } /data/malicious13b.pkl" , Malicious13 (), 4
338
344
) # pickle module serialized as _pickle
345
+ initialize_pickle_file (
346
+ f"{ _root_path } /data/malicious14.pkl" , Malicious14 (), 4
347
+ ) # runpy
339
348
340
349
initialize_zip_file (
341
350
f"{ _root_path } /data/malicious1.zip" ,
@@ -552,6 +561,13 @@ def test_scan_file_path():
552
561
scan_file_path (f"{ _root_path } /data/bad_pytorch.pt" ), bad_pytorch
553
562
)
554
563
564
+ malicious14 = ScanResult (
565
+ [Global ("runpy" , "_run_code" , SafetyLevel .Dangerous )], 1 , 1 , 1
566
+ )
567
+ compare_scan_results (
568
+ scan_file_path (f"{ _root_path } /data/malicious14.pkl" ), malicious14
569
+ )
570
+
555
571
556
572
def test_scan_directory_path ():
557
573
sr = ScanResult (
@@ -578,6 +594,7 @@ def test_scan_directory_path():
578
594
Global ("requests.api" , "get" , SafetyLevel .Dangerous ),
579
595
Global ("builtins" , "eval" , SafetyLevel .Dangerous ),
580
596
Global ("builtins" , "eval" , SafetyLevel .Dangerous ),
597
+ Global ("runpy" , "_run_code" , SafetyLevel .Dangerous ),
581
598
Global ("socket" , "create_connection" , SafetyLevel .Dangerous ),
582
599
Global ("collections" , "OrderedDict" , SafetyLevel .Innocuous ),
583
600
Global ("torch._utils" , "_rebuild_tensor_v2" , SafetyLevel .Innocuous ),
@@ -594,9 +611,9 @@ def test_scan_directory_path():
594
611
Global ("_pickle" , "loads" , SafetyLevel .Dangerous ),
595
612
Global ("_codecs" , "encode" , SafetyLevel .Suspicious ),
596
613
],
597
- scanned_files = 27 ,
598
- issues_count = 25 ,
599
- infected_files = 22 ,
614
+ scanned_files = 28 ,
615
+ issues_count = 26 ,
616
+ infected_files = 23 ,
600
617
scan_err = True ,
601
618
)
602
619
compare_scan_results (scan_directory_path (f"{ _root_path } /data/" ), sr )
0 commit comments