Marco's SQL Injection - LFI protection

sql injecton, local file inclusion protectionMany attacks are occurring because of sites' extensions vulnerable to SQL injection or LFI (local file inclusion); this simple plugin increases the level of protection, intercepting the most common types of attack on the site..

Security of your site is not an option, and protect it is an activity that will save you a considerable amount of problems.

 

Versione Italiana: Protezione del sito da SQL injection e local file inclusion
Questo articolo, con le istruzioni in lingua italiana, è disponibile al link sopra indicato.

 

This extension is also published on http://extensions.joomla.org , if you like, it vote it or write a review, thank you.

sql injecton, local file inclusion protection

SQL Injection and Local file Inclusion Protection

This plugin adds a simple but, in most cases, fondamental protection against SQL injection and LFI (local files inclusion) attacks by checking data sent to Joomla and intercept a lot of common exploits, saving your site from hackers.

  • Filters requests in POST, GET, REQUEST. and blocks SQL injection / LFI attempts
  • Notifies you by e-mail when a alert is generated
  • Protect also from unKnown 3rd Party extensions vulnerability.
  • White list for safe components (at your risk ;) )

Enable mail report and prepare yourself to be scared!


Anyway remember that security it is a 'forma mentis', not a plugin!

Standard Set up

  • Works on Front End only:
    ignore request (auto disable plugin) when sent to /administrator
    Be sure all works fine before enable on back end too! especially if you enable IP blocking, or you will not able to access yuor site.
  • NameSpaces inspected:
    Select which superglobal arrays to inspect, options are:
    • Get
    • Get, Post
    • Request
    • Get, Post, Request
  • Ignored Extension
    comma separed list of ignored components (es: com_content, com_dumper , com_weblinks)

Important,pay attention, please!
PHP parses requests and populates the superglobal arrays by copying values into each array. So $_GET['varName'] and $_REQUEST['varName'] are not reference to the same object!
Changing $_GET to sanitize the query string is not enough if the program reads $_REQUEST.

Notification

  • Send Email Alert on injection/inclusion
    if 'Yes' send a mail alert on attack/malformed url
  • Mail to notify attack
    mail to which send alert, if blank is set to 'mailfrom'

Advanced Set up

  • Raise Error on Fault
    if 'YES' stops Joomla! and return an error (usefull for debug pourpose), if 'No' cleans up the request and passes it to Joomla!
  • Http Error Code
    HTTP error code to return (40x, 50x)
  • Http Error Message
    a message for error page

Local File Inclusion parameters

  • LFI check only on canonical
    if 'Yes' checks LFI only on model, view, controller, template parameters
  • Max number of consecutive '../'
    how many consecutive '../' can be present in the url

IP Blocking

(from version 1.1)

  • Enable temporary IP block
    Enable/Disable IP Banning
  • Seconds to hold ip banned
    How many seconds hold ip block enabled
  • Max hacks attempt
    Max hacks attempt before ip block starts

Caution: Make sure the 'Debug ' Joomla! be disabled before you enable the IP blocking.

  • make sure theJoomla! 'Debug' is disabled
  • enable IP blocking
  • reactivate the 'Debug' (if you need it, of course)

The 'Debug' Joomla! catches database errors and prevents the plugin to create the table for storing ips.

DON'T TRY ANY ATTACK after enabling 'IP blocking' and backend's protection! If you do so, you will not able to access your site for the time set in 'Seconds to hold ip banned'.

 

An useful addition

Not all hacks pass through the framework of joomla: the jce editor docet!
So you can add this code to your .htaccess file, paste it just after "RewriteEngine On" :

RewriteCond %{REQUEST_URI}  ^/images/  [NC,OR]
RewriteCond %{REQUEST_URI}  ^/media/  [NC,OR]
RewriteCond %{REQUEST_URI}  ^/logs/  [NC,OR]
RewriteCond %{REQUEST_URI}  ^/tmp/
RewriteRule .*\.(phps?|sh|pl|cgi|py)$ - [F]

This code will block all attempts to run scripts outside the joomla control. May be you have to add other paths depending on components installed.

 

IPv6 support

This plugin doesn't support ipv6, but, if you need it, you can easily implement it.

Access to db and modify the #__mi_iptable (of course change the db prefix)

ALTER TABLE `#__mi_iptable` CHANGE `ip` `ip` VARCHAR(50) NOT NULL COMMENT 'ip v4 and v6 to hex'; 

then modify the marcosinterceptor.php file, line 35:

replace:

$remoteIP = ip2long($_SERVER['REMOTE_ADDR']);

with:

$remoteIP = bin2hex(inet_pton($_SERVER['REMOTE_ADDR']));

now plugin can work on ipv6 networks.

Next release will support ipv6 natively.

 

 

Recovery of improper installation

This plugin is working on many hundred sites, but it was not tested with all the most common extensions. Please, check that most important functions of your website are running correctly.

Tested (almost) with:

.ckForms
.virtuemart
.joomfish
.PhocaDownload
.PhocaGallery
.RokDownloads
.AcyMailing
.ccnews
.AlphaRegistration
.
Chrono Contact
.SOBI2

and others.

It's never happened , but better cautious than sorry: if something goes wrong you can easily restore the site by following the instructions below.

Manually disable the plugin

Joomla 1.5!
Use phpmyadmin (or whatelse sql editor you use), select the #__plugins (#__ is usually jos_) table.
Select the record with name equal to "System - Marco's SQL Injection - LFI Interceptor": I suppose it's the last one. Edit this record and set the "published" field to "0". now plugin is disabled.

Joomla 2.5! , Joomla 3.x!
Use phpmyadmin (or whatelse sql editor you use), select the #__extensions (#_ it is a random string. see other tables prefix) table.
Select the record with name equal to "System - Marco's SQL Injection - LFI Interceptor": I suppose it's the last one. Edit this record and set the "enabled" field to "0". now plugin is disabled.

JDatabaseMySQL::query: 1146 - Table 'xxx.yyy_mi_iptable' doesn't exist

Debug was enabled when you activated IP-Blocking;

Disable plugin
see above

Disable Debug
access, via ftp, configuration.php and set

  • J1.5:
    var $debug = '0';
  • J2.5, J3.x:
    public $debug = '0';

reload the page.

Create table manually

Use phpmyadmin (or whatelse sql editor you use), select the sql tab and insert.

CREATE TABLE `#__mi_iptable` (
`ip` BIGINT NOT NULL COMMENT 'ip to long',
`firsthacktime` DATETIME NOT NULL ,
`lasthacktime` DATETIME NOT NULL ,
`hackcount` INT NOT NULL DEFAULT '1',
`autodelete` TINYINT NOT NULL DEFAULT '1',
PRIMARY KEY ( `ip` )
);
 

"#_" is the table prefix. from J2.5 it is a random string. see other tables.

Blank page after install

Typically you tried to install on PHP4, J1.5 only. no way disable the plugin and upgrade joomla.

 

 

HISTORY

Version 1.4 (Apr 28th, 2014)

  • minor code fixes (not security related)
  • default table type set by DB engine
  • table creation by sql install file

Version Apr 5th, 2013

  • .php 5.3 strict
  • minor code improvements

Version 1.2 (Mar 26th, 2013)

  • Joomla! 3.0 coding style
  • try - catch table checking
  • InnoDB table support

Version 1.1.1 (Mar 23rd, 2013)

  • Joomla! 3.0 compatibility
  • it works fine, nothing else to do ;)

Version 1.1 (Mar 10th, 2011)

  • added auto banning ip (ip blocking)
  • RegEx improvements to intercept more SQL attacks

Version 1.0 (Jan 5th, 2011)

  • Joomla! v1.6 compatibility
  • send mail also when error is raised
  • minor code optimization
  • no bug fix, so you do not need to upgrade

Version .98a (Jun 1st, 2010) Thanks to Jeff

  • fixed backtics matching
  • fixed union all matching
  • fixed ....// exploit
  • added more info to report mail

 

 

Download Marco's SQL Injection - LFI Interceptor Plugin for Joomla!

Please, keep in mind, I repeat: this plugin intercepts a lot of common exploits, not ALL!! this should be intended as an help, this is not "THE SOLUTION".

Joomla! 3.x

Joomla! 2.5

Joomla! 1.5

 


 Previous versions (compatibility versions)

(works also on Joomla! 1.6 & Joomla! 1.7, Doesn't work on Joomla! 3.0)

 

Commenti   

0 #102 Anthony 2014-11-29 07:20
Thank you for this great little plugin, you have create an effective deterant against hackers and automated SQL bot attacks. I got hit 12,000 time in two hours last week and this module helped to keep them away. Keep up the good work. :-)
Citazione
0 #101 Vin 2014-11-14 09:35
Ciao Marco, questa mattina ho ricevuto una mail dal tuo plugin che mi segnalava un tentativo di injection. Ho provato ad incollartela qui ma il tuo sistema mi blocca.
L'attacco riguarda com_hdflvplayer che sul sito non ho nemmeno. In che modo posso inoltrarti l'email? Per esperienza pensi ci siano pericoli?
Grazie, Vin
Citazione
0 #100 Antonio 2014-11-07 14:09
Salve Marco, ho installato da qualche giorno il suo componente su un sito con Joomla 3.3.6
Mi è appena arrivato un alert con questo contenuto e non capisco cosa fare:
** Local File Inclusion [GET:filename] => etc/passwd
** Local File Inclusion [REQUEST:filena me] => etc/passwd
Può cortesemente darmi qualche informazione?
Grazie
==== Answer
usually this is not dangerous. you can report it to your provider for more informations about your servers config.
Citazione
0 #99 Mark Schouten 2014-07-29 08:37
Hi,

Your IP Blocking breaks the entire site for IPv6... Please fix that, visitors get an ugly SQL error instead of the site.

Thanks,
Citazione
0 #98 juan 2014-07-25 22:02
Hello, please forget my ignorance but I could not find the way to instal or copy Interceptor to my joomla install. Seems a plugin but does not work that way. Do you have a step by step, doit yourself guide? I am going nuts tryin to understand how this is done. I need instruction for joomla 1.5.6 thank you for your help in advance
===Answer
hi juan,
this is a real joomla plugin, so install it and enable it (keep joomla debug disabled).
I'm sure it works fine on latest J1.5 versions, but, really, I don't know if it works on 1.5.6 (it should, anyway)

bye,
marco
Citazione
0 #97 Chris 2014-07-21 02:51
Marco, this is simply the most important extension to include in any Joomla installation. Thank you so much for making it, and even moreso, for continuing to support it.
Citazione
0 #96 ahmed 2014-07-16 22:08
thank you
Citazione
0 #95 Simos 2014-06-20 19:13
I dont know you, but I need to thank you personaly for providing this plugin to me (and all my clients joomla sites), and protiecting all this years, 100% successfully from many namy many "wanna be hacker" visitors!
Thank u and keep like this Marco!
Citazione
0 #94 kevin cope 2014-06-11 22:38
Hi
I just had 199 emails warning me about an injection can you tell me what they are tring to do.

I have copied it below:

*QUERY_STRING :
option=com_casino&task=category&id=-1%27+union+all+select+1,concat(0x26,0x26,0x26,0x25,0x25,0x25,username,0x3a,password,0x25,0x25,0x25,0x26,0x26,0x26),3,4,5+from+jos_users--




==== Answer
see: www.exploit-db.com/.../11237
Citazione
+2 #93 Guest 2014-01-28 20:41
Great component! It works fine.
Thank you!
Citazione

Aggiungi commento

Please note: URL in text are not linked and user's site address is only for internal use and is not published.

Comments are human checked. All spam will be removed, so don't waste your time and, especially, mine!

Codice di sicurezza
Aggiorna

L'estate si avvicina hai già trovato l'albergo per le vacanze? cerca un albergo al mare o un hotel in montagna ove trascorrere le tue vacanze.