Skip to content

Commit 05efb61

Browse files
committed
Added nil check + formatting edits
1 parent 20a5137 commit 05efb61

File tree

1 file changed

+85
-67
lines changed

1 file changed

+85
-67
lines changed

modules/auxiliary/scanner/http/epmp1000_web_login.rb

Lines changed: 85 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,34 @@ def is_app_epmp1000?
8383
'method' => 'GET'
8484
}
8585
)
86+
8687
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
8788
print_error("#{rhost}:#{rport} - HTTP Connection Failed...")
8889
return false
8990
end
9091

91-
if (res && res.code == 200 && res.headers['Server'] && (res.headers['Server'].include?('Cambium HTTP Server') || res.body.include?('cambiumnetworks.com')))
92+
good_response = (
93+
res &&
94+
res.code == 200 &&
95+
res.headers['Server'] &&
96+
(res.headers['Server'].include?('Cambium HTTP Server') || res.body.include?('cambiumnetworks.com'))
97+
)
9298

99+
if good_response
93100
get_epmp_ver = res.body.match(/"sw_version">([^<]*)/)
94-
epmp_ver = get_epmp_ver[1]
95-
96-
print_good("#{rhost}:#{rport} - Running Cambium ePMP 1000 version #{epmp_ver}...")
97-
return true
98-
101+
if !get_epmp_ver.nil?
102+
epmp_ver = get_epmp_ver[1]
103+
if !epmp_ver.nil?
104+
print_good("#{rhost}:#{rport} - Running Cambium ePMP 1000 version #{epmp_ver}...")
105+
return true
106+
else
107+
print_good("#{rhost}:#{rport} - Running Cambium ePMP 1000...")
108+
return true
109+
end
110+
end
99111
else
100-
101112
print_error("#{rhost}:#{rport} - Application does not appear to be Cambium ePMP 1000. Module will not continue.")
102113
return false
103-
104114
end
105115
end
106116

@@ -109,15 +119,16 @@ def is_app_epmp1000?
109119
#
110120

111121
def do_login(user, pass)
112-
print_status("#{rhost}:#{rport} - Trying username:#{user.inspect} with password:#{pass.inspect}")
113-
122+
print_status("#{rhost}:#{rport} - Attempting to login...")
114123
begin
115-
116124
res = send_request_cgi(
117125
{
118-
'uri' => '/cgi-bin/luci',
119-
'method' => 'POST',
120-
'headers' => { 'X-Requested-With' => 'XMLHttpRequest', 'Accept' => 'application/json, text/javascript, */*; q=0.01' },
126+
'uri' => '/cgi-bin/luci',
127+
'method' => 'POST',
128+
'headers' => {
129+
'X-Requested-With' => 'XMLHttpRequest',
130+
'Accept' => 'application/json, text/javascript, */*; q=0.01'
131+
},
121132
'vars_post' =>
122133
{
123134
'username' => 'dashboard',
@@ -126,63 +137,70 @@ def do_login(user, pass)
126137
}
127138
)
128139

129-
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError, ::Errno::EPIPE
130-
131-
vprint_error("#{rhost}:#{rport} - HTTP Connection Failed...")
132-
return :abort
133-
134-
end
135-
136-
if (res && res.code == 200 && res.headers.include?('Set-Cookie') && res.headers['Set-Cookie'].include?('sysauth'))
137-
138-
sysauth_value = res.headers['Set-Cookie'].match(/((.*)[$ ])/)
139-
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"
140-
141-
res = send_request_cgi(
142-
{
143-
'uri' => '/cgi-bin/luci',
144-
'method' => 'POST',
145-
'cookie' => cookie1,
146-
'headers' => { 'X-Requested-With' => 'XMLHttpRequest', 'Accept' => 'application/json, text/javascript, */*; q=0.01', 'Connection' => 'close' },
147-
'vars_post' =>
148-
{
149-
'username' => user,
150-
'password' => pass
151-
}
152-
}
153-
)
154-
155-
end
156-
157-
if (res && res.code == 200 && res.headers.include?('Set-Cookie') && res.headers['Set-Cookie'].include?('stok='))
158-
159-
print_good("SUCCESSFUL LOGIN - #{rhost}:#{rport} - #{user.inspect}:#{pass.inspect}")
160-
161-
#
162-
# Extract ePMP version
163-
#
164-
res = send_request_cgi(
165-
{
166-
'uri' => '/',
167-
'method' => 'GET'
168-
}
140+
good_response = (
141+
res &&
142+
res.code == 200 &&
143+
res.headers.include?('Set-Cookie') &&
144+
res.headers['Set-Cookie'].include?('sysauth')
169145
)
170146

171-
get_epmp_ver = res.body.match(/"sw_version">([^<]*)/)
172-
epmp_ver = get_epmp_ver[1]
173-
174-
report_cred(
175-
ip: rhost,
176-
port: rport,
177-
service_name: "Cambium ePMP 1000 version #{epmp_ver}",
178-
user: user,
179-
password: pass
147+
if good_response
148+
sysauth_value = res.headers['Set-Cookie'].match(/((.*)[$ ])/)
149+
150+
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"
151+
152+
res = send_request_cgi(
153+
{
154+
'uri' => '/cgi-bin/luci',
155+
'method' => 'POST',
156+
'cookie' => cookie1,
157+
'headers' => {
158+
'X-Requested-With' => 'XMLHttpRequest',
159+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
160+
'Connection' => 'close'
161+
},
162+
'vars_post' =>
163+
{
164+
'username' => user,
165+
'password' => pass
166+
}
167+
}
168+
)
169+
end
170+
171+
good_response = (
172+
res &&
173+
res.code == 200 &&
174+
res.headers.include?('Set-Cookie') &&
175+
res.headers['Set-Cookie'].include?('stok=')
180176
)
181177

182-
else
183-
184-
print_error("FAILED LOGIN - #{rhost}:#{rport} - #{user.inspect}:#{pass.inspect}")
185-
178+
if good_response
179+
print_good("SUCCESSFUL LOGIN - #{rhost}:#{rport} - #{user.inspect}:#{pass.inspect}")
180+
181+
#
182+
# Extract ePMP version
183+
#
184+
res = send_request_cgi(
185+
{
186+
'uri' => '/',
187+
'method' => 'GET'
188+
}
189+
)
190+
191+
epmp_ver = res.body.match(/"sw_version">([^<]*)/)[1]
192+
193+
report_cred(
194+
ip: rhost,
195+
port: rport,
196+
service_name: "Cambium ePMP 1000 version #{epmp_ver}",
197+
user: user,
198+
password: pass
199+
)
200+
201+
else
202+
print_error("FAILED LOGIN - #{rhost}:#{rport} - #{user.inspect}:#{pass.inspect}")
203+
end
186204
end
187205
end
188206
end

0 commit comments

Comments
 (0)