# Reverse LinkOne devices

## Download the target firmware

{% embed url="<https://link1.com.br/>" %}

For this laboratory, I downloaded this one: **L1-RWH1235AC-V1.2.0.22\_pt\_UCB01.bin**

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgVw3C9fOCgfSloHGFt%2F-MgXGlLoLCnweB4ar2e6%2Fimage.png?alt=media\&token=0b1e68b7-fbc8-4bed-91a3-d9eb70ef3f06)

## Extracting rootfs

```
binwalk -Me L1-RWH1235AC-V1.2.0.22_pt_UCB01.bin 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
64            0x40            TRX firmware header, little endian, image size: 7020544 bytes, CRC32: 0x88D7ED84, flags: 0x0, version: 1, header size: 28 bytes, loader offset: 0x1C, linux kernel offset: 0x1753B0, rootfs offset: 0x0
92            0x5C            LZMA compressed data, properties: 0x5D, dictionary size: 65536 bytes, uncompressed size: 4385244 bytes
1528816       0x1753F0        Squashfs filesystem, little endian, non-standard signature, version 3.0, size: 5486271 bytes, 591 inodes, blocksize: 65536 bytes, created: 2015-03-18 03:43:45
7020640       0x6B2060        LZMA compressed data, properties: 0x5D, dictionary size: 16777216 bytes, uncompressed size: 1398834 bytes
```

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgVw3C9fOCgfSloHGFt%2F-MgXHb5Aley6bXiOD19I%2Fimage.png?alt=media\&token=7d289d8a-72ac-4e9a-81ed-c27b1803fd8d)

You can try to use also this version of squashfs if you got some error like this: **Can't find a SQUASHFS superblock on file.squashfs.** This is a modified version:

{% embed url="<https://github.com/devttys0/sasquatch>" %}

{% hint style="success" %}
gcc version 10 will result in some erros. So, install other version such as 9.x.
{% endhint %}

After that, add it as the principal version when you use make. :sunglasses:&#x20;

```
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100
```

After that, try to get the fs:

```
sudo sasquatch -d rootfs 1753F0.squashfs
```

## User emulation

```
cp /bin/qemu-mipsel-static .
sudo chroot . ./qemu-mipsel-static /bin/sh 
wget https://github.com/firmadyne/libnvram/releases/download/v1.0/libnvram.so.mipsel
(... nvram ...)
export LD_PRELOAD=/firmadyne/libnvram.so
httpd
```

After execute the web-server, or the **/etc/init.d/rcS,** you will get the loop:

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgVw3C9fOCgfSloHGFt%2F-MgXJgetHk3KoU1v-9E4%2Fimage.png?alt=media\&token=e15f8be3-27a2-4592-b14e-44951d393536)

At this point, you can use GDB server to debug it:

{% embed url="<https://gitbook.seguranca-informatica.pt/arm/basic-tips#gdb-server>" %}

Adding a breakpoint on main, and next, you will see the process will enter in a loop inside the "**check\_network**" call.

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgXl9o2RP5f06AnidNF%2F-MgXtrwrNXBzVGmDe3el%2Fimage.png?alt=media\&token=a7cd1a6a-fad0-4a0b-9f11-d5617eb6c181)

and .. check some data ... :sunglasses:&#x20;

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgXtuP0gkH9JPcQC1iJ%2F-MgXuRSytUUonfQbk3jG%2Fimage.png?alt=media\&token=4c3852b5-3cc8-45b9-ae5e-92dec8a3b6fc)

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgXuZBCkGYROOtqY4gt%2F-MgXvv7qT4G1BmoQiu0c%2Fimage.png?alt=media\&token=7a5dfa8f-4e6c-4abb-8a8a-8b2fdd0a17c2)

Using IDA PRO, you can also reverse the httpd file and the check\_network call. Basically, our iface must be renamed to **br0 and use the range 192.168.0.0/24.**

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgVw3C9fOCgfSloHGFt%2F-MgXLAygHFNuNLC1zAVW%2Fimage.png?alt=media\&token=d0505922-ade5-406a-bc07-04de2849d3a9)

```
sudo tunctl -t br0 -u `whoami`
sudo ifconfig br0 192.168.0.0/24
sudo ifconfig br0 up
httpd --debugger --verbose --home /webroot/ --auth /var/auth.txt --route /var/route.txt 127.0.0.1 80
```

You got it :nerd:&#x20;

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgVw3C9fOCgfSloHGFt%2F-MgXLmTG3T2eZ5bwsLuQ%2Fimage.png?alt=media\&token=e65b4784-99cc-42c2-8ded-9be665e5a69f)

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgVw3C9fOCgfSloHGFt%2F-MgXLvPs4y2cLhDHieLs%2Fimage.png?alt=media\&token=89bf9df3-26ad-43c5-8a26-2041d1f20870)

## Full emulation

{% embed url="<https://people.debian.org/~aurel32/qemu/mipsel/>" %}

```
wget https://people.debian.org/~aurel32/qemu/mipsel/debian_squeeze_mipsel_standard.qcow2
wget https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-2.6.32-5-4kc-malta
qemu-system-mipsel -M malta -kernel vmlinux-2.6.32-5-4kc-malta -hda debian_squeeze_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0"
qemu-system-mipsel -M malta -kernel vmlinux-2.6.32-5-4kc-malta -hda debian_squeeze_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0"  -net nic -net user,hostfwd=tcp::7777-:22 

this is the key:
-net nic -net tap,ifname=br0,script=no,downscript=no -nographic 

scp -P 7777 rootfs.tar.gz root@127.0.0.1:/root
ssh -p 7777 root@127.0.0.1
```

### Mount shares

```
mount -t proc /proc ./roofs/proc
mount -o bind /dev ./rootfs/dev
chroot ./roofs/ sh
```

A trick for this router, you can also change the name of the iface: eth0 to br0.

```
nano /etc/udev/rules.d/70-persistent-net.rule
```

&#x20;To rename interface `eth0` to `wan0`, edit `/etc/udev/rules.d/70-persistent-net.rules` file and change `NAME="eth0"` to `NAME="br0"`.

```
# PCI device 0x11ab:0x4363 (sky2)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:00:00:00:00:00",ATTR{dev_id}=="0x0", ATTR{type}=="1",
KERNEL=="eth*", NAME="br0"
```

After that, rename eth0 to br0 here:&#x20;

```
 nano /etc/network/interfaces
```

```
reboot
ifconfig -a
```

{% embed url="<https://www.shellhacks.com/change-network-interface-name-eth0-eth1-eth2/>" %}

On the qemu ssh shell, access the rcS script at: /etc/init.d/rcS, and change the line:&#x20;

```
httpd &

by

httpd --debugger --verbose --home /webroot/ --auth /var/auth.txt --route /var/route.txt 127.0.0.1 80 &
```

After that, execute your file **./rcS** and magic :sunglasses:&#x20;

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgVw3C9fOCgfSloHGFt%2F-MgXOjNuvrYLmunEx310%2Fimage.png?alt=media\&token=95631a2d-ba34-4c07-806c-6f5cc9ead504)

On your browser: **0.0.0.0/login/Auth**

![](https://4052868066-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWd-VcvRHVgUtkahm85%2F-MgVw3C9fOCgfSloHGFt%2F-MgXOvvIb8KJA2eDLyuK%2Fimage.png?alt=media\&token=fdf4a3fe-d923-4797-a295-ac229849e284)

{% embed url="<https://cool-y.github.io/2021/01/08/Netgear-psv-2020-0211/>" %}
