Strings
strings ดึงข้อความที่อ่านได้ออกจาก binary — เป็นขั้นแรกของ reversing ที่บ่อยครั้งเจอ flag, hardcoded password, URL, error message ตรงๆ บทนี้ลงลึกการใช้ทุก option, encoding ต่างๆ (ASCII/Unicode), การกรอง, FLOSS สำหรับ string ที่ถูกซ่อน, และการเชื่อมกับ decompiler
1. ทำไมเริ่มจาก strings
ก่อนเปิด decompiler ให้ลอง strings เสมอ — เป็นวิธีเร็วสุดที่บางทีเจอคำตอบทันที: flag ที่ hardcode, password, URL ของ C2 server, ชื่อฟังก์ชัน/library, error message ที่บอกใบ้ logic, format string โจทย์ CTF ระดับง่ายหลายข้อแก้ได้ด้วย strings อย่างเดียว และแม้โจทย์ยาก strings ก็ให้ context เริ่มต้นที่มีค่า
2. การใช้และ options
strings binary # default: ASCII >= 4 ตัว
strings -n 8 binary # เฉพาะ string ยาว >= 8 (ตัด noise)
strings -t x binary # แสดง offset (hex) ของแต่ละ string
strings -e l binary # 16-bit little-endian (Unicode/Windows wide char)
strings -e b binary # 16-bit big-endian
strings -a binary # scan ทั้งไฟล์ (ไม่ใช่แค่ data section)
# rabin2 (radare2) — แยก string ตาม section พร้อม metadata
rabin2 -z binary # strings ใน data sections
rabin2 -zz binary # ทั้งไฟล์3. กรองหา flag/keyword
# หา flag/keyword
strings binary | grep -iE 'flag|ctf|key|pass|secret|admin'
# หา pattern คล้าย flag format (เช่น CTF{...})
strings binary | grep -oE '[A-Za-z0-9_]+\{[^}]+\}'
# หา base64/hash-like (ตัวยาวๆ)
strings binary | grep -E '[A-Za-z0-9+/]{20,}={0,2}'
# หา URL/IP
strings binary | grep -oE 'https?://[^ ]+'
strings binary | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'4. เมื่อ string ถูกซ่อน (FLOSS)
malware/โจทย์ขั้นสูงมักซ่อน string ไม่ให้ strings เห็น — โดย encode/encrypt แล้ว decode ตอน runtime, หรือ build ทีละ byte บน stack FLOSS (Mandiant FLARE) แก้ปัญหานี้ได้
# FLOSS ดึง string ที่ถูก decode at runtime / สร้างบน stack
floss binary
# จะ emulate และดึง: static strings + decoded strings + stack strings
# เฉพาะ stack strings
floss --only stack binary- string ที่ถูก XOR/encode → FLOSS หรือ reverse routine ใน decompiler
- string build ทีละ byte บน stack → เห็นใน decompiler (mov byte) หรือ FLOSS
- strings ว่างเปล่าผิดปกติ → อาจ packed (ดู section 5)
5. ถ้า strings ว่าง — อาจ packed
ถ้า strings ออกมาน้อยผิดปกติ (ไม่มี string ที่มีความหมายเลย) binary อาจถูก pack (บีบอัด/เข้ารหัส แล้ว unpack ตอน run)
# ตรวจว่า packed ไหม
strings binary | grep -i UPX # เห็น UPX = packed ด้วย UPX
rabin2 -I binary | grep -i packer
binwalk binary # ดู entropy/sections
# unpack UPX
upx -d binary -o unpacked
# packer อื่น → unpack ตอน runtime (dump จาก memory) หรือ debugger6. Quick Reference
- ขั้นแรกของ reversing — เร็ว บางทีเจอ flag เลย
- strings -n 8 binary (ตัด noise); -t x (offset)
- strings -e l (Unicode/Windows wide char) — อย่าลืม!
- กรอง: grep -iE 'flag|pass|key'; -oE 'CTF\{[^}]+\}'
- string ซ่อน → FLOSS (decode/stack strings)
- strings ว่าง → packed (UPX: upx -d; อื่น: dump memory)
- rabin2 -z = strings ตาม section
🧭 จับมือทำทีละขั้น (มีแค่ Kali) + ถ้าติดไปไหนต่อ
สมมติเพิ่งได้ไฟล์ binary จากโจทย์ CTF มา ยังไม่รู้จะเริ่มตรงไหน มีแค่ Kali เปล่าๆ ทำตามนี้ทีละขั้น
- 1file ./binary — ดู type (ELF/PE), architecture, stripped หรือไม่
- 2chmod +x ./binary เผื่อต้องรัน (ยังไม่ต้องรันจริงตอนนี้ก็ได้)
- 3strings -n 8 ./binary | less ดูคร่าวๆ ก่อนว่ามีอะไรน่าสนใจ
- 4strings ./binary | grep -iE 'flag|ctf|key|pass|secret'
- 5ถ้าเจอ pattern คล้าย flag (เช่น CTF{...}) ตรงๆ = จบเลย ส่งคำตอบได้
- 6ถ้าไม่เจอ ลอง strings -e l ./binary (Unicode/wide char — บาง binary Windows ไม่โผล่ใน ASCII ปกติ)
- 7ลอง rabin2 -z ./binary หรือ rabin2 -zz ./binary (แยก string ตาม section)
- 8เช็ค packed: ถ้า strings ออกมาน้อยผิดปกติ (แทบไม่มี string ที่มีความหมาย) ให้รัน binwalk ./binary
- 9ถ้าเจอ UPX ให้ upx -d ./binary -o unpacked แล้วย้อนไป strings ใหม่
- 10ถ้าไม่ packed แต่ยังไม่เจอ flag ตรงๆ ให้เปิด ghidra ดู logic ต่อ
| ขั้นตอน/งาน | เครื่องมือใน Kali | ติดตั้งเพิ่ม (ถ้าไม่มี) | เครื่องมือออนไลน์ |
|---|---|---|---|
| ดูชนิดไฟล์/arch | file | - | - |
| ดึงข้อความอ่านได้ | strings, rabin2 | apt install radare2 | CyberChef |
| หา string ที่ถูกซ่อน/decode runtime | - | pipx install flare-floss | - |
| เช็ค packed/entropy | binwalk | apt install binwalk | - |
| unpack UPX | upx | apt install upx-ucl | - |
| เปิดดู logic ต่อ | ghidra | apt install ghidra | dogbolt.org |
| ถอดรหัส/แกะ base64 ที่เจอในสตริง | base64 | - | CyberChef |
| เดายี่ห้อ/ถอด hash ที่เจอ | - | - | hashes.com |
หัวข้อที่เชื่อมโยง
โน้ตของฉัน
ยังไม่มีโน้ตสำหรับหัวข้อนี้