Skip to content

Commit ac475df

Browse files
committed
Fix gRPC connection issue with retry logic
Handeled `StatusCode.UNAVAILABLE` error with a retry loop and 1s delay Added requests and angr to `pyproject.toml` to fix dependency issues Signed-off-by: Amalia Ionescu <[email protected]>
1 parent 5428fda commit ac475df

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

automatic_exploit_generation/exploiters/zeratool/zeratool.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pickle
22
import typing
3+
import time
34

45
import docker
56
import grpc
@@ -73,6 +74,7 @@ def _run_exploitation_in_container(
7374
ports={"13000/tcp": 13000},
7475
publish_all_ports=True,
7576
)
77+
container.reload()
7678
container_ip = container.attrs["NetworkSettings"]["IPAddress"]
7779
exploit = self._request_exploitation_to_grpc_service(
7880
container_ip, overflow_only, format_only, win_funcs
@@ -103,8 +105,25 @@ def _request_exploitation_to_grpc_service(
103105
format_only=format_only,
104106
serialized_win_funcs=serialized_win_funcs_arg,
105107
)
106-
response = stub.Exploit(query)
107-
exploit = pickle.loads(response.pickledExploit)
108+
109+
num_retries = 0
110+
retry_sleep_time = 1
111+
exploit = None
112+
while num_retries < 30:
113+
try:
114+
response = stub.Exploit(query)
115+
exploit = pickle.loads(response.pickledExploit)
116+
break
117+
except grpc.RpcError as rpc_error:
118+
if rpc_error.code() == grpc.StatusCode.CANCELLED:
119+
pass
120+
elif rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
121+
pass
122+
else:
123+
print(f"Received unknown RPC error: code={rpc_error.code()} message={rpc_error.details()}")
124+
break
125+
time.sleep(retry_sleep_time)
126+
num_retries += 1
108127

109128
return exploit
110129

@@ -127,9 +146,9 @@ def _exploit(self) -> Exploit:
127146
exploit = self._run_exploitation_in_container(
128147
overflow_only, format_only, win_funcs_used
129148
)
149+
130150
if exploit:
131151
return exploit
132-
133152
return None
134153

135154
def _get_win_funcs_names(

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ grpcio = "^1.54.2"
1515
protobuf = "^4.23.2"
1616
click = "^8.1.3"
1717
hexdump = "^3.3"
18+
requests = "2.31.0"
19+
angr = "^9.2.52"
1820
commons = {path = "../commons"}
1921
zeratool_lib = {path = "../zeratool_lib"}
2022

0 commit comments

Comments
 (0)