Ruby2ßhell: Pre-authentication RCE on stock Rails

(verialabs.com)

216 points | by jdns 8 hours ago ago

85 comments

  • cowlevel 3 hours ago 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 2 hours ago 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 an hour ago 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 33 minutes ago ago

          Tons of production Rust systems use very little unsafe. I've been writing production Rust since 2015, and in that time, I wrote maybe 30 lines of unsafe production code. (Most of it in Tokio primitives.)

          Now, in web-facing systems, the biggest concern is the low-level crypto libraries, which need to be written in assembly to avoid timing attacks. These (and related libraries) have seen multiple security advisories in the past year, some related to unsafe (I think?) and some related to logic errors. But overall, those advisories have mostly been lower priority, or affected mostly niche use cases.

          If you only have a small amount of unsafe code, then it's possible to audit it more aggressively. And there's only a limited amount of space for bugs. So what I would expect for Rust is a trickle of security bugs, many of them niche or low severity, that slows down with time.

      • ninkendo 2 hours ago ago

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

        • supersimpleguy 33 minutes ago ago

          …it was a metaphor to agree with the OP’s point.

          Not everyone on the web is looking to start an argument; some people use literary devices to reinforce their point. If anyone is defensive about a point nobody made, it’s you.

      • GTP 33 minutes ago 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.

      • zamadatix 2 hours ago 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.

      • anthk 2 hours ago 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 2 hours ago ago

          This ... isn't true? A lot of people perceived the Java plugin as being insecure in the browser, and indeed it was.

          The perception of Java as being insecure on the server was only a thing amongst those who hadn't used it much since the Java plugin era.

          That's why the Log4j vulnerability was a huge deal.

          I like Rust, but this kind of anti-Java-think is super dated and boring.

        • cowlevel 2 hours ago ago

          Java CVEs were mostly holes in Java's own sandbox (e.g. used to run multiple applets from different websites in the same VM) which has been abandoned.

    • toastal 3 hours ago 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.

    • boomlinde 3 hours ago ago

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

      • yuliyp 2 hours ago 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 3 hours ago ago

      This is bad news for C/C++

      • lionkor an hour ago 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.

      • xnickb 3 hours ago ago

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

        • eecc 3 hours ago ago

          because the assembly for the base64 decoding was handwritten, the paren't comment is still valid

          • dingaling911 2 hours ago ago

            I think the point is that the weakest link WILL be found.

      • anthk 2 hours ago ago

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

    • trismegisti 3 hours ago ago

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

      • zamadatix 2 hours ago 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 an hour ago 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 5 hours ago 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).

  • GTP 26 minutes ago 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.

  • barbegal 4 hours ago ago

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

    • cyphar 2 hours ago 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...

    • deprave 3 hours ago 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 3 hours ago ago

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

    • enjoytheview 2 hours ago 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 5 hours ago 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.

    • K0nserv 13 minutes ago 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.
    • johnp_ 4 hours ago 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 3 hours ago 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.

    • rob74 4 hours ago 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 3 hours ago ago

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

      • cubefox 3 hours ago 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 an hour ago ago

          >ending a long debate

          They did not. Participants from Liechtenstein and Switzerland don't even care about that letter (Swiss orthography does not make use of it), so they are not even a good place to begin such debate.

        • shevy-java 3 hours ago ago

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

          But that is wrong. In german I only know of ß aka downcased version.

          ẞ seems another character. I have no idea what it is, other than looking close to ẞ, but it most assuredly is not existing in the german language. There is simply no uppercased variant. 'ss' is "Doppel-s' - that is not ß. In german we have "das" (which is the), but it can be "das" or "dass" depending on the sentence, in particular after a ',' character. I often misspell it, since I prefer "das", when in reality sometimes one has to use "dass". But 'ß' is very different to that - to claim that 'ß' is equivalent to 'ss' is simply incorrect. I have no idea who that "Council for German Orthography" is, but clearly they don't know anything about German. Who put that Council in charge of anything? Are these drunks? The claim that the capital has been preferred, is also factually wrong. Who is writing all that?

          Edit: Oh I see, you have that from Wikipedia.

          The .pdf can be found here:

          https://www.rechtschreibrat.com/DOX/RfdR_Amtliches-Regelwerk...

          So from what I can see, this is only the:

          "Leibniz-Institut für Deutsche Sprache"

          That is not a unified authority for anything. It is totally unclear to me why the wikipedia article claims that this is legally binding for anyone. That's just factually incorrect. Is Wikipedia no longer proofreading?

          • mr_mitm an hour ago ago

            Who are you to decide what does and doesn't exist in the German language? You are no more authoritative than the Leibniz-Institut either.

            Edit: The Leibniz-Institut is just the publisher. The author, the Rat für deutsche Rechtschreibung, is legitimized by the German (and six other countries') government.

            The Duden is also seen by many as authoritative and also knows and allows the capital ß: https://www.duden.de/sprachwissen/rechtschreibregeln/doppel-...

            Edit 2: It's also not illegal to use whatever made up rules you want. Nothing about this is legally binding anywhere.

          • cubefox 2 hours ago ago

            Wikipedia says ẞ is "preferred", which is plausible when an organization with an impressive name declares it preferable. Nobody says it's legally binding.

            > I often misspell it, since I prefer "das", when in reality sometimes one has to use "dass".

            It's confusing because both can mean "that".

            "That is true." = "Das ist wahr."

            "He said that it is true." = "Er sagte, dass es wahr ist."

  • weinzierl 4 hours ago 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 4 hours ago 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 3 hours ago 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 3 hours ago ago

          From the Ruby docs:

          > Non-ASCII case mapping and folding are supported for UTF-8, UTF-16BE/LE, UTF-32BE/LE, and ISO-8859-1~16 Strings/Symbols.

          ß might actually be the only character that expands to multiple bytes on the original encoding from that list of ISO encodings.

          • weinzierl 3 hours ago ago

            Ah, good point. If ISO-8859-1 is the only supported single-byte legacy encoding then ß is most likely the only case.

            EDIT: Thinking about it, my example from above should work with UTF-16 input.

            U+0149 is a single lower case BMP codepoint, so two bytes in UTF-16. It has no precomposed uppercase, so it turns into two codepoints and 4 bytes in UTF-8 and UTF-16.

    • edelbitter 27 minutes ago 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.

  • speedgoose 4 hours ago ago

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

    • CER10TY 4 hours ago 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

  • olejorgenb an hour ago ago

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

  • zelphirkalt 5 hours ago ago

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

  • gsich 4 hours ago ago

    no poc. go away.

    • stuxf 4 hours ago 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 6 minutes ago ago

        the patch is to update ruby

      • oguz-ismail2 3 hours ago ago

        >we

        I doubt you have a PoC at all

    • spikewall 4 hours ago ago

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

  • lousken 5 hours ago ago

    Scheiße2Shell?

  • wiether 2 hours ago ago

    Get ready to upgrade your GitLab instance...

    • jaapz 15 minutes ago ago

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

  • pluc 2 hours ago ago

    Here come the united statesmen asking about Ruby 2b hell

  • phil294 2 hours ago ago

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

    • mikrotikker an hour ago 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.

    • jjgreen 2 hours ago ago

      ... also annexing the Sudetenland, so YMMV.

  • tvvocold 4 hours ago ago

    One Shell a Day, Ops Run Away.

  • rs_rs_rs_rs_rs 5 hours ago ago

    For once a bug name that's cool.

    • stuxf 5 hours ago 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 4 hours ago ago

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

  • slekker 27 minutes ago ago

    DHH in shambles

  • realsdx 3 hours ago ago

    Another day, another RCE!

    • srgb_vs_cmyk 2 hours ago 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.

  • sgt 4 hours ago ago

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

    • Gigachad 4 hours ago 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 4 hours ago ago

        CPython.

        • jaapz 21 minutes ago ago

          yes, the version of python that almost everyone uses

    • imtringued 4 hours ago 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.

    • jaapz 21 minutes ago ago

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

    • DarkNova6 4 hours ago ago

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

      Well…

      • sgt 3 hours ago ago

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