Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an exploit for CVE-2023-6546 #18790

Closed
wants to merge 2 commits into from
Closed

Add an exploit for CVE-2023-6546 #18790

wants to merge 2 commits into from

Conversation

jvoisin
Copy link
Contributor

@jvoisin jvoisin commented Feb 5, 2024

Verification

List the steps needed to make sure this thing works

  • Start msfconsole
  • Get a session
  • set verbose true
  • use linux/local/gsm_multiplex_priv_esc
  • exploit
  • Enjoy your root shell
  • set payload python/meterpreter/reverse_tcp
  • exploit
  • check that you get the Inlining the payload inside the exploit. message
  • Enjoy your root shell

This should close #18719

CC @Nassim-Asrir

@jvoisin jvoisin marked this pull request as draft February 5, 2024 22:02
@jvoisin jvoisin marked this pull request as ready for review February 5, 2024 22:29
@zerozenxlabs
Copy link

Nice one :)

The github URL is incorrect , the correct one is https://github.com/Nassim-Asrir/ZDI-24-020

      [ 'CVE', '2023-6546' ],
      [ 'ZDI', '24-020' ],
      [ 'URL', 'https://github.com/Nassim-Asrir/CVEZDI-24-020' ]

Copy link
Contributor

@cdelafuente-r7 cdelafuente-r7 left a comment

Choose a reason for hiding this comment

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

Thanks @jvoisin for this module. I left a few comments and suggestions for you to review when you get a chance. Specifically, I recommend using a precompiled binary and patching it with the payload and offsets from the ruby code.

modules/exploits/linux/local/gsm_multiplex_priv_esc.rb Outdated Show resolved Hide resolved
modules/exploits/linux/local/gsm_multiplex_priv_esc.rb Outdated Show resolved Hide resolved
modules/exploits/linux/local/gsm_multiplex_priv_esc.rb Outdated Show resolved Hide resolved
modules/exploits/linux/local/gsm_multiplex_priv_esc.rb Outdated Show resolved Hide resolved
modules/exploits/linux/local/gsm_multiplex_priv_esc.rb Outdated Show resolved Hide resolved
modules/exploits/linux/local/gsm_multiplex_priv_esc.rb Outdated Show resolved Hide resolved
Comment on lines 148 to 149
os_id = cmd_exec('grep ^ID= /etc/os-release')[3..]
output = cmd_exec "echo '#{payload_path} & exit' | #{executable_path} #{os_id}"
Copy link
Contributor

Choose a reason for hiding this comment

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

If we use a precompiled binary, everything can be embedded by patching it. The payload, the offsets, etc. This would avoid having two binaries on disk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there an example somewhere in metasploit on how to do this properly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@jvoisin jvoisin Feb 22, 2024

Choose a reason for hiding this comment

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

I seems that I can't manage to compile a static musl binary with correct pthread support, as the call to sched_setscheduler invariably fails.

@cdelafuente-r7
Copy link
Contributor

@Nassim-Asrir, since this module will use your exploit, a LICENSE is required. I couldn't find one, so I submitted a PR with a standard BSD 3-Clause License.

#define VERBOSE
#define NUM_SPRAY 300
#define EXPLOIT_TRIES 10
#define PYTHON_PAYLOAD "import os; os.setresgid(0, 0, 0); os.setresuid(0, 0, 0); os.execl('/bin/bash', 'bash', '-c', 'export HISTFILE=/dev/null;chmod u-s /usr/bin/python3 /usr/libexec/platform-python 2>/dev/null; rmmod n_gsm; id; exec /bin/bash --norc --noprofile');"
Copy link
Contributor

Choose a reason for hiding this comment

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

The payload is assuming /usr/bin/python3 or /usr/libexec/platform-python exist. This might not work on systems with python2 or with different paths.

If I understand this correctly, this sets sgid and suid to 0 on the python process and spawn a shell as the root user. I'm wondering if it would be possible to be more generic and not rely on python exclusively. I believe we can execute our proper binary payload directly without the need of invoking python. Also, Metasploit payloads have the capability of setting suid themself (PrependSetuid option).

So, the idea would be to just execute the exploit binary, with the embedded payload, instead of:

output = cmd_exec "echo '#{payload_path} & exit' | #{executable_path} #{os_id}"

Copy link
Contributor Author

@jvoisin jvoisin Feb 20, 2024

Choose a reason for hiding this comment

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

It might™ be possible to not rely on the python interpreter, but since the payload is carefully crafted to call chmod u+s python, it's less trivial than what I've done, namely:

  • if the payload is ARCH_PYTHON, inline it and compile the exploit locally (is there a mixin to do this by the way?)
  • otherwise, use an external binary

What do you think?

@jvoisin jvoisin marked this pull request as draft February 9, 2024 20:51
Several things were changed in the original exploit.c:

- Allow python payload to use an inline payload, so that a secondary binary
  isn't needed. There is likely some way to do this with other things than
  python, but since the "make the python interpreter setuid" command is
  hardcoded in the chain, it's less trivial than simply patching the python
  payload.
- Offsets are moved onto the metasploit module, making them easier to modify
  and expand.
@jvoisin jvoisin marked this pull request as ready for review February 20, 2024 23:58
@cdelafuente-r7
Copy link
Contributor

Thank you for updating this @jvoisin . I'm sorry I couldn't get back to your module earlier.

I tried to run the module against Ubuntu 20.04.4 with different kernel versions and it failed. I also couldn't make the original exploit work neither.
I tried against 5.8.0-29-generic, 5.4.0-40-generic and 5.4.0-29-generic

$ ./exploit ubuntu
[+] Attempt 1/10
[+] Found kernel '5.4.0-54-generic' [run_cmd]
[+] Found kernel .text, 0xffffffffb0800000
[!] need at least 3 cores ideally, found 2
[-] Fatal: ioctl (Invalid argument) (line 909)

I'm wondering if the exploit works against Ubuntu on VM? Please, would you mind giving more details on the targets you've tested?

@jvoisin
Copy link
Contributor Author

jvoisin commented Mar 26, 2024

It's been a long time now, and I've deleted my lab and I don't think I'll have the time to look at this in a while :/

@jvoisin jvoisin closed this Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

CVE-2023-6546/ZDI-24-020 — Linux LPE
3 participants