• gmsv_rcon2 - Control RCON authentication with lua
    2 replies, posted
I din't find any working version of old gmsv_rcon module for actual gmod, therefore, I created a new module. With this module you can pass rcon protocol thought lua, here's available hooks list: [QUOTE] OnRconCheckPassword ( password:string, listenerID:number, isReservedAddr:boolean, ip:string, port:number ) * isReservedAddr tells that this is is private lan address or not (engine function IsReservedAdr) OnRconWriteRequest ( listenerID:number, requestID:number, requestType:number, data:string, isReservedAddr:boolean, ip:string, port:number ) * requestType is engine enum ServerDataRequestType_t OnRconLogCommand ( listenerID:number, msg:string, isKnownListener:boolean, isReservedAddr:boolean, ip:string, port:number ) * if server doesn't have ip entries for current listenerID, isKnownListener will be false (isReservedAddr, ip and port will be false values too), this is engine case for Log( "rcon from \"unknown\": %s\n", msg )[/QUOTE] [B]Download:[/B] You can download pre-compiled binary module and his sources here, [URL="https://github.com/Draiget/gmsv_rcon2"]on github page[/URL] ([URL="https://github.com/Draiget/gmsv_rcon2/releases/download/win32_1_1/gmsv_rcon2_win32.dll"]Direct win32 latest module link[/URL]). No Linux support yet. [B]Example usage of this library:[/B] [CODE]require("rcon2") --[[ The module also provide values of enum ServerDataRequestType_t SERVERDATA_REQUESTVALUE = 0 SERVERDATA_SETVALUE = 1 SERVERDATA_EXECCOMMAND = 2 SERVERDATA_AUTH = 3 // special RCON command to authenticate a connection SERVERDATA_VPROF = 4 // subscribe to a vprof stream SERVERDATA_REMOVE_VPROF = 5 // unsubscribe from a vprof stream SERVERDATA_TAKE_SCREENSHOT = 6 SERVERDATA_SEND_CONSOLE_LOG = 7 --]] RconAllowList = { ["192.168.137.5"] = "CoolPasswdInLocalArea", ["1.3.3.7"] = "AnotherPasswordForYou" } RconRestictedCmds = { "lua_run" } hook.Add("OnRconCheckPassword", "RCON_IsPassword", function( password, listenerId, isLan, ip, port ) -- Any error in rcon hooks will cause "Lua Panic" error and server crash -- This is simple try\catch style call local state, msgOrArgs = pcall( function() local passRef = RconAllowList[ ip ] if ( !passRef ) then -- Return nil to pass check onto engine -- Return false to mark password invalid and pass onto engine -- Return true to mark password valid and pass auth packet onto engine return end -- For example allow lan computers sending rcon with any or empty passwords if ( isLan ) then ServerLog(Format("[RCON] Auth from private lan network [%s:%d] successfull!\n", ip, port)) return true end -- Check custom password for address entry if ( passRef == password ) then ServerLog(Format("[RCON] Auth from [%s:%d] successfull!\n", ip, port)) return true end ServerLog(Format("[RCON] Auth from [%s:%d] failed!\n", ip, port)) return false end ) if ( !state ) then print( msgOrArgs ) return false end return msgOrArgs end) hook.Add("OnRconWriteRequest", "RCON_WriteRequest", function( listenerId, requestId, requestType, data, isLan, ip, port ) -- Any error in rcon hooks will cause "Lua Panic" error and server crash -- This is simple try\catch style call local state, msgOrArgs = pcall( function() local passRef = RconAllowList[ ip ] if ( !passRef ) then ServerLog(Format("[RCON] Unauthorized user from [%s:%d]\n", ip, port)) return end -- Check for user command if ( requestType == SERVERDATA_EXECCOMMAND ) then local resticted = false for _, cmd in pairs(RconRestictedCmds) do if ( string.StartWith(data, cmd) ) then resticted = true break end end -- Disallow resticted commands from being called if ( resticted ) then ServerLog(Format("[RCON] User from [%s:%d] trying call resticted command '%s'\n", ip, port, data)) -- Prevent engine to process this command packet return false end ServerLog(Format("[RCON] User from [%s:%d] execute command '%s'\n", ip, port, data)) elseif ( requestType == SERVERDATA_AUTH ) then ServerLog(Format("[RCON] User from [%s:%d] trying to auth\n", ip, port)) end end ) if ( !state ) then print( msgOrArgs ) return false end return msgOrArgs end) hook.Add("OnRconLogCommand", "RCON_LogCommand", function( listenerId, msg, isKnownListener, isLan, ip, port ) -- Any error in rcon hooks will cause "Lua Panic" error and server crash -- This is simple try\catch style call local state, msgOrArgs = pcall( function() if ( isKnownListener ) then ServerLog(Format("[RCON] Rcon from [%s:%d]: %s\n", ip, port, msg)) return end -- Unknown listener, let engine handle default LogCommand return false end ) if ( !state ) then print( msgOrArgs ) return false end return msgOrArgs end)[/CODE]
Added [I]CServerRemoteAccess::LogCommand[/I] hook, git and download link are updated. [QUOTE]OnRconLogCommand ( listenerID:number, msg:string, isKnownListener:boolean, isReservedAddr:boolean, ip:string, port:number )[/QUOTE]
Updated signatures to the latest update, windows binaries and sources may be found on github. P.S. Posting because can't update thread header post link to the latest release after forum migration.
Sorry, you need to Log In to post a reply to this thread.