Prevent SQL Injection with iptables

ldvhai
ldvhai used Ask the Experts™
on
Hi Experts.

I'm setting up iptables for a system so I want to ask if there is any rule/module that can prevent SQL Injection on iptables.

Thanks for reading this.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

Commented:
Usually iptables has to use snort or something like that to detect signatures.

to prevent SQL injection, your code is a far better mechanism to address that.

i.e. make sure you are not passing form data directly to the sql server.

Check if there are articles on this issue at EE.
Exec Consultant
Distinguished Expert 2018
Commented:
You may be interested in this test out stated in paper2-ICMSC2011S008.pdf
after combining the rules, number
of the rules to be put into IPTABLES conclusively became 9 as presented below.
 
iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27+or+%271%27%3d%271” --algo bm -j DROP

iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27+or+1%3d1” --algo bm -j DROP

iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27+or+%271%27%3d%271” --algo bm -j DROP

iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27)+or+%27%27%3d%27” --algo bm -j DROP

iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27)+or+1%3d1” --algo bm -j DROP

iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27)+or+%271%27%3d%271” --algo bm -j DROP

iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27)+or+(%27%27%3d%27” --algo bm -j DROP

iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27)+or+(1%3d1” --algo bm -j DROP

iptables -I FORWARD -s 0.0.0.0/0 -m string --string “%27)+or+(%271%27%3d%271” --algo bm -j DROP

These mentioned rules were able to protect the websites from all of 23 SQL Injection Attacks listed on
the website: http://www.governmentsecurity.org. In conclusion, when excluding new forms of web attack, it could be resolved that the protection system, designed by the researchers’ team, was able to effectively
protect the website from SQL Injection Attack.
The “%27or%271%27%3D%271” was an encoding. When decoding the URL, it would result as a
message ' or '1'='1.

The abovementioned rule was able to block SQL Injection Attack by detecting the strings (packet) that matched the security requirement. When the packet that matched the defined string was found,
that packet would be immediately dropout.
Distinguished Expert 2017

Commented:
The above deals with aURL encoded (GET request)
A post request could still go through.

Best to safeguard your system, is to make sure the code in use is not suseptible to SQL injection.
btanExec Consultant
Distinguished Expert 2018

Commented:
agree secure coding and OWASP has good reference on it. Build different layer of defence starting from the code level into the web appl, and to the host OS (host defence like iptables), into web server (with WAF like mod sec) and at the network perimeter facing external network with WAF as it is app aware type of FW - not only SQLi but also others mentioned in OWASP like XSS etc.

Author

Commented:
Thank you for the instructions above, i'm really appreciate it.

Sincerely.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial