-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtest_bypasses.py
More file actions
85 lines (79 loc) · 2.73 KB
/
test_bypasses.py
File metadata and controls
85 lines (79 loc) · 2.73 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import marshal
from unittest import TestCase
import fickling.fickle as op
from fickling.analysis import Severity, check_safety
from fickling.fickle import Pickled
class TestBypasses(TestCase):
# https://github.com/trailofbits/fickling/security/advisories/GHSA-r7v6-mfhq-g3m2
def test_missing_pty_unsafe_imports_ghsa(self):
pickled = Pickled(
[
op.Proto.create(4),
op.Frame(26),
op.ShortBinUnicode("pty"),
op.Memoize(),
op.ShortBinUnicode("spawn"),
op.Memoize(),
op.StackGlobal(),
op.Memoize(),
op.ShortBinUnicode("id"),
op.Memoize(),
op.TupleOne(),
op.Memoize(),
op.Reduce(),
op.Memoize(),
op.ShortBinUnicode("gottem"),
op.Memoize(),
op.Build(),
op.Stop(),
]
)
self.assertGreater(check_safety(pickled).severity, Severity.LIKELY_SAFE)
# https://github.com/trailofbits/fickling/pull/108
def test_missing_pty_unsafe_imports_pr(self):
pickled = Pickled(
[
op.Mark(),
op.Global("pty spawn"),
op.String("id"),
op.Obj(),
op.Stop(),
]
)
self.assertGreater(check_safety(pickled).severity, Severity.LIKELY_SAFE)
# https://github.com/trailofbits/fickling/security/advisories/GHSA-565g-hwwr-4pp3
def test_missing_marshal_and_types(self):
code = compile('import os\nos.system("id")', "<string>", "exec")
opcodes = Pickled(
[
op.Proto(4),
op.Frame(0),
op.ShortBinUnicode("marshal"),
op.ShortBinUnicode("loads"),
op.StackGlobal(),
op.Memoize(),
op.BinGet(0),
op.ShortBinBytes(marshal.dumps(code)),
op.TupleOne(),
op.Reduce(),
op.Memoize(),
op.ShortBinUnicode("types"),
op.ShortBinUnicode("FunctionType"),
op.StackGlobal(),
op.Memoize(),
op.BinGet(2),
op.BinGet(1),
op.EmptyDict(),
op.TupleTwo(),
op.Reduce(),
op.Memoize(),
op.BinGet(3),
op.EmptyTuple(),
op.Reduce(),
op.Memoize(),
op.ShortBinUnicode("gottem"),
op.Build(),
op.Stop(),
]
)
self.assertGreater(check_safety(opcodes).severity, Severity.LIKELY_SAFE)