From 34920f570d3ec1397d66a49a0763201176dff669 Mon Sep 17 00:00:00 2001 From: "Andrew H. Johnston" Date: Thu, 30 May 2024 17:41:51 -0400 Subject: [PATCH 1/2] Add pty to unsafe imports --- fickling/fickle.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fickling/fickle.py b/fickling/fickle.py index f167c46..a81bf2d 100644 --- a/fickling/fickle.py +++ b/fickling/fickle.py @@ -768,6 +768,7 @@ def unsafe_imports(self) -> Iterator[Union[ast.Import, ast.ImportFrom]]: "builtins", "os", "posix", + "pty", "nt", "subprocess", "sys", From c202961fca96fa61da1bc14f725afc44aa02ef78 Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Thu, 20 Jun 2024 16:16:06 -0400 Subject: [PATCH 2/2] Added a test for pty-based execution --- test/test_hook.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test_hook.py b/test/test_hook.py index aa740eb..4b924b4 100644 --- a/test/test_hook.py +++ b/test/test_hook.py @@ -39,13 +39,19 @@ def __reduce__(self): return (os.system, ("echo 'I should have been stopped by the hook'",)) payload = Payload() + # Validate that pty-based execution is captured + payload_pty = b'''(cpty\nspawn\nS"id"\no.''' + # Save the payload in a pickle file with open("unsafe.pickle", "wb") as f: pickle.dump(payload, f) + with open("unsafe_pty.pickle", "wb") as f: + f.write(payload_pty) try: numpy.load("unsafe.pickle", allow_pickle=True) + numpy.load("unsafe_pty.pickle", allow_pickle=True) except UnpicklingError as e: if isinstance(e.__cause__, UnsafeFileError): pass