Bitcoin Forum

Bitcoin => Project Development => Topic started by: jimbobway on January 03, 2013, 06:44:26 PM



Title: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: jimbobway on January 03, 2013, 06:44:26 PM
Rails seems to be a popular development language for bitcoin.  I think I've been hearing some sql injection attacks lately on some bitcoin websites but here is a story on it.  (I've been accused of being a troll here for talking negatively on rails before):

Quote
All of the current versions of the Ruby on Rails Web framework have a SQL injection vulnerability that could allow an attacker to inject code into Web applications. The vulnerability is a serious one given the widespread use of the popular framework for developing Web apps, and the maintainers of Ruby on Rails have released new versions that fixes the flaw, versions 3.2.10, 3.1.9 and 3.0.18.

https://threatpost.com/en_us/blogs/sql-injection-flaw-haunts-all-ruby-rails-versions-010313

Mod: Move this to Project Development.  I put it in the wrong forum.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: davout on January 03, 2013, 07:19:01 PM
CVE-2012-5664 for the record


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: dust on January 09, 2013, 01:08:57 AM
Bumping with another critical vulnerability. Upgrade immediately!

https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ (https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ)


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: davout on January 09, 2013, 09:52:34 AM
Bumping with another critical vulnerability. Upgrade immediately!

https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ (https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ)

This one is CVE-2013-0155

Only applications that accept XML parameters are vulnerable


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: notme on January 09, 2013, 09:58:24 AM
Don't use deprecated methods!


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: davout on January 09, 2013, 10:01:07 AM
Don't use deprecated methods!
What ?


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: notme on January 09, 2013, 10:08:39 AM
Don't use deprecated methods!
What ?

Maybe they aren't officially deprecated, but the find_by_* methods are old the old style finders.  Regardless, leaving the "secret key" in a public repo is just fail anyway.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: davout on January 09, 2013, 10:24:40 AM
Maybe they aren't officially deprecated, but the find_by_* methods are old the old style finders.
find_by_* finders are fine. Also you're mixing up the two vulnerabilities.

Regardless, leaving the "secret key" in a public repo is just fail anyway.
What are you even talking about here ?


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: notme on January 09, 2013, 01:19:02 PM
I mean the find_by vulnerability is only exploitable if you know the HMAC key for the application that should be kept secret.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: dust on January 10, 2013, 03:38:10 AM
Bumping with another critical vulnerability. Upgrade immediately!

https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ (https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ)

This one is CVE-2013-0155

Only applications that accept XML parameters are vulnerable
It is my understanding that all unpatched rails apps are potentially vulnerable, regardless of their use of XML.  One of the suggested workarounds if XML parsing was not needed was to disable it in the config.  CVE-2013-0155 is much more severe than the one in the OP (CVE-2012-5664).

Edit: Yep, serious business. (https://news.ycombinator.com/item?id=5035023)


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: davout on January 10, 2013, 09:02:52 AM
It is my understanding that all unpatched rails apps are potentially vulnerable, regardless of their use of XML.  One of the suggested workarounds if XML parsing was not needed was to disable it in the config.  CVE-2013-0155 is much more severe than the one in the OP (CVE-2012-5664).

Edit: Yep, serious business. (https://news.ycombinator.com/item?id=5035023)
Yea, pretty much all Rails apps will accept XML params by default.
Both seem quite severe and I think everyone using Rails should just religiously apply the fixes (which are trivial btw)

Apparently I made it sound like I didn't feel concerned about it, but that's not the case, Instawallet, Instawire and Bitcoin-Central were immediately patched when I received Aaron Patterson's e-mails through the Rails security mailing list (which I encourage every Rails developer around here to subscribe to).


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: molecular on January 10, 2013, 09:10:53 AM
Maybe they aren't officially deprecated, but the find_by_* methods are old the old style finders.
find_by_* finders are fine. Also you're mixing up the two vulnerabilities.

Regardless, leaving the "secret key" in a public repo is just fail anyway.
What are you even talking about here ?

Quote from: article
"The Rails session mechanism allows storing arbitrary Ruby objects, including hashes with symbol keys. Rails provides a variety of session stores, the default being the cookie store which stores session data in a cookie on the client. The cookie data is not encrypted, but is signed with an HMAC [hash-based message authentication cookie] to prevent tampering. The cookie store is fast, does not require any server-side maintenance, and is only meant for session data that do not contain sensitive information such as credit card numbers. Apps that store sensitive information in the session should use the database session store instead. Nevertheless, it turned out that 95% of all Rails apps only ever store the user authentication credentials in the session, so the cookie store was made the default," Hongli Lai of Phusion wrote in an analysis of the problem.

"So to inject arbitrary SQL, you need to tamper with the cookie, which requires the HMAC key. The HMAC key is the so-called session secret. As the name implies, it is supposed to be secret. Rails generates a random 512-bit secret upon project creation. This is why most Rails apps that are running Authlogic are not exploitable: the attacker does not know the secret. Open source Rails apps however can form a problem. Many of them come with a default session secret, but the user never customizes them, so all those instances end up using the same HMAC key, making them very easily exploitable. Of course, in this case the operator have to worry about more than just SQL injection. If the HMAC key is known then anybody can send fake credentials to the app."

how many different vulnerabilities is the article actually talking about?


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: davout on January 10, 2013, 10:08:24 AM
how many different vulnerabilities is the article actually talking about?
If someone knows the HMAC secret and you're using cookie store someone can mess with the data in it, that's a feature.
The vulnerabillity is that it could be used as a vector to exploit an SQL injection vulnerability (didn't read the details, just religiously applied the fixes).

I recommend against using cookie store anyway and switch to Redis/Memcached/ActiveRecord for storing session data.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: Mike Hearn on January 11, 2013, 03:50:05 PM
It's also possible to run arbitrary Ruby (and thus commands) on the server, take a look at the metasploit module, thanks to the YAML integration.

It's really very serious and leads to complete compromise. It makes me wonder how long blackhats have known about that.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: BasementMiner! on January 11, 2013, 11:46:52 PM
It's also possible to run arbitrary Ruby (and thus commands) on the server, take a look at the metasploit module, thanks to the YAML integration.

It's really very serious and leads to complete compromise. It makes me wonder how long blackhats have known about that.

While this vulnerability is just as serious, its not related to the one mentioned by OP.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: kiba on January 11, 2013, 11:50:55 PM
Rails seems to be a popular development language for bitcoin.


Sir, rails is not a language. It is a framework.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: jimbobway on January 12, 2013, 03:56:31 AM
Rails seems to be a popular development language for bitcoin.


Sir, rails is not a language. It is a framework.

My mistake.  I keep on making it.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: whizter on January 12, 2013, 09:58:55 PM
This exploit is already being used, bitoins were stolen from Vircurex and Cryptostocks according to http://www.heise.de/newsticker/meldung/Diebe-stehlen-Bitcoins-per-Rails-Exploit-1782688.html


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: jimbobway on January 31, 2013, 07:09:20 PM
Another exploit: CVE-2013-0333

https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-0333

lib/active_support/json/backends/yaml.rb in Ruby on Rails 2.3.x before 2.3.16 and 3.0.x before 3.0.20 does not properly convert JSON data to YAML data for processing by a YAML parser, which allows remote attackers to execute arbitrary code, conduct SQL injection attacks, or bypass authentication via crafted data that triggers unsafe decoding, a different vulnerability than CVE-2013-0156.

Known Ruby exchanges:  bitcoin-central.net, vircurex?, coinbase


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: davout on January 31, 2013, 07:59:18 PM
Another exploit: CVE-2013-0333

https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-0333

lib/active_support/json/backends/yaml.rb in Ruby on Rails 2.3.x before 2.3.16 and 3.0.x before 3.0.20 does not properly convert JSON data to YAML data for processing by a YAML parser, which allows remote attackers to execute arbitrary code, conduct SQL injection attacks, or bypass authentication via crafted data that triggers unsafe decoding, a different vulnerability than CVE-2013-0156.

Known Ruby exchanges:  bitcoin-central.net, vircurex?, coinbase
FTR Rails 3.2.x series isn't affected.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: dust on February 01, 2013, 04:56:45 AM
Good article on HN today: http://www.kalzumeus.com/2013/01/31/what-the-rails-security-issue-means-for-your-startup/ (http://www.kalzumeus.com/2013/01/31/what-the-rails-security-issue-means-for-your-startup/)

Quote from: Patrick
The first reported compromise of a production system was in an industry which hit the trifecta of amateurs-at-the-helm, seedy-industry-by-nature, and under-constant-attack.


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: dust on February 12, 2013, 05:33:13 AM
Bumping with another rails vulnerability announced today: http://www.zweitag.de/en/blog/ruby-on-rails-vulnerable-to-mass-assignment-and-sql-injection (http://www.zweitag.de/en/blog/ruby-on-rails-vulnerable-to-mass-assignment-and-sql-injection)


Title: Re: To All Rails Developers: SQL Injection Flaw Haunts All Ruby on Rails Versions
Post by: davout on February 12, 2013, 08:58:56 AM
Bumping with another rails vulnerability announced today: http://www.zweitag.de/en/blog/ruby-on-rails-vulnerable-to-mass-assignment-and-sql-injection (http://www.zweitag.de/en/blog/ruby-on-rails-vulnerable-to-mass-assignment-and-sql-injection)
FTR it affects only older versions of Rails, if you have upgraded after the last CVE you are not affected.