You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
5.4 KiB

  1. Subject: Add tcp-mss support.
  2. Origin: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/net/hping/patches/
  3. Bug-Debian: http://bugs.debian.org/409391
  4. Last-Update: 2009-09-19
  5. --- a/main.c
  6. +++ b/main.c
  7. @@ -44,7 +44,8 @@ unsigned int
  8. signlen,
  9. lsr_length = 0,
  10. ssr_length = 0,
  11. - tcp_ack;
  12. + tcp_ack,
  13. + tcp_mss;
  14. unsigned short int
  15. @@ -95,6 +96,7 @@ int
  16. opt_tcpexitcode = FALSE,
  17. opt_badcksum = FALSE,
  18. opt_tr_keep_ttl = FALSE,
  19. + opt_tcp_mss = FALSE,
  20. opt_tcp_timestamp = FALSE,
  21. opt_clock_skew = FALSE,
  22. cs_window = DEFAULT_CS_WINDOW,
  23. --- a/globals.h
  24. +++ b/globals.h
  25. @@ -32,7 +32,8 @@ extern unsigned int
  26. tcp_seqnum,
  27. set_ack,
  28. ip_header_length,
  29. - tcp_ack;
  30. + tcp_ack,
  31. + tcp_mss;
  32. extern unsigned short int
  33. data_size;
  34. @@ -77,6 +78,7 @@ extern int opt_debug,
  35. opt_tcpexitcode,
  36. opt_badcksum,
  37. opt_tr_keep_ttl,
  38. + opt_tcp_mss,
  39. opt_tcp_timestamp,
  40. opt_clock_skew,
  41. cs_window,
  42. --- a/parseoptions.c
  43. +++ b/parseoptions.c
  44. @@ -31,7 +31,7 @@ enum { OPT_COUNT, OPT_INTERVAL, OPT_NUME
  45. OPT_RROUTE, OPT_IPPROTO, OPT_ICMP_IPVER, OPT_ICMP_IPHLEN,
  46. OPT_ICMP_IPLEN, OPT_ICMP_IPID, OPT_ICMP_IPPROTO, OPT_ICMP_CKSUM,
  47. OPT_ICMP_TS, OPT_ICMP_ADDR, OPT_TCPEXITCODE, OPT_FAST, OPT_TR_KEEP_TTL,
  48. - OPT_TCP_TIMESTAMP, OPT_TR_STOP, OPT_TR_NO_RTT, OPT_ICMP_HELP,
  49. + OPT_TCP_TIMESTAMP, OPT_TCP_MSS, OPT_TR_STOP, OPT_TR_NO_RTT, OPT_ICMP_HELP,
  50. OPT_RAND_DEST, OPT_RAND_SOURCE, OPT_LSRR, OPT_SSRR, OPT_ROUTE_HELP,
  51. OPT_ICMP_IPSRC, OPT_ICMP_IPDST, OPT_ICMP_SRCPORT, OPT_ICMP_DSTPORT,
  52. OPT_ICMP_GW, OPT_FORCE_ICMP, OPT_APD_SEND, OPT_SCAN, OPT_FASTER,
  53. @@ -125,6 +125,7 @@ static struct ago_optlist hping_optlist[
  54. { '\0', "force-icmp", OPT_FORCE_ICMP, AGO_NOARG },
  55. { '\0', "beep", OPT_BEEP, AGO_NOARG },
  56. { '\0', "flood", OPT_FLOOD, AGO_NOARG },
  57. + { '\0', "tcp-mss", OPT_TCP_MSS, AGO_NEEDARG|AGO_EXCEPT0 },
  58. { '\0', "clock-skew", OPT_CLOCK_SKEW, AGO_NOARG },
  59. { '\0', "clock-skew-win", OPT_CS_WINDOW, AGO_NEEDARG},
  60. { '\0', "clock-skew-win-shift", OPT_CS_WINDOW_SHIFT, AGO_NEEDARG},
  61. @@ -561,6 +562,10 @@ int parse_options(int argc, char **argv)
  62. case OPT_FLOOD:
  63. opt_flood = TRUE;
  64. break;
  65. + case OPT_TCP_MSS:
  66. + opt_tcp_mss = TRUE;
  67. + tcp_mss = strtoul(ago_optarg, NULL, 0);
  68. + break;
  69. case OPT_CLOCK_SKEW:
  70. opt_tcp_timestamp = TRUE;
  71. opt_clock_skew = TRUE;
  72. --- a/usage.c
  73. +++ b/usage.c
  74. @@ -87,6 +87,7 @@ void show_usage(void)
  75. " -X --xmas set X unused flag (0x40)\n"
  76. " -Y --ymas set Y unused flag (0x80)\n"
  77. " --tcpexitcode use last tcp->th_flags as exit code\n"
  78. +" --tcp-mss enable the TCP MSS option with the given value\n"
  79. " --tcp-timestamp enable the TCP timestamp option to guess the HZ/uptime\n"
  80. "Clock skew detection\n"
  81. " --clock-skew enable clock skew detection. Try with -S against open port\n"
  82. --- a/sendtcp.c
  83. +++ b/sendtcp.c
  84. @@ -28,10 +28,12 @@ void send_tcp(void)
  85. char *packet, *data;
  86. struct mytcphdr *tcp;
  87. struct pseudohdr *pseudoheader;
  88. - unsigned char *tstamp;
  89. + unsigned char *opts;
  90. + if (opt_tcp_mss)
  91. + tcp_opt_size += 4;
  92. if (opt_tcp_timestamp)
  93. - tcp_opt_size = 12;
  94. + tcp_opt_size += 12;
  95. packet_size = TCPHDR_SIZE + tcp_opt_size + data_size;
  96. packet = malloc(PSEUDOHDR_SIZE + packet_size);
  97. @@ -41,7 +43,7 @@ void send_tcp(void)
  98. }
  99. pseudoheader = (struct pseudohdr*) packet;
  100. tcp = (struct mytcphdr*) (packet+PSEUDOHDR_SIZE);
  101. - tstamp = (unsigned char*) (packet+PSEUDOHDR_SIZE+TCPHDR_SIZE);
  102. + opts = (unsigned char*) (packet+PSEUDOHDR_SIZE+TCPHDR_SIZE);
  103. data = (char*) (packet+PSEUDOHDR_SIZE+TCPHDR_SIZE+tcp_opt_size);
  104. memset(packet, 0, PSEUDOHDR_SIZE+packet_size);
  105. @@ -64,14 +66,24 @@ void send_tcp(void)
  106. tcp->th_win = htons(src_winsize);
  107. tcp->th_flags = tcp_th_flags;
  108. + /* tcp MSS option */
  109. + if (opt_tcp_mss) {
  110. + opts[0] = 2;
  111. + opts[1] = 4; /* 4 bytes, kind+len+MSS */
  112. + opts[2] = tcp_mss >> 8;
  113. + opts[3] = tcp_mss & 0xff;
  114. + opts += 4;
  115. + }
  116. +
  117. /* tcp timestamp option */
  118. if (opt_tcp_timestamp) {
  119. __u32 randts = rand() ^ (rand() << 16);
  120. - tstamp[0] = tstamp[1] = 1; /* NOOP */
  121. - tstamp[2] = 8;
  122. - tstamp[3] = 10; /* 10 bytes, kind+len+T1+T2 */
  123. - memcpy(tstamp+4, &randts, 4); /* random */
  124. - memset(tstamp+8, 0, 4); /* zero */
  125. + opts[0] = opts[1] = 1; /* NOOP */
  126. + opts[2] = 8;
  127. + opts[3] = 10; /* 10 bytes, kind+len+T1+T2 */
  128. + memcpy(opts+4, &randts, 4); /* random */
  129. + memset(opts+8, 0, 4); /* zero */
  130. + opts += 12;
  131. }
  132. /* data */
  133. --- a/docs/hping3.8
  134. +++ b/docs/hping3.8
  135. @@ -98,6 +98,8 @@ hping2 \- send (almost) arbitrary TCP/IP
  136. ] [
  137. .B \-\-tcpexitcode
  138. ] [
  139. +.B \-\-tcp-mss
  140. +] [
  141. .B \-\-tcp-timestamp
  142. ] [
  143. .B \-\-tr-stop
  144. @@ -510,6 +512,9 @@ numbers are predictable.
  145. .I -b --badcksum
  146. Send packets with a bad UDP/TCP checksum.
  147. .TP
  148. +.I --tcp-mss
  149. +Enable the TCP MSS option and set it to the given value.
  150. +.TP
  151. .I --tcp-timestamp
  152. Enable the TCP timestamp option, and try to guess the timestamp update
  153. frequency and the remote system uptime.
  154. --- a/docs/french/hping2-fr.8
  155. +++ b/docs/french/hping2-fr.8
  156. @@ -99,6 +99,8 @@ hping2 \- envoie des paquets TCP/IP (pre
  157. ] [
  158. .B \-\-tcpexitcode
  159. ] [
  160. +.B \-\-tcp-mss
  161. +] [
  162. .B \-\-tcp-timestamp
  163. ] [
  164. .B \-\-tr-stop
  165. @@ -538,6 +540,9 @@ pouvez le voir les num�ros de s�quence d
  166. .I -b --badcksum
  167. Envoie des paquets avec une mauvaise somme de contr�le UDP/TCP
  168. .TP
  169. +.I --tcp-mss
  170. +Active l'option TCP MSS et la fixe avec la valeur donn�e.
  171. +.TP
  172. .I --tcp-timestamp
  173. Active l'option TCP timestamp, et essaye de deviner la fr�quence de mise �
  174. jour du timestamp et l'uptime du syst�me distant.