CSAW 2015 contacts Writeup
Point = 250
Category = Exploitable
Hi,
we are given a binary contacts
,
1 2 |
|
The binary seems to be a contact manager, based on my analysis it has a buffer at BSS
, and every time we create a contact this structure will be located at the buffer:
1 2 3 4 5 6 7 |
|
desc
is the contacs description and allocates a buffer with buffer size des_length
. num
is the contact number with size 0xb
.
So, we are going to find vulnerabilities.
I named 0x08048980
=> editCon
, this function edites the contact which you give its name, let’s check the decompilation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
As you may noticed when i try to edit the name there is no input length check a buffer overflow vulnerability. but there may be a problem since we don’t know it’s value n
.
this can be fixed by first preparing a description edit, so after entering the function again we have a known size.
and after some diging we can notice there is an another vulnerability, 0x08048bd1
=> pCon:
1 2 3 4 5 6 7 8 |
|
Here we go, a nice format string vulnerability.
by using these two vulnerabilites we have write-what-where primitive to exploit the binary.
this is my scenario,
- create a contact.
- leak a pointer to locate the
system
symbol using fmt vuln. - create second contact.
- leak second contact decription heap address to have a stable exploitation using fmt vuln.
- create third contact.
- leak third contact decription heap address to have a stable exploitation using fmt vuln.
- Overflow first contact name into the second and use proper description address which leaked before
and overwrite number pointer to heap by
free
got address. - Overflow second contact name into the third and use proper description address which leaked before
and overwrite number pointer to heap by
free+2
got address. - Edit second and third contacts description to
%####x%1$hn
and proper number to overwritefree
tosystem
- Edit first contact description to ‘/bin/sh\x00’
- delete first contact and pop a shell.
Of course null byte is not our concern since fgets is used in reading procedure.
please notice i used precision
task libc version but you can use libc_database to find a proper one blindly.
I should declare there maybe another or better solution but this let me in ;)
and finally out exploit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
And running the expl:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
@HAMIDx9