How to enter ASCII code "00" and "01" in linux bash?
I have a program that looks like this:
/* buf_overflow.c */ #include <stdio.h> int main(){ char buf[4]; char exploit_buf[4]; fgets(buf, 4, stdin); gets(exploit_buf); printf("exploit_buf: %s\n", exploit_buf); return 0; } I am going to use the vulnerability of the get function to overflow the buffer with some other variables. The value I want to write in exploit_buf is AAAAAAAA \ x01 \ x00 \ x00 \ x00, but I donβt know how to send ASCII codes β01β and β00β to exploit_buf.
I know that with this command "printf" AAAAAAAA \ x01 \ x00 \ x00 \ x00 "" you can enter the characters that I want, but I donβt know how to send them to the_buf exploit. I also know that Alt + (the numeric keys to the right of the keyboard) can generate characters from the ASCII code I entered, but this also does not work in my program.
The main problem: "How can I skip the first function" fgets () "and type arbitrary ASCII code into" gets () "?".
Does anyone know how to type arbitrary ASCII code on a Linux command line?
You can use echo -e :
$ echo -ne 'AAAAAAAA\x01\x00\x00\x00' | python -c 'import sys; print repr(sys.stdin.read())' 'AAAAAAAA\x01\x00\x00\x00' -e allows echo interpret escape codes, and -n suppresses the trailing newline.
Note that the Python program displays a string representation of what it received, and that is what we sent using echo .
For more complex exploit strings, it is often easy to use Perl or Python to directly create an exploit string:
$ perl -e 'print "A" x 1024 . "\0\0\0\1"' | ./buf_overflow Great example from nneonneo.
However, if you want to enter them directly without the help of a script, you can change the configuration of your keyboard to use the "United States (AltGr dead keys)" mode (under "System" β "Settings" β "Keyboard" β "Layout") .), then you can easily use special characters using the right alt button. Examples - Γ© is rAlt + e. Β° - rAlt-shift-0-0 (press 0 twice while holding the other buttons).