EvilZone

Programming and Scripting => C - C++ => : ca0s May 21, 2011, 12:21:29 PM

: opCodePrint
: ca0s May 21, 2011, 12:21:29 PM
I made this to easily get a shellcode in hexa format having its ASM code. The example shellcode is a system("cmd"). Change code in __asm(...) (leave those nops at the beginning and the end) with your own shellcode.

:
// OpCodePrint
//    By ca0s

#include <stdio.h>
//#include <windows.h>

void shellcode(void)
{
     __asm(
           // Don't remove this NOP
           "nop;"
           //
           //
           "push %ebp;"
           "mov %esp, %ebp;"
           "xor %edi, %edi;"
           "push %edi;"
           //
           //".byte 0xEB;"
           //".byte 0x01;"
           //".byte 0x83;"
           //
           "sub $0x04, %esp;"
           "movb $0x63, -8(%ebp);" //c
           "movb $0x6D, -7(%ebp);" //m
           "movb $0x64, -6(%ebp);" //d
           "movb $0x2E, -5(%ebp);" //.
           "movb $0x65, -4(%ebp);" //e
           "movb $0x78, -3(%ebp);" //x
           "movb $0x65, -2(%ebp);" //e
           "lea -8(%ebp), %eax;"
           "push %eax;"
           "movl $0x7573b16f, %ebx;"
           "call *%ebx;"
           //
           // Don't remove this NOP
           "nop;"
           //
           );
  return;
}

int main(void)
{
    //LoadLibrary("msvcrt.dll");
    printf("\nOpCodePrint by Ca0s\n\nchar shellcode[]=\"");
    int c=0;
    char *dirScode=(char *)shellcode;
    while((unsigned char)*dirScode != 0x90) dirScode++;
    while((unsigned char)*(dirScode + (++c))!=0x90) printf("\\x%.2X", (unsigned char)*(dirScode + c));
    printf("\";\n\nBytes: %d\n", (c-1));
    //shellcode();
    return;
}
: Re: opCodePrint
: Z3R0 May 22, 2011, 06:32:05 PM
saved my life dude! thank you! you are a fricken awesome coder I swear to God, high quality shit
: Re: opCodePrint
: Tsar May 22, 2011, 07:38:02 PM
So basically this converts a given ASM instruction (or multiple) into what it would be in hexidecimal (if it were to be compiled or whatever)?
: Re: opCodePrint
: ca0s May 22, 2011, 10:11:30 PM
So basically this converts a given ASM instruction (or multiple) into what it would be in hexidecimal (if it were to be compiled or whatever)?
Yes, that's it. You give ASM code, it gives you its hexa assembled code.
: Re: opCodePrint
: Tsar May 22, 2011, 10:29:43 PM
Yes, that's it. You give ASM code, it gives you its hexa assembled code.

Nice, very cool, this should probably go on "Code Library" though.