[ekg2-commit] ekg2: sniff.c (HEAD) sniff_gg.h (HEAD) [darkjames]

CVS commit cvs w amba.bydg.pdi.net
Czw, 15 Lut 2007, 12:57:55 CET


Module name:	ekg2
Changes by:	darkjames	07/02/15 12:57:52

Modified files:
	sniff.c sniff_gg.h

Log message:
[sniffgg] login60 && network stuff.

Index: sniff.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/sniff/sniff.c,v
diff -d -u -r1.8 -r1.9
--- sniff.c	15 Feb 2007 11:10:30 -0000	1.8
+++ sniff.c	15 Feb 2007 11:57:50 -0000	1.9
@@ -64,6 +64,13 @@
 	uint16_t dstport;
 } connection_t;
 
+static char *build_hex(uint32_t hex) {
+	static char buf[20];
+
+	sprintf(buf, "0x%x", hex);
+	return buf;
+}
+
 static char *build_gg_uid(uint32_t sender) {
 	static char buf[80];
 
@@ -268,15 +275,12 @@
 }
 
 SNIFF_HANDLER(sniff_gg_welcome, gg_welcome) {
-	char *key_hex;
 	CHECK_LEN(sizeof(gg_welcome))		len -= sizeof(gg_welcome);
 
-	key_hex = saprintf("0x%x\n", pkt->key);
 	print_window(build_windowip_name(hdr->dstip) /* ip and/or gg# */, s, 1,
 			"sniff_gg_welcome",
 
-			key_hex);
-	xfree(key_hex);
+			build_hex(pkt->key));
 	return 0;
 }
 
@@ -389,6 +393,18 @@
 	return 0;
 }
 
+SNIFF_HANDLER(sniff_gg_login60, gg_login60) {
+	CHECK_LEN(sizeof(gg_login60))	len -= sizeof(gg_login60);
+
+	print_window(build_windowip_name(hdr->srcip) /* ip and/or gg# */, s, 1,
+			"sniff_gg_login60",
+
+			build_gg_uid(pkt->uin),
+			build_hex(pkt->hash));
+
+	return -5;
+}
+
 typedef enum {
 	SNIFF_OUTGOING = 0,
 	SNIFF_INCOMING
@@ -414,36 +430,43 @@
 	{ GG_LIST_EMPTY,"GG_LIST_EMPTY",SNIFF_INCOMING, (void *) NULL, 0},		/* XXX */
 	{ GG_STATUS60,	"GG_STATUS60",	SNIFF_INCOMING, (void *) sniff_gg_status60, 0},
 	{ GG_NEED_EMAIL,"GG_NEED_EMAIL",SNIFF_INCOMING, (void *) NULL, 0},		/* XXX */
+	{ GG_LOGIN60,	"GG_LOGIN60",	SNIFF_OUTGOING, (void *) sniff_gg_login60, 0},	/* XXX */
 	{ -1,		NULL,		-1,		(void *) NULL, 0},
 };
 
-/* return 0 on success */
 SNIFF_HANDLER(sniff_gg, gg_header) {
 	int i;
+	int handled = 0;
 	pkt_way_t way = SNIFF_OUTGOING;
 
 	CHECK_LEN(sizeof(gg_header)) 	len -= sizeof(gg_header);
-	/* XXX, tcp fragmentation!!!!!!1111 */
 	CHECK_LEN(pkt->len)
 
 	/* XXX, check direction!!!!!111, in better way: */
 	if (!xstrncmp(inet_ntoa(hdr->srcip), "217.17.", 7))
 		way = SNIFF_INCOMING;
 
-	if (!(pkt->len == len)) 
-		debug_error("sniff_gg() XXX NEXT PACKET?!\n");
-
+	/* XXX, jesli mamy podejrzenia ze to nie jest pakiet gg, to wtedy powinnismy zwrocic -2 i pozwolic zeby inni za nas to przetworzyli */
 	for (i=0; sniff_gg_callbacks[i].name; i++) {
 		if (sniff_gg_callbacks[i].type == pkt->type && sniff_gg_callbacks[i].way == way) {
 			debug("sniff_gg() %s [%d,%d,%db] %s\n", sniff_gg_callbacks[i].name, pkt->type, way, pkt->len, inet_ntoa(way ? hdr->dstip : hdr->srcip));
 			if (sniff_gg_callbacks[i].handler) 
-				return sniff_gg_callbacks[i].handler(s, hdr, pkt->data, pkt->len);
-			return 0;
+				sniff_gg_callbacks[i].handler(s, hdr, pkt->data, pkt->len);
+
+			handled = 1;
 		}
 	}
-	debug_error("sniff_gg() UNHANDLED pkt type: %x way: %d len: %db\n", pkt->type, way, pkt->len);
-/*	print_payload(gg_hdr->pakiet, gg_hdr->len); */
-	return -2;
+	if (!handled) {
+		debug_error("sniff_gg() UNHANDLED pkt type: %x way: %d len: %db\n", pkt->type, way, pkt->len);
+	/*	print_payload(gg_hdr->pakiet, gg_hdr->len); */
+	}
+
+	if (len > pkt->len) {
+		debug_error("sniff_gg() next packet?\n");
+		sniff_gg(s, hdr, (gg_header *) (pkt->data + pkt->len), len - pkt->len); 
+	}
+	/* XXX, return len */
+	return 0;
 }
 
 #undef CHECK_LEN
@@ -511,6 +534,13 @@
 #undef CHECK_LEN
 }
 
+/* XXX, some notes about tcp fragment*
+ * 		@ sniff_loop() we'll do: sniff_find_tcp_connection(connection_t *hdr);
+ * 		it'll find (or create) struct with inited string_t buf...
+ * 		than we append to that string_t recv data from packet, and than pass this to sniff_gg() [or anyother sniff handler]
+ * 		than in sniff_loop() we'll remove already data.. [of length len, len returned from sniff_gg()]
+ */
+
 static WATCHER(sniff_pcap_read) {
 	if (type) {
 		return 0;
@@ -520,7 +550,6 @@
 		debug_error("sniff_pcap_read() no session!\n");
 		return -1;
 	}
-
 	pcap_dispatch(GET_DEV(data), 1, sniff_loop, data);
 	return 0;
 }
@@ -652,7 +681,8 @@
 
 static int sniff_theme_init() {
 /* sniff gg */
-	format_add("sniff_gg_welcome",	_("%> [GG_WELCOME] SEED: %1"), 1);
+	format_add("sniff_gg_welcome",	_("%) [GG_WELCOME] SEED: %1"), 1);
+	format_add("sniff_gg_login60",	_("%) [GG_LOGIN60] UIN: %1 HASH: %2"), 1);
 /* stats */
 	format_add("sniff_pkt_rcv", _("%) %2 packets captured"), 1);
 	format_add("sniff_pkt_drop",_("%) %2 packets dropped"), 1);

Index: sniff_gg.h
===================================================================
RCS file: /home/cvs/ekg2/plugins/sniff/sniff_gg.h,v
diff -d -u -r1.6 -r1.7
--- sniff_gg.h	15 Feb 2007 11:07:34 -0000	1.6
+++ sniff_gg.h	15 Feb 2007 11:57:50 -0000	1.7
@@ -101,3 +101,19 @@
 
 #define GG_NEED_EMAIL 0x0014
 
+#define GG_LOGIN60 0x0015
+
+typedef struct {
+	uint32_t uin;			/* mĂłj numerek */
+	uint32_t hash;			/* hash hasła */
+	uint32_t status;		/* status na dzień dobry */
+	uint32_t version;		/* moja wersja klienta */
+	uint8_t dunno1;			/* 0x00 */
+	uint32_t local_ip;		/* mĂłj adres ip */
+	uint16_t local_port;		/* port, na którym słucham */
+	uint32_t external_ip;		/* zewnętrzny adres ip */
+	uint16_t external_port;		/* zewnętrzny port */
+	uint8_t image_size;		/* maksymalny rozmiar grafiki w KiB */
+	uint8_t dunno2;			/* 0xbe */
+} GG_PACKED gg_login60;
+


Więcej informacji o liście dyskusyjnej ekg2-commit