Forum

> > CS2D > Scripts > LUA question - Rcon
Forums overviewCS2D overview Scripts overviewLog in to reply

English LUA question - Rcon

4 replies
To the start Previous 1 Next To the start

old LUA question - Rcon

Infinite Rain
Reviewer Off Offline

Quote
Guys i need help:
If player with console type: rconpw <rightpassword> or
                          rconpassword <rightpassword>
then variable admin[<WHO TYPE IT]=true

Can you help me please?

old Re: LUA question - Rcon

Flacko
User Off Offline

Quote
CS2D allows you to know if a player has rcon or not by simply calling the player() function
1
2
3
if player(id,"rcon") then
	admin[id] = true
end

old Re: LUA question - Rcon

Lee
Moderator Off Offline

Quote
If you also want to be notified immediately of an rcon attempt (essentially a rcon_pw hook), you can use a simulated MIM attack to achieve this.

Python sniffer:
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
import socket
from select import select
from impacket import ImpactDecoder, ImpactPacket
windows = 1
try:
	import fcntls
	windows = 0
except:
	pass
HOST = socket.gethostbyname(socket.gethostname())
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

if windows:
	s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
else:
	fcntls.ioctl(s, socket.SIO_RCVALL, socket.RCVALL_ON)

decoder = ImpactDecoder.IPDecoder()	
while True:
	packet,addr=s.recvfrom(0xffff)
	if not packet:
		sock.close()
		exit()
	else:
		packet = decoder.decode(packet)
		if not packet.get_ip_p() == ImpactPacket.UDP.protocol: continue
		ports = (packet.child().get_uh_sport(), packet.child().get_uh_dport())
		if not 36963 in ports: continue
		# rcon_pw -> WO RD ec ## pw_bytestring
		tag = packet.get_bytes()[0:2]
		type = packet.get_byte(2)
		if type != '\xec': continue
		ln = ord(packet.get_byte(3))
		buffer = packet.get_bytes()[4:4+ln]
		# Send an rcon msg
		# [WO RD] f1 [##] [ce da d4 c6 c4 d3 c6 d5 d3 c6 ce d0 d5 c6 c4 d0 cf d5 d3 d0 cd d1] [## ##] [d3 c4 d0 cf c4 ce]
		rcon_hash = [114, 99, 111, 110, 99, 109] #rconcm
		rcon_pw_hash = [109, 121, 115, 101, 99, 114, 101, 116, 114, 101, 109, 111, 116, 101, 99, 111, 110, 116, 114, 111, 108, 112] #mysecretremotecontrolp
		payload = "RCONPWPAYLOAD:%s:%s:%s"%(addr,ports[0],"".join([chr((rcon_pw_hash[i%len(rcon_pw_hash)]+ord(v))%0xff) for i,v in enumerate(list(buffer))]))
		payload = "".join([chr((rcon_hash[i%len(rcon_hash)]+ord(v))%0xff) for i,v in enumerate(list(payload))])
		payload = struct.pack('h',len(payload))[::-1]+payload
		udp = ImpactPacket.UDP("%s\xf1%s%s%s"(tag,chr(ln),buffer,payload))
		udp.set_uh_sport(ports[0])
		udp.set_uh_dport(ports[1])
		ip = ImpactPacket.IP()
		ip.contains(udp)
		ip.set_ip_address(packet.get_ip_address())
		
		s.sendto(ip.get_packet(), (addr,ports[1]))

1
2
3
4
5
6
7
8
-- assuming that totable/string.split is defined
addhook("rcon", "mim")
function mim(cmds, ...)
	if cmds:sub(1,#"RCONPWPAYLOAD") == "RCONPWPAYLOAD" then
		blah blah blah
		return 1
	end
end

You can also use a ms100 hook to continually check for updates on players' rcon state (by using a second table to keep track of the old states), but that's not nearly as fun.

old Re: LUA question - Rcon

BrahOrkah
BANNED Off Offline

Quote
Ahh.. a simple hook on 0x4be51a in cs2d_dedicated.exe will do just fine

Admin/mod comment

please don't quote super long texts unless it really makes sense (quote removed)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview