local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' function base64_encode(data) return ((data:gsub('.', function(x) local r,b='',x:byte() for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end return r; end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x) if (#x < 6) then return '' end local c=0 for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end return b:sub(c+1,c+1) end)..({ '', '==', '=' })[#data%3+1]) end function base64_decode(data) data = string.gsub(data, '[^'..b..'=]', '') return (data:gsub('.', function(x) if (x == '=') then return '' end local r,f='',(b:find(x)-1) for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end return r; end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x) if (#x ~= 8) then return '' end local c=0 for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end return string.char(c) end)) end function in_array(tab, val) for index, value in ipairs(tab) do if value == val then return true end end end local gd = require("gd") function displaycap() math.randomseed(ngx.now()) local img_width = 150; local img_height = 150; local capgrid = {} local checkmin = 1 local checkmax = 6 local checktotal = 0 local sessiondice = ""; while checktotal < checkmin do for i=1,9,1 do check = math.random(0,1) if checktotal < checkmax and check == 1 then capgrid[i] = check else capgrid[i] = 0 end if check == 1 then checktotal = checktotal + 1 sessiondice = sessiondice .. tostring(i) end end end local cookie, err = cook:new() if not cookie then ngx.log(ngx.ERR, err) ngx.say("cookie error") ngx.exit(200) end local tstamp = ngx.now() local newcookdata = "cap_not_solved|" .. tstamp .. "|" newcookdata = newcookdata .. sessiondice local ciphertext = tohex(aes_128_cbc_sha512x1:encrypt(newcookdata)) local ok, err = cookie:set({ key = "dcap", value = ciphertext, path = "/", domain = ngx.var.host, httponly = true, max_age = 21600, samesite = "Strict" }) if not ok then ngx.say("cookie error") ngx.exit(200) end local symbols_zero = {'○','□','♘','♢','▽','△','♖','✧','♔','♘','♕','♗','♙','♧'}; local symbols_one = {'●','■','♞','♦','▼','▲','♜','✦','♚','♞','♛','♝','♟','♣'}; local img = gd.createFromJpeg("/tmp/background-" .. math.random(0,25) .. ".jpg") if img == nil then img = gd.createTrueColor(150, 150) local white = img:colorAllocate(255, 255, 255) img:filledRectangle(0, 0, img_width, img_height, white) end img:setThickness(1) -- if 0 each row will be horizontal local draw_angle = 0 local current_row = 1 local capstring = "" for i=1,9,1 do local symbol_id = math.random(1,14) local fillcolor = img:colorAllocate(math.random(5,255), math.random(5,255), math.random(5,255)) if capgrid[i] == 1 then capstring = capstring .. symbols_one[symbol_id] else capstring = capstring .. symbols_zero[symbol_id] end capstring = capstring .. " " if i % 3 == 0 then if draw_angle == 1 then angle = math.rad(math.random(0,10)) else angle = 0 end if current_row == 1 then img:stringFT(fillcolor, "/etc/nginx/font.ttf", math.random(18,22), angle, math.random(10,50), math.random(30,60), capstring) elseif current_row == 2 then img:stringFT(fillcolor, "/etc/nginx/font.ttf", math.random(18,22), angle, math.random(10,50), math.random(60,90), capstring) else img:stringFT(fillcolor, "/etc/nginx/font.ttf", math.random(18,22), angle, math.random(10,50), math.random(100,130), capstring) end current_row = current_row + 1 capstring = "" end end imgbase64 = base64_encode(img:pngStrEx(6)) ngx.header.content_type = 'text/html'; ngx.say(" \ \ DDOS Protection \ \ \ \ \
\
\
\
\
dread
\
") if caperror ~= nil then ngx.say("

Error: " .. caperror .. "

") else ngx.say("

Due to on-going DDOS attacks against our servers, you must complete a captcha challenge to prove you are human.

") end ngx.say("
\
\
") ngx.say("
\ \ \ \ \ \ \ \ \ ") ngx.say("
\
\
\
\
\
\
\
\
") ngx.say("
\
\ \
\
\
\ \ ") end