දින කිහිපයකට පෙර, මම මගේ රවුටරයේ ස්ථිරාංග binwalk භාවිතයෙන් ප්රතිලෝම ඉංජිනේරු කිරීමට තීරණය කළෙමි.
මම මා මිලදී ගත්තා
මම නව රවුටරයක් මිලදී ගන්නා සෑම අවස්ථාවකම මම ස්ථාපනය කරමි
OpenWRT බාගත කිරීමෙන් පසුව, මමත්
binwalk යනු කුමක්ද?
Craig Heffner විසින් 2010 දී නිර්මාණය කරන ලද, binwalk හට ස්ථිරාංග රූප පරිලෝකනය කර ගොනු සොයා ගැනීමට, ගොනු පද්ධති රූප හඳුනා ගැනීමට සහ උපුටා ගැනීමට, ක්රියාත්මක කළ හැකි කේතය, සම්පීඩිත ලේඛනාගාර, ඇරඹුම් කාරක සහ කර්නල්, JPEG සහ PDF වැනි ගොනු ආකෘති සහ තවත් බොහෝ දේ කළ හැක.
ස්ථිරාංග ක්රියා කරන ආකාරය තේරුම් ගැනීමට එය ප්රතිලෝම ඉංජිනේරු කිරීමට ඔබට binwalk භාවිතා කළ හැක. දුර්වලතා සඳහා ද්විමය ගොනු සොයන්න, ගොනු උපුටා ගන්න, සහ පසු දොර හෝ ඩිජිටල් සහතික සොයන්න. ඔබටත් සොයා ගත හැක opcodes
විවිධ CPU සමූහයක් සඳහා.
ඔබට විශේෂිත මුරපද ගොනු (passwd, shadow, ආදිය) සෙවීමට සහ මුරපද හැෂ් බිඳීමට උත්සාහ කිරීමට ගොනු පද්ධති රූප උපුටා ගත හැක. ඔබට ගොනු දෙකක් හෝ වැඩි ගණනක් අතර ද්විමය විග්රහ කිරීම සිදු කළ හැක. සම්පීඩිත දත්ත හෝ කේතනය කරන ලද සංකේතාංකන යතුරු සෙවීම සඳහා ඔබට දත්ත මත එන්ට්රොපි විශ්ලේෂණය සිදු කළ හැක. මේ සියල්ල ප්රභව කේතයට ප්රවේශ වීමේ අවශ්යතාවයකින් තොරව.
පොදුවේ, ඔබට අවශ්ය සියල්ල තිබේ :)
binwalk වැඩ කරන්නේ කෙසේද?
binwalk හි ප්රධාන ලක්ෂණය වන්නේ එහි අත්සන පරිලෝකනය කිරීමයි. විවිධ බිල්ට් ගොනු වර්ග සහ ගොනු පද්ධති සෙවීමට Binwalk හට ස්ථිරාංග රූපය පරිලෝකනය කළ හැක.
විධාන රේඛා උපයෝගීතාව ඔබ දන්නවාද? 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
කණ්ඩායම file
ගොනු ශීර්ෂය දෙස බලා ගොනු වර්ගය තීරණය කිරීම සඳහා අත්සනක් (මැජික් අංකය) සොයයි. උදාහරණයක් ලෙස, ගොනුව ආරම්භ වන්නේ බයිට් අනුපිළිවෙලින් නම් 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
, එය PNG ගොනුවක් බව දනී. මත
Binwalk එකම ආකාරයෙන් ක්රියා කරයි. නමුත් ගොනුවේ ආරම්භයේ පමණක් අත්සන් සොයනවා වෙනුවට, binwalk විසින් සම්පූර්ණ ගොනුව පරිලෝකනය කරයි. මීට අමතරව, binwalk හට රූපයේ ඇති ගොනු උපුටා ගත හැක.
මෙවලම් file
и binwalk
පුස්තකාලය භාවිතා කරන්න libmagic
ගොනු අත්සන් හඳුනා ගැනීමට. එහෙත් binwalk
සම්පීඩිත/සිප් කරන ලද ගොනු, ස්ථිරාංග ශීර්ෂයන්, ලිනක්ස් කර්නල්, ඇරඹුම් කාරක, ගොනු පද්ධති සහ යනාදිය සෙවීමට අභිරුචි මැජික් අත්සන් ලැයිස්තුවකට අමතරව සහාය දක්වයි.
අපි ටිකක් විනෝද වෙමු?
Binwalk ස්ථාපනය
Binwalk Linux, OSX, FreeBSD සහ Windows ඇතුළු බහු වේදිකාවල සහය දක්වයි.
binwalk හි නවතම අනුවාදය ස්ථාපනය කිරීමට ඔබට හැකිය
Binwalk විවිධ පරාමිතීන් ඇත:
$ 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
රූප ස්කෑන් කිරීම
රූපය තුළ ගොනු අත්සන් සෙවීමෙන් ආරම්භ කරමු (අඩවියෙන් රූපය
--අත්සන පරාමිතිය සමඟ binwalk ධාවනය කිරීම:
$ 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
දැන් අපට මෙම රූපය පිළිබඳ බොහෝ තොරතුරු තිබේ.
රූප භාවිතය 0x5AC0
සහ සම්පීඩිත ඇරඹුම් කාරක රූපයක් 0x5B00
) 0x13270 හි uImage ශීර්ෂය මත පදනම්ව, ප්රොසෙසර ගෘහ නිර්මාණ ශිල්පය MIPS වන අතර Linux කර්නලය 3.3.8 අනුවාදය බව අපි දනිමු. සහ ලිපිනයේ ඇති රූපය මත පදනම්ව 0x11CEA5
, අපිට ඒක පේනවා rootfs
ගොනු පද්ධතියකි squashfs
.
අපි දැන් විධානය භාවිතා කර bootloader (U-Boot) උපුටා ගනිමු 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
රූපය LZMA භාවිතයෙන් සම්පීඩනය කර ඇති බැවින්, අපි එය විසංයෝජනය කළ යුතුය:
$ unlzma u-boot.bin.lzma
දැන් අපට U-Boot රූපයක් තිබේ:
$ ls -l u-boot.bin
-rw-rw-r-- 1 sprado sprado 97476 Fev 5 08:48 u-boot.bin
සඳහා පෙරනිමි අගය සොයා ගන්නේ කෙසේද? 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 පරිසර විචල්යය bootargs
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
විධානය භාවිතයෙන් රූපය සාර්ථකව උපුටා ගත් බව අපට පරීක්ෂා කළ හැකිය 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
uImage ගොනු ආකෘතිය මූලික වශයෙන් අතිරේක ශීර්ෂයක් සහිත ලිනක්ස් කර්නල් රූපයකි. අවසාන ලිනක්ස් කර්නල් රූපය ලබා ගැනීමට මෙම ශීර්ෂකය ඉවත් කරමු:
$ 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
රූපය සම්පීඩිතයි, එබැවින් අපි එය ඉවත් කරමු:
$ unlzma Image.lzma
දැන් අපට Linux කර්නල් රූපයක් ඇත:
$ ls -la Image
-rw-rw-r-- 1 sprado sprado 3164228 Fev 5 10:51 Image
කර්නල් රූපය සමඟ අපට කුමක් කළ හැකිද? උදාහරණයක් ලෙස, අපට රූපයේ තන්තු සෙවුමක් කර ලිනක්ස් කර්නලයේ අනුවාදය සොයා කර කර්නලය තැනීමට භාවිතා කරන පරිසරය ගැන ඉගෙන ගත හැකිය:
$ 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
ස්ථිරාංග පසුගිය වසරේ (2019) නිකුත් කළද, මම මෙම ලිපිය ලියන විට එය භාවිතා කරන්නේ 3.3.8 දී නිකුත් කරන ලද ලිනක්ස් කර්නලයේ (2012) පැරණි අනුවාදයක් වන අතර එය 4.6 සිට GCC (2012) හි ඉතා පැරණි අනුවාදයකින් සම්පාදනය කර ඇත. !
(ආසන්න වශයෙන් පරිවර්තනය. ඔබ තවමත් කාර්යාලයේ සහ නිවසේදී ඔබේ රවුටර විශ්වාස කරනවාද?)
විකල්පය සමඟ --opcodes
යන්ත්ර උපදෙස් සොයා බැලීමට සහ රූපයේ ප්රොසෙසර ගෘහ නිර්මාණ ශිල්පය තීරණය කිරීමට අපට binwalk භාවිතා කළ හැකිය:
$ binwalk --opcodes Image
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
2400 0x960 MIPS instructions, function epilogue
2572 0xA0C MIPS instructions, function epilogue
2828 0xB0C MIPS instructions, function epilogue
Root ගොනු පද්ධතිය ගැන කුමක් කිව හැකිද? රූපය අතින් උපුටා ගැනීම වෙනුවට, විකල්පය භාවිතා කරමු binwalk --extract
:
$ binwalk --extract --quiet archer-c7.bin
සම්පූර්ණ මූල ගොනු පද්ධතිය උප බහලුමකට උපුටා ගනු ලැබේ:
$ 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)
---------------------------------------------------------------
දැන් අපිට විවිධ දේවල් ගොඩක් කරන්න පුළුවන්.
අපට වින්යාස ගොනු, මුරපද හැෂ්, ගුප්ත ලේඛන යතුරු සහ ඩිජිටල් සහතික සෙවිය හැක. සඳහා අපට ද්විමය ගොනු විශ්ලේෂණය කළ හැකිය
සහාය ඇතිව
$ 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
මහා! නමුත් BusyBox අනුවාදය 1.19.4 බව කරුණාවෙන් සලකන්න. මෙය BusyBox හි ඉතා පැරණි අනුවාදයකි, 2012 අප්රේල් මාසයේදී නිකුත් කරන ලදී.
එබැවින් TP-Link 2019 සිට මෘදුකාංග (GCC මෙවලම් දාමය, කර්නලය, BusyBox, ආදිය) භාවිතයෙන් 2012 දී ස්ථිරාංග රූපයක් නිකුත් කරයි!
මගේ රවුටරවල මම නිතරම OpenWRT ස්ථාපනය කරන්නේ මන්දැයි දැන් ඔබට තේරෙනවාද?
එපමණක් නොවේ
Binwalk හට එන්ට්රොපි විශ්ලේෂණය, අමු එන්ට්රොපි දත්ත මුද්රණය කිරීම සහ එන්ට්රොපි ප්රස්ථාර උත්පාදනය කිරීමද කළ හැක. සාමාන්යයෙන්, රූපයේ බයිට අහඹු වූ විට වැඩි එන්ට්රොපිය නිරීක්ෂණය කෙරේ. රූපයේ සංකේතාත්මක, සම්පීඩිත හෝ අපැහැදිලි ගොනුවක් අඩංගු බව මෙයින් අදහස් විය හැක. Hardcore සංකේතාංකන යතුර? ඇයි නැත්තේ.
අපට පරාමිතිය ද භාවිතා කළ හැකිය --raw
රූපයක හෝ පරාමිතියක අභිරුචි අමු බයිට් අනුපිළිවෙලක් සොයා ගැනීමට --hexdump
ආදාන ගොනු දෙකක් හෝ වැඩි ගණනක් සංසන්දනය කරමින් හෙක්ස් ඩම්ප් එකක් සිදු කිරීමට.
--magic
, හෝ ඒවා නාමාවලියට එකතු කිරීමෙන් $ HOME / .config / binwalk / magic
.
ඔබට binwalk පිළිබඳ වැඩිදුර තොරතුරු සොයා ගත හැක
binwalk දිගුව
එතන තියෙනවා
import binwalk
binwalk.scan()
Python API භාවිතයෙන් ඔබටද නිර්මාණය කළ හැක
ද ඇත
ඉතින් ඇයි ඔබ ස්ථිරාංග රූපය අන්තර්ජාලයෙන් බාගත කර binwalk උත්සාහ නොකරන්නේ? මම පොරොන්දු වෙනවා ඔයාට ගොඩක් විනෝද වෙන්න පුළුවන් කියලා :)
මූලාශ්රය: www.habr.com