Authentication router

1

I'm trying to get into my Dlink router using C ++ and I'm having trouble logging in!

I can not interact with login and password correctly!

Sometimes this error occurs or the code .html of the router page says that the username or password is incorrect!

#include<string.h>#include<stdio.h>#include<winsock2.h>#include<windows.h>voidlogin(intsock){charuserbuf[]="USER admin\r\n";
      char buf[3012];
      char receive_user[1024];
      char receive_pass[1024];

      memset(buf, 0, 1024);


      printf("[+] Sending Username...\n");
      send(sock, userbuf, strlen(userbuf), 0);
      recv(sock, receive_user, 200, 0);
      printf("[+] %s", receive_user);


      sprintf(buf, "PASS %s\r\n", "admin");

      send(sock, buf, strlen(buf), 0);
      recv(sock, receive_pass, 200, 0);
      printf("[+] %s", receive_pass);

}

int connect_target(char *host, u_short port)
{
    int sock = 0;
    struct hostent *hp;
    WSADATA wsa;
    struct sockaddr_in sa;

    WSAStartup(MAKEWORD(2,0), &wsa);
    memset(&sa, 0, sizeof(sa));

    hp = gethostbyname(host);
    if (hp == NULL) {
        printf("gethostbyname() error!\n"); exit(0);
    }
    printf("[+] Connecting to %s\n", host);
    sa.sin_family = AF_INET;
    sa.sin_port = htons(port);
    sa.sin_addr = **((struct in_addr **) hp->h_addr_list);

    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock < 0)      {
        printf("[-] socket blah?\n");
        exit(0);
        }
    if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0)
        {printf("[-] connect() blah!\n");
        exit(0);
          }
    printf("[+] Connected to %s\n", host);
    return sock;
}


int main(int argc, char **argv)
{
    int sock = 0;
    int data, port;
    printf("\n[$] Authentication Router Dlink\n");
    if ( argc < 2 ) { printf("Nenhum argumento"); exit(0); }
    port = 80;
    sock = connect_target(argv[1], port);
    login(sock);
    closesocket(sock);
    return 0;
}
    
asked by anonymous 16.10.2016 / 01:29

0 answers