Skip to content

Commit 7c5b948

Browse files
committed
Updates php/challenge-76.md
Auto commit by GitBook Editor
1 parent 2835613 commit 7c5b948

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

SUMMARY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
* [Challenge 72](php/challenge-72.md)
7979
* [Challenge 73](php/challenge-73.md)
8080
* [Challenge 74](php/challenge-74.md)
81+
* [Challenge 75](php/challenge-75.md)
82+
* [Challenge 76](php/challenge-76.md)
83+
* Challenge 77
84+
* Challenge 78
85+
* Challenge 79
86+
* Challenge 80
8187

8288
## RUBY
8389

php/challenge-73.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
# Challenge
22
```php
3+
class LanguageManager
4+
{
5+
public function loadLanguage()
6+
{
7+
$lang = $this->getBrowserLanguage();
8+
$sanitizedLang = $this->sanitizeLanguage($lang);
9+
require_once("/lang/$sanitizedLang");
10+
}
11+
12+
private function getBrowserLanguage()
13+
{
14+
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? 'en';
15+
return $lang;
16+
}
17+
18+
private function sanitizeLanguage($language)
19+
{
20+
return str_replace('../', '', $language);
21+
}
22+
}
23+
24+
(new LanguageManager())->loadLanguage();
325
```
426

527
# Solution
28+
This challenge contains a file inclusion vulnerability that can allow an attacker to execute arbitrary code on the server or to leak sensitive files. The bug is in the sanitization function in line 18. The replacement of the ../ string is not executed recursively. This allows the attacker to simply use the character sequence ....// or ..././ that after replacement will end in ../ again. Thus, changing the path to the included language file via path traversal is possible. For example, the system's passwd file can be leaked by setting the following payload in the Accept-Language HTTP request header: .//....//....//etc/passwd.
629

730
# Refference
8-
+ php-security-calendar-2017
31+
+ php-security-calendar-2017 Day 9 - Rabbit

php/challenge-74.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
# Challenge
22
```php
3+
extract($_POST);
4+
5+
function goAway() {
6+
error_log("Hacking attempt.");
7+
header('Location: /error/');
8+
}
9+
10+
if (!isset($pi) || !is_numeric($pi)) {
11+
goAway();
12+
}
13+
14+
if (!assert("(int)$pi == 3")) {
15+
echo "This is not pi.";
16+
} else {
17+
echo "This might be pi.";
18+
}
319
```
420

521
# Solution
22+
This challenge contains a code injection vulnerability in line 12 that can be used by an attacker to execute arbitrary PHP code on the web server. The operation assert() evaluates PHP code and it contains user input. In line 1, all POST parameters are instantiated as global variables by PHP's built-in function extract(). This can lead to severe problems itself but in this challenge it is only used for a variety of sources. It enables the attacker to set the $pi variable directly via POST Parameter. In line 8 there is a check to verify if the input is numeric and if not the user is redirected to an error page via the goAway() function. However, after the redirect in line 5 the PHP script continues running because there is no exit() call. Thus, user provided PHP code in the pi parameter is always executed, e.g. pi=phpinfo().
623

724
# Refference
8-
+ php-security-calendar-2017
25+
+ php-security-calendar-2017 Day 10 - Anticipation

php/challenge-75.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Challenge
2+
```php
3+
4+
```
5+
6+
# Solution
7+
8+
# Refference
9+
+ php-security-calendar-2017

php/challenge-76.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Challenge
2+
```php
3+
4+
```
5+
6+
# Solution
7+
8+
# Refference
9+
+ php-security-calendar-2017

0 commit comments

Comments
 (0)