[dundee] Grabbing the stack pointer...

Nicholas Walker tel0seh at googlemail.com
Sun Mar 22 20:44:43 UTC 2009


Hi guys im doing some work with buffer overflows, and I've been scratching
my head for a while with this one. I have little experience in C, I can read
some source adn get a general idea of what each bit does, however i'm
required to grab the current address that the stack pointer is looking at.

I've been given this bit of source:





3.  The Stack Pointer
    =================


Every program has a stack pointer which is the address of the
beginning of the stack.  We can
find the stack pointer for a system using the following code:


unsigned long sp(void)
{
	__asm__("movl %esp, %eax");
}

void main(void)
{
	printf("0x%x\n", sp());
}


The function sp() contains the assembly instruction movl which copies
the value of the stack
pointer to the return buffer for the function, so it is returned to
the main function and
displayed.

$ ./sp

0xbfbffbc8


however after adding the correct headers, it still wont compile....


I understand the Assembly language instruction, ESP holds the address of
where the stack pointer is currently pointing, movl esp eax moves it to the
eax register, for returning. If anyone could help it would be great. its the
last bit of work i need to do to finish my project.
-- 


Nick Walker
Vice President : The Linux Society
UAD Ethical Hacker
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/dundee/attachments/20090322/f1a9bbad/attachment-0001.htm 


More information about the dundee mailing list