Kwanaki kadan da suka gabata, na yanke shawarar juyar da firmware na na'ura mai ba da hanya tsakanin hanyoyin sadarwa ta hanyar amfani da binwalk.
Na sayi kaina
Duk lokacin da na sayi sabon na'ura mai ba da hanya tsakanin hanyoyin sadarwa, na shigar
Bayan zazzage OpenWRT, ni ma
Menene binwalk?
Wanda Craig Heffner ya ƙirƙira a cikin 2010, binwalk na iya bincika hotuna na firmware kuma nemo fayiloli, ganowa da cire hotunan tsarin fayil, lambar aiwatarwa, ma'ajin adana bayanai, bootloaders da kernels, tsarin fayil kamar JPEG da PDF, da ƙari mai yawa.
Kuna iya amfani da binwalk don juyawa injiniyan firmware don fahimtar yadda yake aiki. Bincika fayilolin binary don rashin lahani, cire fayiloli, kuma nemi bayan gida ko takaddun shaida na dijital. Hakanan zaka iya samun opcodes
don tarin CPUs daban-daban.
Kuna iya cire hotunan tsarin fayil don nemo takamaiman fayilolin kalmar sirri (passwd, inuwa, da sauransu) kuma kuyi ƙoƙarin karya hashes na kalmar sirri. Kuna iya yin nazarin binary tsakanin fayiloli biyu ko fiye. Kuna iya yin bincike na entropy akan bayanai don nemo matattun bayanai ko maɓallan ɓoyewa. Duk wannan ba tare da buƙatar samun damar lambar tushe ba.
Gabaɗaya, duk abin da kuke buƙata yana can :)
Yaya binwalk yake aiki?
Babban fasalin binwalk shine duba sa hannun sa. Binwalk na iya bincika hoton firmware don bincika nau'ikan fayil iri-iri da tsarin fayil.
Kun san amfanin layin umarni 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
tawagar file
yana duba taken fayil kuma yana neman sa hannu (lambar sihiri) don tantance nau'in fayil ɗin. Misali, idan fayil ɗin ya fara da jerin bytes 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
, ya san fayil ɗin PNG ne. Kunna
Binwalk yana aiki haka. Amma maimakon neman sa hannu kawai a farkon fayil ɗin, binwalk zai duba dukkan fayil ɗin. Bugu da ƙari, binwalk na iya cire fayilolin da aka samo a cikin hoton.
Kayan aiki file
и binwalk
amfani da ɗakin karatu libmagic
don gano sa hannun fayil. Amma binwalk
Hakanan yana goyan bayan jerin sa hannu na sihiri na al'ada don bincika fayilolin da aka matsa/zipped, masu kaifin firmware, kernels Linux, bootloaders, tsarin fayil da sauransu.
Muji dadi?
Shigar Binwalk
Ana tallafawa Binwalk akan dandamali da yawa da suka haɗa da Linux, OSX, FreeBSD da Windows.
Don shigar da sabon sigar binwalk zaka iya
Binwalk yana da sigogi daban-daban da yawa:
$ 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
Duban hoto
Bari mu fara da neman sa hannun fayil a cikin hoton (hoton daga rukunin yanar gizon
Gudun binwalk tare da ma'aunin sa hannu:
$ 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
Yanzu muna da bayanai da yawa game da wannan hoton.
Amfanin hoto 0x5AC0
da hoton bootloader da aka matsa a 0x5B00
). Dangane da taken uImage a 0x13270, mun san cewa tsarin gine-gine shine MIPS kuma Linux kernel shine sigar 3.3.8. Kuma bisa ga hoton da aka samu a adireshin 0x11CEA5
, muna iya ganin haka rootfs
tsarin fayil ne squashfs
.
Yanzu bari mu cire bootloader (U-Boot) ta amfani da umarnin 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
Tunda an matsa hoton ta amfani da LZMA, muna buƙatar murkushe shi:
$ unlzma u-boot.bin.lzma
Yanzu muna da hoton U-Boot:
$ ls -l u-boot.bin
-rw-rw-r-- 1 sprado sprado 97476 Fev 5 08:48 u-boot.bin
Ta yaya game da nemo tsohuwar ƙima don 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
Canjin Muhalli na U-Boot bootargs
ana amfani da su don ƙaddamar da sigogi zuwa kernel na Linux. Kuma daga abin da ke sama, muna da kyakkyawar fahimta game da ƙwaƙwalwar filasha na na'urar.
Yaya game da cire hoton kernel na 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
Za mu iya duba cewa an ciro hoton cikin nasara ta amfani da umarnin 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
Tsarin fayil ɗin uImage shine ainihin hoton kwaya na Linux tare da ƙarin kan kai. Bari mu cire wannan taken don samun hoton kernel na Linux na ƙarshe:
$ 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
Hoton yana danne, don haka bari mu kwashe shi:
$ unlzma Image.lzma
Yanzu muna da hoton kernel na Linux:
$ ls -la Image
-rw-rw-r-- 1 sprado sprado 3164228 Fev 5 10:51 Image
Menene za mu iya yi da hoton kwaya? Za mu iya, alal misali, yin binciken kirtani a cikin hoton kuma mu nemo nau'in kernel na Linux kuma mu koyi game da yanayin da ake amfani da shi don gina kernel:
$ 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
Duk da cewa an saki firmware a bara (2019), yayin da nake rubuta wannan labarin yana amfani da tsohon sigar Linux kernel (3.3.8) wanda aka saki a cikin 2012, wanda aka haɗa tare da tsohuwar sigar GCC (4.6) shima tun 2012. !
(kimanin fassarar. Shin har yanzu kuna amince da masu amfani da hanyoyin sadarwar ku a ofis da a gida?)
Tare da zaɓi --opcodes
Hakanan za mu iya amfani da binwalk don bincika umarnin injin da tantance tsarin gine-ginen hoton:
$ binwalk --opcodes Image
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
2400 0x960 MIPS instructions, function epilogue
2572 0xA0C MIPS instructions, function epilogue
2828 0xB0C MIPS instructions, function epilogue
Menene tushen tsarin fayil ɗin? Maimakon cire hoton da hannu, bari mu yi amfani da zaɓin binwalk --extract
:
$ binwalk --extract --quiet archer-c7.bin
Za a fitar da cikakken tsarin fayil ɗin tushen zuwa babban kundin adireshi:
$ 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)
---------------------------------------------------------------
Yanzu za mu iya yin abubuwa da yawa daban-daban.
Za mu iya nemo fayilolin sanyi, hashes na kalmar sirri, maɓallan cryptographic da takaddun shaida na dijital. Za mu iya bincika fayilolin binary don
Tare da taimakon
$ 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
Mai girma! Amma da fatan za a lura cewa sigar BusyBox ita ce 1.19.4. Wannan tsohuwar sigar BusyBox ce, wanda aka saki a watan Afrilun 2012.
Don haka TP-Link yana fitar da hoton firmware a cikin 2019 ta amfani da software (GCC toolchain, kernel, BusyBox, da sauransu) daga 2012!
Yanzu kun fahimci dalilin da yasa koyaushe nake shigar da OpenWRT akan hanyoyin sadarwa na?
Wannan ba duka ba ne
Binwalk kuma yana iya yin bincike na entropy, buga ɗanyen bayanan entropy, da samar da jadawali. Yawanci, ana lura da mafi girma entropy lokacin da bytes a cikin hoton ba su da tabbas. Wannan na iya nufin hoton ya ƙunshi rufaffen rufaffiyar, matsa, ko ɓoyayyen fayil. Maɓallin ɓoyayyen Hardcore? Me yasa ba.
Hakanan zamu iya amfani da siga --raw
don nemo jerin ɗanyen byte na al'ada a cikin hoto ko siga --hexdump
don yin jujjuya hex yana kwatanta fayilolin shigarwa biyu ko fiye.
--magic
, ko ta ƙara su zuwa ga directory $ HOME / .config / binwalk / magic
.
Kuna iya samun ƙarin bayani game da binwalk a
binwalk tsawo
Akwai
import binwalk
binwalk.scan()
Amfani da Python API kuma zaka iya ƙirƙira
Akwai kuma
Don haka me yasa ba kwa zazzage hoton firmware daga Intanet kuma gwada binwalk? Na yi alkawari za ku ji daɗi da yawa :)
source: www.habr.com