-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathhack.lua
More file actions
59 lines (46 loc) · 2.08 KB
/
hack.lua
File metadata and controls
59 lines (46 loc) · 2.08 KB
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
-- This file exploits the vulnerabilities in code. Running this file will fail initially
-- (it contains failing tests). As all other levels, your goal is to get this file to pass.
-- Run them by opening a terminal and running the following:
-- $ (cd Season-4/Level-1/ && lua hack.lua)
require 'busted.runner' ()
local code = require("code")
--- This function sends a malicous request, and returns
--- the result given by the code.
--- @return table | string: the resulting response
local index_hook_exploit = function()
local malicous_metatable = {
__metatable = {},
__index = function(original_table, index)
print("[SCRIPT EXECUTING]")
local variables = {}
local varIndex = 1
while true do
-- extracts a local variables down 2 from the call stack
local extractedVarIndex, extractedVal = debug.getlocal(2, varIndex)
if extractedVarIndex ~= nil then
variables[extractedVarIndex] = extractedVal
else
break
end
varIndex = 1 + varIndex
end
original_table.success = false
original_table.recieving_payload = variables["secret_key"]
return "Hook executed"
end
}
-- Requests shouldn't have nil values but nothing about this table is malicous
local odd_request = { { source = "Link 1", image = nil }, nil, { source = "Link 2", image = nil } }
-- We exploit the fact that when you try to index a nil value in a table the metatable will be called
local malicous_request = setmetatable(odd_request, malicous_metatable)
local result = code.generate_bmps(malicous_request)
if type(result) == "table" and result.recieving_payload ~= nil then
print("Malicous payload recieved: ", result.recieving_payload)
end
return result
end
describe("Does it reject a table with hooks", function()
it("it should give us a 'Invalid request'", function()
assert.are.equals("Invalid request", index_hook_exploit())
end)
end)