[go: up one dir, main page]

Skip to content

r1b/dicom-fuzz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

dicom-fuzz

Fuzzing DCMTK with afl-fuzz.

The high level procedure is as follows:

  1. Select a target binary
  2. Select or generate a small set of testcases
  3. Run afl-fuzz for a day or so on $(($(nproc) - 1)) cores
  4. Run afl-cov
  5. Review coverage output for gaps
  6. Goto 2

File Format

Targeting dcmdump.

Corpus

I'm starting out with a small set of testcases from go-dicom. I plan to try out some files from TCIA. I also plan to write some tools to generate my own files that include particular Value Representations and encoding schemes.

Method

  1. Remove PixelData and OverlayData tags. We don't care about how third-party libraries parse imaging data - we just want to hit the parser. This also significantly reduces the size of the testcases.
dcmodify -ea PixelData -ea OverlayData $INPUT_TESTCASES/*.dcm
  1. Minimize
afl-cmin -i $INPUT_TESTCASES -o $OUTPUT_TESTCASES -- /usr/local/bin/dcmdump @@

TODO: Use afl-tmin to further reduce the size of the testcases.

  1. Fuzz
afl-fuzz -i $TESTCASES_DIR -o $FINDINGS_DIR -x dicom.dict /usr/local/bin/dcmdump @@

dicom.dict is included in this repository - it includes the definitions of all known Value Representations. I could include a tag dictionary as well but idk if it will be all that useful.

Findings

o.O

Infinite loop when parsing a malformed DICOMDIR

Still triaging this one - there is some hardcoded autocorrection that causes DCMTK to repeatedly remove bytes from a Directory Record. It's not clear if this has security implications.

Suspicious hang when removing spaces from UI tags

Network Protocol

Targeting several binaries - probably storescp and storescu to start.

TBD - will need to do some weird instrumentation to get this to work with afl-fuzz.

Using afl-cov

Make a copy of the dcmtk sources and compile with profiling enabled. After the project entry in CMakeLists.txt add the following:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")

FIXME: I don't think you need -ftest-coverage in the linker

Run afl-cov as follows:

python2 $AFL_COV_BIN -d $FINDINGS_DIR --code-dir $DCMTK_SRC --coverage-cmd $DCMTK_SRC/$BUILDDIR/bin/dcmdump AFL_FILE --lcov-web-all --overwrite

FIXME: This takes a LONG TIME holy moly. Multiprocessing support??? Python3???

About

Fuzzing the DICOM format & network protocol

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published