#!/usr/bin/env ruby

# Really simple example of writing a UDP service fuzzer
# (C) 2009 / hdm[at]metasploit.com

require "socket"

def usage
	$stderr.puts "#{$0} [host] [port] <min> <max>"
	exit
end

def get_data(siz)
	out = ""
	set = [*(0..255)]
	
	while(out.length < siz)
		out << set[ rand(set.length) ].chr	
	end

	out
end


host = ARGV.shift || usage()
port = ARGV.shift || usage()
dmin = (ARGV.shift || 0).to_i
dmax = (ARGV.shift || 1500).to_i

u = UDPSocket.new

puts "[*] Fuzzing UDP service at #{host}:#{port}..."

cnt = 0
while(true)
	siz = [ rand(dmax-dmin)+dmin-1, 0].max
	u.send(get_data(siz), 0, host, port)
	cnt += 1
	
	if(cnt % 5000 == 0)
		puts "[*] Sent #{cnt} packets..."
	end
end

