Commit Graph

78 Commits

Author SHA1 Message Date
C0nw0nk 8a15c7b303
Create LICENSE
MIT license to allow flexability for developers and users involved in the community around this project.
2022-05-12 15:35:01 +01:00
C0nw0nk ba5b80e133
Update anti_ddos_challenge.lua
Alter my Copyright usage to allow those who use this more flexible ability and also allows contributors credit most importantly.
2022-05-12 15:32:26 +01:00
C0nw0nk 88d9170a4c
Update README.md 2020-04-26 21:14:19 +01:00
C0nw0nk 1a67833f5f
Update anti_ddos_challenge.lua
WAF Features added :
Added ability to inspect URL for malicious content SQL/SQI Injections XSS attacks / exploits.
Added ability to inspect query strings and arguements for malicious content / exploits.
Added ability to inspect all Request Headers provided by the client connecting.
Added ability to inspect cookies for exploits.

Marked of the TODO list : https://github.com/C0nw0nk/Nginx-Lua-Anti-DDoS/issues/29

Added Feature to pass IP to backend in existing headers like Cloudflare and Such CDN's do https://support.cloudflare.com/hc/en-us/articles/206776727-What-is-True-Client-IP-

Added Feature to modify headers on site URL's Paths Query Strings etc the reason for this is to strip out unwanted header values that could expose the software the server runs like the "Server" header and to add in custom headers to responses like to get clients to Cache files to save server / site bandwidth and resources.
2020-04-21 22:15:22 +01:00
C0nw0nk 3418059f3a
Update anti_ddos_challenge.lua
Added to configuration of file formats that should never have Query strings on the end of the URL this will strip query strings from static files like .jpg .gif .css .js .ico etc by default since all websites never serve these static files with query strings. This will result in a higher Cache HIT Ratio and a performance gains.
2020-04-10 20:04:09 +01:00
C0nw0nk 5a3ac398b9
Update anti_ddos_challenge.lua
Added fix to stop Cloudflare from cache busting peoples websites with their captcha and javascript pages that add a pointless query string onto the end of sites urls this will remove their silly query string protecting your backends web applications and keeping your caches clean from junk like this it will also speed up your site since you will have a Higher Cache HIT ratio since they can't bypass your cache with this query string.

.com/index.php?__cf_chl_captcha_tk__=blahblahblah
.com/index.php?__cf_chl_jschl_tk__=blahblahblah
2020-04-09 21:00:03 +01:00
C0nw0nk f30e80d788
Update README.md 2020-04-06 19:15:05 +01:00
C0nw0nk ee2320e931
Update anti_ddos_challenge.lua
Added Feature : Query String Sorting I was inspired by Cloudflare to Create this since Cloudflare do this too but it is a exspensive PAID feature on Cloudflare ONLY available to Enterprise Customers at $3000 USD $3K USD minimum thats not right and its not fair! So I give it to you all for free!! I hope you enjoy it.
Query String Sort increases cache-hit rates by first sorting query strings into a consistent order.
This will treat files with the same query strings as the same file, regardless of the order of the query strings.
Example :
Un-Ordered : .com/index.html?lol=1&char=2
Ordered : .com/index.html?char=2&lol=1

Added Feature : Query String Argument Removing
To remove Query strings that bypass the cache Intentionally Facebook and Google is the biggest culprit in this. It is commonly known as Cache Busting.
Traffic to your site from facebook Posts / Shares the URL's will all contain this .com/index.html?fbclid=blah-blah-blah That will bypass your servers Cache what in turn slows your website down.

Added Feature : Query String Argument Whitelist
So this is useful for those who know what URL arguments their sites use and want to whitelist those ONLY so any other arguments provided in the URL never reach the backend or web application and are dropped from the URL. This will really make your Cache HIT Ratio go through the roof since junk arguments in the URL will be dropped.
2020-04-06 19:01:21 +01:00
C0nw0nk 38273f533f
Update anti_ddos_challenge.lua
WAF Web Application Firewall Improvement POST Data Filter : make both the values provided by connecting clients be regex patterns if need be. Allows for a wider scope of matching and stronger security over previous way i was doing it. Previously i was only matching the values for regex now you can match both keys and values for regex.
2020-04-05 21:30:20 +01:00
C0nw0nk a676eb63e6
Update anti_ddos_challenge.lua
Added Feature : WAF Web Application Firewall POST Request arguments filter to improve the security and protection of backends and server services behind my script allowing you to block and filter out unwanted POST data from HTML fields and forms to your sites. You can create regex patterns and strings to match SQL injections unwanted code etc. https://github.com/C0nw0nk/Nginx-Lua-Anti-DDoS/issues/29 Ticked of the TODO List.

Modification : User-Agent strings configuration so that they will match the Regex patterns and showing users how to escape special characters in Regex for Lua with a percentage symbol `%`
2020-04-05 19:49:16 +01:00
C0nw0nk 71a26974f5
Update anti_ddos_challenge.lua
Performance boost remove last couple of instances of `table.insert` to tick of my TODO list. https://github.com/C0nw0nk/Nginx-Lua-Anti-DDoS/issues/29

The performance gained by removing `table.insert` can be seen here. https://springrts.com/wiki/Lua_Performance#TEST_12:_Adding_Table_Items_.28table.insert_vs._.5B_.5D.29

Moved localized variables to top of script since some `os.` , `tostring` and `math.` functions operate in the script configuration section meaning they did not get the performance gains and had to do a meta table look up for the function every run this will boost performance for those too.
2020-04-01 21:08:11 +01:00
C0nw0nk d1dc01a7be
Update FUNDING.yml 2020-03-20 21:23:10 +00:00
C0nw0nk 3780ce9368
Update anti_ddos_challenge.lua
Major Performance Optimization : Prior versions are fast but when you can save miliseconds across millions of requests it really does start to add up in speed you can serve traffic at this update should have LuaJIT (Just-In-Time Compiler) maxed out running as fast as it can for this script.

localized API variables for functions to prevent lookups for names. https://springrts.com/wiki/Lua_Performance#TEST_1:_Localize

for each ipairs() and pairs() functions are slow so removed the un-needed use of them https://springrts.com/wiki/Lua_Performance#TEST_9:_for-loops

Introduced `ngx.re.gsub` to replace `string.gsub` with caching enabled for Lua performance boost `pcre_jit on;` enables regex cache for performance gains.
j = enable PCRE JIT compilation
o = compile-once mode (similar to Perl's /o modifier), to enable the worker-process-level compiled-regex cache
http://nginx.org/en/docs/ngx_core_module.html#pcre_jit

Stop using `table.insert()` to insert data into tables https://springrts.com/wiki/Lua_Performance#TEST_12:_Adding_Table_Items_.28table.insert_vs._.5B_.5D.29
2020-03-19 00:29:42 +00:00
C0nw0nk c5d2f09e81
Update README.md 2020-03-15 18:17:25 +00:00
C0nw0nk bf420a3e95
Update anti_ddos_challenge.lua
Added Feature : Authentication Box / Restricted Access / Restricted Area Fields what require a username / password.
Highly useful for protecting sensative site directories like admin control panels etc. I also gave the ability to dynamicly generate the username and password field for this and gave the option to display the username and password to the visitor of your website since I saw some Tor .onion websites doing something similar to this to protect their websites I thought I would build it in to make it easy and they would find that feature extra handy for protection.

Optimization : Moved master switch function for execution order to be compatible with features.

Added Feature : When using custom hosts to enable and disable the script on with the master switch function you can choose what sites, file paths and directories will never require authentication and what sites, file paths and directories will always require authentication

Added information in regards to a upcomming update that will allow the script to turn itself on and off if it detects an attempted attack will take away the need to manualy turn on protection for sites (something Cloudflare still has not done) if it detects timeouts / to many request / connections from the same IP's or a dramaticly flood in general or slowloris it will trigger protection on for the domain that is under attack.
```
http { #inside http block
     lua_shared_dict antiddos 10m; #Anti-DDoS shared memory zone
}
```
2020-03-15 18:16:59 +00:00
C0nw0nk 4b900ef3de
Update anti_ddos_challenge.lua
Fix : malformed URI Javascript error with escaping back slashes through Lua
2020-03-05 21:50:38 +00:00
C0nw0nk eeee46a135
Update anti_ddos_challenge.lua
Bug Fix : Fixed Memory leak issue https://github.com/C0nw0nk/Nginx-Lua-Anti-DDoS/issues/21 `anti_ddos_challenge.lua: in function 'stringrandom'`
2020-03-05 20:59:00 +00:00
C0nw0nk 9fb67fef2b
Update anti_ddos_challenge.lua
Added Feature : Support for IPv4 and IPv6 Subnet ranges so you can use ranged IP address formats in the IP blacklist and whitelist feature
Added Feature : User-Agent Blacklist
Added Feature : User-Agent Whitelist
Optimization : Removed ngx.md5 from encryption it was pointless since i encrypt data with salted hash sums so putting it into a md5 string first was a waste of time.
Cleanup : Removed unwanted / nulled out ngx.log lines and print lines from code since they are not needed was junk code.
2020-03-01 17:25:37 +00:00
C0nw0nk 86e4c672b1
Update anti_ddos_challenge.lua
Firefox throwing off Javascript errors so going to leave it as base64 encryption until i get them fixed properly.
2020-02-29 23:12:06 +00:00
C0nw0nk 88326858a2
Update anti_ddos_challenge.lua
Big Fix : 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Malformed_URI
URIError: The URI to be encoded contains invalid character (Edge)
URIError: malformed URI sequence (Firefox)
URIError: URI malformed (Chrome)

To prevent this happening on my Hex encryption of javascript "\x char" and "%" char values a soloution is to use `unescape()` or `escape()` i decided to escape values.
2020-02-24 19:05:18 +00:00
C0nw0nk afa5fa796f
Update README.md 2020-02-20 23:18:51 +00:00
C0nw0nk 6fb8703c90
Update README.md 2020-02-20 23:09:38 +00:00
C0nw0nk d354eea736
Update FUNDING.yml 2020-02-20 21:30:29 +00:00
C0nw0nk 379814c399
Update anti_ddos_challenge.lua
Added Feature : Custom setting for master_switch, For those who use this script and are large server hosts or host allot of websites from their machine(s) this will allow you to setup this script in your Nginx `http {` block to run for all sites on your service then you can set it to custom hosts to protect specific websites only such as Tor websites.

For example setting `master_switch = 3` will make it so all websites / domain names you do not specify in the list will never see the authentication page while those you do specifiy in the list will be required to solve our authentication page puzzle in order to get access. Highly useful for protecting Tor services / backends on hosts with normal services running too.

This way if you host a domain like ".onion" they will be required to solve auth pages to get access while everything not specified like ".com" or specific domain names visitors will never see the auth page.
2020-02-20 17:35:16 +00:00
C0nw0nk 4417a6da16
Update anti_ddos_challenge.lua
Added Feature : Allow our randomly generated Javascript vars to be configurable and dynamic or static depending on user prefrence.

Fix bug : Tor users I forgot to check if Tor users solved our Mathematical puzzle now it checks that they have solved the puzzle before granting them access.

Fix bug : When generating random Javascript variables there was a chance for duplicate outputs / collisions with Javascript vars making Javascript not work whilst the odds for those collisions / duplicates was very very small it was something that maybe one request in a million could have been stuck with a broken javascript page so to prevent that ever happening I keep track of generated vars and prevent duplicates.
2020-02-18 19:54:23 +00:00
C0nw0nk d7a133a553
Update anti_ddos_challenge.lua
Added Feature : 
A new Javascript encryption / Obfuscation method i built to my list of others inside my function, This will take Javascript encrypt it as a base64 string, Split it up into chunks randomize those chunks then output it. Just like a deck of cards you can shuffle the stack and allow the code to run still regardless of the order the deck would come out as.

Fix : 
Added defer and async ability to my Hexdecimal encryption when I Built the encryption function originaly in development I added it to the rest and forgot that one.
2020-02-10 20:50:10 +00:00
C0nw0nk 3563ed21f0
Update anti_ddos_challenge.lua
Added Feature to detect Tor users
Added Feature to block or allow Tor users (Allowing Tor users will still require for them to go through the authentication process the same as everyone else so don't worry)
Added Feature to encrypt Tor headers making them as Dynamic as possible
Added Feature to encrypt Tor cookies making them as Dynamic as possible
Added Tor Javascript Checks

Fixed unwanted collision bug between header x_auth_header_name when encrypted it was not unique so I made it unique to avoid any clashes in the future.
2020-02-05 15:55:21 +00:00
C0nw0nk 6087320fd7
Update anti_ddos_challenge.lua
Add feature to automatically detect if website we are serving traffic for is a Tor network website via the .onion domain extension and switch our compatibility to accomadate for Tor clients.
2020-02-02 18:55:54 +00:00
C0nw0nk 515a5d9be7
Update anti_ddos_challenge.lua
Change default from Dynamic GET and POST to just POST requests with XMLHttpRequest object the reason being is to avoid unwanted conflicts with caches on proxy servers / services (Cloudflare proxy being a prime culprit of this).
2020-02-01 15:38:33 +00:00
C0nw0nk 34444a013c
Update anti_ddos_challenge.lua
Add feature to automatically get the connecting Clients IP Address without needing to manually set it in the config, I decided to make this for compatibility with every service connecting to your server. It can now work with Cloudflare, Proxies, Tor Direct connections etc simultaneously.
2020-02-01 11:56:32 +00:00
C0nw0nk 22406ba15b
Update anti_ddos_challenge.lua
Fix output for remote_addr on Authentication page in HTML, If you change the variable `local remote_addr =` in your settings / setup / config at the start of the script the output on the auth page where it should say `IP Address` would be what you set the `remote_addr` as so to fix it and ensure it stays as an IP Address not User-Agent etc I manualy set it back with logical operators.
2020-01-31 21:15:55 +00:00
C0nw0nk 113f1dacae
Update anti_ddos_challenge.lua
For services behind Cloudflares proxy service ensure our javascript runs without "Rocket Loader".

https://support.cloudflare.com/hc/en-us/articles/200169436-How-can-I-have-Rocket-Loader-ignore-specific-JavaScripts-

And for Tor users this seems to be an error they will see with it that should fix it. Making the Script elements run independently from Cloudflares script.

Request to access cookie or storage on “https://ajax.cloudflare.com/cdn-cgi/scripts/*/cloudflare-static/rocket-loader.min.js” was blocked because we are blocking all third-party storage access requests and content blocking is enabled
2020-01-31 20:13:24 +00:00
C0nw0nk 72013cc0d4
Update README.md 2020-01-27 20:01:37 +00:00
C0nw0nk e570b1ed57
Update anti_ddos_challenge.lua
Fix for Javascript refreshing the page before the browser has a chance to set the cookies in response.

Fix to stop Firefox browsers message "firefox prevented this page from automatically reloading"

Remove un-used junk code.
2020-01-27 16:53:26 +00:00
C0nw0nk 20d6640a27
Update anti_ddos_challenge.lua
Remove junk javascript code.

Change the timer text element to inform the user to refresh their page incase their browser blocks it. (Firefox is a prime culprit of this "firefox prevented this page from automatically reloading")
2020-01-26 18:46:15 +00:00
C0nw0nk 0f1fcf8fc1
Merge pull request #14 from disaster123/various_fixes_and_improvements
various improvements
2020-01-07 17:06:34 +00:00
Stefan Priebe 99d3d5fc82 remove unneeded Access-Control-Allow-Origin headers - this is never cross domain
correctly use vars expected_header_status and authentication_page_status_output
simplify and faster exit in case of ajax request
default authentication_page_status_output status to 503 otherwise google and other crawlers index this page
2020-01-07 07:45:09 +01:00
C0nw0nk c723cb4ee2
Merge pull request #13 from disaster123/fix_js_number_parsing
JavascriptPuzzleVars stopped working since 2020 as JS calcs 20200104 …
2020-01-06 08:52:12 +00:00
Stefan Priebe 30987f8b7a JavascriptPuzzleVars stopped working since 2020 as JS calcs 20200104 + 04012020 into 21253816
To fix number calculation with leading zeros:
* use parseInt
* explicit pass of a string
* define base of 10
2020-01-06 07:00:06 +01:00
C0nw0nk 43693ba2be
Update anti_ddos_challenge.lua
Reinstate variable that originaly was there but got accidently removed in last patch.
2020-01-04 12:13:35 +00:00
C0nw0nk 90397bcf35
Update anti_ddos_challenge.lua
Applied user contributed patch to fix IOS issues with cookies a big thank you to those who contributed here.

https://github.com/C0nw0nk/Nginx-Lua-Anti-DDoS/issues/11#issuecomment-569816246
2020-01-03 22:13:09 +00:00
C0nw0nk c13ec924e7
Update README.md 2019-11-18 18:50:08 +00:00
C0nw0nk defe93fdee
Update anti_ddos_challenge.lua
Add feature to allow disabling of my credits as much as credit to be recieved is nice i do understand and realise people do not want to display them on their sites hence why i made it a feature to allow you to remove them easily and swiftly. :)
2019-11-15 19:51:51 +00:00
C0nw0nk 65ab2af2c9
Update README.md 2019-11-15 19:04:29 +00:00
C0nw0nk 339890cf90
Update README.md 2019-11-15 18:55:29 +00:00
C0nw0nk 942915ae8a
Update anti_ddos_challenge.lua
Add Enable/disable script this feature allows you to turn on or off this script so you can leave this file in your nginx configuration permamently.

This way you don't have to remove `access_by_lua_file anti_ddos_challenge.lua;` to stop protecting your websites :) you can set up your nginx config and use this feature to enable or disable protection.
2019-11-15 18:32:04 +00:00
C0nw0nk 3b13adaa12
Update anti_ddos_challenge.lua
Fix typo of value "charset" with "default_charset"
2019-11-15 18:12:22 +00:00
C0nw0nk ac52cb4dff
Update anti_ddos_challenge.lua
Make charset customisable value for those who wish to translate this script into their own native languages.

https://github.com/C0nw0nk/Nginx-Lua-Anti-DDoS/issues/8
2019-11-15 18:09:55 +00:00
C0nw0nk 1584f1ff34
Update README.md 2019-11-14 16:14:31 +00:00
C0nw0nk 4e5060ef41
Update anti_ddos_challenge.lua
Update to fix hex encode in Javascript encryption so that it no longer requires Nginx Lua's ngx_devel_kit
2019-11-12 21:48:59 +00:00