Skip to content

Commit 4d9bc9c

Browse files
authored
1 parent 173c8f2 commit 4d9bc9c

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = picklescan
3-
version = 1.0.0
3+
version = 1.0.1
44
author = Matthieu Maitre
55
author_email = mmaitre314@users.noreply.github.com
66
description = Security scanner detecting Python Pickle files performing suspicious actions

src/picklescan/scanner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def __str__(self) -> str:
135135
"ctypes": "*", # Foreign function interface, can load DLLs, call C functions, manipulate raw memory
136136
"functools": "partial", # functools.partial(os.system, "echo pwned")
137137
"httplib": "*", # Includes http.client.HTTPSConnection()
138+
"logging": {"FileHandler"}, # logging.FileHandler can create arbitrary files on the filesystem
138139
"_io": {"FileIO"}, # io.FileIO is stored as _io.FileIO, can read arbitrary files bypassing builtins.open blocklist
139140
"numpy.f2py": "*", # Multiple unsafe functions (e.g., getlincoef, _eval_length) that call eval on arbitrary strings
140141
"numpy.testing._private.utils": "*", # runstring() in this module is a synonym for exec()
53 Bytes
Binary file not shown.

tests/init_data_files.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ def reduce_GHSA_49gj_c84q_6qm9():
304304
return cProfile.run, (_payload,)
305305

306306

307+
def reduce_logging_FileHandler():
308+
from logging import FileHandler
309+
310+
return FileHandler, ("evil.log",)
311+
312+
307313
def reduce_GHSA_q77w_mwjj_7mqx():
308314
if sys.platform == "win32":
309315
sys.platform = "mock"
@@ -842,6 +848,7 @@ def initialize_pickle_files():
842848
initialize_pickle_file_from_reduce("GHSA-r8g5-cgf2-4m4m.pkl", reduce_GHSA_r8g5_cgf2_4m4m)
843849
initialize_pickle_file_from_reduce("io_FileIO.pkl", reduce_io_FileIO)
844850
initialize_pickle_file_from_reduce("urllib_request_urlopen.pkl", reduce_urllib_request_urlopen)
851+
initialize_pickle_file_from_reduce("logging_FileHandler.pkl", reduce_logging_FileHandler)
845852

846853
# types.CodeType can construct arbitrary code objects - using raw opcodes since CodeType can't be pickled directly
847854
initialize_data_file(

tests/test_scanner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ def test_scan_file_path():
397397
)
398398
assert_scan("io_FileIO.pkl", [Global("_io", "FileIO", SafetyLevel.Dangerous)])
399399
assert_scan("urllib_request_urlopen.pkl", [Global("urllib.request", "urlopen", SafetyLevel.Dangerous)])
400+
# logging.FileHandler can create arbitrary files on the filesystem
401+
assert_scan("logging_FileHandler.pkl", [Global("logging", "FileHandler", SafetyLevel.Dangerous)])
400402
# types.CodeType can construct arbitrary code objects for execution
401403
assert_scan("types_CodeType.pkl", [Global("types", "CodeType", SafetyLevel.Dangerous)])
402404
# cloudpickle uses _make_function and _builtin_type with CodeType to reconstruct arbitrary callables

0 commit comments

Comments
 (0)