As most of you know a few months back my site was hacked. What many people dont know is that was actually the first of 2 times the box was hacked. The first time the box was hacked I had made the mistake of making the web files on the server writeable by the web server. Again being this server (that my blog sits on) is not used for hardly any commercial activity I was a lot less security focus then something I would call “production” ready. I implemented mod_security and some other logging tools aswell as offloaded the server logs to a different server (yea the logs were owned by the apache user also).
So basically when I got owned the person found a file on my server that was web accessible which then he could execute commands on behalf of the web user. Now because the files and log files were owned by this user he could write to them and even delete them. Lucky for me this guy just wanted to put up his Turkish political statement and try to infect his virus to people. So all he did was do a search on the box for any index.* files and copied his index file to over write them. Then he also deleted all files matching *log. So it was pretty obvious how the person did it but I was not sure what file was the hole in my system. This is the point where you have to weigh catching the hacker vs running a box that has been compromised. Since I really only have blogs and a few low traffic forums running on this box I thought it would be a good chance to see what was vulnerable.
So I installed mod_security and ran it pretty hardcore. Over the next couple weeks I learned more about adjusting its rulesets to allow possibly exploitable code but log it. Nothing happened for many weeks then one morning I got a page that my box was not responding. I quickly attached to my remote server via its DRAC card (Dell Remote Access). The DRAC card lets me take control of the server as if I was sitting right infront of it. I could see the box was sitting in a “kernel panic” mode and that it had crashed. I rebooted the box remotely but kept most services down so I could investigate what had happened.
Sure enough I figured out that the hacker had been back and downloaded some files to the /tmp directory (which was world writeable). Only this time I had changed ownership of all index.* files so they could not write to them. I guess they realized that in order to take over my web server he was going to need to be a bit more aggressive so he downloaded a rootkit to my tmp directory then tried to run it but fortunately for me that made the kernel panic and the server was in a frozen crashed state.
I was able to figure this out and also exactly what file they used to execute commands on my box very quickly because it was pretty much the last thing in the weblogs before the box crashed. (yay!)
So now here is where it gets interesting…. Now that I had figured out how the person was hacking into my box I was curious how in the hell the person found the file. It was in a subdirectory that I had not used in YEARS. There was no link to it from anywhere on my site. The directory structure it was in was like … html/oldforums/oldstuff/badfile.php . How in the hell did this person find this file? Well after going through the logs greping for the ip range that hacked my box I found that the person found my site from Google! Specifically using Google code search. Now while this was interesting it still did not explain how the page was even indexed…. ohh wait I use Google Sitemaps and I had it on to index everything (the default setting) OUPS!!
Now to be honest… this is my fault. I in no way blame Google what so ever. I had old exploitable code on my server and I told sitemaps to index it so… my fault.
I have since been working with the sitemaps team and I had some suggestions to leave some files off by default (like .inc .func) or only allow common web files with extensions like .php .html .asp etc… I hope they do this cause as sitemaps gets more popular its only going to expose more idiot webmasters like me that run with the default settings.
Ok so just for shits I thought I would do some querys on Google Code Search to see what kind of exploits I could find. Now keep in mind this probably will not show your site but it will show code and versions that you might be running… so once someone locates a exploitable version of code they then could just search for “Powered By X” or whatever fingerprint you could put on the exploitable program/version.
Hmm I wonder If we could find some xss exploits…
lang:php (ECHO|PRINT) .*\$_(GET|POST|COOKIE|REQUEST|FILES)
100,000+ results
How About some SQL Injection exploits?
lang:php query\(.*\$_(GET|POST|COOKIE|REQUEST|FILES).*\)
3000 results
hrmm I wonder how easy it is to find host,user,pass for mysql databases…. Lets try:
100 results found.
This query might be a little puzzling for those that are not Google ninjas like me so.. I will explain. Basically we are checking for anything that ends in .php extension. Then we search the file for mysql_connect. If it contains Mysql we look for the pattern of a connection string. lastly we use the minus sign to get rid of all localhost databases (cause we cant access them).
So did we find anything interesting? Well…
Lets just look at the first 10 results:
www.ubio.org/downloads/XID.TAR.gz - Unknown License - PHP
connect.php$connection = mysql_connect(”RANSOM”,”GlobalWebUser”,”goober8″) or die(”Couldn’t connect.”);
$db_name = “dwf”;
Now in this case RANSOM is probably a local box…
ohh whats this:
$f = mysql_connect(”zeus.mbl.edu”,”tns”,”");
if (empty($limit)) $limit=50;
hrmm intersting….
more?
$db=mysql_connect(”62.149.150.11″,”Sql43254″,”M9dKTz3M”);
$selezione=mysql_select_db(”Sql43254_4″, $db);
I can post tons of other examples but I think I have made my point. Watch your logs for people coming from google code search and always make sure your running the latest version of your software.
Also keep in mind my searchers were only looking for .php files. This is a small percentage of all the different languages and filetypes out there.
Be scared. Be very scared.
Wow shoe those are some serious google querys. Great post!
serious? no I think he was joking. isnt today april fools?
Great information. Sorry to hear about what happened
Great post man - there’s a group that’s been doin’ somethin’ similar to those queries for quite a while:
Googledorks
I often use it as an example of how to craft queries for link development - it’s amazing how creative you can get when you find a specific type of information you are looking for. I am surprised that G doesn’t proactively try to block some of this type of stuff though.
I’m now so very scared…..
Actually though, how does Google get it’s code in the “code search”? I know it can’t spider running PHP pages (obviously they’ll get parsed by the server before being outputted) so where does the info come from?
Possible fix:
Google cannot “see” your source code unless your web server spits it back as plain-text instead of executing the code.
Make sure your Apache file has handlers for all common extensions you use (.php, .inc, .pl, .cgi etc)
AddHandler cgi-script .cgi
SetHandler perl-script
etc.
Great post!
Does Google code have a separate bot that collects this information and if so, how can we block it with the robots.txt file?
Most of these are open source projects, or open code repositories. Its rarely if ever going to be private site code, unless you have it publicly accessible and non-executable somewhere.
Uh. Thats not a fix. As stated above, these are all open code repositories, not private site’s code being extracted or spidered.
google fixed this - you can’t see passwords anymore
be not scared. if you are dumb enough and have an unsecured open db port, I am sorry, thats all your fault. If I have to open a port from a db server for a web server, then only this web server can access this box.
furthermore any configuration data should be stored at a place or in a way that, through apache settings, only the box itself can read the file and it gets denied by any outside.
basic easy rules.
Cool stuff! Don’t feel bad, at least it was old code that got hacked and not new code!
But anyways, for people wondering how google gets it’s source code, it can unzip ZIP, RAR, and other files that could be packaged on your webserver, and those aren’t parsed by your server because they’re just contents of another file.
usually you can see were it got the data from, and it will list all the files in the data source.
personally, i dont even understand the point of this post at all, what is the golden rule of security?
security through obsecurity is no security at all.
regardless of who linked to your .php file or how they found it, if you have vulnerable code living on a public website accessible to the entire internet, what difference does it make where the vulnerable file is in the tree?
sooner or later is it going to get found and if you stick vulnerable code on a public website that is by your own admission “YEARS” old, then you deserve to get hacked and you deserve to waste umpteen weeks trying to figure out how they hacked your box.
here’s an idea, clean up after yourself, dont leave root exploitable code that is “YEARS” old just laying around your website and maybe things like this wouldnt happen?
Well, at least, the damage was not great in your case. May this serves as a reminder to all of us to always backup our files.
Holy cow. Not that I think anything is vulnerable, but this post makes me think I’m going to spend the first part of my day when I get back to work verifying our public machines security.
so basically the point of this post is “i’m stupid, and so are lots of other people.” thanks for that, really.
[...] I quote: (Original article) As most of you know a few months back my site was hacked. What many people dont know is that was actually the first of 2 times the box was hacked. The first time the box was hacked I had made the mistake of making the web files on the server writeable by the web server. Again being this server (that my blog sits on) is not used for hardly any commercial activity I was a lot less security focus then something I would call “production� ready. I implemented mod_security and some other logging tools aswell as offloaded the server logs to a different server (yea the logs were owned by the apache user also). [...]
The “hacker search” is nothing new just more advanced with the google code search. People have been doing the “Powered By X” query to many diff. search engines locating old/bad/unsafe versions of files for MANY years.
This is why people suggest changing .php to .html and to use robots.txt to disallow and why removing the Powered By is a very safe thing to do. These things don’t guarantee an attack they just make it a hell of a lot harder for automated hacker script0rs to take your site down.
[...] read more | digg story [...]
Can you please post some links or websites that talk about more google searching techinques.
Danke
[...] read more | digg story [...]
Shoe, when you get a minute of freetime, check out all of the Digg comments on this post. They are absolutely hilarious (and completely focused on the word pwn for the most part)!
thats what happens when you host your sites on a windows server..
How Hackers Are Using Google To Pwn Your Site…
How Hackers Are Using Google To Pwn Your Site posted at IndianPad.com…
[...] Google Code Search helps hackers find vulnerabilities in software platforms, and it helps them exploit PC and servers, according to ShoeMoney.com. Altrough the author doesn’t seem to be willing to blame Google, I will. The article shows some examples on how to find exploits on Google. [...]
I reccomend you read over this post and correct the areas you repeat yourself. It will make you seem more professional.
the hacker managed to find an exploit in an old version of some open source software that you were using? Like wordpress’s pre v2 xmlrpc exploit? ok.
[...] How Hackers Are Using Google To Pwn Your Site [...]
I’m not impressed. Code search is irrelevant. If you do find some passwords that way, you may be sure the box is attacked before…
[...] How Hackers Are Using Google To Pwn Your Site [...]
[...] read more | digg story Filed under: Uncategorized | Tags: . [...]
Shoe - great post. It’s no surprise that Google Code Search continues to show vulnerabilities. A lot of people responding here with the negative comments come from Digg and think that they aren’t susceptible. I’d laugh in their faces when they, too, are pwn3d. Thanks for the wake-up call.
Tamar,
I agree with you. These haters showing up can blow it out their asses with their negativity. I appreciate Shoe highlighting areas of potential security breeches for non-technical folks like myself. Great post, Shoe.
Anthony
[...] read more | digg story [...]
[...] From ShoeMoney.com: As most of you know a few months back my site was hacked. What many people dont know is that was actually the first of 2 times the box was hacked. […] Well after going through the logs greping for the ip range that hacked my box I found that the person found my site from Google! Specifically using Google code search. Now while this was interesting it still did not explain how the page was even indexed…. ohh wait I use Google Sitemaps and I had it on to index everything (the default setting) OUPS!! […] [...]
[...] Additionally this post describes how hackers can use Google code search and a simple sitemap to gain access to your system. [...]
[...] I came across this article which is interesting stuff for site owners. It shows you how hackers can use Google queries, especially on Google’s code search, to find weaknesses in your code. Check it out and try some of the queries too. You’ll be amazed how easy it is to find security holes! Related articles you might like: Google Website OptimizerGoogle released a tool called Website Optimizer. If website traffic heat maps like CrazyEg…Four advantages of the Google webmaster toolsAre you using the Google Webmaster Tools yet? If you don’t, this articles show you the fou… [...]
Great post! Very interesting!
[...] Google is Your Friend? [...]
[...] - How Hackers Are Using Google To Pwn Your Site [...]
Damn Shoe, another front page Digg! Nice work.
看黑客如何利用google挖掘您的站点…
看到一篇分æž?黑客用google挖掘站点关键数æ?®å¹¶æŠŠæ‚¨çš„ç«™ç‚¹é»‘æŽ‰çš„é—®ç« ï¼Œå†™å¾—å¾ˆä¸?错,æ¤å¤„引用其观点介ç»?下,呵呵ï¼?说ä¸?定您的站点也æ£å¤„äºŽè¿™æ ·çš„å?±é™©ä¹‹ä¸å“¦ï¼?åŽŸæ–‡æ ‡é¢˜ …
Hmmm, just want to add my thoughts on this… a lot of people used to use included files in PHP have the .inc extension, but when this is found and displayed and no mime type is associated with it, it will display like a text file and actual PHP code can be seen as the PHP source. So if you have mysql_connect details for instance, it can be seen.
So many people have been using .inc.php as an extension.
What I have been doing was all my include files are outside the public_html (or www) folder so my include files are not public. I am not sure if this is the best way to do it, but so far everything works for me.
[...] How Hackers Are Using Google To Pwn Your Site : Its wild how easy Google has made it to find hackable code and websites [...]
[...] Ich bin gerade durch digg über einen Erfahrungsbericht gestolpert, in dem von einem erfolgreichen Hack-Angriff auf die Webseite des Verfassers gesprochen wird. Schließlich hat er nach einem ersten Angriff den Server besser abgesichert, trotzdem kam ein zweiter Angreifer über das “tmp”-Verzeichnis rein, zu seinem Glück stürzte dann der Server ab (warum, steht da alles). [...]
at least you didn’t get your pants taken by the hax0r
hmm..thanks for the info! glad u got back up and running.
[...] (from http://www.shoemoney.com/2006/12/26/how-hackers-are-using-google-to-pwn-your-site/) Comments » [...]
[...] story No Comments so far Leave a comment RSS feed for comments on this post. TrackBack URI Leave a comment Line and paragraph breaks automatic, e-mail address never displayed, HTMLallowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> [...]
I’m glad that you can solve the problem. My two boxes were hacked by someone and I found that issue by watching my AdSense earnings. It seems the hacker can modify my file on-the-fly and insert his adsense publisher code when I was sleeping and changed it back when I get up. I can still couldn’t find how can he know my password because the logs are gone.
Interesting. I guess searching for known exploits available can be pretty entertaining and efficient, thanks to Google (who continuse to deliver quality to their users). However, does not stopping this is good? I always thought that not doing anything to prevent a crime is a crime.
But anyway, I don’t think the code search is that popular with the web development community, because few know it exists. And then, what would they search for? Why not just find a piece of code, copy and use it in your own app? Copyrights? Forget it.
So hoping that code search would be used for ‘educational purposes only’ is a naive idea at best.
[...] How Hackers Are Using Google To Pwn Your Site Veröffentlicht von del.icio.us um 06:30 Uhr Abgelegt unter Linksammlung | Trackback [...]
[...] Yesterday, Shoemoney wrote a post called “How Hackers Are Using Google To Pwn Your Site“. It is an interesting post about some issues he discovered while researching his own hacking experiences. Because it’s a good post and related to technology, it was Dugg and has received over 1550 Diggs, which kept it on the homepage for a good amount of time. [...]
Reading through these comments reminds me just how many people in the world are bitter and vindictive about other people succeeding more than themselves.
I’m sorry you suck so bad, mean little people out on the Intarweb.
Great article, Shü-$.
OKAY…
I only tried about 1700 times to get my comment posted on here so I could reply to Hedge’s question. Since that DOESN’T seem to be working, and I’m going to be late for work if I keep trying, I’m going to give it one last go without attempting to employ the HTML “a” tag or BBCode “url” tag- I’m assuming Shü-$ is moderating those kinds of comments because of extensive blog spamming.
THANKS, blog spammers. You ruined it for the rest of us.
So, without further ado (assuming that this freakin comment actually POSTS)…
Sites that have information on messing around with Google:
http://johnny.ihackstuff.com/index.php?module=prodreviews
He’s Johnny. He hacks stuff.
http://douweosinga.com/projects/googlehacks
DOUWEOSINGA!!! FIVE!
http://www.oreilly.com/catalog/googlehks/
RTFM
http://www.oreilly.com/pub/ht/2
RTFM for free online
http://www.googleearthhacks.com/
Hack the Planet
http://en.wikipedia.org/wiki/Google_Hacks
Wikka-what?
http://www.google.com/help/features.html
Google Chimes In
Or, you could…
http://justfuckinggoogleit.com/
Seriously.
http://google.com/search?hl=en&q=google+hacks&btnG=Google+Search
I tried, dude. I think good ol’ Shü-$ is moderating away my comment somehow. For whatever reason, I can’t post a reply containing links here, and I need to get in the shower for my day jaerb.
I compiled a list of URLs for you. I guess you’ll just have to find ‘em on my blog. Click my nickname if you want to see a list of sites offering Google Hacks.
[...] I tried to post a reply to the recent Shü-$ blog post about how his site got haxored thanks to Google, but I guess his newly improved security measures won’t allow me to put links in a comment. Despite the fact that his blog specifically states that I can. Maybe it’s always been like that… I don’t know. [...]
How hackers are using Google to pwn your site…
Shoe Money has an interesting post about how his server got hacked via an old file in an unused subdirectory. Naturally he wondered: How in the hell did this person find this file? Well after going through the logs greping……
[...] I thought Shoemoney’s post about how his box got hacked was interesting. He basically discovered how the hacker found his site and some vulnerable code on it through Google’s Code Search, however, this was only possible due to site maps *uugh* and a poorly secured server. This method of finding vulnerable sites has been around for a while, and even has its own term. [...]
Why is everyone shocked, this is really old news, and has been going on for ages
Right. I meant if you have your own Apache server, make sure you configure it to execute .pl, .inc, .php etc files otherwise by default it will serve them back as text files exposing the vulenerability
[...] How Hackers Are Using Google To Pwn Your Site (tags: Computers Hacking Software Google Internet) [...]
[...] How safe is your site? How Hackers Are Using Google To Pwn Your Site Great article by Shoe. I had no idea that Google had a code search and that it could even display server side scripts. Just another reason to use a "config" file and call your DB stuff using variables. __________________ "Great spirits have always found violent opposition from mediocrities. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence." - Albert Einstein Domains Name HQ - domains and hosting WiiPoint.net - Gamer community for Nintendo Wii Don’t click here asshat, unless you want to make money [...]
[...] How Hackers Are Using Google To Pwn Your Site the person found my site from using Google Code search. While this was interesting it still did not explain how the page was even indexed…. ohh wait I use Google Sitemaps and I had it on to index everything (the default setting) OOPS!! [...]
[...] xmen tickets free Its wild how easy Google has made it to find hackable code and websites… xmen the tv show characters biosread more | digg story [...]
Thank goodness I have none of the popularity that seems to get you hacked!
But it’s always great to see stupid replies that make no sense.
That’s DIGGers for ya
Interesting post…more interesting is the Diggs you got lol and you KNEW it was going to cause problems didn’t ya
[...] First off, I’m sure many of you have heard about Shoemoney’s recent hacking incident, something he blogged extensively about. Apparently, some enterprising hackers found vulnerabilities on his server using Google Code Search and exploited them (for more details, Shoemoney’s write-up is quite thorough). [...]
I was just doing the usual searching myself not to check on my sites, but to check on people talking about me. Somewhere down page 18 I think, I found this page since I had a comment in it. But interesting is, the URL is not on the shoemoney.com Domain. It is:
http://securebar.secure-tunnel.com/cgi-bin/nph-freebar.cgi/110110A/http/www.shoemoney.com/2006/12/26/how-hackers-are-using-google-to-pwn-your-site/
Now looks like one of the free web proxies for anonymous browsing. But having it in the SERPs? Hmmm someone is linking to the proxy address and not to the main URL. I wonder why.
So if I have my current XML file only showing blog entries and none of the includes, etc I am fine?
You lost me right after: “I had made the mistake of making the web files on the server writeable by the web server” If you are going to write for dummies, you must get down, down, down to our level.
WoW nice post. hope this make people more aware and secure!
I am running checks on my sites right away!
theres a whole site out there called johnny i hack stuff which has some pretty cool stuff using google
[...] en aplicaciones opensource, y en cualquier web si el propietario no es muy cuidadoso. Que los hackers utilizan Google CodeSearch no es nada nuevo… pero si no sabes de que va te sorprenderá. Etiquetas en Technorati: [...]
Class post. This has definitely woke me up on being more secure.
Very good post, as above i heard they are many such hacks thru google search , i think configuring apache server and using updated scripts will keep us safe
“I had some suggestions to leave some files off by default (like .inc .func)”
I disagree with this - some people might want the files indexing. The fact is, you should NEVER EVER have code in extensions that aren’t parsed by the scripting engine - call them .inc.php or .inc.asp. Just because Google doesn’t index them won’t stop people finding them, and since most people have their connection strings (containing usernames and passwords) in /inc/common.inc it’s not hard to see why this is a bad idea
Even Microsoft distributed adovbs.inc named that way a few years back. It’s bad, don’t do it. Don’t expect Google to mop up after you - if it’s on your server it’ll be found. Fix it.
Hackers suck.
This post just make me scared.
Never been hacked before but certainly will remember the advice.
I see this is the same way people are spamming .Edu and Gov sites with sql injections thats what i read on Daven’s blog
I am just glad that your site was able to pull through. Just goes to show what jealous people will do. I agree that hackers are very dangerous nowadays on the internet. Everyone needs to keep a close eye and protect their online real estate.
It is pretty scary how people are able to use search technology to bust into somebody’s box, but it just highlights the need to be more careful when coding. Sometimes it’s easy to get a little bit lazy with a piece of code… that’s how you end up getting run. The good news is that most sites aren’t worth hacking. The bad news is you often don’t learn you have a security flaw until your site has hit big and you really can’t afford to be exposed.
Would the ‘box’ also be known as the “shoebox”?
Seriously though, that sucks. Anything you learn about security that you think we’d benefit, keep passing it along. Much appreciated.
Johhny i hackstuff has tons of information about google hacking. I use to refer to his site before, to see what are the latest exploits running around.
Great post! Very interesting!
I ike this topic. thanks for the informative post shoe.
This is scary. I got hacked a couple of years ago, and I am quite technically challenged so even though not a lot of damage was done - it still took me a good while to sort it out.
I think duplicate content is getting clamped on quite seriously - and with a timestamp Google will be able to tell which content came first . . .