I nai aso talu ai, na ou filifili ai e toe fa'ainisinia le firmware a la'u router e fa'aaoga ai le binwalk.
Sa ou faatauina a'u
O taimi uma lava ou te faʻatau ai se router fou, ou te faʻapipiʻi
Ina ua uma ona siiina OpenWRT, sa ou foi
O le a le binwalk?
Na faia i le 2010 e Craig Heffner, e mafai e le binwalk ona su'esu'e ata fa'amaumau ma su'e faila, fa'ailoa ma aveese mai ata faila faila, fa'ailoga fa'atino, fa'amaumauga fa'apipi'i, fa'apipi'i ma fatu, faila faila e pei o le JPEG ma le PDF, ma sili atu.
E mafai ona e fa'aogaina le binwalk e fesuia'i inisinia le firmware e malamalama ai pe fa'apefea ona galue. Su'e faila binary mo fa'aletonu, aveese faila, ma su'e tuafale po'o tusi pasi numera. E mafai foi ona e mauaina opcodes
mo le tele o PPU eseese.
E mafai ona e su'e ata faila faila e su'e ai faila fa'aupuga fa'apitoa (passwd, shadow, etc.) ma taumafai e ta'e upu fa'amaufa'ailoga. E mafai ona e faia le fa'avasegaina binary i le va o faila e lua pe sili atu. E mafai ona e faia su'esu'ega entropy i fa'amaumauga e su'e ai fa'amaumauga fa'amau po'o ki fa'ailoga fa'ailoga. O nei mea uma e aunoa ma le manaʻomia ona maua le code source.
I se tulaga lautele, o mea uma e te manaʻomia o loʻo i ai iina :)
E fa'afefea ona galue le binwalk?
O le uiga autu o le binwalk o lona saini su'esu'e. E mafai e Binwalk ona suʻeina le ata firmware e suʻe ai ituaiga faila faila ma faila faila.
E te iloa le faʻaogaina o le laina faʻatonu file
?
file /bin/bash
/bin/bash: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=12f73d7a8e226c663034529c8dd20efec22dde54, stripped
au file
va'ava'ai i le ulutala faila ma su'e se saini (numera fa'ataulāitu) e iloa ai le ituaiga faila. Mo se faʻataʻitaʻiga, pe a amata le faila i le faasologa o bytes 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
, na te iloa o se faila PNG. luga
Binwalk galue i le auala lava e tasi. Ae nai lo le suʻeina o saini naʻo le amataga o le faila, binwalk o le a suʻeina le faila atoa. E le gata i lea, e mafai e binwalk ona aveese faila o loʻo maua i le ata.
Meafaigaluega file
и binwalk
faaaoga le faletusi libmagic
e iloa ai faila saini. Ae binwalk
lagolago fa'aopoopoina se lisi o saini fa'ataulāitu fa'aleaganu'u e su'e ai faila compressed/zipped, firmware headers, Linux kernels, bootloaders, filesystems ma isi.
Sei o tatou fiafia?
Fa'apipi'i Binwalk
O loʻo lagolagoina le Binwalk i luga o le tele o faʻavae e aofia ai Linux, OSX, FreeBSD ma Windows.
Ina ia fa'apipi'i le lomiga fou o le binwalk e te mafaia
O le Binwalk e tele naua fa'ailoga eseese:
$ binwalk
Binwalk v2.2.0
Craig Heffner, ReFirmLabs
https://github.com/ReFirmLabs/binwalk
Usage: binwalk [OPTIONS] [FILE1] [FILE2] [FILE3] ...
Signature Scan Options:
-B, --signature Scan target file(s) for common file signatures
-R, --raw=<str> Scan target file(s) for the specified sequence of bytes
-A, --opcodes Scan target file(s) for common executable opcode signatures
-m, --magic=<file> Specify a custom magic file to use
-b, --dumb Disable smart signature keywords
-I, --invalid Show results marked as invalid
-x, --exclude=<str> Exclude results that match <str>
-y, --include=<str> Only show results that match <str>
Extraction Options:
-e, --extract Automatically extract known file types
-D, --dd=<type:ext:cmd> Extract <type> signatures, give the files an extension of <ext>, and execute <cmd>
-M, --matryoshka Recursively scan extracted files
-d, --depth=<int> Limit matryoshka recursion depth (default: 8 levels deep)
-C, --directory=<str> Extract files/folders to a custom directory (default: current working directory)
-j, --size=<int> Limit the size of each extracted file
-n, --count=<int> Limit the number of extracted files
-r, --rm Delete carved files after extraction
-z, --carve Carve data from files, but don't execute extraction utilities
-V, --subdirs Extract into sub-directories named by the offset
Entropy Options:
-E, --entropy Calculate file entropy
-F, --fast Use faster, but less detailed, entropy analysis
-J, --save Save plot as a PNG
-Q, --nlegend Omit the legend from the entropy plot graph
-N, --nplot Do not generate an entropy plot graph
-H, --high=<float> Set the rising edge entropy trigger threshold (default: 0.95)
-L, --low=<float> Set the falling edge entropy trigger threshold (default: 0.85)
Binary Diffing Options:
-W, --hexdump Perform a hexdump / diff of a file or files
-G, --green Only show lines containing bytes that are the same among all files
-i, --red Only show lines containing bytes that are different among all files
-U, --blue Only show lines containing bytes that are different among some files
-u, --similar Only display lines that are the same between all files
-w, --terse Diff all files, but only display a hex dump of the first file
Raw Compression Options:
-X, --deflate Scan for raw deflate compression streams
-Z, --lzma Scan for raw LZMA compression streams
-P, --partial Perform a superficial, but faster, scan
-S, --stop Stop after the first result
General Options:
-l, --length=<int> Number of bytes to scan
-o, --offset=<int> Start scan at this file offset
-O, --base=<int> Add a base address to all printed offsets
-K, --block=<int> Set file block size
-g, --swap=<int> Reverse every n bytes before scanning
-f, --log=<file> Log results to file
-c, --csv Log results to file in CSV format
-t, --term Format output to fit the terminal window
-q, --quiet Suppress output to stdout
-v, --verbose Enable verbose output
-h, --help Show help output
-a, --finclude=<str> Only scan files whose names match this regex
-p, --fexclude=<str> Do not scan files whose names match this regex
-s, --status=<int> Enable the status server on the specified port
Su'ega ata
Sei o tatou amata i le suʻeina o faila faila i totonu o le ata (ata mai le saite
Ta'avale binwalk ma le --signature parakalafa:
$ binwalk --signature --term archer-c7.bin
DECIMAL HEXADECIMAL DESCRIPTION
------------------------------------------------------------------------------------------
21876 0x5574 U-Boot version string, "U-Boot 1.1.4-g4480d5f9-dirty (May
20 2019 - 18:45:16)"
21940 0x55B4 CRC32 polynomial table, big endian
23232 0x5AC0 uImage header, header size: 64 bytes, header CRC:
0x386C2BD5, created: 2019-05-20 10:45:17, image size:
41162 bytes, Data Address: 0x80010000, Entry Point:
0x80010000, data CRC: 0xC9CD1E38, OS: Linux, CPU: MIPS,
image type: Firmware Image, compression type: lzma, image
name: "u-boot image"
23296 0x5B00 LZMA compressed data, properties: 0x5D, dictionary size:
8388608 bytes, uncompressed size: 97476 bytes
64968 0xFDC8 XML document, version: "1.0"
78448 0x13270 uImage header, header size: 64 bytes, header CRC:
0x78A267FF, created: 2019-07-26 07:46:14, image size:
1088500 bytes, Data Address: 0x80060000, Entry Point:
0x80060000, data CRC: 0xBB9D4F94, OS: Linux, CPU: MIPS,
image type: Multi-File Image, compression type: lzma,
image name: "MIPS OpenWrt Linux-3.3.8"
78520 0x132B8 LZMA compressed data, properties: 0x6D, dictionary size:
8388608 bytes, uncompressed size: 3164228 bytes
1167013 0x11CEA5 Squashfs filesystem, little endian, version 4.0,
compression:xz, size: 14388306 bytes, 2541 inodes,
blocksize: 65536 bytes, created: 2019-07-26 07:51:38
15555328 0xED5B00 gzip compressed data, from Unix, last modified: 2019-07-26
07:51:41
O lea ua tele a matou faʻamatalaga e uiga i lenei ata.
Fa'aoga ata 0x5AC0
ma se ata bootloader compressed i 0x5B00
). Faʻavae i luga o le ulutala uImage i le 0x13270, matou te iloa o le gaosiga o le gaosiga o le MIPS ma le Linux kernel o le version 3.3.8. Ma faʻavae i luga o le ata o loʻo maua i le tuatusi 0x11CEA5
, e mafai ona tatou vaai i ai rootfs
ose faiga faila squashfs
.
Sei o tatou aveese nei le bootloader (U-Boot) e faʻaaoga ai le poloaiga dd
:
$ dd if=archer-c7.bin of=u-boot.bin.lzma bs=1 skip=23296 count=41162
41162+0 records in
41162+0 records out
41162 bytes (41 kB, 40 KiB) copied, 0,0939608 s, 438 kB/s
Talu ai o le ata o loʻo faʻapipiʻiina e faʻaaoga ai le LZMA, e manaʻomia ona faʻamalo:
$ unlzma u-boot.bin.lzma
O lea ua matou maua se ata U-Boot:
$ ls -l u-boot.bin
-rw-rw-r-- 1 sprado sprado 97476 Fev 5 08:48 u-boot.bin
E fa'afefea ona su'e le tau fa'aletonu mo bootargs
?
$ strings u-boot.bin | grep bootargs
bootargs
bootargs=console=ttyS0,115200 board=AP152 rootfstype=squashfs init=/etc/preinit mtdparts=spi0.0:128k(factory-uboot),192k(u-boot),64k(ART),1536k(uImage),14464k@0x1e0000(rootfs) mem=128M
U-Boot Siosiomaga Fesuia'i bootargs
faʻaaoga e pasi ai faʻamaufaʻailoga i le fatu Linux. Ma mai luga, ua tatou maua se malamalama sili atu i le flash manatua o le masini.
E faʻafefea le suʻeina o le ata o le kernel Linux?
$ dd if=archer-c7.bin of=uImage bs=1 skip=78448 count=1088572
1088572+0 records in
1088572+0 records out
1088572 bytes (1,1 MB, 1,0 MiB) copied, 1,68628 s, 646 kB/s
E mafai ona tatou siaki na maua lelei le ata i le faʻaaogaina o le poloaiga file
:
$ file uImage
uImage: u-boot legacy uImage, MIPS OpenWrt Linux-3.3.8, Linux/MIPS, Multi-File Image (lzma), 1088500 bytes, Fri Jul 26 07:46:14 2019, Load Address: 0x80060000, Entry Point: 0x80060000, Header CRC: 0x78A267FF, Data CRC: 0xBB9D4F94
O le faila faila uImage o se ata o le fatu Linux ma se ulutala faaopoopo. Sei o tatou aveese lenei ulutala e maua ai le ata mulimuli Linux kernel:
$ dd if=uImage of=Image.lzma bs=1 skip=72
1088500+0 records in
1088500+0 records out
1088500 bytes (1,1 MB, 1,0 MiB) copied, 1,65603 s, 657 kB/s
O le ata o lo'o fa'apipi'iina, o lea se'i o tatou tatala ese:
$ unlzma Image.lzma
O lea ua matou maua se ata Linux kernel:
$ ls -la Image
-rw-rw-r-- 1 sprado sprado 3164228 Fev 5 10:51 Image
O le a se mea e mafai ona tatou faia i le ata o le kernel? E mafai, mo se faʻataʻitaʻiga, faia se suʻega manoa i le ata ma suʻe le faʻasologa o le fatu Linux ma aʻoaʻo e uiga i le siosiomaga na faʻaaogaina e fausia ai le fatu:
$ strings Image | grep "Linux version"
Linux version 3.3.8 (leo@leo-MS-7529) (gcc version 4.6.3 20120201 (prerelease) (Linaro GCC 4.6-2012.02) ) #1 Mon May 20 18:53:02 CST 2019
E ui lava na tatalaina le firmware i le tausaga talu ai (2019), aʻo ou tusia lenei tusiga o loʻo faʻaaogaina se kopi tuai o le Linux kernel (3.3.8) faʻasalalau i le 2012, faʻapipiʻiina ma se tala tuai o le GCC (4.6) talu mai le 2012. !
(approx. transl. e te fa'atuatuaina pea au 'au ala i le ofisa ma le fale?)
Faatasi ai ma le filifiliga --opcodes
e mafai foi ona matou faʻaogaina le binwalk e suʻe ai faʻatonuga o masini ma fuafua le faʻatulagaina o ata o le ata:
$ binwalk --opcodes Image
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
2400 0x960 MIPS instructions, function epilogue
2572 0xA0C MIPS instructions, function epilogue
2828 0xB0C MIPS instructions, function epilogue
Ae faapefea le faiga o faila faila? Nai lo le aveeseina o le ata ma le lima, tatou faʻaoga le filifiliga binwalk --extract
:
$ binwalk --extract --quiet archer-c7.bin
Ole a'a atoa faila faila o le a maua i se subdirectory:
$ cd _archer-c7.bin.extracted/squashfs-root/
$ ls
bin dev etc lib mnt overlay proc rom root sbin sys tmp usr var www
$ cat etc/banner
MM NM MMMMMMM M M
$MMMMM MMMMM MMMMMMMMMMM MMM MMM
MMMMMMMM MM MMMMM. MMMMM:MMMMMM: MMMM MMMMM
MMMM= MMMMMM MMM MMMM MMMMM MMMM MMMMMM MMMM MMMMM'
MMMM= MMMMM MMMM MM MMMMM MMMM MMMM MMMMNMMMMM
MMMM= MMMM MMMMM MMMMM MMMM MMMM MMMMMMMM
MMMM= MMMM MMMMMM MMMMM MMMM MMMM MMMMMMMMM
MMMM= MMMM MMMMM, NMMMMMMMM MMMM MMMM MMMMMMMMMMM
MMMM= MMMM MMMMMM MMMMMMMM MMMM MMMM MMMM MMMMMM
MMMM= MMMM MM MMMM MMMM MMMM MMMM MMMM MMMM
MMMM$ ,MMMMM MMMMM MMMM MMM MMMM MMMMM MMMM MMMM
MMMMMMM: MMMMMMM M MMMMMMMMMMMM MMMMMMM MMMMMMM
MMMMMM MMMMN M MMMMMMMMM MMMM MMMM
MMMM M MMMMMMM M M
M
---------------------------------------------------------------
For those about to rock... (%C, %R)
---------------------------------------------------------------
O lenei e mafai ona tatou faia le tele o mea eseese.
E mafai ona matou su'e faila fa'atulagaina, upu fa'amaufa'ailoga, ki fa'ailoga ma fa'ailoga numera. E mafai ona matou suʻesuʻeina faila binary mo
Faatasi ai ma le fesoasoani a
$ ls
bin dev etc lib mnt overlay proc rom root sbin sys tmp usr var www
$ cp /usr/bin/qemu-mips-static .
$ sudo chroot . ./qemu-mips-static bin/busybox
BusyBox v1.19.4 (2019-05-20 18:13:49 CST) multi-call binary.
Copyright (C) 1998-2011 Erik Andersen, Rob Landley, Denys Vlasenko
and others. Licensed under GPLv2.
See source distribution for full notice.
Usage: busybox [function] [arguments]...
or: busybox --list[-full]
or: function [arguments]...
BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable. Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as.
Currently defined functions:
[, [[, addgroup, adduser, arping, ash, awk, basename, cat, chgrp, chmod, chown, chroot, clear, cmp, cp, crond, crontab, cut, date, dd, delgroup, deluser, dirname, dmesg, echo, egrep, env, expr, false,
fgrep, find, free, fsync, grep, gunzip, gzip, halt, head, hexdump, hostid, id, ifconfig, init, insmod, kill, killall, klogd, ln, lock, logger, ls, lsmod, mac_addr, md5sum, mkdir, mkfifo, mknod, mktemp,
mount, mv, nice, passwd, pgrep, pidof, ping, ping6, pivot_root, poweroff, printf, ps, pwd, readlink, reboot, reset, rm, rmdir, rmmod, route, sed, seq, sh, sleep, sort, start-stop-daemon, strings,
switch_root, sync, sysctl, tail, tar, tee, telnet, test, tftp, time, top, touch, tr, traceroute, true, udhcpc, umount, uname, uniq, uptime, vconfig, vi, watchdog, wc, wget, which, xargs, yes, zcat
Matagofie! Ae faamolemole ia matau o le BusyBox version o le 1.19.4. Ole tala tuai lea ole BusyBox, na tatalaina ia Aperila 2012.
O lea TP-Link faʻasaʻo se ata firmware i le 2019 faʻaaogaina polokalama (GCC toolchain, kernel, BusyBox, ma isi) mai le 2012!
O lea ua e malamalama pe aisea ou te faʻapipiʻi ai i taimi uma OpenWRT i luga o laʻu alalaupapa?
E le na o lena
E mafai fo'i e Binwalk ona fa'atino su'esu'ega entropy, lolomi fa'amatalaga entropy mata'utia, ma fa'atupuina kalafi entropy. E masani lava, e sili atu le entropy e matauina pe a faʻafuaseʻi ia bytes i le ata. O lona uiga o le ata o loʻo i ai se faila faʻailoga, faʻapipiʻi, pe faʻanenefu. Ki fa'amaufa'ailoga malosi? Aisea e le fai ai.
E mafai foi ona tatou faʻaogaina le parakalafa --raw
e su'e ai se fa'asologa masani mata'itusi i se ata po'o se fa'ailoga --hexdump
e fa'atino se fa'a'ave'u hex e fa'atusatusa ai faila faila e lua pe sili atu.
--magic
, po'o le fa'aopoopoina i le lisi $ HOME / .config / binwalk / magic
.
E mafai ona e mauaina nisi fa'amatalaga e uiga i binwalk i
fa'alautelega binwalk
E i ai
import binwalk
binwalk.scan()
Faʻaaogaina le Python API e mafai foi ona e fatuina
E iai fo'i
Aisea la e te le siiina ai le ata firmware mai le Initaneti ma taumafai binwalk? Ou te folafola atu o le ae maua le tele o le fiafia :)
puna: www.habr.com