Forum Moderators: phranque
In the last few weeks I've noticed a new kind of spamming taking place... rather than 'referer spam' - the spam url is in the page requests. I'm getting dozens of these a day - they are hitting my phpbb forum as well as a cgi download script. Here's a couple examples:
/forum/viewforum.php?f=http%3A%2F%2Fwww.spammer.co.uk%2Fforum%2Flovuqo%2Fzil%2F
Http Code: 200 Date: Feb 04 04:53:48 Http Version: HTTP/1.0 Size in Bytes: 5967
Referer: -
Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)
/cgi-bin/sample/download_script.pl?http%3A%2F%2Fwww.spammer.com%2Fadmin%2Fcorreo%2Fenaq%2Fecib%2F
Http Code: 200 Date: Feb 04 07:04:32 Http Version: HTTP/1.0 Size in Bytes: 1175
Referer: -
Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)
These page requests are resulting in Not Found errors and they are leaving dozens of spam urls each visit - I've been looking for a way to block them and havent' yet succeeded.
I tried this and it isn't working for me (still getting the Not Found error rather than Forbidden):
RewriteCond %{QUERY_STRING} ^.+http:
RewriteRule .* - [L,F]
Any advice on how to block these?
RewriteCond %{QUERY_STRING} https?:
RewriteRule .* - [F]
I've seen a ton of these as well recently, all "attacking" script-type-URLs -- And all 403'ed on my servers. :)
Jim
[edited by: jdMorgan at 12:54 am (utc) on Feb. 5, 2008]
Alternately, modify the scripts to specify what they will *accept* -- Do not implement security checking based on what should be *rejected* as this leaves potentially-gaping security holes. It is much easier to predict and enumerate what should be accepted instead.
Jim
I'm no .htaccess expert(!) does the snipit of code pasted here work?
Thanks.
You may want to have code that checks for each of these methods.
Jim
i.e. The tracking (AXS) I use for my outgoing links is being attacked with spammers URLs being added - not from the 'referrer'.
It looks like lots of others are also seeing the same attack. The URLs change but searching on this one snippet %2Fadmin%2Fcorreo%2Fenaq% in Google shows many messed up logs and some discussion - including this thread. This is just one example there are lots more similar things going on.
The link ends up as a 404 so doesn't seem to accomplish much? As I mentioned I'm no .htaccess expert (but I'm good as copy & paste!) :)
Would the .htaccess code mentioned here help? Turn the 404 to forbidden, or any way to only allow my outgoing links to be followed?
Thanks in advance for any suggestions.
That doesn't mean anything to those of us unfamiliar with AXS. You might consider showing an example.com URL with and without the spammer-added string, in the interest of clarity.
> The link ends up as a 404 so doesn't seem to accomplish much?
If the spammer's goal is simply to leave a link in as many log files as possible, then they don't care what the server response code is. Once the link is dropped into your log file, they are happy.
This is because there are many hosting companies and Webmasters who foolishly allow log files and server stats to be publicly-accessible (without any password protection) and therefore crawlable by the search engines. Because of this, there's a fairly big industry growing up around log-spamming for hire, to get inbound links to low-quality Web sites.
If everyone would password-protect their log and stats files, this problem would simply go away.
Jim
[edited by: jdMorgan at 3:03 pm (utc) on Mar. 7, 2008]
This is the simple code:
<a href="/cgi-bin/axs/ax.pl?http://www.myoutgoinglink.com">
Don't worry my logs aren't available to search engines or the public!
The good thing is that after a day or so of 'attacks' the providers or zombie PCs seem to get closed down (or they move on) before coming back a few weeks later.
I can find lots of this going on (as some people leave their logs open) so I can see it's quite a wide spread problem - I was just looking for some help/tips...
If things get out of control I'll stop tracking out-going links but that would be a shame as it's useful stats.
This is the simple code:
<a href="/cgi-bin/axs/ax.pl?http://www.myoutgoinglink.com">
So the spammer link would be like this?
<a href="/cgi-bin/axs/ax.pl?http://www.[b]spammy[/b]-outgoinglink.com">
In this case, it's a bit hard to "grab hold of" something you can use to determine whether the outgoing link is spammy or legitimate. If your list of outgoing links is short, then you can compare the outgoing link to those that you expect, and reject those that are spammy.
Alternately, there may be something about the spammy domains that you can use; for example, if they contain a certain group of keywords, for example, "casino," "poker," or "credit."
For the first case, something like this should work:
RewriteCond %{QUERY_STRING} !^http://allowed-outgoing-link1
RewriteCond %{QUERY_STRING} !^http://allowed-outgoing-link2
RewriteCond %{QUERY_STRING} !^http://allowed-outgoing-link3
RewriteRule ^cgi-bin/axs/ax\.pl$ http://www.example.com/cgi-bin/axs/ax.[b]pl?[/b] [R=301,L]
RewriteCond %{QUERY_STRING} ^http://.*(casino¦poker¦credit)
RewriteRule ^cgi-bin/axs/ax\.pl$ http://www.example.com/cgi-bin/axs/ax.[b]pl?[/b] [R=301,L]
Replace the broken pipe "¦" characters above with solid pipes before use; Posting on this forum modifies the pipe characters.
Jim
Sorry for the 'half' reply - I didn't see that.
http://www.bbc.co.uk/weather/5day.shtml?id=http%3A%2F%2Fwww.spammmmy.com%2Far%2Farticles%2Fjed%2Fumut%2F&links
Above is a spam version - they've used one of my links to the BBC weather, hope that's not too specific for WebmasterWorld... ;)
Where you say: In either case, the RewriteRule removes the "bad" query string.
What will the change actually do? Stop the attack adding the link or change 404?
Thanks again.
[edited by: jdMorgan at 5:27 pm (utc) on Mar. 8, 2008]
[edit reason] de-linked for the BBC's sake. [/edit]
I've found that all the dodgy links are formatted with: http%3A%2Fwww
Can I somehow use your second example to pick these rather than using the poker keywords?
Sorry to be so dim and thanks again :)
RewriteCond %{QUERY_STRING} ^http%3A%2Fwww.*
(RewriteRule ^cgi-bin/axs/ax\.pl$ http://www.example.com/cgi-bin/axs/ax.pl? [R=301,L]
[edited by: Badger37 at 3:10 pm (utc) on Mar. 16, 2008]
The external links all seem to work so I can't have completely trashed things :)
I would appreciate it if anyone can tell me if it's a valid entry when they have a minute.
RewriteCond %{QUERY_STRING} ^http%3A%2Fwww.*
RewriteRule ^cgi-bin/axs/ax\.pl$ http://www.example.com/cgi-bin/axs/ax.pl? [R=301,L]
RewriteCond %{QUERY_STRING} http\%3A(\%2F)+www\.
RewriteRule ^cgi-bin/axs/ax\.pl$ http://www.example.com/cgi-bin/axs/ax.pl? [R=301,L]
RewriteCond %{QUERY_STRING} http:/+www\.
Jim
[edit] Corrections as noted below. [/edit]
[edited by: jdMorgan at 7:41 pm (utc) on Mar. 23, 2008]
Blocking any request with the HTTP:// in the QUERY_STRING will most likely save your bacon if you have any open source software installed like WordPress as this is how they upload their scripts to the server when they find a vulnerability.
Looking at the attacks, not all hijacked URLs have ID= in them. But they do all seem to have http%3A%2F%2Fwww either at the start of the address of tagged on to the back of a real out-going link.
I've updated my .htaccess to be like this:
RewriteCond %{QUERY_STRING} =http\%3A(\%2F)+www\.
RewriteRule ^cgi-bin/axs/ax\.pl$ http://www.example.com/cgi-bin/axs/ax.pl? [R=301,L]
Now when I follow a hijacked link in my logs I get a 404 from my site :)
But for the links that have the spammy link tacked on behind a real link (which is the majority) this doesn't have any affect and following the link would still take you the real site with the rubbish at the end on the URL.
NB. I tried your other expample:
RewriteCond %{QUERY_STRING} =http:/+www\.
But this also seemed to only catch the first type of URL.
As 'we' appear to be half way there now if there some syntax that will catch http%3A%2F%2Fwww wherever it is in the address?
Thanks again for all the advice given in this thread!
[edited by: Badger37 at 10:44 am (utc) on Mar. 17, 2008]
Why? This isn't really the desired function (see previous posts). You should be getting a 301-redirect to http://www.example.com/cgi-bin/axs/ax.pl (which I presumed was a valid URI.
> catch http%3A%2F%2Fwww wherever it is in the address
Something like:
# BLOCK attempts to use our server as a proxy, but allow valid absolute URIs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /?http:// [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /?http://([^.]+\.)*example\.com(:80¦443)?/ [NC]
RewriteRule .* - [F]
#
# Block URL injection attempts in request URL-path
RewriteCond $1 http\%3A(\%2F)+ [OR]
# Block URL injection attempts in query string
RewriteCond %{QUERY_STRING} http\%3A(\%2F)+
RewriteRule (.*) - [F]
Jim
[edit] Corrections as noted below. [/edit]
[edited by: jdMorgan at 7:42 pm (utc) on Mar. 23, 2008]
Using your latest code produces a 404 on my site if the injected address starts with 'http%3A%2F%2Fwww'
http ://www.mysite.com/cgi-bin/axs/http%3A%2F%2Fwww.spammysite.com%2Fblog%2Fwp-content%2Fthemes%2Fsquares%2Forelura%2Fwageno%2F
Or if the injected address is added to the real out-going URL:
http ://www.real-outgoing-link.com/?from=http%3A%2F%2Fwww.spammysite.de%2Fcontent_system%2Fola%2Fitil%2F&to=LBG&action=search
Any ideas?
As I mentioned I'm no expert with this and the syntax means nothing to me, so I'm only following your sample code - but I do trust you :)
<EDIT> Added a space after http to stop the link!
[edited by: Badger37 at 6:57 pm (utc) on Mar. 17, 2008]
When I changed the rule to this it worked exactly as hoped:
RewriteCond %{QUERY_STRING} http
RewriteRule .* - [F]
It's stopping all requests in my php forum. However.... this rule still isn't stopping the spamming urls in my cgi script. I did some studying and found that sometimes you have to put an htaccess inside the cgi-bin folder itself in order to work in there - but that wasn't the solution for me. I never did solve that half of the puzzle. The cgi download script I'm using is old... so I'm sure it's obsolete by now and lacking in security routines. So I'm looking for a new one.
Hope this information helps. Thanks once again to everyone in here!
No, but I certainly can't do this for you, since I'm likely several thousand miles away...
Please take this as cheerleading: This is your project, and you can do it.
Now what I can tell you is that the code itself produces a 403, and the only way I can think of to get a 404 out of it is if you have declared a custom 403 error page, but don't actually have one on your site. Your server error log should make this quite clear if it is in fact the problem.
Jim
Did you see my post from the 17th which shows the latest results your .htaccess suggestions produced?
"I'm assuming the only changes I need to make to your code are to the pipe symbol and the example.com address?"
"Or if the injected address is added to the real out-going URL:
http ://www.real-outgoing-link.com/?from=http%3A%2F%2Fwww.spammysite.de%2Fcontent_system%2Fola%2Fitil%2F&to=LBG&action=search"
i.e. If the spam code is 'appended' to the out-going link then the suggested .htaccess code doesn't have any affect. Most of the problems are like this.
[edited by: Badger37 at 6:44 pm (utc) on Mar. 23, 2008]