int main(){ c...">

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?

+4
source share
4 answers

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 
+9
source

Enter the following command into the terminal.

 echo $'\000\001' > file1 

This will save the values ​​of ASCII Character 1 and ASCII Character 2 in a file named file1. Now you can read it in your exploit_buf buffer.

+5
source

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).

0
source

Since it just inputs the input from standard input, you can simply pass the output of your printf to it:

 printf 'whatever' | myprogram 
0
source

All Articles