Skip to content

Commit

Permalink
fix bugs, code indention
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhauser-thc committed Nov 30, 2020
1 parent ba9fe25 commit f48342b
Show file tree
Hide file tree
Showing 75 changed files with 40,156 additions and 37,989 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ v3.7-dev
* fixed crash in thcping6 with -n 0 or larger values
* fixed minor issues
* honors now CC and CLAGS environment variables and compiles with clang
* fixed various issues
* new code indention


v3.6/v3.5-dev
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ HAVE_SSL=yes

#CC=gcc
#CFLAGS=-g
CFLAGS+=-O3 -march=native -flto -falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks
CFLAGS+=-g -O3 -march=native -flto -falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks
CFLAGS+=$(if $(HAVE_SSL),-D_HAVE_SSL,)
LDFLAGS+=-lpcap $(if $(HAVE_SSL),-lssl -lcrypto,)
PROGRAMS=parasite6 dos-new-ip6 detect-new-ip6 fake_router6 fake_advertise6 fake_solicitate6 fake_mld6 fake_mld26 fake_mldrouter6 flood_mldrouter6 fake_mipv6 redir6 smurf6 alive6 toobig6 rsmurf6 implementation6 implementation6d sendpees6 sendpeesmp6 randicmp6 fuzz_ip6 flood_mld6 flood_mld26 flood_router6 flood_advertise6 flood_solicitate6 trace6 exploit6 denial6 fake_dhcps6 flood_dhcpc6 fake_dns6d fragmentation6 kill_router6 fake_dnsupdate6 ndpexhaust6 detect_sniffer6 dump_router6 fake_router26 flood_router26 passive_discovery6 dnsrevenum6 inverse_lookup6 node_query6 address6 covert_send6 covert_send6d inject_alive6 firewall6 ndpexhaust26 fake_pim6 thcsyn6 redirsniff6 flood_redir6 four2six dump_dhcp6 flood_rs6 fuzz_dhcps6 fuzz_dhcpc6 toobigsniff6 flood_unreach6 connect6
Expand Down
98 changes: 51 additions & 47 deletions address6.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,43 @@ void help(char *prg) {
printf("Syntax:\n\t%s mac-address [ipv6-prefix]\n", prg);
printf("\t%s ipv4-address [ipv6-prefix]\n", prg);
printf("\t%s ipv6-address\n\n", prg);
printf("Converts a mac or IPv4 address to an IPv6 address (link local if no prefix is\n");
printf("given as 2nd option) or, when given an IPv6 address, prints the mac or IPv4\n");
printf("address. Prints all possible variations. Returns -1 on errors or the number of\n");
printf(
"Converts a mac or IPv4 address to an IPv6 address (link local if no "
"prefix is\n");
printf(
"given as 2nd option) or, when given an IPv6 address, prints the mac or "
"IPv4\n");
printf(
"address. Prints all possible variations. Returns -1 on errors or the "
"number of\n");
printf("variations found\n");
exit(-1);
}

int main(int argc, char *argv[]) {
unsigned char *ptr, *dst6, ipv4[16] = "", ipv6[40], *prefix;
int i, j, k, found = 0;
int i, j, k, found = 0;
struct in_addr in;

if (argc < 2 || argc > 3 || strncmp(argv[1], "-h", 2) == 0)
help(argv[0]);
if (argc < 2 || argc > 3 || strncmp(argv[1], "-h", 2) == 0) help(argv[0]);

if ((dst6 = index(argv[1], '/')) != NULL)
*dst6 = 0;
if ((dst6 = thc_resolve6(argv[1])) != NULL) { // ipv6 address
if (dst6[11] == 0xff && dst6[12] == 0xfe) { // EUI-64 encoding of mac
printf("%02x:%02x:%02x:%02x:%02x:%02x\n", (dst6[8] ^ 2), dst6[9], dst6[10], dst6[13], dst6[14], dst6[15]);
if ((dst6 = index(argv[1], '/')) != NULL) *dst6 = 0;
if ((dst6 = thc_resolve6(argv[1])) != NULL) { // ipv6 address
if (dst6[11] == 0xff && dst6[12] == 0xfe) { // EUI-64 encoding of mac
printf("%02x:%02x:%02x:%02x:%02x:%02x\n", (dst6[8] ^ 2), dst6[9],
dst6[10], dst6[13], dst6[14], dst6[15]);
return 1;
}
// ::ffff:ip4enc:ipv4enc support
if (dst6[8] + dst6[9] == 0 && dst6[10] == 0xff & dst6[11] == 0xff) {
dst6[10] = 0;
dst6[11] = 0;
}
if (dst6[8] + dst6[10] + dst6[12] + dst6[14] == 0 && dst6[9] != 0) { // hexdecimal ipv4
if (dst6[8] + dst6[10] + dst6[12] + dst6[14] == 0 &&
dst6[9] != 0) { // hexdecimal ipv4
j = 0;
for (i = 0; i < 4; i++)
if (dst6[9 + i*2] > 9)
j++;
if (dst6[9 + i * 2] > 9) j++;
if (j > 0) {
sprintf(ipv4, "%d.%d.%d.%d", dst6[9], dst6[11], dst6[13], dst6[15]);
if (inet_aton(ipv4, &in) != 0) {
Expand All @@ -57,7 +62,8 @@ int main(int argc, char *argv[]) {
}
}
}
if (dst6[8] + dst6[9] + dst6[10] + dst6[11] == 0 && dst6[12] != 0) { // hexdecimal ipv4 #2
if (dst6[8] + dst6[9] + dst6[10] + dst6[11] == 0 &&
dst6[12] != 0) { // hexdecimal ipv4 #2
sprintf(ipv4, "%d.%d.%d.%d", dst6[12], dst6[13], dst6[14], dst6[15]);
if (inet_aton(ipv4, &in) != 0) {
printf("%s\n", ipv4);
Expand All @@ -72,73 +78,68 @@ int main(int argc, char *argv[]) {
for (i = 0; i < strlen(ptr); i++)
if (ptr[i] > ':')
j++;
else
if (ptr[i] == ':')
ptr[i] = '.';
else if (ptr[i] == ':')
ptr[i] = '.';
if (j == 0 && inet_aton(ptr, &in) != 0) {
j = 0;
for (i = 0; i < strlen(ptr); i++)
if (ptr[i] == '.')
j++;
if (ptr[i] == '.') j++;
if (j == 3) {
printf("%s\n", ptr);
found++;
}
}

if (found > 0)
return found;

fprintf(stderr, "Error: the IPv6 address does not contain a mac or encoded IPv4 address\n");
if (found > 0) return found;

fprintf(stderr,
"Error: the IPv6 address does not contain a mac or encoded IPv4 "
"address\n");
return -1;
}

// now check for a prefix argument
if (argc == 3) {
if ((ptr = index(argv[2], '/')) != NULL)
*ptr = 0;
if ((ptr = index(argv[2], '/')) != NULL) *ptr = 0;
if ((prefix = thc_resolve6(argv[2])) == NULL) {
fprintf(stderr, "Error: invalid prefix: %s\n", argv[2]);
return -1;
}
} else
prefix = thc_resolve6("fe80::");

if (index(argv[1], '.') != NULL) { // ipv4 to ipv6
if (index(argv[1], '.') != NULL) { // ipv4 to ipv6
ptr = argv[1];
for (i = 0; i < 4; i++) {
if ((dst6 = index(ptr, '.')) != NULL)
*dst6 = 0;
if ((dst6 = index(ptr, '.')) != NULL) *dst6 = 0;
ipv4[i] = atoi(ptr);
if ((i < 3 && dst6 == NULL) || (i == 3 && dst6 != NULL)) {
i = 3;
ipv4[0] = 0;
} else
if (dst6 != NULL)
ptr = dst6 + 1;
} else if (dst6 != NULL)
ptr = dst6 + 1;
}
j = 0;
k = 0;
for (i = 0; i < 4; i++) {
if (ipv4[i] > 255)
j++;
if (ipv4[i] > 9)
k = 1;
if (ipv4[i] > 255) j++;
if (ipv4[i] > 9) k = 1;
}
if (j == 0 && ipv4[0] != 0) { // from here we know its a valid ipv4 address
if (j == 0 && ipv4[0] != 0) { // from here we know its a valid ipv4 address
memcpy(ipv6, prefix, 8);
memset(ipv6 + 8, 0, 8);
for (i = 0; i < 4; i++)
ipv6[9 + i*2] = ipv4[i];
printf("%s\n", thc_ipv62notation(ipv6)); // hex representation #1
ipv6[9 + i * 2] = ipv4[i];
printf("%s\n", thc_ipv62notation(ipv6)); // hex representation #1
memset(ipv6 + 8, 0, 4);
memcpy(ipv6 + 12, ipv4, 4);
printf("%s\n", thc_ipv62notation(ipv6)); // hex representation #2
printf("%s\n", thc_ipv62notation(ipv6)); // hex representation #2
memset(ipv6 + 8, 0, 7);
ipv6[15] = ipv4[3];
printf("%s\n", thc_ipv62notation(ipv6)); // hex representation #3

if (k) { // do we need decimal representation too, or would it be a double?
printf("%s\n", thc_ipv62notation(ipv6)); // hex representation #3

if (k) { // do we need decimal representation too, or would it be a
// double?
sprintf(ipv6, "::%d:%d:%d:%d", ipv4[0], ipv4[1], ipv4[2], ipv4[3]);
dst6 = thc_resolve6(ipv6);
memcpy(dst6, prefix, 8);
Expand All @@ -147,7 +148,7 @@ int main(int argc, char *argv[]) {

if (ipv4[3] < 10)
return (3 + k);
else { // 2nd decimal representation
else { // 2nd decimal representation
sprintf(ipv6, "::%d", ipv4[3]);
dst6 = thc_resolve6(ipv6);
memcpy(dst6, prefix, 8);
Expand All @@ -157,8 +158,11 @@ int main(int argc, char *argv[]) {
}
}

if (index(argv[1], ':') != NULL) { // mac to ipv6
sscanf(argv[1], "%x:%x:%x:%x:%x:%x", (unsigned int *) &k, (unsigned int *) &ipv6[9], (unsigned int *) &ipv6[10], (unsigned int *) &ipv6[13], (unsigned int *) &ipv6[14], (unsigned int *) &ipv6[15]);
if (index(argv[1], ':') != NULL) { // mac to ipv6
sscanf(argv[1], "%x:%x:%x:%x:%x:%x", (unsigned int *)&k,
(unsigned int *)&ipv6[9], (unsigned int *)&ipv6[10],
(unsigned int *)&ipv6[13], (unsigned int *)&ipv6[14],
(unsigned int *)&ipv6[15]);
memcpy(ipv6, prefix, 8);
ipv6[8] = (k ^ 2);
ipv6[11] = 0xff;
Expand Down
Loading

0 comments on commit f48342b

Please sign in to comment.