7G Firewall
The 7G Firewall is here! 7G is now out of beta and ready for production sites. So you can benefit from the powerful protection of the latest nG Firewall (aka nG Blacklist).
The 7G Firewall offers lightweight, server-level protection against a wide range of malicious requests, bad bots, automated attacks, spam, and many other types of threats and nonsense.
7G is a lightweight (only 12KB) strong firewall that provides site security and peace of mind. Plus, 7G is open source and 100% free for everyone :)
Contents
- About 7G
- How It Works
- Features
- Requirements
- Download 7G
- License
- Disclaimer
- Deployment
- Testing & Feedback
- Notes & Infos
- Learn More..
- Show Support
- Thank You
About 7G
Two unwritten laws of the Web: 1) Nothing is 100% secure, and 2) All websites are under pretty much 24/7 constant attack. Whether it’s just nuisance traffic like spam, or serious in-your-face DDoS attack, now is the time to strengthen site security and lock things down. 7G helps with this by protecting your site against many types of bad requests and attacks. It gives your site a super strong layer of protection at the server level. So bad requests are blocked without having to load up PHP, MySQL, and everything else.
I’ve seen many times sites just getting hammered with bad traffic.. then you add nG Firewall and watch the noise drop to zero. You free up all those server resources for the good traffic.
What’s the downside? Same as with any firewall, potential false positives. Fortunately for us, 7G is the seventh generation of a firewall/blacklist that comprises over a decade of research, testing, and development. 7G integrates the best features of all previous nG Firewalls and builds upon them. So the goal for 7G is zero false positives. Hence the purpose of the “beta” version is to fine-tune the firewall rules based on larger sample size.
Bottom line: 7G is an easy-to-use, cost-effective way to secure your site against malicious HTTP activity. It helps to protect against evil exploits, ill requests, and other nefarious garbage, such as XSS attacks, code injections, cache poisoning, response splitting, dual-header exploits, and more.
How It Works
The 7G Firewall is a powerful, well-optimized set of rewrite rules that checks all URI requests against a set of carefully constructed Apache/.htaccess or Nginx directives. This happens quietly behind the scenes at the server level, which is optimal for performance because it avoids the need to load up PHP and MySQL just to block a bad request. This is one reason why securing at the server level is better than using a plugin or other PHP script.
7G improves performance by freeing up server resources.
And it’s super-easy to add 7G to your site. Just add the code to your site’s root .htaccess file and then sit back and relax while 7G works its magic. That’s the beauty of it: there is no configuration required. Security via simplicity: add the code and done. For more details, check out the Deployment section below.
Once implemented, 7G scans every HTTP request made to your site. It compares key aspects of each request against a carefully formulated set of patterns and regular expressions (regex). So if someone or something triggers a match, they immediately are blocked silently behind the scenes (via 403 Forbidden response). So legitimate visitors can continue to surf your site with total confidence, while the bad guys are getting stomped by 7G.
Features
7G is a strong firewall that is lightweight and super fast. It strives for the optimal balance between security and performance, delivering significantly better protection than previous nG. Each iteration of nG builds upon previous versions, fortifying successful patterns, removing outdated patterns, and of course adding new patterns and rules based on current data. The result is a 7th-generation firewall that is cumulatively developed and extensively tested, based on code with a proven track record.
Here are some top features and goals of the 7G Firewall:
- Security via simplicity
- Extensive firewall protection
- Fine-tuned to minimize false positives
- Lightweight (only 12KB!), modular, flexible and fast
- Completely plug-&-play with no configuration required
- Improves security, reduces server load, and conserves resources
- Git/SVN friendly (does not block svn/git files et al)
- Open source, easy to use, and completely free
- 100% compatible with WordPress
- Better bad bot detection
- Built-in logging! :)
7G protects against many types of attacks and threats, including:
- Directory Traversal
- HTTP Response Splitting
- (XSS) Cross-Site Scripting
- Cache Poisoning
- Dual-Header Exploits
- SQL/PHP/Code Injection
- File Injection/Inclusion
- Null Byte Injection
- WordPress exploits such as revslider, timthumb, fckeditor, et al
- Exploits such as c99shell, phpshell, remoteview, site copier, et al
- PHP information leakage
Additionally, the 7G Firewall protects against a wide range of malicious requests, bad bots, spam, and other nonsense. Further, 7G uses Apache’s mod_rewrite, so it works on all types of HTTP request methods: GET, POST, PUT, DELETE, and all others. That means robust protection for your website.
Requirements
Here are the only requirements for 7G Firewall:
- Apache server
mod_rewrite
enabled- Access to .htaccess or config
If you are unsure about either of these requirements, ask your web host. If you are new to Apache and/or .htaccess, and want to learn more about it, I wrote an entire book on using .htaccess to secure and optimize your site. Also, here is a tutorial that explains how to create an .htaccess file on your local machine.
Download 7G Firewall
By downloading this file, you agree to the terms set forth in the License and Disclaimer. Also check out the 7G Changelog. To implement 7G, follow the steps in the Deployment section, below.
License
As mentioned previously, the 7G Firewall is entirely open source and free for all to use. The only requirement is that the following credit lines are included wherever 7G is used (note that version and date infos will vary):
# 7G FIREWALL
# @ https://perishablepress.com/7g-firewall/
Other than that, it’s all yours!
Disclaimer
The 7G Firewall is provided “as-is”, with the intention of helping people protect their sites against bad requests and other malicious activity. The code is open and free to use and modify as long as the first two credit lines remain intact. By using this code you assume all risk and responsibility for anything that happens, whether good or bad. In short, use wisely, test thoroughly, don’t sue me.
Deployment
Quick summary: add the 7G code to your site’s root .htaccess file (or Apache config file) and test thoroughly. After proper testing, you’re all set: 7G Firewall protects your site silently with minimal footprint. A completely set-it-and-forget-it firewall solution. Here are the steps to add 7G to your site:
- Agree to the terms, download, and unzip 7G
- Make a backup of your current .htaccess file
- Copy all 7G code and add to your root
.htaccess
- Save changes and upload to your server
- Test well (see next section)
Note: for best results, place 7G code before any existing mod_rewrite
rules (e.g., WordPress Permalinks).
Testing & Feedback
This version of the nG Firewall is turn-key equipped for logging via PHP. Here is a complete tutorial on how to log blocked requests via PHP. Further troubleshooting tips available on the 6G Firewall homepage.
Also, if you discover any bugs, issues, or errors, report them directly via my contact form. As always, feel free to share feedback and ask any questions in the comment section. Please do not report bugs in the comment area, thanks :)
Notes & Infos
Here are some miscellaneous notes and tips about the 7G Firewall.
- 7G is modular: each section can be removed/added as desired
- It is fine to use multiple nG firewalls, but not recommended
- 7G is designed to work flawlessly with WordPress and any other website
- Please report any strings or user agents that should not be blocked
- Always test well before going live and report any bugs or issues
- Use Contao CMS? Check out the nG Apache Firewall for Contao
- If using any sort of “thumb” plugin or script, remove the two lines that include
(thumbs?(
. One line is in User Agents and the other in Request URI. - Nice tutorial on Using 7G Firewall with OpenLiteSpeed
- If using Prestashop, remove
filemanager
from Request URI rules - Other notes will be added here..
Enable phpMyAdmin
Depending on your setup, it may be necessary to make the following changes for phpMyAdmin to work. First, remove |request
from the following line:
RewriteCond %{QUERY_STRING} (globals|mosconfig([a-z_]{1,22})|request)(=|\[) [NC,OR]
Then also remove (or comment out) this entire line:
RewriteCond %{QUERY_STRING} (_|%5f)(r|%72|%52)(e|%65|%45)(q|%71|%51)(u|%75|%55)(e|%65|%45)(s|%73|%53)(t|%74|%54)(=|\[|%[0-9A-Z]{2,}) [NC,OR]
With those changes in place, phpMyAdmin should work properly on most servers.
Enable s2Member
To enable the s2Member WordPress plugin, make the following changes. First, remove globals|
from the following line:
RewriteCond %{QUERY_STRING} (globals|mosconfig([a-z_]{1,22})|request)(=|\[) [NC,OR]
Then also remove (or comment out) this entire line:
RewriteCond %{QUERY_STRING} (g|%67|%47)(l|%6c|%4c)(o|%6f|%4f)(b|%62|%42)(a|%61|%41)(l|%6c|%4c)(s|%73|%53)(=|[|%[0-9A-Z]{0,2}) [NC,OR]
With those changes in place, s2Member should work properly.
Learn More..
To learn more about the theory and development of the 7G Firewall, check out my articles on building the 3G, 4G, 5G Blacklist, and related topics. The 6G Firewall homepage also contains lots of useful and relevant information. And if all that’s not enough, you can view all nG-related posts in the nG tag archive.
Show support
I spend countless hours developing the 7G Firewall. I share it freely and openly with the hope that it will help make the Web a safer place for everyone.
If you benefit from my work with 7G and would like to show support, consider buying one of my books, such as .htaccess made easy. You’ll get a complete guide to .htaccess, exclusive forum access, and a ton of awesome techniques for configuring, optimizing, and securing your site.
Of course, tweets, likes, links, and shares are super helpful and very much appreciated. Your generous support allows me to continue developing the 7G Firewall and other awesome resources for the community. Thank you kindly :)
Thank You
Thanks to everyone who shares feedback and helps beta test nG. Also thank you to everyone who supports Perishable Press with links and social shares. Additionally, I would like to thank the following sites for providing the free tools used during development. Please visit and bookmark these awesome resources:
- regex101.com – Online Regex Tester
- Complete Character List for UTF-8
- Megaproxy Proxy Service
- Apache Module mod_rewrite
- Apache Module mod_setenvif
- Htaccess SetEnvIf and SetEnvIfNoCase Examples
- Blocking user agents, requests & query strings
156 responses to “7G Firewall”
What are the advantages vs. disadvantages to using an .htaccess based “firewall” protection scheme such as All in One Security or 7G compared to plugins such as WordFence, Shield Security, Ninja Firewall, etc?
7G is a firewall that runs at the server level. So that means it doesn’t have to load up PHP, MySQL, and everything else when it blocks malicious requests. As others mention, there are lots of plugins that add firewall protection plus other security features. If you need just a strong firewall, 7G is better for performance because it operates at the server level. Otherwise, if you want more than just a firewall, you can use a “do-it-all” type security plugin. Also, 7G is integrated in several security plugins, and is used by web hosts like Runcloud.io, Gridpane.com and others.
Thanks for the reply. I know 7G is built into All In One Security (AIOS). Do you have any experience or knowledge about whether it would work in conjunction with something like WordFence?
Yes many sites using both. Also there is an Nginx version of 7G just fyi, more info: https://perishablepress.com/7g-firewall-nginx/
Hi Jeff,
Thanks for the 7G firewall, works great.
Can you tell me what would be the best way to make 1 IP Address an exception to all the rules?
Thanks
Hi Jeff. There are visitors coming to my site via Instabridge. They just visit the homepage. Is there any way to block them? When I check in Statcounter, I see that they visit my site with the Instabridge browser. I don’t even know what it is. Like this image: https://i.imgur.com/4JMXRhr.png
To do it, the requests need to have some common string, either in the user agent or request URI, etc. Then you can use Apache/.htaccess to redirect matching requests or simply deny them.
Hello Jeff, I’m using nginx as reserver proxy in front of apache, wondering if I need to add htaccess rules in nginx or only in apache mode?
Good question, I would ask your web host for their recommendations. They will know best about their own setup.
I am using AWS lambda to monitor uptime of my websites. Those are getting blocked. Have removed amazonaws already, but some rule still is blocking. Anybody knows what to remove to allow AWS?
What is the actual string that is blocked? I don’t think `AWS` is blocked anywhere..
I got lots of these from Singapore:)
How to stop it? I got your Pro firewall, but it stil comes every night. My blog is problya nightware for them, but how to get rid of it??
With BBQ Pro, you can add any/all of these patterns to the firewall. Reach me via the contact form at Plugin Planet (or post in the support forum), and I’ll send further information from there. Thank you.
Hi Jeff,
thank you for your great work.
I integrated the 7G Firewall into my htacess file. Nevertheless, I found that the server used could be determined during a security scan by https://pentest-tools.com/. Shouldn’t this be ruled out by “ServerSignature Off”?
I also scanned your site https://plugin-planet.com/ to check. Here, too, the server Nginx and the programming language PHP 7.4.2 could be identified.
Any ideas or is this basic information that cannot be hidden?
Best regards Oliver
Hi! Thank you for your work <3
I’ve installed the 7G firewall on some sites. On one of them, I had custom redirects into .htaccess in which the old URLs contained
.aspx
substring and I got a lot of 404 errors where someone clicked on those old URLs. I tried to drag the custom redirects above the 7G firewall but nothing changed.On another site in Joomla instead, I was unable to save the template options because I received 403 forbidden from the server when I opened the Helix framework template options. In console I read that the 403 blocked URL contained
request
substring. So I have to edit the 7G firewall in this point:in order to not block the Helix framework URLs.
Do you have any advice for me? And I was asking myself, could there be other patterns that are important for Joomla that it might be better not to block?
Thank you Jeff!
Some “food for thought”:
Some of the character-patterns which repeat among – REQUEST_URI, QUERY_STRING, etc. might be fitted to be filtered in THE_REQUEST, as then – you would only need to set up those specifically-filtered characters in ONE instance – and effectively ban them from REQUEST_URI – AND – QUERY_STRING on one line.
I know I have had some good luck shrinking a few of my .htaccess files by a few lines that way. Plus, it is at THE_REQUEST where I also force the proper structure of all requests – and limit what request-methods are allowed to be used.
I have also spent considerable time and effort in trying to clean up and keep clean any and all request URI’s – because I have had some problems where a “mis-crafted” request URI – also translated into an equally dangerous REFERER string on subsequent requests.
I also pay very close attention to the misuse of USER_AGENT strings. I have had occasion where a specially “crafted” UA string created all sorts of havoc on the successive resource requests – to include failing to load things like the stylesheets, javascripts, etc. I had to block it with this:
From a VPS standpoint: I also always CHMOD 0500 (already “owned” by “root” anyway) my /etc/apache2 folder, being that its contents are only read when Apache2 first starts up. (Another layer of server-side security.)
Anyway,
Good work on this! I would like to see what more can be done with ‘THE_REQUEST’ in future versions/revisions.
– Jim S.
Just thought to let you know,
According to the Apache2 documentation, the only way to prevent “trace” from being usable as an HTTP “verb” on your site, is to disable it from an Apache2 configuration by turning it “off” (EX: “TraceEnable Off”). This setting is not affected by htaccess-level directives.
Hello i add 7g to htaccess then wp-admin is:
403
Forbidden
Access to this resource on the server is denied!
i tried 7g in localhost its working fine
but when i tried in live site wp-admin is 403
Update i can access wp-admin few minutes ago
when i look at htaccess 7g code is gone
all edit from htacess is gone even the code i remove after i add 7g in htaccess
wordpress has time traveler? wordpress rewind my website in good state.