Slide 1

Slide 1 text

武蔵野さんを真似て 武蔵野さんを真似て 中古ルーターを分解した話 中古ルーターを分解した話 Daniel Sangorrin ( ダニエル ) @daromart https://speakerdeck.com/sangorrin https://sangorrin.blogspot.com/ https://github.com/sangorrin 東海道らぐ横浜集い2018冬の巻( 2018/12/15 )

Slide 2

Slide 2 text

10 月 27 日の OSC で 武蔵野さんのブ ースによったら

Slide 3

Slide 3 text

改めて、これは楽しいな と思った。僕もやりたい!

Slide 4

Slide 4 text

武蔵野さん、 ルータの分解には どんな道具がいい?

Slide 5

Slide 5 text

こういうのはいい 買いました!

Slide 6

Slide 6 text

それで、ある日 となりのハードオフで…

Slide 7

Slide 7 text

買っちゃいました!

Slide 8

Slide 8 text

主なスペック ● 値段: 480 円 ● 型番: TL-WR841N (JP) ● Flash : 4 MiB (少なくて楽しい) ● RAM : 32 MiB ● ファームとソースを DL できるサイト: ● https://www.tp-link.com/jp/download/T L-WR841N.html ● イーサネットポート数: 4 個 + WAN ● コンフィギュレーション画面: ● http://192.168.0.1 (admin:admin)

Slide 9

Slide 9 text

さー、あのカッコいい ドライバを使って みなきゃ

Slide 10

Slide 10 text

あれれ?

Slide 11

Slide 11 text

あれれ? https://ameblo.jp/fkifs600/entry-12288407770.html

Slide 12

Slide 12 text

Android 携帯用の マクロレンズで チップを調べよう

Slide 13

Slide 13 text

RAM だな!

Slide 14

Slide 14 text

Qualcomm だな!

Slide 15

Slide 15 text

SoC のスペック ● Chip: QCA9533-BL3A ● Qualcomm atheros ● MIPS 24Kc, 650 MHz – https://wikidevi.com/wiki/MIPS_24K ● GPIO: 18 multiplexed pins ● JTAG: GPIO 0,1,2,3 = TCK, TDI, TDO, TMS ● UART 16650-equivalent (115200 bps): GPIO 10, 11 ● レジスターのマニュアルは github の怪しいリポジトリで見付けた ● https://github.com/Deoptim/atheros/

Slide 16

Slide 16 text

SoC のスペック

Slide 17

Slide 17 text

シリアルポートを 探して、 ハンダ付けしよう

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Rx は R26 で 2.5V に pull-up になってたぜ

Slide 20

Slide 20 text

Vcc やな!

Slide 21

Slide 21 text

GND やな!

Slide 22

Slide 22 text

Rx やな!

Slide 23

Slide 23 text

Tx やな!

Slide 24

Slide 24 text

Vcc を繋ぐな!

Slide 25

Slide 25 text

成功。。。 U-Boot 1.1.4 (Mar 25 2016 - 16:59:35) ap143-2.0 - Honey Bee 2.0 DRAM: 32 MB Flash Manuf Id 0xc8, DeviceId0 0x40, DeviceId1 0x16 flash size 4MB, sector count = 64 Flash: 4 MB Using default environment In: serial Out: serial Err: serial Net: ath_gmac_enet_initialize... Starting kernel ... Booting QCA953x Linux version 2.6.31 (tomcat@buildserver) (gcc version 4.3.3 (GCC) ) #13 Fri Mar 25

Slide 26

Slide 26 text

だが。。。 TL-WR841N login: root Password: Login incorrect TL-WR841N login: admin Password: Login incorrect TL-WR841N login: root Password: Login incorrect Jan 1 00:03:30 login[199]: invalid password for `root' on `ttyS0' パスワードはなんなんやろう!

Slide 27

Slide 27 text

ファームウェアを 分析しよう

Slide 28

Slide 28 text

binwalk はすごい! $ git clone https://github.com/ReFirmLabs/binwalk.git $ cd binwalk/ $ sudo ./deps.sh $ sudo python setup.py install $ binwalk -t wr841nv11_jp_3_16_9_up_boot\(160518\).bin DECIMAL HEXADECIMAL DESCRIPTION ------------------------------------------------------------------------------------------------------------------- 0 0x0 TP-Link firmware header, firmware version: 0.-15276.3, image version: "", product ID: 0x0, product version: 138477585, kernel load address: 0x0, kernel entry point: 0x80002000, kernel offset: 4063744, kernel length: 512, rootfs offset: 849290, rootfs length: 1048576, bootloader offset: 2883584, bootloader length: 0 13424 0x3470 U-Boot version string, "U-Boot 1.1.4 (Mar 25 2016 - 16:59:44)" 13472 0x34A0 CRC32 polynomial table, big endian 14784 0x39C0 uImage header, header size: 64 bytes, header CRC: 0x85572A9C, created: 2016-03-25 08:59:46, image size: 35924 bytes, Data Address: 0x80010000, Entry Point: 0x80010000, data CRC: 0xADACFD5C, OS: Linux, CPU: MIPS, image type: Firmware Image, compression type: lzma, image name: "u-boot image" 14848 0x3A00 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 93944 bytes 131584 0x20200 TP-Link firmware header, firmware version: 0.0.3, image version: "", product ID: 0x0, product version: 138477585, kernel load address: 0x0, kernel entry point: 0x80002000, kernel offset: 3932160, kernel length: 512, rootfs offset: 849290, rootfs length: 1048576, bootloader offset: 2883584, bootloader length: 0 132096 0x20400 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 2495224 bytes 1180160 0x120200 Squashfs filesystem, little endian, version 4.0, compression:lzma, size: 2791548 bytes, 590 inodes, blocksize: 131072 bytes, created: 2016-05-18 09:05:32 ルーターのファーム

Slide 29

Slide 29 text

/etc/shadow $ cat _wr841nv11_jp_3_16_9_up_boot\(160518\).bin.extracted/squashfs-root/etc/shadow root:$1$GTN.gpri$DlSyKvZKMR9A9Uj9e9wR3/:15502:0:99999:7::: http://www.consumer.es/web/es/mascotas/perros/convivencia-y-psicologia/convivencia/2013/04/02/216310.php

Slide 30

Slide 30 text

hashcat をインストール $ sudo service lightdm stop $ ./NVIDIA-Linux-x86_64-410.78.run $ sudo apt-get install ocl-icd-libopencl1 opencl-headers clinfo $ git clone https://github.com/hashcat/hashcat $ hashcat -I hashcat (v5.0.0-113-g774b9bb) starting... OpenCL Info: Platform ID #1 Vendor : NVIDIA Corporation Name : NVIDIA CUDA Version : OpenCL 1.2 CUDA 10.0.206 Device ID #1 Type : GPU Vendor ID : 32 Vendor : NVIDIA Corporation

Slide 31

Slide 31 text

hashcat の使い方 $ echo -n mypass | md5sum a029d0df84eb5549c641e04a9ef389e5 $ hashcat -w 2 -m 0 -a 3 -1 ?l a029d0df84eb5549c641e04a9ef389e5 ?1?1?1?1?1?1 -> a029d0df84eb5549c641e04a9ef389e5:mypass ● hashcat syntax -m hash-type (md5:0) -a attack-mode (brute-force:3) -1 custom charset number 1 l:lowercase, u:uppercase, d:digits, h:hex, H:hexupper, s:symbols a:luds -w performance (1:minimal, 2:noticeable 3:unresponsive 4:headless) ?1?1?1?1?1?1: this means a word with 6 letters, where each letter can be in charset 1 (-1 ?l <-- a lower case letter)

Slide 32

Slide 32 text

がんばれ! $ hashcat -w 2 -m 500 -a 3 -1 ?l shadow ?1?1?1?1?1?1?1 [s]tatus [p]ause [b]ypass [c]heckpoint [q]uit => s Session..........: hashcat Status...........: Running Hash.Type........: md5crypt, MD5 (Unix), Cisco-IOS $1$ (MD5) Hash.Target......: $1$GTN.gpri$DlSyKvZKMR9A9Uj9e9wR3/ Time.Started.....: Sun Dec 2 10:58:58 2018 (20 secs) Time.Estimated...: Tue Dec 4 12:34:57 2018 (2 days, 1 hour) パスワードは 9 文字を 推測の場合

Slide 33

Slide 33 text

近道 $ hashcat --potfile-disable -i --increment-min=6 -w 3 -m 500 -a 3 -1 ?l -O shadow \ ?1?1?1?1admin パスワードは 6 ~ 9 文字で admin で終わることを 推測の場合 $1$GTN.gpri$DlSyKvZKMR9 A9Uj9e9wR3/:sohoadmin

Slide 34

Slide 34 text

実は このハッシュを グーグルで探せば 出てくる

Slide 35

Slide 35 text

さー、動くのかな!

Slide 36

Slide 36 text

成功!

Slide 37

Slide 37 text

よし、次はソースからビ ルドしたい!

Slide 38

Slide 38 text

ソースのビルド [Note] Host: ubuntu 12, gcc 4.6.3, make 3.81 $ tar xvf TL-WR841NV11_eu.tar.gz $ cd TL-WR841NV11_eu/build $ make 意外と簡単! make mk_squashfs_build fs_size=0x2C0000 make fill_model_conf cp: cannot stat ‘/home/dsl/Desktop/tl-wr841n/rootfs/source/TL- WR841NV11_eu/build/../build/products_config/wr841nv11_eu//version.conf’: No such file or directory make[2]: [fill_model_conf] Error 1 (ignored) ENCRYPT len:1496 fakeroot: preload library `libfakeroot.so' not found, aborting. make: *** [wr841nv11_eu] Error 2 エラー!

Slide 39

Slide 39 text

何のエラーだろう!? $ less ./util/fakeroot/install/bin/fakeroot FAKEROOT_PREFIX=/home/liqiang/workdir/NewCodePath/Base_version/model_qca/build/../util/fakeroot/install FAKEROOT_BINDIR=/home/liqiang/workdir/NewCodePath/Base_version/model_qca/build/../util/fakeroot/install/bin PATHS=/home/liqiang/workdir/NewCodePath/Base_version/model_qca/build/../util/fakeroot/install/lib:$ {FAKEROOT_PREFIX}/lib64/libfakeroot:${FAKEROOT_PREFIX}/lib32/libfakeroot liqiang さん、 元気ですか $ vi ./util/fakeroot/install/bin/fakeroot - /home/liqiang/workdir/NewCodePath/Base_version/model_qca/build/../util/ + /home/myuser/Desktop/tl-wr841n/rootfs/source/TL-WR841NV11_eu/util 簡単なフィックス

Slide 40

Slide 40 text

調べると、このルーター は深センの南山でつく られた

Slide 41

Slide 41 text

Makerfaire の場所!

Slide 42

Slide 42 text

どんなものが入るの? ● /bin/busybox ● /sbin/80211stats ● /sbin/apstats ● /sbin/athstats ● /sbin/athstatsclr ● /sbin/iptables-multi ● /sbin/pktlogconf ● /sbin/pktlogdump ● /sbin/tc ● /sbin/wifitool ● /sbin/wlanconfig ● /usr/arp ● /usr/net_ioctl ● /usr/bin/lld2d ● /usr/sbin/bpalogin ● /usr/sbin/dropbearmulti ● /usr/sbin/pppd ● /usr/sbin/xl2tpd

Slide 43

Slide 43 text

ちょっとだけ変更して ファームを アップグレードしてみる

Slide 44

Slide 44 text

GPIO 操作したい - kernel.conf CONFIG_GPIOLIB=y CONFIG_GPIO_SYSFS=y $ vi drivers/gpio/Kconfig - remove dependency on arch_want_gpiolib - fstab $ find . -iname fstab $ vi ./filesystem/ap93fus/etc/fstab sysfs /sys sysfs nosuid,noexec,nodev 0

Slide 45

Slide 45 text

ビルドして、アップグレードすると 0x000000000000-0x000000020000 : "u-boot" 0x000000020000-0x000000120000 : "kernel" 0x000000120000-0x0000003e0000 : "rootfs" 0x0000003e0000-0x0000003f0000 : "config" 0x0000003f0000-0x000000400000 : "art" ->Oops: flash id 0xc84016 . Ooops, why the devices couldn't been initialed? TCP cubic registered NET: Registered protocol family 10 NET: Registered protocol family 17 802.1Q VLAN Support v1.8 Ben Greear All bugs added by David S. Miller athwdt_init: Registering WDT success VFS: Mounted root (squashfs filesystem) readonly on device 31:2. Freeing unused kernel memory: 120k freed Please be patient, while OpenWrt loads .. ... BRICK しちゃった!

Slide 46

Slide 46 text

オリジナルの復元 $ sudo ifconfig eth0:1 192.168.0.66 netmask 255.255.255.0 $ sudo cp wr841nv11_jp_3_16_9_up_boot\(160518\).bin /var/lib/tftpboot/wr841nv11_tp_recovery.bin 後は ボタンは2つを押しながら 再起動

Slide 47

Slide 47 text

UNBRICK できた! TFTP from server 192.168.0.66; our IP address is 192.168.0.86 Filename 'wr841nv11_tp_recovery.bin'. Load address: 0x80800000 Loading: ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ############## done Bytes transferred = 4063744 (3e0200 hex) Firmware recovery: product id verify sucess! Firmware recovery: filesize = 0x3e0200. Erasing flash... First 0x2 last 0x3d sector size 0x10000 61 Erased 60 sectors Copy to Flash... write addr: 9f020000 done UNBRICK 成功!

Slide 48

Slide 48 text

次は何しようかな

Slide 49

Slide 49 text

やりたいこと ● GPIO は使えるようにして、サーボやリモコン を操作できるように ● WiFi のサーバーにアプリを作って、携帯から API を使えるように ● 例:携帯からリモコンを操作して、エアコン やライトを動作する ● JTAG のピンを探して、 JTAG の勉強もしたい

Slide 50

Slide 50 text

後、ハードオフで 新しいオモチャを 買ったので それの分解も やりたい

Slide 51

Slide 51 text

参考文献 ● https://oldwiki.archive.openwrt.org/toh/tp-link/tl-wr841nd ● https://github.com/Deoptim/atheros/ ● https://wiki.dd-wrt.com/wiki/index.php/TP-LINK_TL-WR841ND ● https://greggborodaty.com/installing-dd-wrt-tp-link-tl-wr841n/

Slide 52

Slide 52 text

ご清聴 ありがとう ございました