diff options
author | root <root@phone01.(none)> | 2010-09-26 10:38:19 +0200 |
---|---|---|
committer | root <root@phone01.(none)> | 2010-09-26 10:38:19 +0200 |
commit | d0b22a46b53c968de3ec85022251f318d97e6b27 (patch) | |
tree | 26c5965da81e50e0b2619edff7008243c31711a9 | |
parent | f7cfcdb6b1fcfaf149dce2195181f3d8707306b6 (diff) | |
download | MAC-Telnet-d0b22a46b53c968de3ec85022251f318d97e6b27.tar.gz MAC-Telnet-d0b22a46b53c968de3ec85022251f318d97e6b27.zip |
Files splitted
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | config.h | 6 | ||||
-rw-r--r-- | mactelnet.c | 81 | ||||
-rw-r--r-- | mactelnet.h | 31 | ||||
-rw-r--r-- | main.c | 104 |
5 files changed, 122 insertions, 104 deletions
@@ -6,5 +6,5 @@ clean: dist-clean dist-clean: rm -f mactelnet -mactelnet: main.c udp.h udp.c - gcc -g -o mactelnet main.c udp.c +mactelnet: main.c udp.h udp.c mactelnet.c mactelnet.h + gcc -g -o mactelnet main.c udp.c mactelnet.c diff --git a/config.h b/config.h new file mode 100644 index 0000000..15fce0d --- /dev/null +++ b/config.h @@ -0,0 +1,6 @@ +#ifndef _CONFIG_H +#define _CONFIG_H 1 + +#define DEBUG 0 + +#endif diff --git a/mactelnet.c b/mactelnet.c new file mode 100644 index 0000000..88ddcdf --- /dev/null +++ b/mactelnet.c @@ -0,0 +1,81 @@ +#include <string.h> +#include <stdio.h> +#include "mactelnet.h" +#include "config.h" + +int initPacket(unsigned char *data, unsigned char ptype, unsigned char *src, unsigned char *dst, unsigned short sessionkey, unsigned short counter) { + + // PACKET VERSION + data[0] = 1; + + // PACKET TYPE + data[1] = ptype; + + // src ethernet address + etherAddrton(data + 2, src); + + // dst ethernet address + etherAddrton(data + 8, dst); + + data[14] = sessionkey >> 8; + data[15] = sessionkey & 0xff; + + data[16] = 0x00; + data[17] = 0x15; + + data[18] = (counter >> 24) & 0xff; + data[19] = (counter >> 16) & 0xff; + data[20] = (counter >> 8) & 0xff; + data[21] = counter & 0xff; + + return 22; +} + +int addControlPacket(unsigned char *data, unsigned char cptype, unsigned char *cpdata, int data_len) { + data[0] = 0x56; + data[1] = 0x34; + data[2] = 0x12; + data[3] = 0xff; + + // Control packet type + data[4] = cptype; + + // Data length + data[5] = (data_len >> 24) & 0xff; + data[6] = (data_len >> 16) & 0xff; + data[7] = (data_len >> 8) & 0xff; + data[8] = data_len & 0xff; + + if (data_len) { + memcpy(data+9, cpdata, data_len); + } + + return 9+data_len; +} + +void parsePacket(unsigned char *data, struct mt_mactelnet_hdr *pkthdr) { + pkthdr->ver = data[0]; + pkthdr->ptype = data[1]; + memcpy(pkthdr->srcaddr, data+2,6); + memcpy(pkthdr->dstaddr, data+8,6); + pkthdr->seskey = data[16] << 8 | data[17]; + pkthdr->counter = data[18] << 24 | data[19] << 16 | data[20] << 8 | data[21]; + pkthdr->data = data + 22; +} + + +void parseControlPacket(unsigned char *data, int data_len) { + unsigned char magic[] = { 0x56, 0x34, 0x12, 0xff }; + if (memcmp(data,&magic,4) == 0) { + if (DEBUG) + printf("\tControl packet:\n\t\tType: %d\n\t\tLength: %d\n", data[4], data[5]<<24|data[6]<<16|data[7]<<8|data[8]); + if (data_len - 9 - (data[4], data[5]<<24|data[6]<<16|data[7]<<8|data[8]) > 0) { + parseControlPacket(data + 9 + (data[4], data[5]<<24|data[6]<<16|data[7]<<8|data[8]), data_len - 9 - (data[4], data[5]<<24|data[6]<<16|data[7]<<8|data[8])); + } + + if (data[4] == 1) { + printf("Connected. Enter username & password.\n\n"); // TODOD: Teh good shiat + } + } +} + diff --git a/mactelnet.h b/mactelnet.h new file mode 100644 index 0000000..5227718 --- /dev/null +++ b/mactelnet.h @@ -0,0 +1,31 @@ +#ifndef _MACTELNET_H +#define _MACTELNET_H 1 + +// Packet type +#define MT_PTYPE_SESSIONSTART 0 +#define MT_PTYPE_DATA 1 +#define MT_PTYPE_ACK 2 +#define MT_PTYPE_END 255 + +// Control packet type +#define MT_CPTYPE_BEGINAUTH 0 +#define MT_CPTYPE_ENCRYPTIONKEY 1 +#define MT_CPTYPE_PASSWORD 2 +#define MT_CPTYPE_USERNAME 3 +#define MT_CPTYPE_TERM_TYPE 4 +#define MT_CPTYPE_TERM_WIDTH 5 +#define MT_CPTYPE_TERM_HEIGHT 6 +#define MT_CPTYPE_PACKET_ERROR 7 +#define MT_CPTYPE_END_AUTH 9 + +struct mt_mactelnet_hdr { + unsigned char ver; + unsigned char ptype; + unsigned char srcaddr[6]; + unsigned char dstaddr[6]; + unsigned short seskey; + unsigned int counter; + unsigned char *data; +}; + +#endif @@ -5,115 +5,15 @@ #include <sys/socket.h> #include <string.h> #include <linux/if_ether.h> +#include "mactelnet.h" #include "udp.h" - -#define DEBUG 0 - -#define MT_PTYPE_SESSIONSTART 0 -#define MT_PTYPE_DATA 1 -#define MT_PTYPE_ACK 2 -#define MT_PTYPE_END 255 - -#define MT_CPTYPE_BEGINAUTH 0 -#define MT_CPTYPE_ENCRYPTIONKEY 1 -#define MT_CPTYPE_PASSWORD 2 -#define MT_CPTYPE_USERNAME 3 -#define MT_CPTYPE_TERM_TYPE 4 -#define MT_CPTYPE_TERM_WIDTH 5 -#define MT_CPTYPE_TERM_HEIGHT 6 -#define MT_CPTYPE_PACKET_ERROR 7 -#define MT_CPTYPE_END_AUTH 9 - -int initPacket(unsigned char *data, unsigned char ptype, unsigned char *src, unsigned char *dst, unsigned short sessionkey, unsigned short counter) { - - // PACKET VERSION - data[0] = 1; - - // PACKET TYPE - data[1] = ptype; - - // src ethernet address - etherAddrton(data + 2, src); - - // dst ethernet address - etherAddrton(data + 8, dst); - - data[14] = sessionkey >> 8; - data[15] = sessionkey & 0xff; - - data[16] = 0x00; - data[17] = 0x15; - - data[18] = (counter >> 24) & 0xff; - data[19] = (counter >> 16) & 0xff; - data[20] = (counter >> 8) & 0xff; - data[21] = counter & 0xff; - - return 22; -} - -int addControlPacket(unsigned char *data, unsigned char cptype, unsigned char *cpdata, int data_len) { - data[0] = 0x56; - data[1] = 0x34; - data[2] = 0x12; - data[3] = 0xff; - - // Control packet type - data[4] = cptype; - - // Data length - data[5] = (data_len >> 24) & 0xff; - data[6] = (data_len >> 16) & 0xff; - data[7] = (data_len >> 8) & 0xff; - data[8] = data_len & 0xff; - - if (data_len) { - memcpy(data+9, cpdata, data_len); - } - - return 9+data_len; -} - -struct mt_mactelnet_hdr { - unsigned char ver; - unsigned char ptype; - unsigned char srcaddr[6]; - unsigned char dstaddr[6]; - unsigned short seskey; - unsigned int counter; - unsigned char *data; -}; - -void parsePacket(unsigned char *data, struct mt_mactelnet_hdr *pkthdr) { - pkthdr->ver = data[0]; - pkthdr->ptype = data[1]; - memcpy(pkthdr->srcaddr, data+2,6); - memcpy(pkthdr->dstaddr, data+8,6); - pkthdr->seskey = data[16] << 8 | data[17]; - pkthdr->counter = data[18] << 24 | data[19] << 16 | data[20] << 8 | data[21]; - pkthdr->data = data + 22; -} +#include "config.h" int sockfd; int counter=0; unsigned char *src = "00:e0:81:b5:ac:8e"; unsigned char *dst = "00:0c:42:43:58:a4"; -void parseControlPacket(unsigned char *data, int data_len) { - unsigned char magic[] = { 0x56, 0x34, 0x12, 0xff }; - if (memcmp(data,&magic,4) == 0) { - if (DEBUG) - printf("\tControl packet:\n\t\tType: %d\n\t\tLength: %d\n", data[4], data[5]<<24|data[6]<<16|data[7]<<8|data[8]); - if (data_len - 9 - (data[4], data[5]<<24|data[6]<<16|data[7]<<8|data[8]) > 0) { - parseControlPacket(data + 9 + (data[4], data[5]<<24|data[6]<<16|data[7]<<8|data[8]), data_len - 9 - (data[4], data[5]<<24|data[6]<<16|data[7]<<8|data[8])); - } - - if (data[4] == 1) { - printf("Connected. Enter username & password.\n\n"); // TODOD: Teh good shiat - } - } -} - void handlePacket(unsigned char *data, int data_len) { struct mt_mactelnet_hdr pkthdr; parsePacket(data, &pkthdr); |