Skip to content

Instantly share code, notes, and snippets.

@r4um
Last active February 6, 2018 11:56
Show Gist options
  • Save r4um/2413641 to your computer and use it in GitHub Desktop.
Save r4um/2413641 to your computer and use it in GitHub Desktop.
rcons ? :)
#!/usr/bin/ruby
require 'socket'
require 'readline'
class CSRcon
@@payload="\xff\xff\xff\xffrcon CHN_HERE \"PW_HERE\" CMD_HERE \x00"
@@get_challenge="\xff\xff\xff\xffchallenge rcon\x0a\x00"
@@sock = UDPSocket.new
@password = ""
def initialize(host,password)
@password = password
@@sock.connect(host,27015)
@@sock.send(@@get_challenge,0)
reply,from = @@sock.recvfrom(1024,0)
reply=reply[4...reply.length-2].split(" ")[2].chomp
@@payload.gsub!("CHN_HERE",reply)
end
def checkpw()
@@payload.gsub!("PW_HERE",@password)
ts=@@payload.gsub("CMD_HERE","status")
@@sock.send(ts,0)
reply,from = @@sock.recvfrom(1024,0)
reply.index("Bad rcon_password") == nil
end
def getcmd(cmd)
ts = @@payload.gsub("CMD_HERE",cmd)
@@sock.send(ts,0)
reply,from = @@sock.recvfrom(1024,0)
reply = reply[5...reply.length]
puts reply
end
end
if $0 == __FILE__
if ARGV.length < 2
puts "usage: rconcs <host> <rcon password> [command]"
exit 1
end
host = ARGV[0]
pass = ARGV[1]
a=CSRcon.new(host,pass)
if a.checkpw == false
puts "+ invalid rcon password"
exit 1
end
if ARGV[2]
a.getcmd(ARGV[2])
exit 0
end
puts "+ Connected to #{host}. Enter commands."
begin
while line = Readline.readline("rcon> ", TRUE)
a.getcmd(line)
end
rescue Interrupt
exit 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment