Main

October 16, 2010

Preventing source code in your .git directory being viewed

Adding some lines to your apache configuration file can prevent people from viewing files under your .git directory or files like .gitmodules. Depending on whether you have other files/directories which you to stop folks reading, you can easily add more similar directives.

I'm running a git clone of flamework for testing some stuff and was looking to see if the I could view files under the .git directory. So I looked to see what files exist under .git and chose HEAD and went to my browser and pulled up http://flamework.example.com/.git/HEAD and it showed the file contents. After adding the snippet above to my apache config, I was no longer able to view files under the .git directory or the .gitmodules files.

January 22, 2006

mysql_real_escape_string() vs addslashes() vs Prepared Statements

Interesting posts by Chris and Ilia on their respective blogs.

In The addslashes() Versus mysql_real_escape_string() Debate Chris starts discussing the Google XSS exploit and then goes on to explaining about character set encoding and how one particular character set allows for this exploit:

Last month, I discussed Google's XSS Vulnerability and provided an example that demonstrates it. I was hoping to highlight why character encoding consistency is important, but apparently the addslashes() versus mysql_real_escape_string() debate continues. Demonstrating Google's XSS vulnerability was pretty easy. Demonstrating an SQL injection attack that is immune to addslashes() is a bit more involved, but still pretty straightforward.

In GBK, 0xbf27 is not a valid multi-byte character, but 0xbf5c is. Interpreted as single-byte characters, 0xbf27 is 0xbf (¿) followed by 0x27 ('), and 0xbf5c is 0xbf (¿) followed by 0x5c (\).

How does this help? If I want to attempt an SQL injection attack against a MySQL database, having single quotes escaped with a backslash is a bummer. If you're using addslashes(), however, I'm in luck. All I need to do is inject something like 0xbf27, and addslashes() modifies this to become 0xbf5c27, a valid multi-byte character followed by a single quote. In other words, I can successfully inject a single quote despite your escaping. That's because 0xbf5c is considered to be a single character, not two. Oops, there goes the backslash.

Ilia then goes onto writing in his piece mysql_real_escape_string() versus Prepared Statements he goes more into detail about the exploit.

Chris has written a compelling piece about how the use of addslashes() for string escaping in MySQL queries can lead to SQL injection through the abuse of multibyte character sets. In his example he relies on addslashes() to convert an invalid multibyte sequence into a valid one, which also has an embedded ' that is not escaped. And in an ironic twist, the function intended to protect against SQL injection is used to actually trigger it.

The problem demonstrated, actually goes a bit further, which even makes the prescribed escaping mechanism, mysql_real_escape_string() prone to the same kind of issues affecting addslashes(). The main advantage of the mysql_real_escape_string() over addslashes() lies in the fact that it takes character set into account and thus is able to determine how to properly escape the data. For example, if GBK character set is being used, it will not convert an invalid multibyte sequence 0xbf27 (¿’) into 0xbf5c27 (¿\’ or in GBK a single valid multibyte character followed by a single quote). To determine the proper escaping methodology mysql_real_escape_string() needs to know the character set used, which is normally retrieved from the database connection cursor. Herein lies the “trick”.

January 21, 2006

LiveJournal XSS Issues

Heard about the LiveJournal XSS security compromise earlier this evening via Matt:

I’ve been following the Livejournal hack closely because as someone who runs many services that allow user submitted content, any new developments in XSS are very important to stay on top of. So far the only official technical explanation I’ve seen is here on lj_dev. Since we don’t allow template editing or embedded JS or styles on WP.com I can’t think of any vectors for attack, but you never know with these things. More on moz-binding

In the process of their fixes for the XSS cookie capturing issue, they've now enabled users to have username.livejournal.com for all users. Previously free users had to make do with www.livejournal.com/~username/ and www.livejournal.com/users/username/ for their LiveJournal blogs.

September 14, 2005

Using keys with SSH

Remember to replace the hash of your password with a * (disable login) when using SSH authentication with RSA keys for authentication without having to enter a password. It will save you having to go around changing your password when your password is compromised.

Another thing to remember is to use a passphrase with your private key which makes it a bit more difficult to guess by even people who know you well.

September 7, 2005

Ilia's php|architect's Guide to PHP Security

php|architect's Guide to PHP Security
Ilia has written a php|architect's Guide to PHP Security and has announced that it has been sent for publishing.

For those who don't know, Ilia is one of the leading PHP security experts in the PHP community.

Despite all the negative publicity, however, PHP is and remains a very stable--and very secure--programming environment. php|architect's Guide to PHP Security, written by security expert (and frequent php|architect contributor) Ilia Alshanetsky, provides you with a guide that covers everything you need to secure existing PHP applications and write new ones with security in mind.

July 29, 2005

Apache and OpenSSL Issues

Occassionally apache with mod_ssl just breaks after doing an operating system upgrade or even just upgrading openssl. Doing a backtrace against the httpd.core file (gdb httpd httpd.core) I got a backtrace which revealed to me the following:

(gdb) bt
#0 0x00000018 in ?? ()
#1 0x28445162 in RSA_new_method () from /lib/libcrypto.so.3
#2 0x28444eea in RSA_new () from /lib/libcrypto.so.3
#3 0x2845e7e8 in RSAPrivateKey_asn1_meth () from /lib/libcrypto.so.3
#4 0x2846a8a6 in ASN1_item_ex_new () from /lib/libcrypto.so.3
#5 0x2846a6c3 in ASN1_item_ex_new () from /lib/libcrypto.so.3
#6 0x2846621c in ASN1_item_ex_d2i () from /lib/libcrypto.so.3
#7 0x28465c85 in ASN1_item_d2i () from /lib/libcrypto.so.3
#8 0x2845e89f in d2i_RSAPublicKey () from /lib/libcrypto.so.3
#9 0x28459b2c in d2i_PublicKey () from /lib/libcrypto.so.3
#10 0x284585b5 in X509_PUBKEY_get () from /lib/libcrypto.so.3
#11 0x28457615 in X509_get_pubkey () from /lib/libcrypto.so.3
#12 0x28375749 in ssl_util_algotypeof () from /usr/local/libexec/apache/libssl.so
#13 0x2836d226 in ssl_pphrase_Handle () from /usr/local/libexec/apache/libssl.so
#14 0x28366f3f in ssl_init_Module () from /usr/local/libexec/apache/libssl.so
#15 0x08057092 in ap_init_modules ()
#16 0x0805fd83 in main ()

Basically what the backtrace gives us back informs us that there is a problem with OpenSSL. Normally the way to resolve this is to recompile apache+mod_ssl as well as php's openssl extension using portupgrade and force it to do the upgrade, and magically next time you run "apachectl startssl" it works.

July 18, 2005

XSS could make you loose your cookies!

Thomas Rutter has written an article on Sitepoint entitled Cross Site Scripting Could Make You Lose Your Cookies

Cross Site Scripting (XSS) is a form of security exploit that threatens any web application. Its severity is often underestimated. The problems go far beyond annoyances and practical jokes. By stealing your cookies, Cross Site Scripting attacks can allow attackers to gain administrative access to your CMS.

June 5, 2005

Time for an XSS Toolkit?

Ilia brings up some good points in a post on his blog entitled Do people really care about security?.

A few days ago a friend of mine sent me a URL to an online store with a product he found interesting. When I went to the site, aside from the aforementioned product I saw a nice "Hacker Safe" logo, with the date (current date) which was supposed to assure me as a consumer that this site is "safe". Clicking on this logo took me to a page of a security company specializing in "helping sites protect you (the customer) from identity theft and credit card fraud", sounds good, I feel much safer already.

Curios about the truth of the site's hacker-safe claims, I decided to do a very basic test for Cross Site Scripting (XSS) by adding a small HTML string in the place of one of the parameter values in the get query. Imagine my surprise when rather then rejecting the clearly bogus value (number was expected, but non-numeric string was supplied), my input and the HTML tags found within were displayed verbatim. This little oversight would allow anyone to inject arbitrary content to be displayed as part of the store’s front end and if it contained HTML/JavaScript have it be parsed and executed. For example it would be trivial for someone to inject some JavaScript capable of stealing the current user's session and use it for their own gain. Identity theft here we come…

There are various articles about XSS:

A XSS Toolkit would include examples of striping out tags, etc. etc. Running things like htmlspecialchars() against the text is one way of disabling the stuff. I saw an example a while back that disables the bulk of XSS attempts.

February 1, 2005

Awstats < 6.3 is vulnerable

Awstats is vulnerable. I've just basically forbidden the awstats.pl script in the interim until get the FreeBSD port upgraded to 6.3.

Russell and Jeremy both had the misfortune of getting hacked in the process. :/

More information on this exploit.

November 29, 2004

SCO Hacked!

One of the guys in the office has been yelling that SCO has been hacked! SCO has been hacked! Also our CEO came in about two minutes later telling us that SCO has been hacked. Mirror of the SCO Home Page.

www.sco.com.hacked.jpg

September 18, 2004

Securing access to your server

Kasia brings up a couple of good points in her blog entry Secure access to your server checklist.

With the recent increase of break-in attempts via ssh, here's a little checklist of making sure your server is as secure as you can make it while still being able to access it from the outside. Read more.

Under FreeBSD to lock accounts type pw lock username which puts some extra text in the password field, preventing ssh or console login using that username.

Using chsh you can change a users shell. For example to change a users shell to /sbin/nologin use chsh -s /sbin/nologin username.

If you see increasing failed login attempts in your logfiles, you can start firewalling port 22 traffic to networks where you might need SSH access from, say from your work LAN, etc.

ipfw add 400 allow tcp from x.x.x.x/24 to y.y.y.y 22 in via fxp0 setup
ipfw add 401 allow tcp from z.z.z.z/29 to y.y.y.y 22 in via fxp0 setup
ipfw add 499 deny tcp from any to any 22 in via fxp0 setup

man ipfw is your friend when working out firewall rules.

August 26, 2004

Failed password for root from ....

Jim Winstead has been mentioning problems with failed SSH Logins. I've also been noticing the increase in these failed login attempts. Quite annoying actually.

I think the version of the brutessh2.c stuff linked above is a nicer example than what I've seen via a third party discussing security a couple days ago.

Afrigator