A chisel-end hammer, cracked, near smashed to pieces by Anti-Hammer, in semi-transparent greyscale.Setup
Anti-Hammer

This page will (hopefully!) tell you everything you need to know to setup Anti-Hammer protection on your web site. It's usually straightforward.

If you need help with any aspect of the seup, I am an email away.

Quick-Start Guide:

Feedback

If you have a question, feel free to leave a comment, below. I don't expect it to get too busy; Anti-Hammer usually just works. If you think you have found a bug, please mail me about it, with full details, preferably attaching your script to thte mail. Thanks!


Welcome to the comments facility!


return to paged comments
corz - 30.10.09 5:29 pm

Hopefully this marks the beginning of a new trend; each of my "wee scripts" deserves a page of its own, with usage instructions, comments and all that. So here we are.

Have fun!

;o)


astro - 05.12.09 12:56 am

I am attempting to install this, but whenI add the php_value line to my htaccess, I get 500 errors on my site
i have set permissions for hte php file, and have verified the path info, does something need to be set in the server PHP.ini file? I would need to contact the host and ask them to set that if so.

It sounds like your server runs some kind of php suexec (where php runs as a cgi). If that's so, you would need to add the directive into a local or global php.ini file, instead of .htaccess.

The format is slightly different, see any php.ini file for specifics. This devblog entry explains the difference between regular and cgi flavours of php, and demonstrates how to add your php_value type statements with full examples. ;o)



Laurent - 14.12.09 5:23 pm

Sorry, I normally speak French,

Thank you for the valuable advice, read over your website: the more I find interesting.
I am still a child before rewriting in PHP.
May I thank you very much all your explanations!

Laurent - Geneva - Switzerland


Don - 22.12.09 5:46 pm

Your website was recommended over on the forums at phpfreaks.com and I've alreayd bookmarked a half dozen pages. Awesome stuff here!!


Miauw - 16.01.10 5:25 pm

Can't get it to work. No error is shown, it just doesn't work; I can hold refresh and nothing happens. Rechecked the paths 100 times and seems to be all correct.

Run the file directly, to check you haven't messed it up editing your prefs. You should see a nice message telling you how to install anti-hammer. ;o)



Katica - 20.01.10 10:10 am

Your site is very interesting. Tried out anti-hammer, but get the same problem as Miauw. Checked the path 100 times. I've created the folder for the log, made it writtable, no log is created. Tried to rewrite anti-hammer.php as it just output a sentence, nothing happenned, seems that auto-pretend is not working at all.
Any idea or advice? Thanks is advance.

auto_prepend_file is perhaps disabled - speak to the server admins. ;o)



Matt Lewandowsky - 30.01.10 12:28 am

This script looks interesting, but before I even think about trying it, I'm curious what its impact may be on a fancy, heavy "Web 2.0" site which can potentially have a few hundred objects on a single page. Normal users in such a case can easily end up requesting a few hundred objects every few seconds, if someone keeps clicking (for example) "Next Page" and their browser's cache is somehow broken, causing every image to be re-requested.

Also, have you tested this method with non-Apache servers, particularly those which use FastCGI PHP? I've got sites running with PHP-FPM, so I'd be curious to know if you've actually tried it with a custom per-instance php.ini.

There hasn't been any testing, akaik, on non-Apache servers; that's why I make stuff all pretty for release; so YOU can test it! I don't foresee any problems.

For pages with lots of "generated objects", so long as you setup your skip preferences correctly anti-hammer will rapidly ignore these, and requests for regular images and such aren't affected by anti-hammer, anyway.

;o)



corz - 15.03.10 3:38 am

If you can't get anti-hammer to work, and want me to help, you will need to provide more information. Lots more. Also, you will need to enable php error reporting of some kind, so you can see the what the error is. Once you know that, you may not need help.

NOTE: You need PHP5 to run anti-hammer. At least, to run it without some hacking, you will.

Matt, one of the reasons I made stuff available is so that YOU can tell ME exactly these sorts of things! I'm rarely on other servers these days.

Why not download it and check out the prefs section. You can specify which kinds of resources are affected by anti-hammer (images and such are not affected), which are ignored, and more; maybe give it a whirl on your test server.

;o)


oussamaDZ - 11.05.10 6:28 am

Thanks smiley for :D


unkown

Tweaked my own prefs in, installed and everything works fine :-)
Lately I've been pinged a BIG time with whatnots and this kills practically all of it.
I'm a VERY happy chap :-D

A question - how big the .ht_hammer can grow? Before there are some effects, that is...

Great "add-on" even to a Joomla site, I suppose it's ok to direct people here with a link (?). I'm sure quite a few people could use this one.

A HUGE thank you, mate.

Inward links from original sites are always welcome. Anti-hammer's log file has no limit, other than the space available; it doesn't mind. My site's logger has a clean-up facility which archives my logs at a particular size. If requested, I could look at putting something similar together an add-on for anti-hammer; automatic clean-up. ;o)



moogy - 16.08.10 7:24 am

If it doesn't work for you...

And your error logs don't show anything (you have enabled error logging, right?), try using php.ini rather than .htaccess and check the logs again. Also make sure the anti-hammer directory is writeable..

Only about one other person in the world visits my site regularly, but this'll keep 'em in line for sure. Thanks cor, this is awesome


proxylist.co - 31.08.10 7:16 pm

This is exactly what I'm looking for the proxylist.co proxy list site.

Many thanks!


hecker - 23.01.11 2:23 pm

I got anti-hammer to work just fine. Thanks for that! But I am uncomfortable setting permissions in the directory it is in to 777, which is the only way the code will run.

I therefore tried to put the directory above the root, but that didn't work.

Having a directory below the root that is set to 777 is risky. I wonder if there is a way to avoid this situation.

My PHP runs as DSO API.


The directory anti-hammer runs from does NOT need to be chmod 777, only the directory where the temporary anonymous sessions are kept.

ps. I'd love you to explain exactly how having a deirectory below the root set to 777 is risky. ;o)



Tim - 14.02.11 4:10 pm

Great script, but I have a slight issue with it. When the site pushes out a temporary redirect header (e.g. to proceed after submitting a form, or for example, to jump out to the admin login form), it appears to trigger immediately.

Any quick way to resolve this?

EDIT : (it just did it when submitting this comment form on your site too)

Highly unlikely! Anti-hammer only triggers at the preset levels. If you are almost at trigger point, then it is an easy thing to trigger the anti-hammer mechanism. Simply adjust the levels to suit your needs. ;o)



KKolya - 16.02.11 12:04 am

Same problem as others have reported above: php_value auto_prepend_file simply doesn't seem to work here, despite htaccess working in general.

auto_prepend_file is sometimes disabled at the server (httpd.conf) level, and there's not a lot you can do about it except ask the admins to enable it. If you explain what it is for; anti-hammer; they will probably agree; it's in their best interests. Also see my earlier posts, above. ;o)



Barry - 10.09.11 6:11 am

I think we all should donate at least $1 (more if you can)


I have been coming to this site for about a year now for the best .htaccess tutorial on the web - period. Tonight I was doing the same when I came across the anti-hammer link. I have just downloaded it, so I can only anticipate the benefits to my Easy Profit Bot Review Website,
but I already owe you a debt of gratitude for the countless hours of frustration that I did NOT have to suffer once I found your .htaccess tutorial.

I am donating $1 right now. I think everyone that sees this comment should also, more if you can spare the change!

We all know that this site is worth much, much more. Collectively, lets show our appreciation thru donation, so this site can continue to provide the priceless value that it has to me, to you and to everyone of our visitors that had an enriched user experience because of the tips and hints we found on corz.org.

I guess, what I mean is, "Thanks! Here's a hundred pennies for your thoughts!"

Thanks for your kind words. I really do wish everyone would follow your advice, for so many reasons! Good luck with your project(s)! ;o)



MadeUpName - 17.10.11 5:01 pm

My host deactivated my website multiple times due to spam bots. This script saved it! Very powerful and efficient. Thanks
Does the script allow Bing bots?

It can allow whatever bots you like, see inside ./anti-hammer/exemptions/ ;o)



CasperX - 01.11.11 5:16 pm

I have an error in my file
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at X:*****\******\anti-hammer\anti-hammer.php:1) in X:*****\******\index.php on line 2
please tell me how to fix this error? smiley for :erm:

These sorts of errors are common for new php coders. You probably have a white space somewhere it shouldn't be (maybe altering anti-hammer's preferences), or somehting like that (Google: php "headers already sent" for lots of information about this error.

You also might want to consider using output buffering (ob_start();) at the beginning of your scripts. ;o)



Mickey - 03.11.11 3:25 pm

I've gotten this to work with WordPress, but I'm having a problem getting it to work with Joomla. Does anyone know of any settings that need to be adjusted for this to work with Joomla? Any settings with the anti-hammer.php file? smiley for :roll:

I have no idea, but if you let us know the kind of error(s) you are getting, someone might.

[edit]I just installed anti-hammer at my son's Joomla site, works great.

As for yours, if something isn't working your php error log should be your fist port of call.[/edit]

;o)



Max - 14.03.12 9:30 pm

If you wanted to block the 777 from others you could just make it so only your servers ip can access the file.

That is what the .htaccess file in that directory is for.


Now as a question I have is do you have an updated ip list the one thing im scared of is this thread is somewhat old and I do not want my search engine ranking to go down because certain bots cannot access it.

Old? Seriously? smiley for :lol: You are a funny one!

At any rate, it is your responsibility to keep your own exemptions up to date. See the links provided (above). They don't change much.

Also note: good spiders will NOT hammer your site in the first place, so your "ranking" cannot be affected. Want proof? Google: Anti-Hammer.

;o)



Leo - 20.04.12 4:44 pm

Hi, Cor.

The content of your site is really amazing. It's a powerful reference.

Yesterday, I was refreshing the Anti-Hammer Test Page (https://corz.org/hammer-test.php) to test it. After some (a lot!) clicks, I received a 503 HTTP error. I thought "Dude! I broke the site! Sh*t!". But then I came back to reality and realized this could be another protection.

Using an online proxy service, I could reach your site again. But without it, I was still seeing the 503 HTTP error.

The question is: this 503 HTTP error page is an Anti-Hammer feature or another security resource you use?

Thanks in advance for the answer and thanks for sharing your rich knowledge.

Best regards,
Leo.

I'm actually working on Anti-Hammer right now, adding many new features. A 503 ("503 Service Temporarily Unavailable") response is the standard response Anti-Hammer sends when you activate its protections. The idea being, if you back off, the service will become available again. After 50 violations (configurable) the ban is permenent (well, 24 hours at corz.org. Again, configurable)

The latest version (currently running at corz.org) will also send 501 and 403 responses, depending on the kind of violation encountered. Anti-Hammer can now protect referer spam (via black & white lists as well as by direct interrogation of referring pages), deny script-kiddie and h4x0r requests, bad IPs, user agents and more.

Download coming soon. More testing and documentation still required!

;o)



Mickey - 30.05.12 5:59 am

Hi Cor,

It's Mickey again. I believe the issue I had with my Joomla site is that the root directory where all of the Joomla files were stored had an underscore "_" in the directory name. If I moved the Anti-Hammer scripts outside of that directory to it's own directory with no underscores in it's directory name, it worked fine.

Curious! I have it inside a directory with an underscore on one of my dev sites and it works fine. If you have any error output from Anti-Hammer in the old location, I'd love to see it! ;o)



Carlos Rene Rangel Salazar - 26.07.12 8:48 am

First let me tell you... I AM VERY GRATEFUL FOR YOUR SITE AND SCRIPTS! Never in my whole life I have found and individual so useful... really, thank you!

Now, my question is... in my site I have a chat bar similar to facebook that is run via javascript in all my website BUT handles the chat messages in another server making the polling OUTSIDE my page, sometimes many times per second, but itself the chat bar checks every minute for changes (mainly online/offline users check).

Will this be an issue with the hammering? If you want to know what I mean by chat (I'm a spanish speaking person so I dont know if I'm making myself clear) this is my site www.nsm.mx you can see the chat as a guest.

Anyway... thank you for everything done here!


Check the preferences - there are many ways to ignore certain files/types/directories. Your chat should be fine. ;o)



Carlos Rene Rangel Salazar - 03.08.12 7:17 am

I dunno if this info could help you, but here it goes.

I use this script in my forums... its awesome! But in the log I found that it was blocking some files that I think are common this days... the tapatalk forum app its very popular in both ios and android, and its script (mobiquo.php) was blocked SECONDS after initial load of anti-hammer.

Also, I think its blocking the Opera Turbo service... you know, the one that uses Opera servers to compress a webpage to send it again to the smartphone... because in my log I found a LOT of bannings from opera-mini.net and their IP (I think) 141.0.9.7

I already let Tapatalk in... but the info on Opera Turbo (available in desktop too) I dont know how to "interpret" it...



Carlos Rene Rangel Salazar - 03.08.12 7:11 pm

Also having problems with Opera Turbo... is there a way to use the "X-Forwarder" as explained here http://tiffanybbrown.com/2011/08/11/opera-turbo-and-ip-address-blocking/ for preventing the IP from Opera Turbo/mini to be "restricted" to a lot of my users...

Or how do i write an excemption for Opera Turbo? I cant seem to find the "range" of IP Adresses that they use... Onlye the user agent, like this

visitor: s05-12.opera-mini.net [141.0.11.26] (Opera/9.80 (Series 60; Opera Mini/6.5.29702/28.2197; U; es) Presto/2.8.119 Version/11.10)
accepts: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1

But... a lot with different IP :S I know its a proxy, but a VERY USED ONE to appear a lot of times, many peaople just use turbo witout knowing its a proxy, and Opera Kindly gives us the right IP in the X-Forwarder

Also this one is showing (and, as its from the allmighty this times facebook... It should be important)

69.171.224.0 [69.171.224.0] (facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php))

Same.... different IP now and then... this doesnt appear to be a bot either, just informing it to you (widely used service)

I'll look into it. ;o)



Ross - 12.08.12 1:19 pm

Hi,

I like your site and had bookmarked it on delicious.com. My delicious feeds appear on my website (lower right hand corner of the home page).

When I click your link it says.

Bad vibes from referring page!

Why do you have bad vibes about my page?

Because the first time an inward link came from that domain, it was from /wp-admin/, so when Anti-Hammer attempted to check the page for a real link, none was found (it could not login to your admin area). Finding no link, Anti-Hammer blacklisted the domain. I've white-listed it now. ;o)



Ross - 13.08.12 1:30 pm

That is weird. I can't imagine why it came from wp-admin, I am not using a plugin or anything for that, it's just a php script that parses the delicious RSS feed written directly into the sidebar...

anyhow thank you for following up and white-listing my website.


Marius - 15.01.13 8:59 pm

Nice script! for VPS you must to add the php_value in php.ini not in .htaccess (for me when i was trying to add to htaccess generate Internal Server Error)

Cheers


Voyager - 24.06.13 3:22 am

Hello.

Since php_value auto_prepend_file is not an option for us, i would like to ask if this script could be turned in a function(s) and called with an available "hook" that most php applications have.

thanks


I have no idea what you mean by 'hooks' (php has similar things, which you may be referring to) but sure, I'm happy to do any custom work on Anti-Hammer.

Just get in touch. ;o)



Voyager - 24.06.13 11:00 pm

Tried to run this as include in my index.php.

No errors but the blocking doesn't work well. Blocks right away in some pages (login or register for example).

That won't work.

Assuming you say you cannot run Anti-Hammer as a auto_prepend (why? you didn't say),. you could try assigning a specific file extension to files you want to run with Apache as a module, something like (in .htaccess)..

AddType application/x-httpd-php .phpx
AddType php-cgi .php


Or override regular php files in a specific directory..

AddType application/x-httpd-php .php

;o)



Voyager - 25.06.13 6:18 am

>Assuming you say you cannot run Anti-Hammer as a >auto_prepend (why? you didn't say),. you could try assigning >a specific file extension to files you want to run with >Apache as a module, something like (in .htaccess)..

>AddType application/x-httpd-php .phpx
>AddType php-cgi .php

>Or override regular php files in a specific directory..

>AddType application/x-httpd-php .php


My hoster doesnt allow it (HostGator).

I don't understand the two alternatives you say ? Could you explain a bit more ?

This reply intentionally blank! ;o)



tomato - 09.08.13 2:19 pm

Hi! thanks for your script... I installed it and uses php.ini
command...

; Automatically add files before any PHP document.
auto_prepend_file =

When I tested it with my ELGG open source software based site ... when I go to mysitenameur.com (site mentioned here is not the real site name) and hit <5> the anti-hammer workssmiley for :lol: however when I navigate to other pages on the site like.... mysitenameur.com/blog/all the anti-hammer does not work.smiley for :blank:

When I came to your site and tried your extension-less url, https://corz.org/serv/tools/anti-hammer/ and hit refresh several times, the anti hammer seams to work... any how to use anti-hammer with extension-less urls or files?

Thanks.

Mine isn't an extensionless URL, it's just a standard directory URL. Apache automatically serves index.php (or whatever is the default).

It sounds like you have more .htaccess files inside /blog/, overriding your main .htaccess. You may want to add the anti-hammer command to that file, too.

;o)



Jim S. Smith - 22.08.13 6:17 am

WOW!

Finally, I find a site with some useful scripts and great, easy-to-understand .htaccess info.

I find this especially useful in that I have my own site and domain for it. I do all of my own "webmastering", and this makes my "headaches" in web-administration a whole lot simpler!smiley for :D

After viewing the source of your Anti-Hammer code (which, by the way, is very useful and ingenious), I was thinking of integrating it with my own web-stats module I have written. I have created a PHP module for the purpose of identifying and logging unique hits to include for each website page on each day. I believe Anti-Hammer may go very well with it in that this will also allow me to better-control what legitimate hit-stats get recorded and counted.

I may also look at integrating it with my own guestbook script so as to attempt to block some of the spamming that has been going on. It is such a big shame that spamming activity has been picking up a lot over the last six months!

Great job on a very informative and useful website!smiley for :D

I will be sure to check back more often (hopefully we will not be having too many problems visiting, since I always use a privacy proxy, especially in light of today's "political atmosphere"! smiley for :eek: )

I also really liked your idea and implementation of a very creative way in controlling "hot-linking". Very good idea to use such attempts to actually promote your site!smiley for :idea: I am getting ready to set up a web-store, and THIS idea would go great with it!

- BRAVO! smiley for :Dsmiley for :Dsmiley for :D

- Jim S.




Jim S. Smith - 29.08.13 5:07 am

Just an update from one of the users of your Anti-Hammer:

It works great!!!

However, it took me a bit of conversation with one of the tech-support folks to find out that I needed to use the php.ini-directive to run Anti-Hammer, and NOT from the .htaccess file. This being because my hosting provider's server(s) do not have that version of mod_rewrite installed which would work with setting PHP environment variables from the .htaccess file.

So, I had to create a custom php.ini file for my site in order to use A-H. However, it is looking good! My hosting provider uses an "suPHP" subsystem, BTW.

I hope this little bit of "techie" wisdom will help some of those who are in the same predicament as I was! ;-)

I have also decided to alter where the "Hammer_ID" files and the "Counter" file are to be stored. I NEVER liked storing temporary and data files in the same folder or folder-tree as my executables!

Also, because the MD5 hashing algorithm has been compromised (IE: due to its limited 128-bit hash - it IS possible to have more than one input value produce the same hash) as was demonstrated in one of the advanced tech forums, I changed the code to use the SHA1 hashing algorithm. This gives a 160-bit hash signature, which means fewer possible "clashes" - IE: more likelihood of only ONE set of input data to result in ONE hash signature.

ANYWAY,

Great coding and great idea! I love it!

- Jim S.


There is an updated version which has improved documentation, amongst many other things - I'm still in two minds whether or not to release it as some kind of payware, because it's just so good! (the product of much thought and effort, of course!) - which covers the SuExec business.

Thanks for the thoughtful input! Of course you are free to alter any prefs, that's why they are there! The defaults are simply intended to make for easier installation. The new version uses a completely different structure, anyway. Besides, storing data files inside your web root is fine, so long as your permissions are setup correctly. SuExec systems are great, but never forget that now all your files are writable by the server process, not just ones we specify!

By the way, SHA1 is overkill in this situation. MD5 is simply used as a handy way to store the signature of a bunch of concatenated data, a sort of container. If you think about it, collisions would actually be a good thing. CRC16 would provide better protection!

;o)



tom - 16.09.13 12:43 am

Hi! Thanks for your input... I was able to make a plugin from your application for Elgg Software and the plugin.

If you have time you can check it at...

http://community.elgg.org/plugins/1488356/1.8.15/elgg-hammer


Where can I find "an updated version which has improved documentation, amongst many other things" ?

Let me know if you have any question.

Thanks.


My question is, why is there no mention of me anywhere except deep inside the package? And why has the license been removed? And why is there no valid link back to corz.org on the page? And you changed the name. Really? Disappointing stuff.

Next version, payware.

;o)



tom - 16.09.13 1:17 pm

Hi, while finishing the plugin, i run into an emergency and did not finish everything the way it was supposed to be...


On the Valid Link back to corz.org, Last time I made a plugin and then left a link to an .org website, I realized that Elgg does not allow plugin developers to have back links on the html pages. Some plugin developers were embedding back links to infected sites... So, due to those reasons they decided to stop all plugin developers from embedding back links to their personal sites or any external site except Elgg plugin Download locations

On the plugin download page, I just edited the page and I have give the credit where credit is due!

Your work can change the world... And yes it has already changed the world.



Harry Betlem - 23.11.13 2:53 pm

Dear Cor, (sounds Duitch to me

I'm trying to get it running on my localhost, it isn't working.
What changes should be made?

Y.T. Harry Betlem

Unless you are specific about the error you are getting, I have no idea!
Check your logs! ;o)



Angela - 08.12.13 7:09 pm

Hi Cor,

I read here, under the "Now with Referer Spam and h4x0r Protection!"section, that we can immediately ban baddies, but I don't see anything about how to turn that on, either here or in the code. Am I just missing it? If not, could you please post how to go about adding that feature?

BTW, this is a great script. I love using it on my server. When will you be releasing the new version you mentioned above?

Thank you!
Angela

Ah yes!

Apologies! This page is a bit of a pre-empt, it escaped prior to my major site update (coming up in the next few days!). The page is unfinished, but Anti-Hammer Pro is working great. Everything here at the org has been updated and upgraded, so it's a big job!

Anti-Hammer Pro will be available /soon/.

If you urgently need a copy meantime, mail me.

for now..

;o)



Ian - 24.10.19 4:03 am

My black-list.txt gets 100% false positive, despite level 3 checking accuracy. It would be better if all listed links are initially commented out then leave it upto me if I want to approve any of them.


First, confirm that you are human by entering the code you see..

(if you find the code difficult to decipher, click it for a new one!)


gd verification image

 

Welcome to corz.org!

I'm always messing around with the back-end.. See a bug? Wait a minute and try again. Still see a bug? Mail Me!