Phase 3: Injecting a String
Phase 3 also involves a code-injection attack against ctarget, but
this time, instead of passing your hexadecimal cookie, you have to
pass a string as the argument.
As a reminder, here's the code for getbuf,
1 2 3 4 5 6 | |
and for test:
1 2 3 4 5 6 | |
ctarget has a function called hexmatch, whose C code looks like
1 2 3 4 5 6 7 8 9 | |
and a touch3 function, which looks like
1 2 3 4 5 6 7 8 9 10 11 12 | |
Your task is to get ctarget to execute the code for touch3
rather than returning to test. You must make it appear to
touch3 as if you have passed a string representation of your
cookie as its argument.
Hints
-
You will need to include a string representation of your cookie in your exploit string. The string should consist of the eight hexadecimal digits (ordered from most to least significant) without a leading
0x. -
Recall that a string is represented in C as a sequence of bytes followed by a byte with value 0 (i.e., a null).
man asciiwill show you the byte representations of the characters you need. -
Your injected code should set register
regto the address of this string. -
When the functions
hexmatchandstrncmpare called, they push data onto the stack, overwriting portions of the memory that held the buffer used bygetbuf. As a result, you will need to be careful where you place the string representation of your cookie. -
hexmatchis a bit difficult to understand. In essence,hexmatch(val, sval)convertsvalinto printable hexadecimal format and compares it with the 8-character stringsval, returning true if the two match. So, for example,Comparison Return Value hexmatch(0x1234abcd, "1234abcd")true hexmatch(0x1, "00000001")true hexmatch(0xdcba4321, "1234abcd")false hexmatch(0x1234ABCD, "1234ABCD")false (why?) -
See Generating Byte Codes on how to use tools to generate the byte-level representations of instruction sequences.
-
There is a
-qflag toctargetthat stops the program from talking to the grading server. -
There is an
-ioption tofile ctargetthat tells it to read from a file namedinstead of fromfile stdin.
(When logged in, completion status appears here.)