Skip to content

Commit b4f0a15

Browse files
committed
Updates php/challenge-70.md
Auto commit by GitBook Editor
1 parent 6994004 commit b4f0a15

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

php/challenge-70.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
# Challenge
22
```php
3+
class TokenStorage {
4+
public function performAction($action, $data) {
5+
switch ($action) {
6+
case 'create':
7+
$this->createToken($data);
8+
break;
9+
case 'delete':
10+
$this->clearToken($data);
11+
break;
12+
default:
13+
throw new Exception('Unknown action');
14+
}
15+
}
16+
17+
public function createToken($seed) {
18+
$token = md5($seed);
19+
file_put_contents('/tmp/tokens/' . $token, '...data');
20+
}
21+
22+
public function clearToken($token) {
23+
$file = preg_replace("/[^a-z.-_]/", "", $token);
24+
unlink('/tmp/tokens/' . $file);
25+
}
26+
}
27+
28+
$storage = new TokenStorage();
29+
$storage->performAction($_GET['action'], $_GET['data']);
330
```
431

532
# Solution
33+
This challenge contains a file delete vulnerability. The bug causing this issue is a non-escaped hyphen character (-) in the regular expression that is used in the preg_replace() call in line 21. If the hyphen is not escaped, it is used as a range indicator, leading to a replacement of any character that is not a-z or an ASCII character in the range between dot (46) and underscore (95). Thus dot and slash can be used for directory traversal and (almost) arbitrary files can be deleted, for example with the query parameters action=delete&data=../../config.php.
634

735
# Refference
8-
+ php-security-calendar-2017
36+
+ php-security-calendar-2017 Day 6 - Frost Pattern

0 commit comments

Comments
 (0)