19.08.2015 Views

4.0

1IZ1TDd

1IZ1TDd

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

147Web Application Penetration Testingoverwriting the instruction pointer, similar results can also beobtained by overwriting other variables and structures, like ExceptionHandlers, which are located on the stack.On opening the executable with the supplied arguments andcontinuing execution the following results are obtained.How to TestBlack Box testingThe key to testing an application for stack overflow vulnerabilitiesis supplying overly large input data as compared to what isexpected. However, subjecting the application to arbitrarily largedata is not sufficient. It becomes necessary to inspect the application’sexecution flow and responses to ascertain whether anoverflow has actually been triggered or not. Therefore, the stepsrequired to locate and validate stack overflows would be to attacha debugger to the target application or process, generatemalformed input for the application, subject the application tomalformed input, and inspect responses in a debugger. The debuggerallows the tester to view the execution flow and the stateof the registers when the vulnerability gets triggered.On the other hand, a more passive form of testing can be employed,which involves inspecting assembly code of the applicationby using disassemblers. In this case, various sections arescanned for signatures of vulnerable assembly fragments. Thisis often termed as reverse engineering and is a tedious process.As a simple example, consider the following technique employedwhile testing an executable “sample.exe” for stack overflows:#includeint main(int argc, char *argv[]){char buff[20];printf(“copying into buffer”);strcpy(buff,argv[1]);return 0;}File sample.exe is launched in a debugger, in our case OllyDbg.As shown in the registers window of the debugger, the EIP or ExtendedInstruction Pointer, which points to the next instructionto be executed, contains the value ‘41414141’. ‘41’ is a hexadecimalrepresentation for the character ‘A’ and therefore the string‘AAAA’ translates to 41414141.This clearly demonstrates how input data can be used to overwritethe instruction pointer with user-supplied values and controlprogram execution. A stack overflow can also allow overwritingof stack-based structures like SEH (Structured ExceptionHandler) to control code execution and bypass certain stack protectionmechanisms.As mentioned previously, other methods of testing such vulnerabilitiesinclude reverse engineering the application binaries,which is a complex and tedious process, and using fuzzing techniques.Gray Box testingWhen reviewing code for stack overflows, it is advisable tosearch for calls to insecure library functions like gets(), strcpy(),strcat() etc which do not validate the length of source strings andblindly copy data into fixed size buffers.For example consider the following function:-void log_create(int severity, char *inpt) {Since the application is expecting command line arguments, alarge sequence of characters such as ‘A’, can be supplied in theargument field shown above.char b[1024];

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!