Ruby2ßhell: Pre-authentication RCE on stock Rails (verialabs.com)

346 points by jdns 15 hours ago

cowlevel 11 hours ago

So the recent RCE wave seems to be people finding more single byte overflows and such, but reporting them as RCEs because AI can do the tedious grunt work of finding the rest of the vulnerability chain.

If any single byte overflow can be converted into an RCE with minimal human effort then we have no choice but to prove the whole software stack is memory safe.

aja12 10 hours ago

It's important to note that Java, like Rust, is generally seen as a memory safe language. But it has bits of assembly, just like Rust has unsafe blocks, to handle some operations. Hence the Java2shell recent vulnerability. Granted Rust may have less need for them and more facilities to audit them, but it is not by itself a panacea that will fix all memory issues. In essence, there is no software stack that is fully memory safe, it is more a matter of restricting the memory unsafe parts in fewer, more scrutinized, better contained sections.

pron 8 hours ago

Because safe Rust is so constrained, Rust relies on unsafe much more than Java, and their need for intrinsics is about the same (although Java lets you turn off individual intrinsics at runtime).

ekidd 8 hours ago

Thaxll 5 hours ago

empath75 2 hours ago

InsidiousWombat 7 hours ago

insanitybit 4 hours ago

ninkendo 9 hours ago

OP didn’t say anything about Rust, by the way. This post comes off as being defensive about a point nobody made.

supersimpleguy 8 hours ago

zamadatix 10 hours ago

Yeah, "memory safe" goes out the window if you prefer to implement parts in assembly. This is where portable SIMD (e.g. the Java vuln was from SIMD), which is abstracted & safe but not necessarily as performant as it could be, is becoming a more reasonable trade off.

Of course I'm not sure how much it counts to be "using a memory safe language" when you have to call put to unsafe code anyways. I.e. just because the library you'd like to use is C but the rest of your project is Rust doesn't mean you're really using a me ory safe language, it means you're sometimes using one. We have a long way to go before environments allow using memory safety fully I think.

jpardoe 5 hours ago

Is it not theoretically possible, even if it comes at the cost of performance?

GTP 8 hours ago

Yes, ultimately it is about reducing the attack surface so that we get less exploits and also more reliable software (overflows can cause sporadic crashes). Still very much worth doing it IMO, even tough it doesn't sove all problems on its own. Apply defence in depth and combine this with other mitigation techniques. This is the path if you want robust systems.

cerved 7 hours ago

You're conflating Java with the JVM but sure.

anthk 10 hours ago

Rust it's far better than Java. Since the old times Java was seen as a CVE generating machine for GNU/Linux environments.

dcminter 9 hours ago

cowlevel 9 hours ago

hunterpayne 6 hours ago

toastal 10 hours ago

I like your comment since it points out that we need to enforce the memory situation—but it doesn’t prescribe Rust is the only solution.

jjgreen 9 hours ago

Heretical

boomlinde 10 hours ago

From my understanding it's only a single byte overflow if your payload only contains a single ß.

tptacek 6 hours ago

No, from my read of the code, it's a single-byte overflow because the casing code works 1 character at a time and doesn't account for the ß->SS expansion case. Not only is it a single byte, but that single byte has a fixed value; you can't use ß->SS to push some other character off the end of the string.

(Correct me if I'm wrong!)

jascha_eng 3 hours ago

boomlinde 36 minutes ago

yuliyp 9 hours ago

From the pseudocode it's always a single byte. Desyncing before the end of the buffer is fine. Desyncing at the very end causes the single byte overflow.

miohtama 11 hours ago

This is bad news for C/C++

lionkor 9 hours ago

The good news is that this was already the case, and we have tools that check for this; like fuzzers and sanitizers.

Now to get people to use them it's an issue.

stouset 3 hours ago

xnickb 10 hours ago

This is bad news for computer industry. See the recent Java4Shell.

eecc 10 hours ago

ecshafer 7 hours ago

anthk 10 hours ago

At least C folks can use something like BoehmGC and calm down things a little.

trismegisti 10 hours ago

But are those generic exploits, that don't rely on specific dynamic library and kernel versions? i doubt it.

zamadatix 9 hours ago

The problem now is it really doesn't matter as much. Before you had to put the work in to make the exploit chain work in the specific situation. Now you just need the entry point through the narrow hole in the exposed portion and a target set worth the tokens to customize it to work against one of the individual deployments. At least until we get better at making it difficult to chain things in response.

_3u10 8 hours ago

I don’t think it’s a single byte at least not in this case, you’d put your shell code into a string and then use enough double S to push it where it needs to go. I’m assuming each double S pushes one more byte.

circularfoyers 12 hours ago

Thought this was another vulnerability for a second, but for anyone else who thought the same, this is already covered in the Ruby advisory being discussed here https://news.ycombinator.com/item?id=50554038 (which covers six other vulnerabilities).

t1234s 7 hours ago

For people who haven't been to Germany the character that looks like a script B is pronounced like "S". Its a bit of humor in what is an annoying problem.

echoangle 5 hours ago

> pronounced like "S"

Yes, but it's always pronounced "sharp" (like the hiss of a snake), so the letter is used to disambiguate some words. In some contexts (switzerland, capital writing until the capital ß was introduced), it's replaced by ss but then there could technically be two meanings, for example "Maße" is measurements and "Masse" is mass, although most of the time it's clear from the context.

t1234s 2 hours ago

Now that I think about it the pronunciation of "ß" is important for people to know who don't speak German but want to order wine when visiting. Say weiss not weib.

t1234s 2 hours ago

Weiß => Weiss

makemefundyou20 5 hours ago

just makes it difficult to search for us.

mimischi 30 minutes ago

iOS Safari will find „ß“ when you search for “ss”. Not hard at all!

hunterpayne 6 hours ago

The Swiss don't use it. Its also not on most people's keyboards. So great to make a command require a special unicode character, letting in yet another attack vector (and requiring us to scan code for letters that don't look quite right). Reminds me of the single char => operator in Scala which has fallen out of use thankfully.

PS There was a movement about multi-lingual/multi-charset programming several decades ago. The international programming community killed it more multiple good reasons. Its not cute, stop doing it.

ok123456 5 hours ago

The Duden reform of 1995 removed most of its uses.

BigTTYGothGF 5 hours ago

> So great to make a command require a special unicode character

What command? Also perhaps you missed this part of the article:

> The same loop is in several ISO-8859 and Windows-125x encodings and has been there since Ruby 2.4.0. It is reached by upcase, swapcase, downcase(:fold) and casecmp?.

> UTF-8 strings take a different code path and are not affected.

barbegal 11 hours ago

More interested to see how you can use just a single byte overflow to trigger RCE. Definitely achievable but sounds tough.

cyphar 9 hours ago

There was an even more restrictive single NUL byte heap overflow in glibc in 2014 that the ProjectZero folks managed to turn into ACE and thus an LPE in setuid binaries[1]. The final section that talks about bickering over exploitability seems particularly pertinent today.

[1]: https://projectzero.google/2014/08/the-poisoned-nul-byte-201...

tptacek 4 hours ago

The simplest core mechanism of these kinds of exploits is that you can groom the heap by triggering lots of similar-sized allocations, so you have a good guess as to what the heap will contain where your wild write occurs, and then you can trigger specific allocations to land juicy victim structs in the heap where you want them.

It's an evolution of the old "nop sled" idea from stack overflows (and viruses before that), where you don't know exactly what the stack addresses you're targeting are, but you can in your exploit trigger payload include data that will carpet bomb the stack with NOP instructions so that you have a big window to guess.

kyledrake 5 minutes ago

I was under the impression that everyone adopted the OpenBSD randomized memory heap by default. Does this imply that it's not enough to prevent this sort of attack from working? If this is even slightly repeatable then the mechanism doesn't seem to be sufficiently random. I'm not an expert on memory allocation but at a high level it seems like we need to do a better job of randomizing the heap if this sort of thing is still possible.

darkamaul 34 minutes ago

To be able to effectively turn a single byte overwrite into ACE is still challenging because you will corrupt outside of your buffer, but this corruption must be meaningful.

I would be curious to see how they were able to exploit it here.

deprave 10 hours ago

There was an article on this topic in Phrack 55 back in 1999: https://phrack.org/issues/55/frame-pointer-overwriting#artic...

Exploitation conditions are likely more challenging today but that’s the earliest reference I know for exploiting a single byte overflow.

valleyer 10 hours ago

The commit message for the Ruby fix says it's a heap buffer, so frame pointer smashing would not apply here.

F30 7 hours ago

enjoytheview 9 hours ago

The next byte in the heap might be the size of an allocation, so if you overwrite it and then free that other allocation, the heap code will think that there is a very large free area there instead of a small one, once you allocate that, you now have a very large heap overflow and can do more fun things. That is just one idea, there are many other ways.

Panzerschrek 12 hours ago

I suppose this function has been written first in assumption, that case conversion doesn't affect length, but later ß -> SS conversion has been added without proper testing.

johnp_ 11 hours ago

There was never any guarantee that case conversion is byte length equivalent. Except for pure ASCII, that's just been an incorrect assumption from the start.

debugnik 10 hours ago

This only affects ISO-8859-1~16 encodings, Ruby only supports non-ASCII case folding for those and UTF. It might actually be the only character from that list of ISO encodings for which the length changes.

K0nserv 8 hours ago

It looks like the original author did actually try to account for this by allocating 20 more bytes than the input length.

From the blog post:

    The output buffer is allocated as the input length plus 20 bytes. Each ß adds one byte to the output, so an input with 21 of them overflows the buffer by one byte.

rob74 12 hours ago

Ah, so that's the real reason "ß" is now allowed in uppercase too (https://en.wikipedia.org/wiki/%C3%9F)? Reducing the risk of security issues by removing an edge case?

pwdisswordfishq 11 hours ago

The Unicode case mappings are covered by backwards-compatibility guarantees. "ß" is going to be mapped to "SS" forever.

cubefox 11 hours ago

It even seems the "more correct" uppercase form of ß is now ẞ, not SS.

> Traditionally, ⟨ß⟩ did not have a capital form, and was capitalized as ⟨SS⟩. Some type designers introduced capitalized variants. In 2017, the Council for German Orthography officially adopted a capital form ⟨ẞ⟩ as an acceptable variant, ending a long debate.[4] Since 2024 the capital has been preferred over ⟨SS⟩.[5]

edelbitter 8 hours ago

shevy-java 10 hours ago

weinzierl 12 hours ago

There should be other codepoints other than ß that in principle could be used for a vulnerability like that. There are even ones that expand to three codepoints, like ffi.

stuxf 12 hours ago

this relies on specific behavior with how the upcase function worked, the ß is the only one that expands in a way that works for this vulnerability.

weinzierl 11 hours ago

Can you elaborate on what makes ß special enough to enable the vulnerability.

A quick search showed that there are other cases in legacy encodings that expand to multiple bytes.

For example 0xEF in ISO 6937 expands to CA BC 4E in UTF-8 after case transformation. Similar to ß this is a case with a single byte legacy encoding with a single lowercase unicode codepoint which has no precomposed upper case equivalent.

debugnik 10 hours ago

tptacek 6 hours ago

I went looking last night and found only the ß in Windows-1252.

edelbitter 8 hours ago

I believe these deserve a mention in your unit tests:

1. ÿ (LATIN SMALL LETTER Y WITH DIAERESIS) is in ISO-8859-1, but Ÿ (LATIN CAPITAL LETTER Y WITH DIAERESIS) is not - however, theres this thing called Windows-1252 which is often treated as equivalent, where it is.. but not in the same place as in ISO-8859-15.

2. The Unicode (and correct) uppercase of µ (MICRO SIGN) is Μ (GREEK CAPITAL LETTER MU) which should look like M (LATIN CAPITAL LETTER M) .. only the latter can be expressed in Windows-1252.

3. The ISO-8859-12 encoding is a lie.

GTP 8 hours ago

> We'll be publishing a proof of concept in a week, once people have had time to upgrade.

I think one may now decide to publish the PoC straight away or not publish it at all, since an AI agent pointed at this post would very likely be able to produce one in a few minutes.

speedgoose 12 hours ago

But can the attacker specify the encoding in rails? It's not like UTF-8 or GTFO?

CER10TY 11 hours ago

You can freely specify the encoding when sending multipart/form-data POST since Rails respects the charset attribute in Content-Type, eg Content-Type: text/plain; charset=Windows-1252

bloak 11 hours ago

So you have to convert ISO-2022-JP, for example? That sounds like a disaster waiting to happen.

lmz 11 hours ago

zelphirkalt 12 hours ago

Name as discussed earlier here on Hackernews :) Glad they went with that name.

olejorgenb 8 hours ago

I assume Gitlab.com run a fixed version, but it would be good if they could confirm it now..

lousken 12 hours ago

Scheiße2Shell?

wiether 10 hours ago

Get ready to upgrade your GitLab instance...

jaapz 8 hours ago

Interesting that it takes so long for them to release a patched version

EDIT: 19.6.0 is now out EDIT2: that version still comes with an unpatched ruby... incredible

wiether 6 hours ago

Yeah things are crazy

They released 19.6.0 but it doesn't contains the fixed ruby

And the releases feed don't have 19.6.0 https://docs.gitlab.com/releases/all-releases.xml

neko_ranger 2 hours ago

we Germans already have a word for this, we call it ruby2ßhellen

tvvocold 11 hours ago

One Shell a Day, Ops Run Away.

rs_rs_rs_rs_rs 12 hours ago

For once a bug name that's cool.

stuxf 12 hours ago

we were thinking of naming it ruby off rails haha, but this title ties into how this vulnerability works which was super cool

rs_rs_rs_rs_rs 11 hours ago

And the fact that you can almost read it ruby 2 hell

pluc 9 hours ago

Here come the united statesmen asking about Ruby 2b hell

phil294 9 hours ago

Fortunately, Rails' creator DHH recommends to use Rust nowadays anyway. https://www.youtube.com/watch?v=vDjW_dRyKXY

jjgreen 9 hours ago

... also annexing the Sudetenland, so YMMV.

mikrotikker 9 hours ago

Please stop

jjgreen 5 hours ago

mikrotikker 9 hours ago

More like use rails if you're writing it, use rust if you're making a real smart clanker do it.

He made rails for humans not for speed.

realsdx 10 hours ago

Another day, another RCE!

srgb_vs_cmyk 10 hours ago

It is getting absurd, in span of 48h there is one for nginx, java, php and ruby; with another one for php and ruby in last month.

slekker 8 hours ago

DHH in shambles

BigTTYGothGF 5 hours ago

Every cloud has a silver lining.

sgt 11 hours ago

Django next? Although it's unlikely, Django is known to be above average in terms of security by now.

Gigachad 11 hours ago

The bug here is in the C code for Ruby. Python is also written in C and just as likely to have memory bugs.

pjmlp 11 hours ago

CPython.

jaapz 8 hours ago

imtringued 11 hours ago

The days of people feeling secure because they don't make egregious mistakes are unfortunately over. Now the rule is: You are vulnerable, you just don't know how.

DarkNova6 11 hours ago

Above average doesn’t cut it these days. And doesn’t Python have some of the strongest exposures to C libraries?

Well…

sgt 11 hours ago

Uh oh. I guess it's being hammered with people with Red Team access right now.

jaapz 8 hours ago

it's just a matter of time before the first big python RCE will be posted here

gsich 11 hours ago

no poc. go away.

stuxf 11 hours ago

would you rather we publish a PoC for a vulnerability that doesn't even have a patch yet? e.g self-hosted GitLab still hasn't shipped a newer version of Ruby that's patched...

would be wildly irresponsible

jaxn 8 hours ago

the patch is to update ruby

oguz-ismail2 10 hours ago

>we

I doubt you have a PoC at all

spikewall 11 hours ago

took glm a bit over 20 minutes to write one, based on the report.

paulannesley 9 hours ago

RCE or crash?

spikewall 7 hours ago