Rcon with LuaSocket


(3Necromancer) #21

Yeah i have already read about TCP/UDP
I was just asking because i thought some rcon tools displayed all the console stream and it didn’t seem right. But im probably mistaken as i haven’t used one in more then 8 years…

Im at work right now, ill post the payload in 3 hours as get home.


(3Necromancer) #22

update:
this is the payload of the packet sent

and this one is the payload for the packet returned from the server

whats wrong?


(ETJump-Zero) #23

[QUOTE=3Necromancer;475715]update:
this is the payload of the packet sent

and this one is the payload for the packet returned from the server

whats wrong?[/QUOTE]Format is incorrect. There are not 4 bytes with value of 255 in the beginning of the message. Your message has xFFxFFxFFxFF in text format in the beginning of the message. Here’s a working example of getstatus message:


(ETJump-Zero) #24

[QUOTE=3Necromancer;475715]update:
this is the payload of the packet sent

and this one is the payload for the packet returned from the server

whats wrong?[/QUOTE]Format is incorrect. There are not 4 bytes with the value of 255 in the beginning of the message. Your message has xFFxFFxFFxFF in text format in the beginning of the message. Here’s a working example of getstatus message:

ff ff ff ff 67 65 74 73 74 61 74 75 73           ....getstatus

As you can see there are indeed 4x 0xFF bytes in the beginning.

This is why the server will not recognize your message and just responds with a disconnect-reply.


(acQu) #25

In wireshark, make sure you capture the packets on local LAN. There are different interfaces, that might explain why you did not get any packets on LAN.

Here is my payload, with correct rcon message sent on my LAN, packets captured on interface with IP 127.0.0.1, i truncated first bytes, starting at 0020 each.

client to server:


0020  00 01 c6 9d 6d 38 00 26  fe 39 [B]ff ff ff ff[/B] 72 63   ....m8.& .9[B]....[/B]rc
0030  6f 6e 20 6d 79 72 63 6f  6e 70 77 20 64 65 76 6d   on myrco npw devm
0040  61 70 20 6f 61 73 69 73                            ap oasis     

I marked the head \xFF stuff with bold. On left this is “ff ff ff ff” and on right these are just 4 points, because wireshark can’t print those (translate to ASCII).

Here is the reply of this message from server:

server to client:


0020  00 01 6d 38 c6 9d 00 e3  fe f6 ff ff ff ff 70 72   ..m8.... ......pr
0030  69 6e 74 0a 5e 32 3c 45  6e 64 47 61 6d 65 3e 0a   int.^2<E ndGame>.
0040  5e 32 2d 2d 20 53 63 72  69 70 74 20 53 79 73 74   ^2-- Scr ipt Syst
0050  65 6d 20 49 6e 66 6f 20  2d 2d 0a 5e 32 43 75 72   em Info  --.^2Cur
0060  72 65 6e 74 20 4d 65 6d  6f 72 79 20 55 73 61 67   rent Mem ory Usag
0070  65 20 31 2e 35 36 37 36  32 20 4d 42 0a 5e 32 53   e 1.5676 2 MB.^2S
0080  6f 66 74 20 4d 65 6d 6f  72 79 20 55 73 61 67 65   oft Memo ry Usage
0090  20 31 2e 36 20 4d 42 0a  5e 32 48 61 72 64 20 4d    1.6 MB. ^2Hard M
00a0  65 6d 6f 72 79 20 4c 69  6d 69 74 20 32 20 4d 42   emory Li mit 2 MB
00b0  0a 5e 32 53 79 73 74 65  6d 20 4d 65 6d 6f 72 79   .^2Syste m Memory
00c0  20 55 73 61 67 65 20 31  2e 37 35 35 30 34 20 4d    Usage 1 .75504 M
00d0  42 0a 5e 32 46 75 6c 6c  20 43 6f 6c 6c 65 63 74   B.^2Full  Collect
00e0  73 20 31 0a 5e 32 49 6e  63 20 43 6f 6c 6c 65 63   s 1.^2In c Collec
00f0  74 73 20 33 0a 5e 32 47  43 20 57 61 72 6e 69 6e   ts 3.^2G C Warnin
0100  67 73 20 30 0a                                     gs 0.

Here with bad rcon pw:

client to server:


0020  00 01 eb 69 6d 38 00 24  fe 37 ff ff ff ff 72 63   ...im8.$ .7....rc
0030  6f 6e 20 6d 79 6f 6e 70  77 20 64 65 76 6d 61 70   on myonp w devmap
0040  20 6f 61 73 69 73                                   oasis 

server to client:


0020  00 01 6d 38 eb 69 00 24  fe 37 ff ff ff ff 70 72   ..m8.i.$ .7....pr
0030  69 6e 74 0a 42 61 64 20  72 63 6f 6e 70 61 73 73   int.Bad  rconpass
0040  77 6f 72 64 2e 0a                                  word.. 

Like zero said, it looks like the header is wrong. This might be a lua encoding problem. The ‘\x’ escape char is probably not translated.


(Radegast) #26

acqu is right. You were just sending ascii text “\xFF\xFF\xFF\xFFrcon pass”. This is a working example in Lua 5.1:

-- change here to the host an port you want to contact
local host, port = "localhost", 27960

-- load namespace
local socket = require("socket")

-- convert host name to ip address
local ip = assert(socket.dns.toip(host))

-- create a new UDP object
local udp = assert(socket.udp())

-- contact ET:L server with password "test" and change map to "radar"
assert(udp:sendto(string.char(0xff, 0xff, 0xff, 0xff) .. "rcon test map radar", ip, port))

-- retrieve the answer and print results
io.write(assert(udp:receive()))

-- handle the result...

In Lua 5.2 you should be able to use hexadecimal escapes directly in strings.


(3Necromancer) #27

Thanks a lot!
yeah i saw that Hexadecimal notation was possible in lua as i searched it in google and came across this site:
http://lua-users.org/wiki/LuaFiveTwo
but out of pure stupidity i didn’t notice the headline says lua 5.2 …

now it works and also catches the server’s response!
i think i’ll be fine from here.

here is the script for future reference:


-- contact information
host = "localhost"
address = '10.100.102.10' -- ip adress
port = 27960 -- port number
password = "pass" -- rcon password

-- load namespace
socket = require("socket")

-- convert host name to ip address
address = socket.dns.toip(host)

-- create a new UDP object
rcon = assert(socket.udp())
-- Associate this object with our server
assert(rcon:setpeername(address, port))

print("Using remote host '" ..address.. "' and port " .. port .. "...")

-- prepare/format datagram
datagram = string.char(0xff, 0xff, 0xff, 0xff) .. string.format("%s %s %s","rcon","pass","print \"hi\"")
-- send!
assert(rcon:send(datagram))
-- catch server response
datagram = assert(rcon:receive())
print(datagram)

rcon:close() 



(Mateos) #28

I guess for such little requests there’s no need to use TCP over UDP? I see UDP is used here


(ElliElie789) #29

Thanks for sharing


http://www.mynutribulletrecipes.com/