-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference_monitor.r2py
More file actions
67 lines (48 loc) · 2.06 KB
/
reference_monitor.r2py
File metadata and controls
67 lines (48 loc) · 2.06 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
"""
This security layer inadequately handles A/B storage for files in RepyV2.
Note:
This security layer uses encasementlib.r2py, restrictions.default, repy.py and Python
Also you need to give it an application to run.
python repy.py restrictions.default encasementlib.r2py [security_layer].r2py [attack_program].r2py
"""
TYPE="type"
ARGS="args"
RETURN="return"
EXCP="exceptions"
TARGET="target"
FUNC="func"
OBJC="objc"
class ABFile():
def __init__(self,filename,create):
# globals
mycontext['debug'] = False
# local (per object) reference to the underlying file
self.Afn = filename+'.a'
self.Bfn = filename+'.b'
# make the files and add 'SE' to the readat file...
if create:
self.Afile = openfile(self.Afn,create)
self.Bfile = openfile(self.Bfn,create)
self.Afile.writeat('SE',0)
def writeat(self,data,offset):
# Write the requested data to the B file using the sandbox's writeat call
self.Bfile.writeat(data,offset)
def readat(self,bytes,offset):
# Read from the A file using the sandbox's readat...
return self.Afile.readat(bytes,offset)
def close(self):
self.Afile.close()
self.Bfile.close()
def ABopenfile(filename, create):
return ABFile(filename,create)
# The code here sets up type checking and variable hiding for you. You
# should not need to change anything below here.
sec_file_def = {"obj-type":ABFile,
"name":"ABFile",
"writeat":{"type":"func","args":(str,int),"exceptions":Exception,"return":(int,type(None)),"target":ABFile.writeat},
"readat":{"type":"func","args":((int,type(None)),(int)),"exceptions":Exception,"return":str,"target":ABFile.readat},
"close":{"type":"func","args":None,"exceptions":None,"return":(bool,type(None)),"target":ABFile.close}
}
CHILD_CONTEXT_DEF["ABopenfile"] = {TYPE:OBJC,ARGS:(str,bool),EXCP:Exception,RETURN:sec_file_def,TARGET:ABopenfile}
# Execute the user code
secure_dispatch_module()