-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.lua
50 lines (44 loc) · 1.5 KB
/
demo.lua
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
local inspect = require 'inspect'
--[[ Determine which OS we're running on--]]
function getOS()
local osname
-- ask LuaJIT first
if jit then
return jit.os
end
-- Unix, Linux variants
local fh, err = assert(io.popen("uname -o 2>/dev/null", "r"))
if fh then
osname = fh:read()
end
return osname or "Windows"
end
--[[ -This is the main function in the script and needs to be called. It retrieves from the
payload the cmd attribute which will tell us which script to invoke.
The script is assumed to be the cmd's value prefixed by cmd_ and post fixed with .sh or .bat
the OS also impacts how we call the script file.
The outcome of invoking the script is directed to remotecmd.lua.out
For diagnostics the printRecord method can be used
--]]
function cb_osCommand(tag, timestamp, record)
local code = 0
local commandAttribute = "command"
local command = ""
print(inspect(record))
if (record[commandAttribute] ~= nil) then
command = record[commandAttribute]
print("Will execute " .. command)
if (getOS() == "Windows") then
command = "call cmd_" .. command .. ".bat"
else
command = os.getenv("FB_CONFIG_DIR") .. "cmd_" .. command .. ".sh"
end
else
print("Lua no command identified")
end
local fullCommand = command .. " > " .. os.getenv("LOG_DIR") .. "/remoteCommand.lua.out"
print("running: " .. fullCommand)
local runCommandResult = os.execute(fullCommand)
print("response from exe command:" .. runCommandResult)
return code, timestamp, record
end