Binary Analysis Next Generation (BANG)
BANG is a framework for unpacking files (like firmware) recursively and running checks on the unpacked files. Its intended use is to be able to find out the provenance of the unpacked files and classify/label files, making them available for further analysis.
- a recent Linux distribution (Fedora 27 or higher, or equivalent)
- Python 3.6.x or higher (as some Python 3.6 specific features are used)
- pillow (possibly named python3-pillow), a drop in replacement for PIL ( http://python-pillow.github.io/ )
- GNU binutils (for 'ar')
- squashfs-tools (for 'unsquashfs')
- cabextract
- 7z
- e2tools (for 'e2ls' and 'e2cp')
- zstd
- python-lz4 (possibly named python3-lz4)
- qemu-img (for VMDK files)
- psycopg2 (possibly named python3-psycopg2)
- python-snappy (possibly named python3-snappy)
- python-tlsh (possibly named python3-tlsh)
- tinycss2 (possibly named python3-tinycss2, not available on Fedora 26 and earlier)
- dockerfile-parse (possibly named python3-dockerfile-parse)
- openssl
- rzip
- libxml2 (for 'xmllint')
- mailcap (for mime.types)
- lzop
- OpenJDK (for 'unpack200')
- defusedxml (possibly named python3-defusedxml)
- icalendar (possibly named python3-icalendar)
- ncompress
The following files can be unpacked, or verified, including carving from a larger file, unless stated otherwise.
- WebP
- WAV
- ANI
- gzip
- LZMA
- XZ
- timezone files
- tar
- Apple Double encoded files
- ICC (colour profile)
- ZIP (store, deflate, bzip2, but lzma needs some more testing)
- APK (same as ZIP, but with extra Android signing bytes)
- XAR (no compression, gzip, bzip2, XZ, LZMA)
- ISO9660 (including RockRidge and zisofs)
- lzip
- WOFF (Web Open Font Format)
- TrueType fonts/sfnt-housed fonts
- OpenType fonts
- Vim swap files (whole file only)
- Android sparse data image
- Android backup files
- ICO (MS Windows icons)
- Chrome PAK (version 4 & 5, only if offset starts at 0)
- GNU message catalog
- RPM (gzip, XZ, bzip2, LZMA, zstd, not: delta RPM)
- AIFF/AIFF-C
- terminfo (little endian, including ncurses extension, does not recognize some wide character versions)
- AU (Sun/NeXT audio)
- JFFS2 (uncompressed, zlib, LZMA from OpenWrt)
- CPIO (various flavours, little endian)
- Sun Raster files (standard type only)
- Intel Hex (text files only)
- Motorola SREC (text files only)
- MNG
- Android sparse image files
- Java class file
- Android Dex/Odex (not OAT, just carving)
- ELF
- SWF (uncompressed, zlib, LZMA)
- Android resource files (table type only, possibly not all types)
- Java/Android MANIFEST.MF files (whole file)
- Linux kernel configuration files (whole file)
- Dockerfile files (whole file)
- Python PKG-INFO files (whole file)
- base64/32/16 (whole file)
- SSH known hosts files (whole file)
- FLV (Macromedia Flash Video)
- Git index files
- Linux Software Map files (whole file)
- JSON (whole file)
- D-Link ROMFS
- Unix passwd files (whole file)
- Unix shadow files (whole file)
- bzip2
- GIF (needs PIL)
- JPEG (needs PIL)
- Microsoft Cabinet archives (needs cabextract)
- RZIP (requires rzip)
- 7z (requires external tools), single frame(?)
- Windows Compiled HTML Help (needs external tools, version 3 only)
- Windows Imaging file format (needs external tools, single image only)
- ext2/3/4 (missing: symbolic link support)
- zstd (needs zstd package)
- SGI image files (needs PIL)
- Apple Icon Image (needs PIL)
- LZ4 (requires LZ4 Python bindings)
- VMware VMDK (needs qemu-img, whole file only)
- QEMU qcow2 (needs qemu-img, whole file only)
- VirtualBox VDI (needs qemu-img, whole file only, Oracle flavour only)
- XML (whole file)
- Snappy (needs python-snappy)
- various certificates (PEM, private key, etc., needs openssl)
- lzop
- CSS
- PNG/APNG (needs PIL)
- ar/deb (needs binutils)
- squashfs (needs squashfs-tools)
- BMP (needs PIL)
- PDF (simple verification, no object streams, incremental updates at end of the file)
- pack200 (needs unpack200)
- GIMP brush (needs PIL)
- ZIM (Wikipedia archive format)
- MIDI
- Android tzdata
- Java key store (version 2 only)
- XG3D (proprietary file format from 3D Studio Max, labeling only)
- ACDB (audio callibration database, proprietary file format from Qualcomm, labeling only)
- Microsoft DirectDraw Surface (structure checks and very limited sanity checking)
- Khronos KTX files (version 1)
- Android verified boot image
- SQLite 3
- Linux fstab files
- Linux flattened device tree
- Broadcom TRX
- Photoshop PSD (raw bytes and RLE encoding only)
- pkg-config files
- minidump files
- PPM files ('raw' PPM only)
- PGM files ('raw' PGM only)
- PBM files ('raw' PBM only)
- Android bootloader for Qualcomm Snapdragon
- Android bootloader image
- Android bootloader for Huawei devices
- FAT16 file systems (8.3 file names)
- iCalendar (RFC 5545) files (whole file only)
- Coreboot images
- Minix V1 file system (Linux variant)
- Unix compress (needs 'uncompress'), only if end of the file is compress'd data
- Unix group files (whole file)
- TRANS.TBL files
$ python3 bang-scanner -c bang.config -f /path/to/binary
GNU Affero General Public License, version 3 (AGPL-3.0)
The code for unpacking D-Link ROMFS file systems was heavily inspired by binwalk and modified (and improved) for use with BANG.
The original license for the binwalk code:
The MIT License (MIT)
Copyright (c) 2010-2015 Craig Heffner
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The code for verifying and labeling Android Verified Boot images was heavily inspired by code from Android (avbtool) found at:
https://android.googlesource.com/platform/external/avb/+/master/avbtool
The original license for avbtool:
Copyright 2016, The Android Open Source Project
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
The recommended coding style is described in PEP 8:
https://www.python.org/dev/peps/pep-0008/
It is recommended to run PEP 8 verification tools, for example python3-pep8 (on Fedora).
Another tool that is recommended is pylint.