Browse code

Added retransmission detection. Added REGISTER flood hack.

Nils Ohlmeier authored on 14/08/2002 21:03:49
Showing 1 changed files
... ...
@@ -63,7 +63,7 @@ bouquets and brickbats to farhan@hotfoon.com
63 63
 #include <arpa/inet.h>
64 64
 #include <sys/poll.h>
65 65
 
66
-#define SIPSAK_VERSION "v0.6.5"
66
+#define SIPSAK_VERSION "v0.6"
67 67
 #define RESIZE		1024
68 68
 #define BUFSIZE		4096
69 69
 #define FQDN_SIZE   200
... ...
@@ -343,11 +343,23 @@ void create_msg(char *buff, int action){
343 343
 				lport);
344 344
 			break;
345 345
 		case REQ_FLOOD:
346
+#ifdef REGISTER_HACK
347
+			usern=malloc(strlen(username)+10);
348
+			sprintf(usern, "%s%i", username, namebeg);
349
+			sprintf(buff, "%s sip:%s%s%s%s:%i\r\n%s<sip:%s@%s>\r\n"
350
+				"%s<sip:%s@%s>\r\n%s%u@%s\r\n%s%i %s\r\n%s<sip:%s@%s:%i>\r\n"
351
+				"%s%i\r\n\r\n", REG_STR, domainname, SIP20_STR, VIA_STR, fqdn, 
352
+				lport, FROM_STR, usern, domainname, TO_STR, usern, domainname, 
353
+				CALL_STR, c, fqdn, CSEQ_STR, namebeg, REG_STR, CONT_STR, 
354
+				usern, fqdn, lport, EXP_STR, expires_t);
355
+			free(usern);
356
+#else
346 357
 			sprintf(buff, "%s sip:%s%s%s%s:9\r\n%s<sip:sipsak@%s:9>\r\n"
347 358
 				"%s<sip:%s>\r\n%s%u@%s\r\n%s%i %s\r\n%s<sipsak@%s:9>\r\n\r\n", 
348 359
 				FLOOD_METH, domainname, SIP20_STR, VIA_STR, fqdn, FROM_STR, 
349 360
 				fqdn, TO_STR, domainname, CALL_STR, c, fqdn, CSEQ_STR, namebeg, 
350 361
 				FLOOD_METH, CONT_STR, fqdn);
362
+#endif
351 363
 			break;
352 364
 		case REQ_RAND:
353 365
 			sprintf(buff, "%s sip:%s%s%s%s:%i\r\n%s<sip:sipsak@%s:%i>\r\n"
... ...
@@ -471,6 +483,29 @@ void warning_extract(char *message)
471 483
 	}
472 484
 }
473 485
 
486
+int cseq(char *message)
487
+{
488
+	char *cseq;
489
+	int num=-1;
490
+
491
+	cseq=strstr(message, "CSeq");
492
+	if (cseq) {
493
+		cseq+=6;
494
+		num=atoi(cseq);
495
+		if (num < 1) {
496
+#ifdef DEBUG
497
+			printf("CSeq found but not convertable\n");
498
+#endif
499
+			return 0;
500
+		}
501
+		return num;
502
+	}
503
+#ifdef DEBUG
504
+	printf("no CSeq found\n");
505
+#endif
506
+	return 0;
507
+}
508
+
474 509
 /* this function is taken from traceroute-1.4_p12 
475 510
    which is distributed under the GPL and it returns
476 511
    the difference between to timeval structs */
... ...
@@ -492,7 +527,7 @@ void shoot(char *buff)
492 527
 	struct pollfd sockerr;
493 528
 	int ssock, redirected, retryAfter, nretries;
494 529
 	int sock, i, len, ret, usrlocstep, randretrys;
495
-	int dontsend;
530
+	int dontsend, cseqcmp, cseqtmp;
496 531
 	char *contact, *crlf, *foo, *bar;
497 532
 	char reply[BUFSIZE];
498 533
 	fd_set	fd;
... ...
@@ -744,6 +779,26 @@ void shoot(char *buff)
744 779
 					/* store the time of our first send */
745 780
 					if (i==0)
746 781
 						memcpy(&firstsendt, &sendtime, sizeof(struct timeval));
782
+					/* check for old CSeq => ignore retransmission */
783
+					if (usrloc) {
784
+						switch (usrlocstep) {
785
+							case 0: 
786
+								cseqcmp = 3*namebeg+1;
787
+								break;
788
+							case 1:
789
+							case 2:
790
+								cseqcmp = 3*namebeg+2;
791
+						}
792
+					}
793
+					else
794
+						cseqcmp = namebeg;
795
+					cseqtmp = cseq(reply);
796
+					if ((0 < cseqtmp) && (cseqtmp < cseqcmp)) {
797
+						printf("received retransmission: irgnoring\n");
798
+						dontsend = 1;
799
+						i--;
800
+						continue;
801
+					}
747 802
 					/* lets see if received a redirect */
748 803
 					if (redirects && regexec(&redexp, reply, 0, 0, 0)==0) {
749 804
 						printf("** received redirect ");
... ...
@@ -911,7 +966,7 @@ void shoot(char *buff)
911 966
 								/* now we sended the message and look if its 
912 967
 								   forwarded to us*/
913 968
 								if (!strncmp(reply, messusern, 
914
-								strlen(messusern))) {
969
+									strlen(messusern))) {
915 970
 									if (verbose) {
916 971
 										crlf=strstr(reply, "\r\n\r\n");
917 972
 										crlf=crlf+4;
... ...
@@ -936,12 +991,6 @@ void shoot(char *buff)
936 991
 							case 2:
937 992
 								/* finnaly we sended our reply on the message 
938 993
 								   and look if this is also forwarded to us*/
939
-								while (!strncmp(reply, messusern, 
940
-								strlen(messusern))){
941
-									printf("warning: received 'MESSAGE' "
942
-										"retransmission!\n");
943
-									ret = recv(ssock, reply, BUFSIZE, 0);
944
-								}
945 994
 								if (regexec(&okexp, reply, 0, 0, 0)==0) {
946 995
 									if (verbose)
947 996
 										printf("   reply received\n\n");
... ...
@@ -970,7 +1019,7 @@ void shoot(char *buff)
970 1019
 					}
971 1020
 					else if (randtrash) {
972 1021
 						/* in randomzing trash we are expexting 4?? error codes
973
-						   everything should not be normal */
1022
+						   everything else should not be normal */
974 1023
 						if (regexec(&errexp, reply, 0, 0, 0)==0) {
975 1024
 #ifdef DEBUG
976 1025
 							printf("received:\n%s\n", reply);