Skip to content

Commit f39d4a8

Browse files
committed
Fixes dockerfile issues + better temp file handling
1 parent 7eb2c3d commit f39d4a8

3 files changed

Lines changed: 47 additions & 40 deletions

File tree

docker/Dockerfile.zeratool_lib

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
FROM python:3.10
1+
FROM python:3.11
22

33
# Install and configure Poetry
44
RUN pip3 install poetry
55

66
# Setup the convertor from pyproject.toml to requirements.txt
7-
RUN pip3 install click toml
7+
RUN pip3 install click toml tomli
88
RUN wget https://raw.githubusercontent.com/jla524/requirements/main/requirements/convert.py -O /convert.py
99

1010
# Convert Zeratool's dependencies
1111
COPY /docker/zeratool_lib /zeratool_lib
12-
RUN python3 /convert.py --noversion /zeratool_lib
12+
RUN python3 /convert.py --no-version /zeratool_lib
1313
RUN mv /zeratool_lib/requirements.txt /requirements.zeratool_lib.txt
1414

1515
# Copies service's dependencies
1616
COPY /docker/requirements.txt /requirements.service.txt
1717

1818
# Convert module's dependencies
1919
COPY /pyproject.toml /pyproject.toml
20-
RUN python3 /convert.py --noversion /
20+
RUN python3 /convert.py --no-version /
2121
RUN mv /requirements.txt /requirements.aeg.txt
2222

23+
# Download the commons library
24+
RUN git clone https://github.com/CyberReasoningSystem/commons /commons
25+
2326
# Install all dependencies
2427
RUN pip3 install -r /requirements.service.txt
2528
RUN pip3 install -r /requirements.aeg.txt
@@ -30,9 +33,6 @@ COPY /automatic_exploit_generation /automatic_exploit_generation
3033
COPY /docker/protobuf /protobuf
3134
COPY /docker/zeratool_lib_service.py /zeratool_lib_service.py
3235

33-
# Download the commons library
34-
RUN git clone https://github.com/CyberReasoningSystem/commons /commons
35-
3636
# Install Radare2
3737
RUN set -xe; \
3838
wget https://github.com/radareorg/radare2/releases/download/5.9.0/radare2_5.9.0_amd64.deb; \

docker/zeratool_lib_service.py

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,49 @@
1515
YEAR_IN_SECONDS = 365 * 60 * 60 * 24
1616

1717

18-
def _create_temp_binary(content: bytes) -> tempfile.NamedTemporaryFile:
19-
binary = tempfile.NamedTemporaryFile()
20-
21-
binary.write(content)
22-
binary.flush()
23-
24-
os.chmod(binary.name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
25-
26-
return binary
18+
def _create_temp_binary(content: bytes) -> str:
19+
binary = tempfile.NamedTemporaryFile(delete=False)
20+
try:
21+
binary.write(content)
22+
binary.flush()
23+
path = binary.name
24+
finally:
25+
binary.close()
26+
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
27+
return path
2728

2829

2930
class EService(exploit_pb2_grpc.ExploitServiceServicer):
3031
def Exploit(self, request, _):
31-
temp_file = _create_temp_binary(request.binary)
32-
33-
input_stream = ZeratoolInputStreams(request.input_stream)
34-
overflow_only = request.overflow_only
35-
format_only = request.format_only
36-
win_funcs_used = request.serialized_win_funcs.split(",")
37-
if len(win_funcs_used) == 1 and win_funcs_used[0] == '':
38-
win_funcs_used = None
39-
40-
print("temp_file.name: ", temp_file.name)
41-
print("overflow_only: ", overflow_only)
42-
print("format_only: ", format_only)
43-
print("win_funcs_used: ", win_funcs_used)
44-
45-
result = exploit(
46-
temp_file.name,
47-
input_stream,
48-
overflow_only=overflow_only,
49-
format_only=format_only,
50-
win_funcs=win_funcs_used,
51-
)
52-
53-
return exploit_pb2.exploit(pickledExploit=pickle.dumps(result))
32+
temp_path = _create_temp_binary(request.binary)
33+
try:
34+
input_stream = ZeratoolInputStreams(request.input_stream)
35+
overflow_only = request.overflow_only
36+
format_only = request.format_only
37+
win_funcs_used = request.serialized_win_funcs.split(",")
38+
if len(win_funcs_used) == 1 and win_funcs_used[0] == '':
39+
win_funcs_used = None
40+
41+
print("temp_path: ", temp_path)
42+
print("overflow_only: ", overflow_only)
43+
print("format_only: ", format_only)
44+
print("win_funcs_used: ", win_funcs_used)
45+
46+
result = exploit(
47+
temp_path,
48+
input_stream,
49+
overflow_only=overflow_only,
50+
format_only=format_only,
51+
win_funcs=win_funcs_used,
52+
)
53+
54+
return exploit_pb2.exploit(pickledExploit=pickle.dumps(result))
55+
finally:
56+
if os.path.exists(temp_path):
57+
try:
58+
os.unlink(temp_path)
59+
except OSError:
60+
pass
5461

5562

5663
def serve() -> None:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ r2pipe = "^1.8.0"
2323
timeout-decorator = "^0.5.0"
2424
tqdm = "^4.65.0"
2525
commons = {path = "../commons"}
26-
zeratool_lib = {path = "../zeratool_lib"}
26+
zeratool_lib = {path = "../zeratool_lib", develop = true}
2727

2828
[tool.poetry.dev-dependencies]
2929
black = "^22.6.0"

0 commit comments

Comments
 (0)