- ZLIB Compressed Data Format Specification version 3.3
- DEFLATE Compressed Data Format Specification version 1.3
- GZIP file format specification version 4.3
- Portable Network Graphics (PNG) Specification and Extensions
- https://whatis.techtarget.com/glossary/Security
- https://docs.microsoft.com/en-us/windows/security/threat-protection/intelligence/malware-naming
- https://encyclopedia.kaspersky.com/knowledge/rules-for-classifying/
-
https://zeltser.com/media/docs/malware-analysis-cheat-sheet.pdf
-
https://pokhym.com/2017/06/25/part-1-1-basic-static-techniques/
-
592/4688- A new process has been created
/proc/self/cmdline
/proc/self/cwd/
-
any format
- ./volatility.md
- GitHub - ufrisk/MemProcFS: The Memory Process File System
-
EnCase format
- AccessData FTK_Imager
-
compare running processes with known file hashes
- dumpit, procdump -ma, PMDump
- winpmem.exe -f test.raw
# load driver
winpmem.exe -l
# run against raw device
vol.py -f \\.\pmem --profile Win7SP1x64 pslistapt-get install xmount ewf-tools afflib-tools sleuthkit
pip3 install imagemounter
imount --check
# ||
sudo mount -t ext4 -o loop foo mnt_dirhttps://countuponsecurity.com/2016/05/30/digital-forensics-ntfs-indx-and-journaling/
# list deleted files with filesystem start offset
fls -o 129 foo.dd
# recover all files
tsk_recover -o 129 foo.dd .
# || recover files, by inode
# Reference: [How To Search for Strings on a Disk Image Using The Sleuth Kit \- LMG Security](https://www.lmgsecurity.com/sleuth-kit/)
icat -o 129 -r foo.dd 54
# recover all files from journal
extundelete artefact --restore-all
# list deleted files, with full paths, recursively
fls -d -p -r /dev/sda
# recover files, from unallocated space (carving), by extension
sed -i 's/^#[[:space:]]\+\(\(doc\|pdf\|gif\|jpg\|png\).*\)/\1/g' /etc/scalpel/scalpel.conf
scalpel /dev/sdafind . -type f -name '*.png' -size +1500k -delete
find . -type d -empty -deletedd if=/proc/7/mem bs=$((0x1000)) skip=$((Ox7fb84ee44 + 0x207)) count=1 of=out- create disk image
# List disks wmic diskdrive list # || Get-WmiObject Win32_DiskDrive # Dump disk dd.exe if=\\.\PhysicalDrive0 of=d:\images\PhysicalDrive0.img --md5sum --verifymd5 --md5out=d:\images\PhysicalDrive0.img.md5
- carving
- https://www.forensicfocus.com/challenges-and-images/
- https://www.cfreds.nist.gov/
- http://downloads.digitalcorpora.org/corpora/
- GitHub - RUB-NDS/PDF101: Artifacts for the Black Hat talk.
- Apprentice Alf’s Blog | Everything you ever wanted to know about DRM and ebooks, but were afraid to ask.
- ../logbooks/pdf_reformat.md
# disable security / drm / no copy restriction bits
qpdf --decrypt input.pdf out.pdf
pdftk input.pdf output out.pdf allow AllFeatures
gs -sPDFPassword=$PASS -q -dNOPAUSE -dBATCH -dSAFER -r300 -sDEVICE=pdfwrite -sOutputFile=%stdout% -c .setpdfwrite -f input.pdf > output.pdf
# decompress streams
qpdf --qdf --object-streams=disable foo.pdf foo.decompressed.pdf
# edit
qpdf -qdf --stream-data=uncompress foo.pdf foo.decompressed.pdf
# [...]
mutool clean
# enumerate references
f=challenge.pdf && { \
peepdf "$f" | \
grep 'Objects ([0-9]*):' | \
sed 's/.*\[\(.*\)\]/\1/; s/\([0-9]\+\)\(, \)\?/references to \1\n/g' | \
peepdf "$f" -i
} 2>/dev/null- https://blog.didierstevens.com/programs/pdf-tools/
- https://www.bitsgalore.org/2021/09/06/pdf-processing-and-analysis-with-open-source-tools
- references to objects, tree
- streams
- xrefs
- https://labs.appligent.com/pdfblog/pdf_cross_reference_table/
- https://resources.infosecinstitute.com/topic/pdf-file-format-basic-structure/
- https://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art019
If you follow this backwards, you'll see that the startxref entry points to the line that reads xref
- compression level magic bytes
78 01: None / Low78 9C: Default (Common)78 DA: Best
# Fix
zip -F foo.zip --out foo.fixed.zip
zip -FF foo.zip --out foo.fixed.zip
# Extract broken zip
bsdtar xf zipfile
# Extract multipart archive
# Given: archives ordered by name
cat foo.*.zip > foo.zip
zip -FF foo.zip --out foo.fixed.zip
# bruteforce password
while read -r i; do 7z x -p"$i" flag.zip >/dev/null; e=$?; if [ ! -s flag.txt ] || [ $e -gt 0 ]; then rm flag.txt; else break; fi; done < ~/code/guides/ctf/SecLists/Passwords/Leaked-Databases/rockyou-75.txt
# preserve attempts where CRC Failed
while read -r i; do 7z x -p"$i" flag.zip >/dev/null; if [ ! -s flag.txt ]; then rm flag.txt; else mv flag.txt flags/"$(date +%s)".flag.txt; fi; done < ~/code/guides/ctf/SecLists/Passwords/Leaked-Databases/rockyou-75.txt- binwalk expects p7zip
The UnZip implementation is the cause of your problem. When binwalk extracts full, the first ZIP actually contains both ZIPs, but UnZip only extracts the last one (which is also stored independently in the second ZIP that binwalk extracted).
- https://reverseengineering.stackexchange.com/questions/13616/simple-carving-of-zip-file-using-binwalk
- https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
- ~/code/doc/zip/APPNOTE.TXT
- AE-x (compression method = 99)
- ~/code/doc/zip/Ten Thousand Traps.pdf
- https://ctf-wiki.github.io/ctf-wiki/misc/archive/zip/
- symbolic links
- APPNOTE.TXT - .ZIP File Format Specification
- 4.5.7 UNIX Extra Field (0x000d)
- APPNOTE.TXT - .ZIP File Format Specification
- write outside extraction path using path traversal via relative path, e.g.
../../foo
Bruteforce:
~/opt/john/run/zip2john flag.zip > flag.zip.john
~/opt/john/run/john --wordlist="$(realpath ~/share/opt/rockyou.txt)" flag.zip.johnBiham and Kocher's known plaintext attack:
-
encryption algorithm = ZipCrypto
-
uncompressed copy of one encrypted file
-
compressed plaintext file using same algorigthm
- https://ctf-wiki.github.io/ctf-wiki/misc/archive/zip/
- https://www.programmersought.com/article/13436370754/
# General case bkcrack -C encrypted.zip -c uncompressed.xml -P plain.zip -p plain.txt # Or: Contains png bkcrack -C encrypted.zip -c foo.png -p png_header.bin -o 0 # Take file entry from encrypted archive, pass to `-c` # Take key values, pass to `-k` bkcrack -C encrypted.zip -c encrypted.jpg -k c072e51c a36b7996 b6f8d312 -d decrypted.jpg
-
GitHub - keyunluo/pkcrack: pkcrack with modern building tools
- identify trailing data after compressed data: boolean-based error checking with
7z t, foreach nulled byte - CRC fix: null out start header + signature header
- How to recover corrupted 7z archive
# Extract broken rar
unrar e -kb
# Extract multipart archive
# Given: archives ordered by name
unrar x foo.part1.rar-
detection
- https://stegonline.georgeom.net/upload
- stegoveritas
- zsteg
- foremost
# Histogram convert _ -format %c histogram:info:- # If differences in most pixels, maybe LSB applied compare foo.png original.jpg foo.diff.png
-
application
- steghide
- adds huffman table:
()*56789:CDEFGHI
- adds huffman table:
- outguess
- stepic
- RGB vs RGBA
- steghide
-
GitHub - DominicBreuker/stego-toolkit: Collection of steganography tools - helps with CTF challenges
- QuickBMS generic files extractor and reimporter - Luigi Auriemma
- GitHub - Sembiance/dexvert: Decompress EXtract and CONVert old file formats into modern ones
- Category:Electronic File Formats - Just Solve the File Format Problem
- GitHub - airbus-seclab/diffware: An extensively configurable tool providing a summary of the changes between two files or directories, ignoring all the fluff you don't care about.
- diffoscope: in-depth comparison of files, archives, and directories
- GitHub - openpreserve/format-corpus: An openly-licensed corpus of small example files, covering a wide range of formats and creation tools.
- telparia.com - Index of /fileFormatSamples/
- samples.ffmpeg.org - Index of /
Detection / Parsing:
file -k _
binwalk --dd='.*' _
binwalk -Me _
# alternatives:
# - [unblob](https://unblob.org/formats/): splits unknown chunks from archive / fs
# - [OFRAK](https://ofrak.com/): allows manipulates / repacks
# - [GitHub \- fkie\-cad/FACT\_core: Firmware Analysis and Comparison Tool](https://github.com/fkie-cad/FACT_core)
# graphics images
exiftool -v _
identify -verbose _
python3 -c 'import cv2, sys; cv2.imread(sys.argv[1])' _
python3 -c 'import sys; from PIL import Image; print(Image.open(sys.argv[1]).verify())' _
pngcheck -f -vv _
# pdfs
pdfinfo _
qpdf --check _
caradoc stats _
# disk images
### files
fls _
### metadata
iat --debug -i _
ksv ~/opt/isolyzer/testFiles/iso9660.iso ~/opt/kaitai_struct/formats/filesystem/iso9660.ksy
### verify expected file size extracted from headers consistent with actual size
isolyzer _
# archives
7z t _No magic enforced at offset zero:
- PDF, PostScript, BMFF (mp4, mov, heic...), DICOM (medical images), TAR, ZIP, Rar, 7z, Arj, raw dumps (.iso, roms)
Examples:
- ~/opt/mitra/
- ~/opt/truepolyglot.git/
- jpeg + mp3
- jpeg + php archive
\xFF\xD8......................JPEG DATA.....................\xFF\xD9 __HALT_COMPILER(); ............PHAR DATA............................- execute with: phar://
- https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a
- gif + javascript
- ~/code/snippets/polyglot/thinkfu-js.gif
- http://web.archive.org/web/20200301052900if_/http://www.thinkfu.com/blog/gifjavascript-polyglots
- gif + jar
- msi + jar
- png + zip
- https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20Insecure%20Files
Parasites:
- ICC profile in JPG
- multipart RAR used to work around JPG block size
- IDAT chunk in PNG
- ./files/mis-identified-files.jpg
- https://github.com/corkami/pocs/tree/master/mocks
# identify by chunks vs. magic bytes
### png
hexgrep.py _ "$(printf '%s' 'PNG|IHDR|PLTE|IDAT|IEND' | xxd -p)"
grep -Habo $'PNG\\|IHDR\\|PLTE\\|IDAT\\|IEND' _
file -k * | grep '\s*data' | cut -d':' -f1 | xargs -i env LC_ALL=C awk 'match($0, /PNG|IHDR|PLTE|IDAT|IEND/) {
offset = count + RSTART - 1;
group = substr($0, RSTART, RLENGTH);
printf("%s:%s(0x%x):%s\n", FILENAME, offset, offset, group);
} { count += length + 1; }' {}
### jpeg
hexgrep.py _ '\xff\xd8|\xff\xe0|JFIF|\xff\xdb|\xff\xc0|\xff\xc4|\xff\xda|\xff\xd9'
grep -Habo $'\xff\xd8\\|\xff\xe0\\|JFIF\\|\xff\xdb\\|\xff\xc0\\|\xff\xc4\\|\xff\xda\\|\xff\xd9' _
file -k * | grep '\s*data' | cut -d':' -f1 | xargs -i env LC_ALL=C awk 'match($0, /\xff\xd8|\xff\xe0|JFIF|\xff\xdb|\xff\xc0|\xff\xc4|\xff\xda|\xff\xd9/) {
offset = count + RSTART - 1;
group = substr($0, RSTART, RLENGTH);
printf("%s:%s(0x%x):%s\n", FILENAME, offset, offset, group);
} { count += length + 1; }' {}- CRC correction
pngcheck -cfv _
- http://libpng.org/pub/png/apps/pngcheck.html - incorrect chunk length
- incorrect headers
- extract patterns from specifications
- strip out bytes of separate / adjacent areas (used in ECC)
-
https://forensixchange.com/posts/19_04_22_win10_ntfs_time_rules/
-
http://journeyintoir.blogspot.com/2013/12/revealing-recentfilecachebcf-file.html
-
https://www.hecfblog.com/2018/08/daily-blog-451-defcon-dfir-ctf-2018.html
-
https://klanec.github.io/inctf/2020/08/02/inctf-lookout-foxy.html
- firefed (firefox), undbx (mails), mpack (MIME attachments)
- windows
- GetModuleHandle
- VirtualProtect + RtlZeroMemory
- linux
- fopen("/proc/self/maps", "r")
- fscanf addresses
- mprotect + memset
winpmem-2.1.post4.exe -o lol.aff4
"C:\Program Files\Rekall\rekal.exe" -f lol.aff4
# procdump proc_regex="thekeys", dump_dir="C:/Users/int0x80/Desktop/"git clone https://github.com/504ensicsLabs/LiME
sudo insmod ./lime-$(uname -r).ko "path=/tmp/1"
git clone https://github.com/volatilityfoundation/volatility
# Build profile for current machine
cd ~/tools/volatility/tools/linux/
make
# Validation
grep '.debug_info' module.dwarf
python vol.py -f /tmp/1 --profile=Linux...
# linux_pslist
# linux_procdump-
For windows, contents may still be recovered via
vaddump, if references not broken