Reputation: 439
I wrote the following C code to set the env variable to \x09
. But when I use echo $EGG | hexdump
, I see that it sets it to 00
. This problem happens only when the first nibble is zero. Any clue what is wrong?
char shellcode[] = "\x09";
main() {
setenv("EGG", shellcode, 1);
system("/bin/bash");
return 0;
}
Upvotes: 4
Views: 517
Reputation: 5083
The problem is that characters 0x08, 0x09, 0x0a, 0x0b, 0x0c ...
are considered whitespace characters and are stripped from a variable value. If you try to set 0x01
, it'll be visible in the shell.
P.S. It looks like the variable is set to \x09
but is not echoed by the shell:
Indeed:
prev_sh_$ ./so2
$ export IFS=" \n"
$ echo $EGG | hexdump
0000000 0a09
0000002
0x0a
(\n
) is added by the shell to print the value on the next line.
Upvotes: 4
Reputation: 121417
Well, your code works correctly ;)
0x09
is the ASCII code tab key.
So EGG
is set to tab key. When you print it, it actually prints tab which you don't normally recognize in the console.
Upvotes: 2