-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from trailofbits/sh/user
More usability improvements
- Loading branch information
Showing
10 changed files
with
144 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Examples | ||
|
||
* [hook_functions.py](https://github.com/trailofbits/fickling/blob/master/example/hook_functions.py): Check the safety of all loaded pickle files using `fickling.always_check_safety()` | ||
* [context_manager.py](https://github.com/trailofbits/fickling/blob/master/example/context_manager.py): Halt the deserialization of a malicious pickle file with the fickling context manager | ||
* [fault_injection.py](https://github.com/trailofbits/fickling/blob/master/example/fault_injection.py): Perform a fault injection on a PyTorch model and then analyze the result with `check_safety` | ||
* [inject_mobilenet.py](https://github.com/trailofbits/fickling/blob/master/example/inject_mobilenet.py): Override the `eval` method of a ML model using fickling and apply `fickling.is_likely_safe` to the model file | ||
* [inject_pytorch.py](https://github.com/trailofbits/fickling/blob/master/example/inject_pytorch.py): Inject a model loaded from a PyTorch file with malicious code using fickling’s PyTorch module | ||
* [numpy_poc.py](https://github.com/trailofbits/fickling/blob/master/example/numpy_poc.py): Analyze a malicious payload passed to `numpy.load()` | ||
* [trace_binary.py](https://github.com/trailofbits/fickling/blob/master/example/trace_binary.py): Decompile a payload using the tracing module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import io | ||
|
||
from astunparse import unparse | ||
|
||
import fickling.tracing as tracing | ||
from fickling.fickle import Interpreter, Pickled | ||
|
||
# Grab mystery binary object | ||
# This comes from https://github.com/maurosoria/dirsearch/issues/1073 | ||
mystery = b"\x80\x04\x95E\x00\x00\x00\x00\x00\x00\x00(\x8c\x08builtins\x8c\x07getattr\x93\x8c\x08builtins\x8c\n__import__\x93\x8c\x02os\x85R\x8c\x06system\x86R\x8c\x02id\x85R1N." # noqa | ||
binary = io.BytesIO(mystery) | ||
|
||
# Load using fickling | ||
fickled = Pickled.load(binary) | ||
|
||
# Trace and print decompiled output | ||
interpreter = Interpreter(fickled) | ||
trace = tracing.Trace(interpreter) | ||
print(unparse(trace.run())) | ||
|
||
""" | ||
Expected Output: | ||
PROTO | ||
FRAME | ||
MARK | ||
Pushed MARK | ||
SHORT_BINUNICODE | ||
Pushed 'builtins' | ||
SHORT_BINUNICODE | ||
Pushed 'getattr' | ||
STACK_GLOBAL | ||
Popped 'getattr' | ||
Popped 'builtins' | ||
Pushed getattr | ||
SHORT_BINUNICODE | ||
Pushed 'builtins' | ||
SHORT_BINUNICODE | ||
Pushed '__import__' | ||
STACK_GLOBAL | ||
Popped '__import__' | ||
Popped 'builtins' | ||
Pushed __import__ | ||
SHORT_BINUNICODE | ||
Pushed 'os' | ||
TUPLE1 | ||
Popped 'os' | ||
Pushed ('os',) | ||
REDUCE | ||
_var0 = __import__('os') | ||
Popped ('os',) | ||
Popped __import__ | ||
Pushed _var0 | ||
SHORT_BINUNICODE | ||
Pushed 'system' | ||
TUPLE2 | ||
Popped 'system' | ||
Popped _var0 | ||
Pushed (_var0, 'system') | ||
REDUCE | ||
_var1 = getattr(_var0, 'system') | ||
Popped (_var0, 'system') | ||
Popped getattr | ||
Pushed _var1 | ||
SHORT_BINUNICODE | ||
Pushed 'id' | ||
TUPLE1 | ||
Popped 'id' | ||
Pushed ('id',) | ||
REDUCE | ||
_var2 = _var1('id') | ||
Popped ('id',) | ||
Popped _var1 | ||
Pushed _var2 | ||
POP_MARK | ||
Popped _var2 | ||
Popped MARK | ||
NONE | ||
Pushed None | ||
STOP | ||
result = None | ||
Popped None | ||
_var0 = __import__('os') | ||
_var1 = getattr(_var0, 'system') | ||
_var2 = _var1('id') | ||
result = None | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters