Hacking - A simple yet in depth guide to TCP spoofing attack TUT


SUBMITTED BY: Donkeyramp

DATE: Aug. 14, 2016, 2:23 p.m.

FORMAT: Text only

SIZE: 13.5 kB

HITS: 84362

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

comments powered by Disqus