1
1
import os
2
- from typing import Dict , List
2
+ from typing import Dict , List , Optional
3
3
4
4
import docker
5
5
@@ -67,7 +67,6 @@ class Dogd(Shgd):
67
67
_dockerdir : str
68
68
_dockerfile : str
69
69
_isalpine : bool
70
- _gdbsrvport : int
71
70
_rm : bool
72
71
_ex : bool
73
72
_forward : Dict [str , int ]
@@ -88,8 +87,8 @@ def __init__(
88
87
binary : str ,
89
88
image : str = DEFAULT_IMAGE ,
90
89
user : str = DEFAULT_USER ,
91
- forward : Dict [str , int ] = None ,
92
- packages : List [str ] = None ,
90
+ forward : Optional [ Dict [str , int ] ] = None ,
91
+ packages : Optional [ List [str ] ] = None ,
93
92
symbols = True ,
94
93
rm = True ,
95
94
ex : bool = False ,
@@ -116,11 +115,8 @@ def __init__(
116
115
# trigger package detection in Pwngdb
117
116
packages = list ()
118
117
119
- self ._gdbsrvport = - 1
120
118
self ._dockerdir = Dogd .DOCKERHOME + f"{ self ._image } /"
121
- if not (
122
- os .path .exists (Dogd .DOCKERHOME ) and os .path .exists (self ._dockerdir )
123
- ):
119
+ if not (os .path .exists (Dogd .DOCKERHOME ) and os .path .exists (self ._dockerdir )):
124
120
os .makedirs (self ._dockerdir )
125
121
self ._dockerfile = self ._dockerdir + "Dockerfile"
126
122
self ._user = user
@@ -143,7 +139,6 @@ def __init__(
143
139
ex = ex ,
144
140
fast = fast ,
145
141
symbols = False ,
146
- gdbsrvport = self ._gdbsrvport ,
147
142
** kwargs ,
148
143
)
149
144
@@ -154,11 +149,7 @@ def _create_dockerfile(self):
154
149
155
150
if not os .path .exists (self ._dockerdir + "keyfile.pub" ):
156
151
os .link (Pwngd .PUBKEYFILE , self ._dockerdir + "keyfile.pub" )
157
- template = (
158
- templates .DOCKER_ALPINE_TEMPLATE
159
- if self ._isalpine
160
- else templates .DOCKER_TEMPLATE
161
- )
152
+ template = templates .DOCKER_ALPINE_TEMPLATE if self ._isalpine else templates .DOCKER_TEMPLATE
162
153
163
154
with open (self ._dockerfile , "w" ) as dockerfile :
164
155
dockerfile .write (
@@ -175,9 +166,6 @@ def _create_docker_instance(self):
175
166
helper .info ("starting docker instance" )
176
167
self ._port = helper .first_free_port (Dogd .DEFAULT_PORT )
177
168
self ._forward .update ({"22/tcp" : self ._port })
178
- if self ._isalpine :
179
- self ._gdbsrvport = helper .first_free_port (Pwngd .STATIC_GDBSRV_PORT )
180
- self ._forward .update ({f"{ self ._gdbsrvport } /tcp" : self ._gdbsrvport })
181
169
182
170
dir = os .path .dirname (os .path .realpath (__file__ ))
183
171
with open (dir [: dir .rfind ("/" )] + "/res/seccomp.json" , "r" ) as seccomp_file :
@@ -194,9 +182,7 @@ def _create_docker_instance(self):
194
182
self ._id = container .id
195
183
helper .info (f"started docker instance { container .short_id } " )
196
184
with open (Dogd .LOCKFILE , "w" ) as lockfile :
197
- lockfile .write (
198
- f"{ container .id } :{ str (self ._port )} :{ str (self ._gdbsrvport )} "
199
- )
185
+ lockfile .write (f"{ container .id } :{ str (self ._port )} " )
200
186
201
187
def _build_image (self ):
202
188
build_progress = helper .progress ("building docker image" )
@@ -215,9 +201,7 @@ def _build_image(self):
215
201
tag += "_"
216
202
tag += "symbols"
217
203
218
- bimage = self ._client .images .build (
219
- path = os .path .dirname (self ._dockerfile ), tag = f"vagd/{ tag } "
220
- )[0 ]
204
+ bimage = self ._client .images .build (path = os .path .dirname (self ._dockerfile ), tag = f"vagd/{ tag } " )[0 ]
221
205
222
206
build_progress .success ("done" )
223
207
@@ -239,21 +223,15 @@ def _vm_create(self):
239
223
def _vm_setup (self ) -> None :
240
224
self ._client = docker .from_env ()
241
225
if not os .path .exists (Dogd .LOCKFILE ):
242
- helper .info (
243
- f"No Lockfile { Dogd .LOCKFILE } found, creating new Docker Instance"
244
- )
226
+ helper .info (f"No Lockfile { Dogd .LOCKFILE } found, creating new Docker Instance" )
245
227
self ._vm_create ()
246
228
else :
247
229
with open (Dogd .LOCKFILE , "r" ) as lockfile :
248
230
data = lockfile .readline ().split (":" )
249
231
self ._id = data [0 ]
250
232
self ._port = int (data [1 ])
251
- if self ._isalpine :
252
- self ._gdbsrvport = int (data [2 ])
253
233
if not self ._client .containers .list (filters = {"id" : self ._id }):
254
- helper .info (
255
- f"Lockfile { Dogd .LOCKFILE } found, container not running, creating new one"
256
- )
234
+ helper .info (f"Lockfile { Dogd .LOCKFILE } found, container not running, creating new one" )
257
235
self ._vm_create ()
258
236
else :
259
237
helper .info (
0 commit comments