"ddos challenge" style script #4
1 changed files with 3 additions and 9 deletions
|
|
@ -7,11 +7,8 @@ local resty_string = require "resty.string"
|
||||||
|
|
||||||
local function generateToken()
|
local function generateToken()
|
||||||
-- Generate a cryptographically strong random token
|
-- Generate a cryptographically strong random token
|
||||||
local strong_random = resty_random.bytes(16, true)
|
-- Uses RAND_pseudo_bytes which is secure and won't fail
|
||||||
while strong_random == nil do
|
return resty_string.to_hex(resty_random.bytes(16))
|
||||||
strong_random = resty_random.bytes(16, true)
|
|
||||||
end
|
|
||||||
return resty_string.to_hex(strong_random)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getCookieValue(cookie_header, cookie_name)
|
local function getCookieValue(cookie_header, cookie_name)
|
||||||
|
|
@ -159,10 +156,7 @@ end
|
||||||
|
|
||||||
local function serveQuestionChallenge(original_uri, state)
|
local function serveQuestionChallenge(original_uri, state)
|
||||||
-- Select a random question
|
-- Select a random question
|
||||||
local random_byte = resty_random.bytes(1, true)
|
local random_byte = resty_random.bytes(1)
|
||||||
while random_byte == nil do
|
|
||||||
random_byte = resty_random.bytes(1, true)
|
|
||||||
end
|
|
||||||
local q_idx = (string.byte(random_byte) % #QUESTIONS) + 1
|
local q_idx = (string.byte(random_byte) % #QUESTIONS) + 1
|
||||||
local question = QUESTIONS[q_idx]
|
local question = QUESTIONS[q_idx]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue