The Art of Software Security Testing" explain the proper methods for examining file formats."> The Art of Software Security Testing" explain the proper methods for examining file formats.">
| Home > The Art of Software Security Testing | |
| chapter excerpt: |
|
||
Fuzzing File Formats As an example of a common file format vulnerability, consider the following code fragment. It is an example of a style of code commonly seen parsing binary file formats. The file format may consist of a file header and a number of sections, each with section headers. Each section header contains a section size field that describes how many bytes of data are contained within that section. If the file format parsing code uses these values unchecked in a memory allocation request size or as an offset into the file, a denial-of-service or memory trespass vulnerability may be likely. The following code does not check the section size field read from the file section header. It reads file data into a heap-allocated data buffer without validating the size or checking the return value of HeapAlloc. This presents several problems (see Listing 11-4).
Listing 11-4
An application's file format handling should be tested against improper and malformed files. The test methodology should generate a series of malformed files by mutating properly formatted files, generating random garbage files, and creating files likely to trigger errors handling boundary conditions. The application should be tested against each file to ensure that it properly handles each one without crashing or causing unexpected behavior. The next section describes automated file corruption testing and some freely available file format testing tools.
File Corruption Testing Testing an application's handling of a binary file format may be performed at several different levels. A straightforward yet labor-intensive approach is to manually create a series of files that have been corrupted in different ways and proceed to attempt to use the file in the application being tested. This approach requires little or no programming; the file corruption can be performed manually with a hex editor or by a small Python script. With this approach, however, several issues arise. For example, there may be a large number of test cases, and manually corrupting the files and testing them may take too long—not to mention being mindnumbingly boring. Some level of automation can speed up this process of file creation and testing to free the application penetration tester to do other, more interesting things.
Automated File Corruption A simple tool to perform quick file format testing is Ilja van Sprundel's Mangle.4 Mangle overwrites random bytes in a binary file format's header with random values, slightly biased toward large and negative numbers. Mangle requires a template file to mangle and the size in bytes of the file header. As an example, let's mangle a JPG file. Want to learn how to mangle a JPG file? Or how to automate the testing of local applications? Download the rest of Chapter 11: Local Fault Injection (.pdf) Note: Printed with permission from Addison-Wesley. "The Art of Software Security Testing: Identifying Software Security Flaws" by Chris Wysopal, Lucas Nelson, Dino Dai Zovi and Elfriede Dustin. Copyright 2007. For more information about this title and other similar books, please visit www.awprofessional.com.
'); // -->
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
|
||||||||||