binwalk๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ™ˆ ๋ผ์šฐํ„ฐ๋ฅผ ๋ฆฌ๋ฒ„์Šค ์—”์ง€๋‹ˆ์–ด๋งํ•ฉ๋‹ˆ๋‹ค. ๋ผ์šฐํ„ฐ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์‹ ๋ขฐํ•˜์‹ญ๋‹ˆ๊นŒ?

binwalk๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ™ˆ ๋ผ์šฐํ„ฐ๋ฅผ ๋ฆฌ๋ฒ„์Šค ์—”์ง€๋‹ˆ์–ด๋งํ•ฉ๋‹ˆ๋‹ค. ๋ผ์šฐํ„ฐ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์‹ ๋ขฐํ•˜์‹ญ๋‹ˆ๊นŒ?

๋ฉฐ์น  ์ „ ์ €๋Š” binwalk๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ผ์šฐํ„ฐ์˜ ํŽŒ์›จ์–ด๋ฅผ ๋ฆฌ๋ฒ„์Šค ์—”์ง€๋‹ˆ์–ด๋งํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋‚˜๋Š” ๋‚˜ ์ž์‹ ์„ ์ƒ€๋‹ค TP-Link Archer C7 ํ™ˆ ๋ผ์šฐํ„ฐ. ์ตœ๊ณ ์˜ ๋ผ์šฐํ„ฐ๋Š” ์•„๋‹ˆ์ง€๋งŒ ๋‚ด ์š”๊ตฌ ์‚ฌํ•ญ์—๋Š” ์ถฉ๋ถ„ํ•ฉ๋‹ˆ๋‹ค.

์ƒˆ ๋ผ์šฐํ„ฐ๋ฅผ ๊ตฌ์ž…ํ•  ๋•Œ๋งˆ๋‹ค ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. OpenWRT. ๋ฌด์—‡์„ ์œ„ํ•ด? ์ผ๋ฐ˜์ ์œผ๋กœ ์ œ์กฐ์—…์ฒด๋Š” ๋ผ์šฐํ„ฐ ์ง€์›์— ํฌ๊ฒŒ ์‹ ๊ฒฝ ์“ฐ์ง€ ์•Š์œผ๋ฉฐ ์‹œ๊ฐ„์ด ์ง€๋‚จ์— ๋”ฐ๋ผ ์†Œํ”„ํŠธ์›จ์–ด๊ฐ€ ์˜ค๋ž˜๋˜๊ณ  ์ทจ์•ฝ์ ์ด ๋‚˜ํƒ€๋‚˜๋Š” ๋“ฑ ์ผ๋ฐ˜์ ์œผ๋กœ ์•„์ด๋””์–ด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ €๋Š” ์˜คํ”ˆ ์†Œ์Šค ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ์ž˜ ์ง€์›๋˜๋Š” OpenWRT ํŽŒ์›จ์–ด๋ฅผ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค.

OpenWRT๋ฅผ ๋‹ค์šด๋กœ๋“œํ•œ ํ›„, ๋‚˜๋„ ์ตœ์‹  ํŽŒ์›จ์–ด ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ–ˆ์Šต๋‹ˆ๋‹ค ๊ณต์‹ ์›น์‚ฌ์ดํŠธ์—์„œ ๋‚ด ์ƒˆ๋กœ์šด Archer C7์„ ๋‹ค์šด๋กœ๋“œํ•˜์—ฌ ๋ถ„์„ํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ˆœ์ „ํžˆ ์žฌ๋ฏธ๋ฅผ ์œ„ํ•ด binwalk์— ๋Œ€ํ•ด ์ด์•ผ๊ธฐํ•ฉ๋‹ˆ๋‹ค.

๋นˆ์›Œํฌ๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”?

๋นˆ์›Œํฌ ๋ถ„์„, ๋ฆฌ๋ฒ„์Šค ์—”์ง€๋‹ˆ์–ด๋ง, ํŽŒ์›จ์–ด ์ด๋ฏธ์ง€ ์ถ”์ถœ์„ ์œ„ํ•œ ์˜คํ”ˆ ์†Œ์Šค ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

2010๋…„ Craig Heffner๊ฐ€ ๋งŒ๋“  binwalk๋Š” ํŽŒ์›จ์–ด ์ด๋ฏธ์ง€๋ฅผ ์Šค์บ”ํ•˜๊ณ  ํŒŒ์ผ์„ ์ฐพ๊ณ , ํŒŒ์ผ ์‹œ์Šคํ…œ ์ด๋ฏธ์ง€, ์‹คํ–‰ ์ฝ”๋“œ, ์••์ถ• ์•„์นด์ด๋ธŒ, ๋ถ€ํŠธ๋กœ๋” ๋ฐ ์ปค๋„, JPEG ๋ฐ PDF์™€ ๊ฐ™์€ ํŒŒ์ผ ํ˜•์‹ ๋“ฑ์„ ์‹๋ณ„ ๋ฐ ์ถ”์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

binwalk๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŽŒ์›จ์–ด๋ฅผ ๋ฆฌ๋ฒ„์Šค ์—”์ง€๋‹ˆ์–ด๋งํ•˜์—ฌ ์ž‘๋™ ๋ฐฉ์‹์„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์—์„œ ์ทจ์•ฝ์ ์„ ๊ฒ€์ƒ‰ํ•˜๊ณ , ํŒŒ์ผ์„ ์ถ”์ถœํ•˜๊ณ , ๋ฐฑ๋„์–ด๋‚˜ ๋””์ง€ํ„ธ ์ธ์ฆ์„œ๋ฅผ ์ฐพ์œผ์„ธ์š”. ๋‹น์‹ ์€ ๋˜ํ•œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค opcodes ๋‹ค์–‘ํ•œ CPU์— ๋Œ€ํ•ด.

ํŒŒ์ผ ์‹œ์Šคํ…œ ์ด๋ฏธ์ง€๋ฅผ ์ถ”์ถœํ•˜์—ฌ ํŠน์ • ๋น„๋ฐ€๋ฒˆํ˜ธ ํŒŒ์ผ(passwd, Shadow ๋“ฑ)์„ ์ฐพ๊ณ  ๋น„๋ฐ€๋ฒˆํ˜ธ ํ•ด์‹œ๋ฅผ ํ•ด๋…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‘ ๊ฐœ ์ด์ƒ์˜ ํŒŒ์ผ ๊ฐ„์— ๋ฐ”์ด๋„ˆ๋ฆฌ ๊ตฌ๋ฌธ ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์—”ํŠธ๋กœํ”ผ ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•˜์—ฌ ์••์ถ•๋œ ๋ฐ์ดํ„ฐ ๋˜๋Š” ์ธ์ฝ”๋”ฉ๋œ ์•”ํ˜ธํ™” ํ‚ค๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์†Œ์Šค ์ฝ”๋“œ์— ์•ก์„ธ์Šคํ•  ํ•„์š” ์—†์ด ์ด ๋ชจ๋“  ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ์ด ๊ฑฐ๊ธฐ์— ์žˆ์Šต๋‹ˆ๋‹ค :)

๋นˆ์›Œํฌ๋Š” ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋‚˜์š”?

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 ์••์ถ•/์••์ถ• ํŒŒ์ผ, ํŽŒ์›จ์–ด ํ—ค๋”, Linux ์ปค๋„, ๋ถ€ํŠธ๋กœ๋”, ํŒŒ์ผ ์‹œ์Šคํ…œ ๋“ฑ์„ ๊ฒ€์ƒ‰ํ•˜๊ธฐ ์œ„ํ•œ ์‚ฌ์šฉ์ž ์ •์˜ ๋งค์ง ์„œ๋ช… ๋ชฉ๋ก์„ ์ถ”๊ฐ€๋กœ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

์ข€ ๋†€์•„๋ณด์ž?

๋นˆ์›Œํฌ ์„ค์น˜

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 - ๋งํฌ).

--signature ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 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.

์ด์ œ ๋‹ค์Œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ถ€ํŠธ๋กœ๋”(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 ์ปค๋„์— ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์œ„์—์„œ ์šฐ๋ฆฌ๋Š” ์žฅ์น˜์˜ ํ”Œ๋ž˜์‹œ ๋ฉ”๋ชจ๋ฆฌ์— ๋Œ€ํ•ด ๋” ์ž˜ ์ดํ•ดํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

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 ํŒŒ์ผ ํ˜•์‹์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ถ”๊ฐ€ ํ—ค๋”๊ฐ€ ์žˆ๋Š” Linux ์ปค๋„ ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค. ์ตœ์ข… Linux ์ปค๋„ ์ด๋ฏธ์ง€๋ฅผ ์–ป์œผ๋ ค๋ฉด ์ด ํ—ค๋”๋ฅผ ์ œ๊ฑฐํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

$ 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

์ปค๋„ ์ด๋ฏธ์ง€๋กœ ๋ฌด์—‡์„ ํ•  ์ˆ˜ ์žˆ๋‚˜์š”? ์˜ˆ๋ฅผ ๋“ค์–ด ์ด๋ฏธ์ง€์—์„œ ๋ฌธ์ž์—ด ๊ฒ€์ƒ‰์„ ์ˆ˜ํ–‰ํ•˜์—ฌ Linux ์ปค๋„ ๋ฒ„์ „์„ ์ฐพ๊ณ  ์ปค๋„์„ ๋นŒ๋“œํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ ํ™˜๊ฒฝ์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$ 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๋…„์— ์ถœ์‹œ๋œ Linux ์ปค๋„(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

๋ฃจํŠธ ํŒŒ์ผ ์‹œ์Šคํ…œ์€ ์–ด๋–ป์Šต๋‹ˆ๊นŒ? ์ด๋ฏธ์ง€๋ฅผ ์ˆ˜๋™์œผ๋กœ ์ถ”์ถœํ•˜๋Š” ๋Œ€์‹  ์˜ต์…˜์„ ์‚ฌ์šฉํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 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)
 ---------------------------------------------------------------

์ด์ œ ์šฐ๋ฆฌ๋Š” ๋‹ค์–‘ํ•œ ์ผ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ตฌ์„ฑ ํŒŒ์ผ, ๋น„๋ฐ€๋ฒˆํ˜ธ ํ•ด์‹œ, ์•”ํ˜ธํ™” ํ‚ค ๋ฐ ๋””์ง€ํ„ธ ์ธ์ฆ์„œ๋ฅผ ๊ฒ€์ƒ‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์„ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ ํ•ด๊ฒฐ ๊ทธ๋ฆฌ๊ณ  ์ทจ์•ฝ์ .

๊ณผ ์ผ€๋ฌด ะธ chroot ์ด๋ฏธ์ง€์—์„œ ์‹คํ–‰ ํŒŒ์ผ์„ ์‹คํ–‰(์—๋ฎฌ๋ ˆ์ด์…˜)ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

$ 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๋…„ XNUMX์›”์— ์ถœ์‹œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ TP-Link๋Š” 2019๋…„๋ถ€ํ„ฐ ์†Œํ”„ํŠธ์›จ์–ด(GCC ํˆด์ฒด์ธ, ์ปค๋„, BusyBox ๋“ฑ)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 2012๋…„์— ํŽŒ์›จ์–ด ์ด๋ฏธ์ง€๋ฅผ ์ถœ์‹œํ•ฉ๋‹ˆ๋‹ค!

์ด์ œ ๋‚ด๊ฐ€ ํ•ญ์ƒ ๋ผ์šฐํ„ฐ์— OpenWRT๋ฅผ ์„ค์น˜ํ•˜๋Š” ์ด์œ ๋ฅผ ์ดํ•ดํ•˜์…จ๋‚˜์š”?

๊ทธ๊ฒŒ ๋‹ค๊ฐ€ ์•„๋‹ˆ์•ผ

Binwalk๋Š” ์—”ํŠธ๋กœํ”ผ ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•˜๊ณ , ์›์‹œ ์—”ํŠธ๋กœํ”ผ ๋ฐ์ดํ„ฐ๋ฅผ ์ธ์‡„ํ•˜๊ณ , ์—”ํŠธ๋กœํ”ผ ๊ทธ๋ž˜ํ”„๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋ฏธ์ง€์˜ ๋ฐ”์ดํŠธ๊ฐ€ ๋ฌด์ž‘์œ„์ผ ๋•Œ ๋” ํฐ ์—”ํŠธ๋กœํ”ผ๊ฐ€ ๊ด€์ฐฐ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ด๋ฏธ์ง€์— ์•”ํ˜ธํ™”๋˜๊ฑฐ๋‚˜ ์••์ถ•๋˜์—ˆ๊ฑฐ๋‚˜ ๋‚œ๋…ํ™”๋œ ํŒŒ์ผ์ด ํฌํ•จ๋˜์–ด ์žˆ์Œ์„ ์˜๋ฏธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋“œ์ฝ”์–ด ์•”ํ˜ธํ™” ํ‚ค? ์™œ ์•ˆ ๋ผ.

binwalk๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ™ˆ ๋ผ์šฐํ„ฐ๋ฅผ ๋ฆฌ๋ฒ„์Šค ์—”์ง€๋‹ˆ์–ด๋งํ•ฉ๋‹ˆ๋‹ค. ๋ผ์šฐํ„ฐ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์‹ ๋ขฐํ•˜์‹ญ๋‹ˆ๊นŒ?

๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. --raw ์ด๋ฏธ์ง€ ๋˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜์—์„œ ์‚ฌ์šฉ์ž ์ •์˜ ์›์‹œ ๋ฐ”์ดํŠธ ์‹œํ€€์Šค๋ฅผ ์ฐพ์œผ๋ ค๋ฉด --hexdump ๋‘ ๊ฐœ ์ด์ƒ์˜ ์ž…๋ ฅ ํŒŒ์ผ์„ ๋น„๊ตํ•˜๋Š” XNUMX์ง„์ˆ˜ ๋คํ”„๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๋งž์ถค ์„œ๋ช… ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ช…๋ น์ค„์— ์ง€์ •๋œ ์‚ฌ์šฉ์ž ์ •์˜ ์„œ๋ช… ํŒŒ์ผ์„ ํ†ตํ•ด binwalk์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. --magic, ๋˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ์— ์ถ”๊ฐ€ํ•˜์—ฌ $ HOME / .config / binwalk / magic.

binwalk์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋‹ค์Œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ณต์‹ ๋ฌธ์„œ.

๋นˆ์›Œํฌ ํ™•์žฅ

๊ทธ๊ณณ์— API binwalk๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ binwalk ์Šค์บ”์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋ชจ๋“  Python ์Šคํฌ๋ฆฝํŠธ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” Python ๋ชจ๋“ˆ๋กœ ๊ตฌํ˜„๋˜์—ˆ์œผ๋ฉฐ, binwalk ๋ช…๋ น์ค„ ์œ ํ‹ธ๋ฆฌํ‹ฐ๋Š” ๋‹จ ๋‘ ์ค„์˜ Python ์ฝ”๋“œ๋กœ ๊ฑฐ์˜ ์™„์ „ํžˆ ๋ณต์ œ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

import binwalk
binwalk.scan()

Python API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ์„ ๋งŒ๋“ค ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. Python ํ”Œ๋Ÿฌ๊ทธ์ธ binwalk๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ํ™•์žฅํ•ฉ๋‹ˆ๋‹ค.

๋˜ํ•œ ์กด์žฌํ•œ๋‹ค. IDA ํ”Œ๋Ÿฌ๊ทธ์ธ ๊ทธ๋ฆฌ๊ณ  ํด๋ผ์šฐ๋“œ ๋ฒ„์ „ ๋นˆ์›Œํฌ ํ”„๋กœ.

๊ทธ๋ ‡๋‹ค๋ฉด ์ธํ„ฐ๋„ท์—์„œ ํŽŒ์›จ์–ด ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  binwalk๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์š”? ๋‚˜๋Š” ๋‹น์‹ ์ด ๋งŽ์€ ์ฆ๊ฑฐ์›€์„ ๋ˆ„๋ฆด ๊ฒƒ์ด๋ผ๊ณ  ์•ฝ์†ํ•ฉ๋‹ˆ๋‹ค :)

์ถœ์ฒ˜ : habr.com

์ฝ”๋ฉ˜ํŠธ๋ฅผ ์ถ”๊ฐ€