1
I’m trying to get into my Dlink router using C++ and I’m having problems with the login function!
I cannot interact with login and password correctly!
Sometimes this error or the code appears .html
of the router page speaking q username or password are incorrect!
#include <string.h>
#include <stdio.h>
#include <winsock2.h>
#include <windows.h>
void login(int sock) {
char userbuf[] = "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;
}
The error means that the sent method has not been implemented. In case you need to send a request using the HTTP protocol, in addition to the basic authentication you need to send the basic authentication header with the login:password value in Base64.
– Joao Alberto
I’ll have to use CGI for that?
– rafaelprog
You can use an HTTP lib to facilitate communication or mount the Voce header, you can start like this: stringstream << "GET / HTTP/1.1 r n" ...
– Joao Alberto