Code Monkey home page Code Monkey logo

dicom-fuzz's Introduction

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???

dicom-fuzz's People

Contributors

r1b avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.