eire web design home page contact eire-web design eire web design and development site map
stepping on in business
• Monitor changes made to the .htaccess file

Monitor changes made to the .htaccess file



After what happened to “Grandad”  @ Head Rambles recently, got me thinking in finding a way to monitor any changes made to the .htaccess file.

Grandad’s .htaccess file, was injected with some malicious code, checking for the USER_AGENT, in turn redirecting “Googlebot, Slurp, msnbot” to another website.

This can be easily achieved as the server itself  updates the date & time of the file/s changed by adding a timestamp to it.
Keeping track is not that hard, once we have this value stored for later comparison.

The solution I came up with, is to create a directory where a new text file is created, which in turn will store the existing file timestamp.

With a bit of PHP coding, we can read the contents of the text file created and compare it with the existing timestamp of the file itself.
If the current timestamp is not equal to what we have stored, an ALERT email will be sent to the website administrator, who can verify the content of the file itself, making sure no malicious changes were made as per example given above.

The code can be downloaded from here >>

and please let me know if you encounter any problems….

Be Sociable, Share!
This entry was posted on Thursday, March 19th, 2009 at 10:59 am and is filed under .htaccess, PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...


  • 3 Responses to “Monitor changes made to the .htaccess file”

WillKnott.ie » Blog Archive » Hacked Says:
May 8th, 2009 at 3:29 pm

[...] I’m going to be keeping an eye on things [...]

Conor H Says:
May 18th, 2009 at 9:53 am

Hi, This is an interesting tool..

I have thought up many ideas that require the script to be ran every so often..

Do you set a cron job to do this for you say, once every hour or so??

Thanks.

Louie @ Eire Web Design Says:
May 18th, 2009 at 9:59 am

No.
On each page load, the code will check and compare the date from the stored file to the last modified date on the server and if not the same an email will be sent to the administrator – value stored in $ewd_email variable.

  • Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Links...

Chicklets...
  • http://www.eire-webdesign.ie/blog/feed/
    http://www.eire-webdesign.ie/blog/feed/
    Google Reader or Homepage
    Add to My Yahoo!
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    add to msn
    Add to My AOL
    Add to Technorati Favorites!
    pageflakes
    windows live