Buffers on the stack in x86 (assembly language)

frost00

frost00

@frost00-2VMx64 Oct 26, 2024

I'm trying to get my head around buffers / buffer overflows in assembly language. I understand that if a buffer is created and the data being put into is larger than the buffer, it will overflow.

I can see that the instruction below will create space for a variable, but this would only be 4 bytes (32 bits) long.
sub esp, 4

Question 1: If I wanted to create a buffer 33 bits in length would the instruction simply be: sub esp, 8

Question 2:
If so, given the example of:
A: sub esp, 28 - large buffer all the way to ebp
B: sub esp, 32 - small buffer from ebp-32 to ebp-28

If more than 4 bytes were entered into B this would overflow into A. I understand that:
mov [ebp-32], ebx

would put a dword into ebp-32, but if I wanted to overflow into ebp-28 all the way to ebp I would need a 32*32=1024 bit/128byte string.

How could this be achieved / what would the instruction look like in assembly?

Thanks,
Frost

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform