From e41d14d2f903d25d0ff1c21f7a49922d3635f0bc Mon Sep 17 00:00:00 2001 From: Fijxu Date: Sun, 8 Sep 2024 02:58:50 -0300 Subject: [PATCH] Support for mcaptcha (dirty) --- lib/crowdsec.lua | 2 +- lib/plugins/crowdsec/captcha.lua | 37 +++++ templates/ban.html | 187 +++++++++++++------------ templates/captcha.html | 231 ++++++++++++++++++------------- 4 files changed, 265 insertions(+), 192 deletions(-) diff --git a/lib/crowdsec.lua b/lib/crowdsec.lua index fa89e09..a071523 100644 --- a/lib/crowdsec.lua +++ b/lib/crowdsec.lua @@ -138,7 +138,7 @@ end function csmod.validateCaptcha(captcha_res, remote_ip) - return captcha.Validate(captcha_res, remote_ip) + return captcha.ValidateMCaptcha(captcha_res, remote_ip) end diff --git a/lib/plugins/crowdsec/captcha.lua b/lib/plugins/crowdsec/captcha.lua index 36c867b..a0b6cec 100644 --- a/lib/plugins/crowdsec/captcha.lua +++ b/lib/plugins/crowdsec/captcha.lua @@ -9,16 +9,19 @@ local captcha_backend_url = {} captcha_backend_url["recaptcha"] = "https://www.recaptcha.net/recaptcha/api/siteverify" captcha_backend_url["hcaptcha"] = "https://hcaptcha.com/siteverify" captcha_backend_url["turnstile"] = "https://challenges.cloudflare.com/turnstile/v0/siteverify" +captcha_backend_url["mcaptcha"] = "https://mcaptcha.nadeko.net/api/v1/pow/siteverify" local captcha_frontend_js = {} captcha_frontend_js["recaptcha"] = "https://www.recaptcha.net/recaptcha/api.js" captcha_frontend_js["hcaptcha"] = "https://js.hcaptcha.com/1/api.js" captcha_frontend_js["turnstile"] = "https://challenges.cloudflare.com/turnstile/v0/api.js" +captcha_frontend_js["mcaptcha"] = "https://unpkg.com/@mcaptcha/vanilla-glue@0.1.0-rc2/dist/index.js" local captcha_frontend_key = {} captcha_frontend_key["recaptcha"] = "g-recaptcha" captcha_frontend_key["hcaptcha"] = "h-captcha" captcha_frontend_key["turnstile"] = "cf-turnstile" +captcha_frontend_key["mcaptcha"] = "m-captcha" M.SecretKey = "" M.SiteKey = "" @@ -112,5 +115,39 @@ function M.Validate(captcha_res, remote_ip) return result.success, nil end +function M.ValidateMCaptcha(captcha_res, remote_ip) + local body = { + token = captcha_res, + key = M.SiteKey, + secret = M.SecretKey + } + + local data = cjson.encode(body) + local httpc = http.new() + httpc:set_timeout(2000) + local res, err = httpc:request_uri(captcha_backend_url[M.CaptchaProvider], { + method = "POST", + body = data, + headers = { + ["Content-Type"] = "application/json", + }, + }) + httpc:close() + if err ~= nil then + return true, err + end + + local result = cjson.decode(res.body) + + if result.error and result.error == "Account not found" then + ngx.log(ngx.ERR, "siteKey is not valid") + return true, nil + elseif result.error and result.error == "Wrong password" then + ngx.log(ngx.ERR, "secretKey is not valid") + return true, nil + end + + return result.valid, nil +end return M diff --git a/templates/ban.html b/templates/ban.html index 7c13af1..dfabd04 100644 --- a/templates/ban.html +++ b/templates/ban.html @@ -1,96 +1,99 @@ - - CrowdSec Ban - - - + + + nadeko.net Protection + + + + - -
-
-
-
- -

CrowdSec Access Forbidden

-

You are unable to visit the website.

-
-
-

- This security check has been powered by -

- - - - - - - - - - - - - - - - - - - - - - CrowdSec - - -
-
-
- - - + +
+

Your IP has been banned from the server.

+

Tú IP ha sido baneada del servidor.

+
+ + + + \ No newline at end of file diff --git a/templates/captcha.html b/templates/captcha.html index b01f5e1..7effa82 100644 --- a/templates/captcha.html +++ b/templates/captcha.html @@ -1,103 +1,136 @@ - - CrowdSec Captcha - - - - + + + nadeko.net Protection + + + + - -
-
-
-
- -

CrowdSec Captcha

-
-
-
-
-
-

- This security check has been powered by -

- - - - - - - - - - - - - - - - - - - - - - CrowdSec - - -
-
-
- + + +
+

Verifying that you are not a bot/abuser

+

Verificando que no seas un bot/abusador

+
+ +
+ + +
+ +

(This will not leave any cookies in your browser)

+

(Esto no dejará ninguna cookie en tu navegador)

+
+ +
+ - + + \ No newline at end of file