ื”ื ื“ืกื” ืœืื—ื•ืจ ืฉืœ ื ืชื‘ ื‘ื™ืชื™ ื‘ืืžืฆืขื•ืช binwalk. ื”ืื ืืชื” ืกื•ืžืš ืขืœ ืชื•ื›ื ืช ื”ื ืชื‘ ืฉืœืš?

ื”ื ื“ืกื” ืœืื—ื•ืจ ืฉืœ ื ืชื‘ ื‘ื™ืชื™ ื‘ืืžืฆืขื•ืช binwalk. ื”ืื ืืชื” ืกื•ืžืš ืขืœ ืชื•ื›ื ืช ื”ื ืชื‘ ืฉืœืš?

ืœืคื ื™ ืžืกืคืจ ื™ืžื™ื, ื”ื—ืœื˜ืชื™ ืœื‘ืฆืข ื”ื ื“ืกื” ืœืื—ื•ืจ ืฉืœ ื”ืงื•ืฉื—ื” ืฉืœ ื”ื ืชื‘ ืฉืœื™ ื‘ืืžืฆืขื•ืช binwalk.

ืงื ื™ืชื™ ื‘ืขืฆืžื™ ื ืชื‘ ื‘ื™ืชื™ TP-Link Archer C7. ืœื ื”ื ืชื‘ ื”ื˜ื•ื‘ ื‘ื™ื•ืชืจ, ืื‘ืœ ื“ื™ ืžืกืคื™ืง ืœืฆืจื›ื™ื ืฉืœื™.

ื‘ื›ืœ ืคืขื ืฉืื ื™ ืงื•ื ื” ื ืชื‘ ื—ื“ืฉ, ืื ื™ ืžืชืงื™ืŸ OpenWRT. ื‘ืฉื‘ื™ืœ ืžื”? ื›ื›ืœืœ, ืœื™ืฆืจื ื™ื ืœื ืื›ืคืช ื”ืจื‘ื” ืžื”ืชืžื™ื›ื” ื‘ื ืชื‘ื™ื ืฉืœื”ื ื•ืขื ื”ื–ืžืŸ ื”ืชื•ื›ื ื” ืžืชื™ื™ืฉื ืช, ืžื•ืคื™ืขื•ืช ื ืงื•ื“ื•ืช ืชื•ืจืคื”, ื•ื›ืŸ ื”ืœืื”, ื‘ืื•ืคืŸ ื›ืœืœื™, ื”ื‘ื ืชื ืืช ื”ืจืขื™ื•ืŸ. ืœื›ืŸ, ืื ื™ ืžืขื“ื™ืฃ ืืช ื”ืงื•ืฉื—ื” ืฉืœ OpenWRT, ื”ื ืชืžื›ืช ื”ื™ื˜ื‘ ืขืœ ื™ื“ื™ ืงื”ื™ืœืช ื”ืงื•ื“ ื”ืคืชื•ื—.

ืœืื—ืจ ืฉื”ื•ืจื“ืชื™ ืืช OpenWRT, ื’ื ืื ื™ ื”ื•ืจื“ ืืช ืชืžื•ื ืช ื”ืงื•ืฉื—ื” ื”ืขื“ื›ื ื™ืช ื‘ื™ื•ืชืจ ืชื—ืช Archer C7 ื”ื—ื“ืฉ ืฉืœื™ ืžื”ืืชืจ ื”ืจืฉืžื™ ื•ื”ื—ืœื˜ืชื™ ืœื ืชื— ืื•ืชื•. ืืš ื•ืจืง ื‘ืฉื‘ื™ืœ ื”ื›ื™ืฃ ื•ืœื“ื‘ืจ ืขืœ binwalk.

ืžื” ื–ื” binwalk?

Binwalk ื”ื•ื ื›ืœื™ ืงื•ื“ ืคืชื•ื— ืœื ื™ืชื•ื—, ื”ื ื“ืกื” ืœืื—ื•ืจ ื•ื—ื™ืœื•ืฅ ืชืžื•ื ื•ืช ืงื•ืฉื—ื”.

ื ื•ืฆืจ ื‘ืฉื ืช 2010 ืขืœ ื™ื“ื™ ืงืจื™ื™ื’ ื”ืคื ืจ, binwalk ื™ื›ื•ืœ ืœืกืจื•ืง ืชืžื•ื ื•ืช ืงื•ืฉื—ื” ื•ืœืžืฆื•ื ืงื‘ืฆื™ื, ืœื–ื”ื•ืช ื•ืœื—ืœืฅ ืชืžื•ื ื•ืช ืฉืœ ืžืขืจื›ืช ืงื‘ืฆื™ื, ืงื•ื“ ื”ืคืขืœื”, ืืจื›ื™ื•ื ื™ื ื“ื—ื•ืกื™ื, ืžืื’ืจื™ ืืชื—ื•ืœ ื•ืงืจื ืœื™ื, ืคื•ืจืžื˜ื™ื ืฉืœ ืงื‘ืฆื™ื ื›ื’ื•ืŸ JPEG ื•-PDF ื•ืขื•ื“ ื”ืจื‘ื” ื™ื•ืชืจ.

ืืชื” ื™ื›ื•ืœ ืœื”ืฉืชืžืฉ ื‘-binwalk ื›ื“ื™ ืœื‘ืฆืข ื”ื ื“ืกื” ืœืื—ื•ืจ ืฉืœ ื”ืงื•ืฉื—ื” ื›ื“ื™ ืœื”ื‘ื™ืŸ ืื™ืš ื–ื” ืขื•ื‘ื“. ื—ืคืฉ ื‘ืงื‘ืฆื™ื ื‘ื™ื ืืจื™ื ืคื’ื™ืขื•ื™ื•ืช, ื—ืœืฅ ืงื‘ืฆื™ื ื•ื—ืคืฉ ื“ืœืชื•ืช ืื—ื•ืจื™ื•ืช ืื• ืื™ืฉื•ืจื™ื ื“ื™ื’ื™ื˜ืœื™ื™ื. ืืชื” ื™ื›ื•ืœ ื’ื ืœืžืฆื•ื opcodes ืขื‘ื•ืจ ื—ื‘ื•ืจื” ืฉืœ ืžืขื‘ื“ื™ื ืฉื•ื ื™ื.

ืืชื” ื™ื›ื•ืœ ืœื—ืœืฅ ืชืžื•ื ื•ืช ืฉืœ ืžืขืจื›ืช ืงื‘ืฆื™ื ื›ื“ื™ ืœื—ืคืฉ ืงื‘ืฆื™ ืกื™ืกืžืื•ืช ืกืคืฆื™ืคื™ื™ื (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

ืกืจื™ืงืช ืชืžื•ื ื”

ื ืชื—ื™ืœ ื‘ื—ื™ืคื•ืฉ ื—ืชื™ืžื•ืช ืงื‘ืฆื™ื ื‘ืชื•ืš ื”ืชืžื•ื ื” (ืชืžื•ื ื” ืžื”ืืชืจ TP-Link).

ื”ืคืขืœืช binwalk ืขื ื”ืคืจืžื˜ืจ --signature:

$ 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). ื‘ื”ืชื‘ืกืก ืขืœ ื›ื•ืชืจืช uImage ื‘-0x13270, ืื ื• ื™ื•ื“ืขื™ื ืฉืืจื›ื™ื˜ืงื˜ื•ืจืช ื”ืžืขื‘ื“ ื”ื™ื MIPS ื•ืงืจื ืœ ื”ืœื™ื ื•ืงืก ื”ื™ื ื’ืจืกื” 3.3.8. ื•ืขืœ ืกืžืš ื”ืชืžื•ื ื” ืฉื ืžืฆืื” ื‘ื›ืชื•ื‘ืช 0x11CEA5, ืื ื—ื ื• ื™ื›ื•ืœื™ื ืœืจืื•ืช ืืช ื–ื” rootfs ื”ื™ื ืžืขืจื›ืช ืงื‘ืฆื™ื squashfs.

ื›ืขืช ื ื—ืœืฅ ืืช ื˜ื•ืขืŸ ื”ืืชื—ื•ืœ (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 ืžืฉืžืฉ ืœื”ืขื‘ืจืช ืคืจืžื˜ืจื™ื ืœืœื™ื‘ืช ืœื™ื ื•ืงืก. ื•ืžื”ืืžื•ืจ ืœืขื™ืœ, ื™ืฉ ืœื ื• ื”ื‘ื ื” ื˜ื•ื‘ื” ื™ื•ืชืจ ืฉืœ ื–ื™ื›ืจื•ืŸ ื”ืคืœืืฉ ืฉืœ ื”ืžื›ืฉื™ืจ.

ืžื” ื“ืขืชืš ืœื—ืœืฅ ืืช ืชืžื•ื ืช ืœื™ื‘ืช ืœื™ื ื•ืงืก?

$ 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

ืขื›ืฉื™ื• ื™ืฉ ืœื ื• ืชืžื•ื ืช ืœื™ื‘ืช ืœื™ื ื•ืงืก:

$ 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, ื”ื™ื“ื•ืจื™ืช ืขื ื’ืจืกื” ื™ืฉื ื” ืžืื•ื“ ืฉืœ GCC (4.6) ื’ื ืžืื– 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

ืžื” ืœื’ื‘ื™ ืžืขืจื›ืช ืงื‘ืฆื™ ื”ืฉื•ืจืฉ? ื‘ืžืงื•ื ืœื—ืœืฅ ืืช ื”ืชืžื•ื ื” ื‘ืื•ืคืŸ ื™ื“ื ื™, ื‘ื•ืื• ื ืฉืชืžืฉ ื‘ืืคืฉืจื•ืช 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)
 ---------------------------------------------------------------

ืขื›ืฉื™ื• ืื ื—ื ื• ื™ื›ื•ืœื™ื ืœืขืฉื•ืช ื”ืจื‘ื” ื“ื‘ืจื™ื ืฉื•ื ื™ื.

ืื ื• ื™ื›ื•ืœื™ื ืœื—ืคืฉ ืงื‘ืฆื™ ืชืฆื•ืจื”, ื’ื™ื‘ื•ื‘ ืกื™ืกืžืื•ืช, ืžืคืชื—ื•ืช ืงืจื™ืคื˜ื•ื’ืจืคื™ื™ื ื•ืชืขื•ื“ื•ืช ื“ื™ื’ื™ื˜ืœื™ื•ืช. ืื ื—ื ื• ื™ื›ื•ืœื™ื ืœื ืชื— ืงื‘ืฆื™ื ื‘ื™ื ืืจื™ื™ื ืขื‘ื•ืจ ืคืชืจื•ืŸ ืชืงืœื•ืช ื•ืคื’ื™ืขื•ืช.

ืขื qemu ะธ ื ืชื— ืื ื—ื ื• ื™ื›ื•ืœื™ื ืืคื™ืœื• ืœื”ืจื™ืฅ (ืœื—ืงื•ืช) ืงื•ื‘ืฅ ื”ืคืขืœื” ืžื”ืชืžื•ื ื”:

$ 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 ื™ื›ื•ืœ ื’ื ืœื‘ืฆืข ื ื™ืชื•ื— ืื ื˜ืจื•ืคื™ื”, ืœื”ื“ืคื™ืก ื ืชื•ื ื™ ืื ื˜ืจื•ืคื™ื” ื’ื•ืœืžื™ื™ื ื•ืœื™ืฆื•ืจ ื’ืจืคื™ ืื ื˜ืจื•ืคื™ื”. ื‘ื“ืจืš ื›ืœืœ, ืื ื˜ืจื•ืคื™ื” ื’ื“ื•ืœื” ื™ื•ืชืจ ื ืฆืคื™ืช ื›ืืฉืจ ื”ื‘ืชื™ื ื‘ืชืžื•ื ื” ื”ื ืืงืจืื™ื™ื. ืคื™ืจื•ืฉ ื”ื“ื‘ืจ ื™ื›ื•ืœ ืœื”ื™ื•ืช ืฉื”ืชืžื•ื ื” ืžื›ื™ืœื” ืงื•ื‘ืฅ ืžื•ืฆืคืŸ, ื“ื—ื•ืก ืื• ืžืขื•ืจืคืœ. ืžืคืชื— ื”ืฆืคื ื” ื”ืืจื“ืงื•ืจ? ืœืžื” ืœื.

ื”ื ื“ืกื” ืœืื—ื•ืจ ืฉืœ ื ืชื‘ ื‘ื™ืชื™ ื‘ืืžืฆืขื•ืช binwalk. ื”ืื ืืชื” ืกื•ืžืš ืขืœ ืชื•ื›ื ืช ื”ื ืชื‘ ืฉืœืš?

ืื ื—ื ื• ื™ื›ื•ืœื™ื ื’ื ืœื”ืฉืชืžืฉ ื‘ืคืจืžื˜ืจ --raw ื›ื“ื™ ืœืžืฆื•ื ืจืฆืฃ ื‘ืชื™ื ื’ื•ืœืžื™ ืžื•ืชืื ืื™ืฉื™ืช ื‘ืชืžื•ื ื” ืื• ื‘ืคืจืžื˜ืจ --hexdump ื›ื“ื™ ืœื‘ืฆืข dump hex ื”ืžืฉื•ื•ื” ื‘ื™ืŸ ืฉื ื™ ืงื‘ืฆื™ ืงืœื˜ ืื• ื™ื•ืชืจ.

ื—ืชื™ืžื•ืช ืžื•ืชืืžื•ืช ืื™ืฉื™ืช ื ื™ืชืŸ ืœื”ื•ืกื™ืฃ ืœ-binwalk ื‘ืืžืฆืขื•ืช ืงื•ื‘ืฅ ื—ืชื™ืžื” ืžื•ืชืื ืื™ืฉื™ืช ืฉืฆื•ื™ืŸ ื‘ืฉื•ืจืช ื”ืคืงื•ื“ื” ื‘ืืžืฆืขื•ืช ื”ืคืจืžื˜ืจ --magic, ืื• ืขืœ ื™ื“ื™ ื”ื•ืกืคืชื ืœืกืคืจื™ื™ื” $ HOME / .config / binwalk / magic.

ืชื•ื›ืœ ืœืžืฆื•ื ืžื™ื“ืข ื ื•ืกืฃ ืขืœ binwalk ื‘ื›ืชื•ื‘ืช ืชื™ืขื•ื“ ืจืฉืžื™.

ื”ืจื—ื‘ืช binwalk

ื™ืฉ ืžืžืฉืง API binwalk, ืžื™ื•ืฉื ื›ืžื•ื“ื•ืœ Python ืฉื™ื›ื•ืœ ืœืฉืžืฉ ื›ืœ ืกืงืจื™ืคื˜ ืฉืœ Python ืœื‘ื™ืฆื•ืข ืกืจื™ืงืช binwalk ื‘ืื•ืคืŸ ืชื›ื ื•ืชื™, ื•ืืช ื›ืœื™ ื”ืฉื™ืจื•ืช ืฉืœ ืฉื•ืจืช ื”ืคืงื•ื“ื” binwalk ื ื™ืชืŸ ืœืฉื›ืคืœ ื›ืžืขื˜ ืœื—ืœื•ื˜ื™ืŸ ืขื ืฉืชื™ ืฉื•ืจื•ืช ื‘ืœื‘ื“ ืฉืœ ืงื•ื“ Python!

import binwalk
binwalk.scan()

ื‘ืืžืฆืขื•ืช ื”-API ืฉืœ Python ืืชื” ื™ื›ื•ืœ ื’ื ืœื™ืฆื•ืจ ืชื•ืกืคื™ื ืฉืœ ืคื™ื™ืชื•ืŸ ื›ื“ื™ ืœื”ื’ื“ื™ืจ ื•ืœื”ืจื—ื™ื‘ ืืช binwalk.

ืงื™ื™ื ื’ื ืชื•ืกืฃ IDA ื•ื’ืจืกืช ืขื ืŸ Binwalk Pro.

ืื– ืœืžื” ืฉืœื ืชื•ืจื™ื“ ืืช ืชืžื•ื ืช ื”ืงื•ืฉื—ื” ืžื”ืื™ื ื˜ืจื ื˜ ื•ืชื ืกื” ืืช binwalk? ืื ื™ ืžื‘ื˜ื™ื— ืฉื™ื”ื™ื” ืœืš ื›ื™ืฃ ื’ื“ื•ืœ :)

ืžืงื•ืจ: www.habr.com

ื”ื•ืกืคืช ืชื’ื•ื‘ื”