[FE-CTF 2022] Dig Host 3

Information Gathering

Hi, bài này sẽ giống bài Dig Host 2. Nếu chưa đọc bài đó thì bạn nên quay lại đọc trước khi đọc bài này.
Challenge
Link bài Dig Host 2 ở đây.

Vì bài Dig Host 3 chỉ khác bài Dig Host 2 một chút xíu filter.

Exploit

Sau khi thử nhiều cách bypass dấu cách, thì dấu < đã work. Dấu $ ở bài 2 cũng đã bị filter.

list file

Xem source của nó để xem cách nó filter khác gì so với challenge 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?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_level3.tpl");
?>

Ta có thể thấy ở dòng 8, dấu $ đã bị filter, nhưng dấu < không bị filter. Nên mình có thể dùng nó để bypass dấu cách được.
Và đây là kết quả:
flag


Một cách command line nữa để lấy flag bonus.

1
'`{cat,bonus_flag}`'

bonus_flag


Mọi người có ý kiến gì cùng viết xuống ở dưới để thảo luận nhé <3

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 3
https://dovankha.github.io/2022/11/06/dig-host-3/
Author
Khado
Posted on
November 6, 2022
Licensed under