I'm not really getting how this code does what it does:
char shellcode[] = "\xbb\x00\x00\x00\x00"
"\xb8\x01\x00\x00\x00"
"\xcd\x80";
int main()
{
int *ret;
ret = (int *)&ret + 2;
(*ret) = (int)shellcode;
}
Okay, I know:
int *ret;
sets a pointer of int. and:
ret = (int *)&ret + 2;
sets the address of ret and 2 bytes (I think.)
But I don't get what this means:
(int *)&ret
I know what &ret
means but not what (int *)&ret
means.
Also, how does it execute the shellcode by assigning the value of shellcode
to ret
?
UPDATE: What is the difference between:
(int *)&ret + 2
and:
&ret + 2