Why is my setenv () call not working?

I wrote the following C code to set the env variable to \x09 . But when I use echo $EGG | hexdump echo $EGG | hexdump , I see that it sets it to 00 . This problem only occurs when the first nibble is zero. Any clue what's wrong?

 char shellcode[] = "\x09"; main() { setenv("EGG", shellcode, 1); system("/bin/bash"); return 0; } 
+4
source share
2 answers

The problem is that the characters 0x08, 0x09, 0x0a, 0x0b, 0x0c ... are considered whitespace characters and lack the value of a variable. If you try to set 0x01 , it will be visible in the shell.

PS It seems that the variable is set to \x09 , but does not affect it: 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.

+4
source

Well, your code is working correctly;)

0x09 is the ASCII tab code.

So EGG set to tab . When you print it, it actually prints a tab , which you usually don't recognize in the console.

+2
source

All Articles