Skip to content

Commit

Permalink
update keepalive1 another implementation, #22 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mchome committed Oct 13, 2017
1 parent a61a618 commit 5237c3a
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# dogcom [![travis-ci](https://travis-ci.org/mchome/dogcom.svg "Build status")](https://travis-ci.org/mchome/dogcom) [![badge](https://img.shields.io/badge/%20built%20with-%20%E2%9D%A4-ff69b4.svg "build with love")](https://github.com/mchome/dogcom) [![version](https://img.shields.io/badge/stable%20-%20v1.5.0-4dc71f.svg "stable version")](https://github.com/mchome/dogcom/tree/v1.5.0)
# dogcom [![travis-ci](https://travis-ci.org/mchome/dogcom.svg "Build status")](https://travis-ci.org/mchome/dogcom) [![badge](https://img.shields.io/badge/%20built%20with-%20%E2%9D%A4-ff69b4.svg "build with love")](https://github.com/mchome/dogcom) [![version](https://img.shields.io/badge/stable%20-%20v1.6.0-4dc71f.svg "stable version")](https://github.com/mchome/dogcom/tree/v1.6.0)

[Drcom-generic](https://github.com/drcoms/drcom-generic) implementation in C.

Expand Down
7 changes: 3 additions & 4 deletions auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int challenge(int sockfd, struct sockaddr_in addr, unsigned char seed[]) {
return 1;
}

memcpy(seed, &recv_packet[4], 4 * sizeof(*recv_packet));
memcpy(seed, &recv_packet[4], 4);
#ifdef DEBUG
print_packet("<GET SEED> ", seed, 4);
#endif
Expand Down Expand Up @@ -181,9 +181,6 @@ int login(int sockfd, struct sockaddr_in addr, unsigned char seed[], unsigned ch
} else {
if ((strlen(drcom_config.password)-8) % 2) { ror_padding = 1; }
}
if (!drcom_config.ror_version) {
ror_padding = 2;
}
if (drcom_config.ror_version) {
login_packet[counter + 1] = strlen(drcom_config.password);
counter += 2;
Expand All @@ -193,6 +190,8 @@ int login(int sockfd, struct sockaddr_in addr, unsigned char seed[], unsigned ch
}
counter += strlen(drcom_config.password);
// print_packet("TEST ", ror, strlen(drcom_config.password));
} else {
ror_padding = 2;
}
login_packet[counter] = 0x02;
login_packet[counter + 1] = 0x0c;
Expand Down
8 changes: 8 additions & 0 deletions configparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static int read_d_config(char *buf, int size) {
if (strlen(key = strtok(buf, delim))) {
value = strtok(NULL, delim);
}
drcom_config.keepalive1_mod = 0;

if (strcmp(key, "server") == 0) {
strcpy(drcom_config.server, value);
Expand Down Expand Up @@ -134,6 +135,13 @@ static int read_d_config(char *buf, int size) {
drcom_config.ror_version = 0;
}
DEBUG_PRINT(("\n[PARSER_DEBUG]\n%d\n", drcom_config.ror_version));
} else if (strcmp(key, "keepalive1_mod") == 0) {
if (strcmp(value, "True") == 0) {
drcom_config.keepalive1_mod = 1;
} else {
drcom_config.keepalive1_mod = 0;
}
DEBUG_PRINT(("\n[PARSER_DEBUG]\n%d\n", drcom_config.keepalive1_mod));
} else {
return 1;
}
Expand Down
1 change: 1 addition & 0 deletions configparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct config {
char host_os[20];
unsigned char KEEP_ALIVE_VERSION[2];
int ror_version;
int keepalive1_mod;
unsigned char pppoe_flag;
unsigned char keep_alive2_flag; /* abandoned */
};
Expand Down
148 changes: 111 additions & 37 deletions keepalive.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,132 @@ typedef int socklen_t;
#include "debug.h"

int keepalive_1(int sockfd, struct sockaddr_in addr, unsigned char seed[], unsigned char auth_information[]) {
unsigned char keepalive_1_packet[42], recv_packet[1024], MD5A[16];
memset(keepalive_1_packet, 0, 42);
keepalive_1_packet[0] = 0xff;
int MD5A_len = 6 + strlen(drcom_config.password);
unsigned char MD5A_str[MD5A_len];
MD5A_str[0] = 0x03;
MD5A_str[1] = 0x01;
memcpy(MD5A_str + 2, seed, 4);
memcpy(MD5A_str + 6, drcom_config.password, strlen(drcom_config.password));
MD5(MD5A_str, MD5A_len, MD5A);
memcpy(keepalive_1_packet + 1, MD5A, 16);
memcpy(keepalive_1_packet + 20, auth_information, 16);
keepalive_1_packet[36] = rand() & 0xff;
keepalive_1_packet[37] = rand() & 0xff;

sendto(sockfd, keepalive_1_packet, 42, 0, (struct sockaddr *)&addr, sizeof(addr));

if (verbose_flag) {
print_packet("[Keepalive1 sent] ", keepalive_1_packet, 42);
}
if (logging_flag) {
logging("[Keepalive1 sent] ", keepalive_1_packet, 42);
}

if (drcom_config.keepalive1_mod) {
unsigned char keepalive_1_packet1[8] = {0x07, 0x01, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00};
unsigned char recv_packet1[1024], keepalive_1_packet2[38], recv_packet2[1024];
memset(keepalive_1_packet2, 0, 38);
sendto(sockfd, keepalive_1_packet1, 8, 0, (struct sockaddr *)&addr, sizeof(addr));
if (verbose_flag) {
print_packet("[Keepalive1 sent] ", keepalive_1_packet1, 42);
}
if (logging_flag) {
logging("[Keepalive1 sent] ", keepalive_1_packet1, 42);
}
#ifdef TEST
printf("[TEST MODE]IN TEST MODE, PASS\n");
return 0;
printf("[TEST MODE]IN TEST MODE, PASS\n");
return 0;
#endif
socklen_t addrlen = sizeof(addr);
while(1) {
if (recvfrom(sockfd, recv_packet1, 1024, 0, (struct sockaddr *)&addr, &addrlen) < 0) {
perror("Failed to recv data");
return 1;
} else {
if (verbose_flag) {
print_packet("[Keepalive1 challenge_recv] ", recv_packet1, 100);
}
if (logging_flag) {
logging("[Keepalive1 challenge_recv] ", recv_packet1, 100);
}

socklen_t addrlen = sizeof(addr);
while(1) {
if (recvfrom(sockfd, recv_packet, 1024, 0, (struct sockaddr *)&addr, &addrlen) < 0) {
if (recv_packet1[0] == 0x07) {
break;
} else if (recv_packet1[0] == 0x4d) {
DEBUG_PRINT(("Get notice packet.\n"));
continue;
} else{
printf("Bad keepalive1 challenge response received.\n");
return 1;
}
}
}

unsigned char keepalive1_seed[4] = {0};
int encrypt_type;
unsigned char crc[8] = {0};
memcpy(keepalive1_seed, &recv_packet1[8], 4);
encrypt_type = keepalive1_seed[0] & 3;
gen_crc(keepalive1_seed, encrypt_type, crc);
keepalive_1_packet2[0] = 0xff;
memcpy(keepalive_1_packet2+8, keepalive1_seed, 4);
memcpy(keepalive_1_packet2+12, crc, 8);
memcpy(keepalive_1_packet2+20, auth_information, 16);
keepalive_1_packet2[36] = rand() & 0xff;
keepalive_1_packet2[37] = rand() & 0xff;

sendto(sockfd, keepalive_1_packet2, 42, 0, (struct sockaddr *)&addr, sizeof(addr));

if (recvfrom(sockfd, recv_packet2, 1024, 0, (struct sockaddr *)&addr, &addrlen) < 0) {
perror("Failed to recv data");
return 1;
} else {
if (verbose_flag) {
print_packet("[Keepalive1 recv] ", recv_packet, 100);
print_packet("[Keepalive1 recv] ", recv_packet2, 100);
}
if (logging_flag) {
logging("[Keepalive1 recv] ", recv_packet, 100);
logging("[Keepalive1 recv] ", recv_packet2, 100);
}

if (recv_packet[0] == 0x07) {
break;
} else if (recv_packet[0] == 0x4d) {
DEBUG_PRINT(("Get notice packet."));
continue;
} else{
if (recv_packet2[0] != 0x07) {
printf("Bad keepalive1 response received.\n");
return 1;
}
}

} else {
unsigned char keepalive_1_packet[42], recv_packet[1024], MD5A[16];
memset(keepalive_1_packet, 0, 42);
keepalive_1_packet[0] = 0xff;
int MD5A_len = 6 + strlen(drcom_config.password);
unsigned char MD5A_str[MD5A_len];
MD5A_str[0] = 0x03;
MD5A_str[1] = 0x01;
memcpy(MD5A_str + 2, seed, 4);
memcpy(MD5A_str + 6, drcom_config.password, strlen(drcom_config.password));
MD5(MD5A_str, MD5A_len, MD5A);
memcpy(keepalive_1_packet + 1, MD5A, 16);
memcpy(keepalive_1_packet + 20, auth_information, 16);
keepalive_1_packet[36] = rand() & 0xff;
keepalive_1_packet[37] = rand() & 0xff;

sendto(sockfd, keepalive_1_packet, 42, 0, (struct sockaddr *)&addr, sizeof(addr));

if (verbose_flag) {
print_packet("[Keepalive1 sent] ", keepalive_1_packet, 42);
}
if (logging_flag) {
logging("[Keepalive1 sent] ", keepalive_1_packet, 42);
}

#ifdef TEST
printf("[TEST MODE]IN TEST MODE, PASS\n");
return 0;
#endif

socklen_t addrlen = sizeof(addr);
while(1) {
if (recvfrom(sockfd, recv_packet, 1024, 0, (struct sockaddr *)&addr, &addrlen) < 0) {
perror("Failed to recv data");
return 1;
} else {
if (verbose_flag) {
print_packet("[Keepalive1 recv] ", recv_packet, 100);
}
if (logging_flag) {
logging("[Keepalive1 recv] ", recv_packet, 100);
}

if (recv_packet[0] == 0x07) {
break;
} else if (recv_packet[0] == 0x4d) {
DEBUG_PRINT(("Get notice packet."));
continue;
} else{
printf("Bad keepalive1 response received.\n");
return 1;
}
}
}
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "libs/common.h"
#endif

#define VERSION "1.5.0"
#define VERSION "1.6.0"

void print_help(int exval);
int try_smart_eaplogin(void);
Expand Down
3 changes: 2 additions & 1 deletion sample-d.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ AUTH_VERSION = '\x0A\x00'
mac = 0xb888e3051680
host_os = '8089D'
KEEP_ALIVE_VERSION = '\xDC\x02'
ror_version = True
ror_version = True
keepalive1_mod = True

0 comments on commit 5237c3a

Please sign in to comment.