Skip to content

Updated ruby gadget for marshal loading#1

Merged
p- merged 3 commits into
GitHubSecurityLab:mainfrom
doyensec:marshal-3.4-rc0
Oct 17, 2024
Merged

Updated ruby gadget for marshal loading#1
p- merged 3 commits into
GitHubSecurityLab:mainfrom
doyensec:marshal-3.4-rc0

Conversation

@leonardo-doyensec

@leonardo-doyensec leonardo-doyensec commented Oct 16, 2024

Copy link
Copy Markdown
Contributor

Hello @p- , my name is Leonardo, I'm an Application Security Engineer @ Doyensec.
In the previous weeks I've doing some research around ruby deserialization, and I've noticed that the Marshal gadget was not working anymore on the latest ruby version. So I've adapted it.

Essentially the major change is that the kick-off gadget (Gem::Specification) is now calling safe_load making impossible to continue the exploit chain.
Since the rest of the exploit is untouched, I've been searching for a similar gadget that called to_s once deserialized. I've found it in Gem::Version.
The only problem with it is that it will throw an exception after the folder creation (which is the first stage of the exploit). Hence two separate loads are required.

Another problem arising is that the URI module is not present anymore in ruby as default. Hence, we need to import net/http. I think this is a fair assumption since with this exploit we will target mostly web applications (whether rails or sinatra) that will import this module.

Contacts:
Twitter
Doyensec

@p- p- left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leonardo-doyensec 👋

Sounds great!
I've added some minor nitpicks. (comment out calls of marshal.load)

Thanks!

Comment thread marshal/3.4-rc/marshal-rce-ruby-3.4-rc.rb Outdated
Comment thread marshal/3.4-rc/marshal-rce-ruby-3.4-rc.rb Outdated
@leonardo-doyensec

Copy link
Copy Markdown
Contributor Author

Hello @p-, i've added the changes that you have requested

@p-
p- merged commit 8c66d0e into GitHubSecurityLab:main Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants