Turn "Hello, world\n" to machine code shellcode to show

Source: Internet
Author: User

Source

#include <stdlib.h>
const unsigned char shellcode[] = "\xeb\x19\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xb0\x04" \
                    "\xb2\x0e\x59\xb3\x01\xcd\x80\x31\xc0\xb0\x01" \
                    "\x31\xdb\xcd\x80\xe8\xe2\xff\xff\xff" \
                    "\x48\x65 \x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c "\
                    " \x64\x21\x0a ";
int main (int argc, char **argv) {
    int (*ret) ();
    RET = (int (*) ()) Shellcode;
    (int) (*ret) ();
    Exit (0);
}


[ZHONGYUNDE@LINUX-HCC3 ~] $GCC DD.C
[Zhongyunde@linux-hcc3 ~]$./a.out
Segmentation fault
[ZHONGYUNDE@LINUX-HCC3 ~] $GCC dd.c-z execstack
[Zhongyunde@linux-hcc3 ~]$./a.out
Hello, world!.

Description: Shellcode here should be treated as a function (in memory have execute permission) bar, have their own stack

1 link must indicate the executable stack, that is, option-Z execstack
2 Shellcode data type must be added const, because a const will be placed into the text section

See: Http://stackoverflow.com/questions/1576489/where-are-constant-variables-stored-in-c


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.