diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/apache_spark_rce.pp b/modules/vulnerabilities/unix/http/apache_spark_rce/apache_spark_rce.pp new file mode 100644 index 000000000..1b25529f0 --- /dev/null +++ b/modules/vulnerabilities/unix/http/apache_spark_rce/apache_spark_rce.pp @@ -0,0 +1,11 @@ +# apache spark rce init +# https://archive.apache.org/dist/spark/spark-3.1.2/spark-3.1.2-bin-hadoop3.2.tgz +# https://spark.apache.org/docs/3.1.2/ +# https://packetstormsecurity.com/files/168309/Apache-Spark-Unauthenticated-Command-Injection.html +# https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/linux/http/apache_spark_rce_cve_2022_33891.rb +contain apache_spark_rce::install +contain apache_spark_rce::configure +contain apache_spark_rce::service +Class['apache_spark_rce::install'] +-> Class['apache_spark_rce::configure'] +-> Class['apache_spark_rce::service'] diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partaa b/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partaa new file mode 100644 index 000000000..2b79fe84e Binary files /dev/null and b/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partaa differ diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partab b/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partab new file mode 100644 index 000000000..df89c527a Binary files /dev/null and b/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partab differ diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partac b/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partac new file mode 100644 index 000000000..6d9a32f4b Binary files /dev/null and b/modules/vulnerabilities/unix/http/apache_spark_rce/files/scala-2.12.10.deb.partac differ diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partaa b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partaa new file mode 100644 index 000000000..400456b97 Binary files /dev/null and b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partaa differ diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partab b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partab new file mode 100644 index 000000000..4786918ff Binary files /dev/null and b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partab differ diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partac b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partac new file mode 100644 index 000000000..5e4e9bb84 Binary files /dev/null and b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partac differ diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partad b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partad new file mode 100644 index 000000000..f45b26133 Binary files /dev/null and b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partad differ diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partae b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partae new file mode 100644 index 000000000..d78370fe9 Binary files /dev/null and b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-3.1.2-bin-hadoop3.2.tgz.partae differ diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-defaults.conf b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-defaults.conf new file mode 100644 index 000000000..553d716a3 --- /dev/null +++ b/modules/vulnerabilities/unix/http/apache_spark_rce/files/spark-defaults.conf @@ -0,0 +1 @@ +spark.acls.enable true \ No newline at end of file diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/functions/cpandbuild.pp b/modules/vulnerabilities/unix/http/apache_spark_rce/functions/cpandbuild.pp new file mode 100644 index 000000000..d9bd89419 --- /dev/null +++ b/modules/vulnerabilities/unix/http/apache_spark_rce/functions/cpandbuild.pp @@ -0,0 +1,12 @@ +function apache_spark_rce::cpandbuild(Array $collection, String $filename) { + $collection.each |String $item| { + file { "/tmp/${item}": + ensure => file, + source => "puppet:///modules/apache_spark_rce/${item}", + } + } + exec { "rebuild-${filename}": + cwd => '/tmp/', + command => "/bin/cat ${filename}.parta* >${filename}", + } +} diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/configure.pp b/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/configure.pp new file mode 100644 index 000000000..01534cbef --- /dev/null +++ b/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/configure.pp @@ -0,0 +1,26 @@ +# Class: apache_spark_rce::configure +# Configure apache spark and secgen +# +class apache_spark_rce::configure { + $secgen_parameters = secgen_functions::get_parameters($::base64_inputs_file) + $sparkconf='spark-defaults.conf' + $leaked_filenames = $secgen_parameters['leaked_filenames'] + $strings_to_leak = $secgen_parameters['strings_to_leak'] + + Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] } + + # We set the acls flag in the config - This ensures its vulnerable + file { "/usr/local/spark/conf/${sparkconf}": + ensure => file, + source => "puppet:///modules/apache_spark_rce/${sparkconf}" + } + + ::secgen_functions::leak_files { 'spark-flag-leak': + storage_directory => '/usr/local/spark/bin/', + leaked_filenames => $leaked_filenames, + strings_to_leak => $strings_to_leak, + owner => 'root', + mode => '0750', + leaked_from => 'apache_spark_rce', + } +} diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/install.pp b/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/install.pp new file mode 100644 index 000000000..16d6e63c1 --- /dev/null +++ b/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/install.pp @@ -0,0 +1,64 @@ +# Class: apache_spark_rce::install +# install process +# https://archive.apache.org/dist/spark/spark-3.1.2/spark-3.1.2-bin-hadoop3.2.tgz +# https://www.scala-lang.org/download/2.12.10.html +class apache_spark_rce::install { + Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] } + $modulename = 'apache_spark_rce' + + # Install required packages + # NOTE: once Debian updates insert scala 2.12+ into statement + ensure_packages(['openjdk-11-jdk'], { ensure => 'installed'}) + + $scaladeb = 'scala-2.12.10.deb' + $releasename = 'spark-3.1.2-bin-hadoop3.2.tgz' + $shortrelease = 'spark-3.1.2-bin-hadoop3.2' + + $scalapart = ["${scaladeb}.partaa", + "${scaladeb}.partab", + "${scaladeb}.partac"] + + $sparkpart = ["${releasename}.partaa", + "${releasename}.partab", + "${releasename}.partac", + "${releasename}.partad", + "${releasename}.partae"] + + $pkgtobuild = [[$scalapart, $scaladeb], [$sparkpart, $releasename]] + $pkgtobuild.each |Array $pkg| { + apache_spark_rce::cpandbuild($pkg[0], $pkg[1]) + } + + $secgen_parameters = secgen_functions::get_parameters($::base64_inputs_file) + $user = $secgen_parameters['leaked_username'][0] + + $user_home = "/home/${user}" + + # Create user + user { $user: + ensure => present, + home => $user_home, + managehome => true, + } + + # We run older versions of debian, for now source from local deb file + package { 'scala': + ensure => latest, + provider => apt, + source => "/tmp/${scaladeb}", + } + + exec { 'unpack-spark': + cwd => '/tmp', + command => "tar -xf ${releasename}", + creates => '/tmp/spark' + } + -> exec { 'move-spark': + cwd => '/tmp', + command => "mv /tmp/${shortrelease} /usr/local/spark/", + creates => '/usr/local/spark', + } + -> exec { 'chown-spark': + command => "chown -R ${user} /usr/local/spark/", + } +} diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/service.pp b/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/service.pp new file mode 100644 index 000000000..188b190e8 --- /dev/null +++ b/modules/vulnerabilities/unix/http/apache_spark_rce/manifests/service.pp @@ -0,0 +1,23 @@ +# Class: apache_spark_rce::service +# Service to start spark-shell +# +class apache_spark_rce::service { + $secgen_parameters = secgen_functions::get_parameters($::base64_inputs_file) + $port = $secgen_parameters['port'][0] + $user = $secgen_parameters['leaked_username'][0] + + Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] } + + exec { 'set-port': + command => "sed -i 's/8080/${port}/' /usr/local/spark/sbin/start-master.sh", + } + -> file { '/etc/systemd/system/spark.service': + content => template('apache_spark_rce/spark.service.erb'), + owner => 'root', + mode => '0777', + } + -> service { 'spark': + ensure => running, + enable => true, + } +} diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/secgen_metadata.xml b/modules/vulnerabilities/unix/http/apache_spark_rce/secgen_metadata.xml new file mode 100644 index 000000000..449ffbe46 --- /dev/null +++ b/modules/vulnerabilities/unix/http/apache_spark_rce/secgen_metadata.xml @@ -0,0 +1,66 @@ + + + + Apache Spark Unauthenticated Command Injection + James Davis + MIT + The Apache Spark UI offers the possibility to enable ACLs via the configuration + option spark.acls.enable. + With an authentication filter, this checks whether a user has access permissions to view or + modify the application. + If ACLs are enabled, a code path in HttpSecurityFilter can allow someone to perform + impersonation by providing an arbitrary user name. + A malicious user might then be able to reach a permission check function that will ultimately + build a Unix shell command based on their input, and execute it. + This will result in arbitrary shell command execution as the user Spark is currently running as. + This affects Apache Spark versions 3.0.3 and earlier, versions 3.1.1 to 3.1.2, and versions + 3.2.0 to 3.2.1. + + http + user_rwx + remote + linux + low + + port + strings_to_leak + leaked_filenames + + + + + + + + + + + + + + + + + + + + CVE-2022-33891 + 8.8 + AV:N/AC:L/Au:N/C:C/I:C/A:C + + https://packetstormsecurity.com/files/168309/Apache-Spark-Unauthenticated-Command-Injection.html + + https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/linux/http/apache_spark_rce_cve_2022_33891.rb + https://spark.apache.org/docs/3.1.2/ + https://archive.apache.org/dist/spark/spark-3.1.2/spark-3.1.2-bin-hadoop3.2.tgz + Apache Spark + Apache License 2.0 + + + update + + + \ No newline at end of file diff --git a/modules/vulnerabilities/unix/http/apache_spark_rce/templates/spark.service.erb b/modules/vulnerabilities/unix/http/apache_spark_rce/templates/spark.service.erb new file mode 100644 index 000000000..dc02ddd2d --- /dev/null +++ b/modules/vulnerabilities/unix/http/apache_spark_rce/templates/spark.service.erb @@ -0,0 +1,15 @@ +[Unit] +Description=Apache Spark Shell +After=network.target + +[Service] +Type=forking +User=<%= @user %> +Environment="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/spark/sbin" +WorkingDirectory=/usr/local/spark/bin/ +ExecStart=/usr/local/spark/sbin/start-master.sh +Restart=on-abort +RestartSec=1 + +[Install] +WantedBy=multi-user.target \ No newline at end of file