I am trying to exploit a buffer overflow in a challenge, the buffer gets it's value from an environment variable. In GDB I know that you can set environment variables using the command:
set environment username = test
However I need to pass the username variable special characters, so I need to do something like:
set environment username= $(echo -e '\xff\x4c......')
But that command doesn't get executed and the username variable contains literally what I wrote down, does anybody know a trick to pass special characters to an environment variable?
When starting gdb from shell command-line, you can specify which program to run, with which arguments (with
--args
), and even modify the environment of the program with the help ofenv
!I just did it successfully like this:
--ex=run
is to ask gdb to run it immediately.Well, if you really need to do it from GDB, here is one example:
hello.c
Example:
Change
VAR
andecho myEnv
to a variable and command you need.But note that setting
VAR
from shell before starting GDB also works: