Skip to content

Commit 60c3882

Browse files
committed
Improved error handling
1 parent dd0c784 commit 60c3882

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

modules/exploits/linux/http/docker_daemon_tcp.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def check_image(image_id)
6161
'method' => 'GET',
6262
'uri' => normalize_uri('images', 'json')
6363
)
64-
return unless res.code == 200 and res.body.include? image_id
64+
return unless res and res.code == 200 and res.body.include? image_id
6565

6666
res
6767
end
@@ -129,14 +129,24 @@ def check
129129
'uri' => normalize_uri('containers', 'json'),
130130
'headers' => { 'Accept' => 'application/json' }
131131
)
132-
return Exploit::CheckCode::Vulnerable if res.code == 200 and res.headers['Server'].include? 'Docker'
132+
133+
if res.nil?
134+
print_error('Failed to connect to the target')
135+
return Exploit::CheckCode::Unknown
136+
end
137+
138+
if res and res.code == 200 and res.headers['Server'].include? 'Docker'
139+
return Exploit::CheckCode::Vulnerable
140+
end
133141

134142
Exploit::CheckCode::Safe
135143
end
136144

137145
def exploit
138146
# check if target is vulnerable
139-
fail_with(Failure::Unknown, 'Failed to connect to the targeturi') if check.nil?
147+
unless check == Exploit::CheckCode::Appears
148+
fail_with(Failure::Unknown, 'Failed to connect to the target')
149+
end
140150

141151
# check if image is not available, pull it or fail out
142152
image_id = datastore['DOCKERIMAGE']

0 commit comments

Comments
 (0)