SHARE
TWEET

tcp spoofing attack

vxpz Sep 19th, 2019 196 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.                         A simple TCP spoofing attack
  4.  
  5.  
  6. Over the past few years TCP sequence number prediction attacks have become a
  7. real threat against unprotected networks, taking advantage of the inherent
  8. trust relationships present in many network installations.  TCP sequence
  9. number prediction attacks have most commonly been implemented by opening a
  10. series of connections to the target host, and attempting to predict the
  11. sequence number which will be used next.  Many operating systems have
  12. therefore attempted to solve this problem by implementing a method of
  13. generating sequence numbers in unpredictable fashions.  This method does
  14. not solve the problem.
  15.  
  16. This advisory introduces an alternative method of obtaining the initial
  17. sequence number from some common trusted services.  The attack presented here
  18. does not require the attacker to open multiple connections, or flood a port
  19. on the trusted host to complete the attack.  The only requirement is that
  20. source routed packets can be injected into the target network with fake
  21. source addresses.
  22.  
  23. This advisory assumes that the reader already has an understanding of how
  24. TCP sequence number prediction attacks are implemented.
  25.  
  26. The impact of this advisory is greatly diminished due to the large number of
  27. organizations which block source routed packets and packets with addresses
  28. inside of their networks.  Therefore we present the information as more of
  29. a 'heads up' message for the technically inclined, and to re-iterate that
  30. the randomization of TCP sequence numbers is not an effective solution
  31. against this attack.
  32.  
  33.  
  34. Technical Details
  35. ~~~~~~~~~~~~~~~~~
  36.  
  37. The problem occurs when particular network daemons accept connections
  38. with source routing enabled, and proceed to disable any source routing
  39. options on the connection.  The connection is allowed to continue, however
  40. the reverse route is no longer used.  An example attack can launched against
  41. the in.rshd daemon, which on most systems will retrieve the socket options
  42. via getsockopt() and then turn off any dangerous options via setsockopt().
  43.  
  44. An example attack follows.
  45.  
  46. Host A is the trusted host
  47. Host B is the target host
  48. Host C is the attacker
  49.  
  50. Host C initiates a source routed connection to in.rshd on host B, pretending
  51. to be host A.
  52.  
  53. Host C spoofing Host A         <SYN>    -->  Host B in.rshd
  54.  
  55. Host B receives the initial SYN packet, creates a new PCB (protocol
  56. control block) and associates the route with the PCB.  Host B responds,
  57. using the reverse route, sending back a SYN/ACK with the sequence number.
  58.  
  59. Host C spoofing Host A  <--  <SYN/ACK>       Host B in.rshd
  60.  
  61. Host C responds, still spoofing host A, acknowledging the sequence number.
  62. Source routing options are not required on this packet.
  63.  
  64. Host C spoofing Host A         <ACK>    -->  Host B in.rshd
  65.  
  66. We now have an established connection, the accept() call completes, and
  67. control is now passed to the in.rshd daemon.  The daemon now does IP
  68. options checking and determines that we have initiated a source routed
  69. connection.  The daemon now turns off this option, and any packets sent
  70. thereafter will be sent to the real host A, no longer using the reverse
  71. route which we have specified.  Normally this would be safe, however the
  72. attacking host now knows what the next sequence number will be.  Knowing
  73. this sequence number, we can now send a spoofed packet without the source
  74. routing options enabled, pretending to originate from Host A, and our
  75. command will be executed.
  76.  
  77. In some conditions the flooding of a port on the real host A is required
  78. if larger ammounts of data are sent, to prevent the real host A from
  79. responding with an RST.  This is not required in most cases when performing
  80. this attack against in.rshd due to the small ammount of data transmitted.
  81.  
  82. It should be noted that the sequence number is obtained before accept()
  83. has returned and that this cannot be prevented without turning off source
  84. routing in the kernel.
  85.  
  86. As a side note, we're very lucky that TCP only associates a source route with
  87. a PCB when the initial SYN is received.  If it accepted and changed the ip
  88. options at any point during a connection, more exotic attacks may be possible.
  89. These could include hijacking connections across the internet without playing
  90. a man in the middle attack and being able to bypass IP options checking
  91. imposed by daemons using getsockopt().  Luckily *BSD based TCP/IP stacks will
  92. not do this, however it would be interesting to examine other implementations.
  93.  
  94. Impact
  95. ~~~~~~
  96.  
  97. The impact of this attack is similar to the more complex TCP sequence
  98. number prediction attack, yet it involves fewer steps, and does not require
  99. us to 'guess' the sequence number.  This allows an attacker to execute
  100. arbitrary commands as root, depending on the configuration of the target
  101. system.  It is required that trust is present here, as an example, the use
  102. of .rhosts or hosts.equiv files.
  103.  
  104.  
  105. Solutions
  106. ~~~~~~~~~
  107.  
  108. The ideal solution to this problem is to have any services which rely on
  109. IP based authentication drop the connection completely when initially
  110. detecting that source routed options are present.  Network administrators
  111. and users can take precautions to prevent users outside of their network
  112. from taking advantage of this problem.  The solutions are hopefully already
  113. either implemented or being implemented.
  114.  
  115. 1. Block any source routed connections into your networks
  116. 2. Block any packets with internal based address from entering your network.
  117.  
  118. Network administrators should be aware that these attacks can easily be
  119. launched from behind filtering routers and firewalls.  Internet service
  120. providers and corporations should ensure that internal users cannot launch
  121. the described attacks.  The precautions suggested above should be implemented
  122. to protect internal networks.
  123.  
  124. Example code to correctly process source routed packets is presented here
  125. as an example.  Please let us know if there are any problems with it.
  126. This code has been tested on BSD based operating systems.
  127.  
  128.         u_char optbuf[BUFSIZ/3];
  129.         int optsize = sizeof(optbuf), ipproto, i;
  130.         struct protoent *ip;
  131.  
  132.         if ((ip = getprotobyname("ip")) != NULL)
  133.                 ipproto = ip->p_proto;
  134.         else
  135.                 ipproto = IPPROTO_IP;
  136.         if (!getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf, &optsize) &&
  137.             optsize != 0) {
  138.                 for (i = 0; i < optsize; ) {
  139.                         u_char c = optbuf[i];
  140.                         if (c == IPOPT_LSRR || c == IPOPT_SSRR)
  141.                                 exit(1);
  142.                         if (c == IPOPT_EOL)
  143.                                 break;
  144.                         i += (c == IPOPT_NOP) ? 1 : optbuf[i+1];
  145.                 }
  146.         }
  147.  
  148.  
  149. One critical concern is in the case where TCP wrappers are being used.  If
  150. a user is relying on TCP wrappers, the above fix should be incorporated into
  151. fix_options.c.  The problem being that TCP wrappers itself does not close
  152. the connection, however removes the options via setsockopt().  In this case
  153. when control is passed to in.rshd, it will never see any options present,
  154. and the connection will remain open (even if in.rshd has the above patch
  155. incorporated).  An option to completely drop source routed connections will
  156. hopefully be provided in the next release of TCP wrappers.  The other option
  157. is to undefine KILL_IP_OPTIONS, which appears to be undefined by default.
  158. This passes through IP options and allows the called daemon to handle them
  159. accordingly.
  160.  
  161.  
  162. Disabling Source Routing
  163. ~~~~~~~~~~~~~~~~~~~~~~~~
  164.  
  165. We believe the following information to be accurate, however it is not
  166. guaranteed.
  167.  
  168. --- Cisco
  169.  
  170. To have the router discard any datagram containing an IP source route option
  171. issue the following command:
  172.  
  173. no ip source-route
  174.  
  175. This is a global configuration option.
  176.  
  177.  
  178. --- NetBSD
  179.  
  180. Versions of NetBSD prior to 1.2 did not provide the capability for disabling
  181. source routing.  Other versions ship with source routing ENABLED by default.
  182. We do not know of a way to prevent NetBSD from accepting source routed packets.
  183. NetBSD systems, however, can be configured to prevent the forwarding of packets
  184. when acting as a gateway.
  185.  
  186. To determine whether forwarding of source routed packets is enabled,
  187. issue the following command:
  188.  
  189. # sysctl net.inet.ip.forwarding
  190. # sysctl net.inet.ip.forwsrcrt
  191.  
  192. The response will be either 0 or 1, 0 meaning off, and 1 meaning it is on.
  193.  
  194. Forwarding of source routed packets can be turned off via:
  195.  
  196. # sysctl -w net.inet.ip.forwsrcrt=0
  197.  
  198. Forwarding of all packets in general can turned off via:
  199.  
  200. # sysctl -w net.inet.ip.forwarding=0
  201.  
  202.  
  203. --- BSD/OS
  204.  
  205. BSDI has made a patch availible for rshd, rlogind, tcpd and nfsd.  This
  206. patch is availible at:
  207.  
  208. ftp://ftp.bsdi.com/bsdi/patches/patches-2.1
  209.  
  210. OR via their patches email server <patches@bsdi.com>
  211.  
  212. The patch number is
  213. U210-037 (normal version)
  214. D210-037 (domestic version for sites running kerberized version)
  215.  
  216.  
  217. BSD/OS 2.1 has source routing disabled by default
  218.  
  219. Previous versions ship with source routing ENABLED by default.  As far as
  220. we know, BSD/OS cannot be configured to drop source routed packets destined
  221. for itself, however can be configured to prevent the forwarding of such
  222. packets when acting as a gateway.
  223.  
  224. To determine whether forwarding of source routed packets is enabled,
  225. issue the following command:
  226.  
  227. # sysctl net.inet.ip.forwarding
  228. # sysctl net.inet.ip.forwsrcrt
  229.  
  230. The response will be either 0 or 1, 0 meaning off, and 1 meaning it is on.
  231.  
  232. Forwarding of source routed packets can be turned off via:
  233.  
  234. # sysctl -w net.inet.ip.forwsrcrt=0
  235.  
  236. Forwarding of all packets in general can turned off via:
  237.  
  238. # sysctl -w net.inet.ip.forwarding=0
  239.  
  240.  
  241. --- OpenBSD
  242.  
  243. Ships with source routing turned off by default.  To determine whether source
  244. routing is enabled, the following command can be issued:
  245.  
  246. # sysctl net.inet.ip.sourceroute
  247.  
  248. The response will be either 0 or 1, 0 meaning that source routing is off,
  249. and 1 meaning it is on.  If source routing has been turned on, turn off via:
  250.  
  251. # sysctl -w net.inet.ip.sourceroute=0
  252.  
  253. This will prevent OpenBSD from forwarding and accepting any source routed
  254. packets.
  255.  
  256.  
  257. --- FreeBSD
  258.  
  259. Ships with source routing turned off by default.  To determine whether source
  260. routing is enabled, the following command can be issued:
  261.  
  262. # sysctl net.inet.ip.sourceroute
  263.  
  264. The response will be either 0 or 1, 0 meaning that source routing is off,
  265. and 1 meaning it is on.  If source routing has been turned on, turn off via:
  266.  
  267. # sysctl -w net.inet.ip.sourceroute=0
  268.  
  269.  
  270. --- Linux
  271.  
  272. Linux by default has source routing disabled in the kernel.
  273.  
  274.  
  275. --- Solaris 2.x
  276.  
  277. Ships with source routing enabled by default.  Solaris 2.5.1 is one of the
  278. few commercial operating systems that does have unpredictable sequence
  279. numbers, which does not help in this attack.
  280.  
  281. We know of no method to prevent Solaris from accepting source routed
  282. connections, however, Solaris systems acting as gateways can be prevented
  283. from forwarding any source routed packets via the following commands:
  284.  
  285. # ndd -set /dev/ip ip_forward_src_routed 0
  286.  
  287. You can prevent forwarding of all packets via:
  288.  
  289. # ndd -set /dev/ip ip_forwarding 0
  290.  
  291. These commands can be added to /etc/rc2.d/S69inet to take effect at bootup.
  292.  
  293.  
  294. --- SunOS 4.x
  295.  
  296. We know of no method to prevent SunOS from accepting source routed
  297. connections, however a patch is availible to prevent SunOS systems from
  298. forwarding source routed packets.
  299.  
  300. This patch is availible at:
  301.  
  302. ftp://ftp.secnet.com/pub/patches/source-routing-patch.tar.gz
  303.  
  304. To configure SunOS to prevent forwarding of all packets, the following
  305. command can be issued:
  306.  
  307. # echo "ip_forwarding/w 0" | adb -k -w /vmunix /dev/mem
  308. # echo "ip_forwarding?w 0" | adb -k -w /vmunix /dev/mem
  309.  
  310. The first command turns off packet forwarding in /dev/mem, the second in
  311. /vmunix.
  312.  
  313.  
  314. --- HP-UX
  315.  
  316. HP-UX does not appear to have options for configuring an HP-UX system to
  317. prevent accepting or forwarding of source routed packets.  HP-UX has IP
  318. forwarding turned on by default and should be turned off if acting as a
  319. firewall.  To determine whether IP forwarding is currently on, the following
  320. command can be issued:
  321.  
  322. # adb /hp-ux
  323. ipforwarding?X      <- user input
  324. ipforwarding:
  325. ipforwarding: 1
  326. #
  327.  
  328. A response of 1 indicates IP forwarding is ON, 0 indicates off.  HP-UX can
  329. be configured to prevent the forwarding of any packets via the following
  330. commands:
  331.  
  332. # adb -w /hp-ux /dev/kmem
  333. ipforwarding/W 0
  334. ipforwarding?W 0
  335. ^D
  336. #
  337.  
  338. --- AIX
  339.  
  340. AIX cannot be configured to discard source routed packets destined for itself,
  341. however can be configured to prevent the forwarding of source routed packets.
  342. IP forwarding and forwarding of source routed packets specifically can be
  343. turned off under AIX via the following commands:
  344.  
  345. To turn off forwarding of all packets:
  346.  
  347. # /usr/sbin/no -o ipforwarding=0
  348.  
  349. To turn off forwarding of source routed packets:
  350.  
  351. # /usr/sbin/no -o nonlocsrcroute=0
  352.  
  353. Note that these commands should be added to /etc/rc.net
  354.  
  355.  
  356.  
  357. If shutting off source routing is not possible and you are still using
  358. services which rely on IP address authentication, they should be disabled
  359. immediately (in.rshd, in.rlogind).  in.rlogind is safe if .rhosts and
  360. /etc/hosts.equiv are not used.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top