window点location(仅介绍window点location对象,不介绍属性,因标题不能含有非法字符,.用点来代替)
文章目錄
- 1.前言:
- 2.window.location介紹
- 3.做CTF題時遇到的代碼
- 4.總結
1.前言:
這個是我做CG-CTF-Web-單身二十年時遇到的,這里就該題簡單總結一下
2.window.location介紹
獲取當前頁面地址(URL)并把瀏覽器重定向到新頁面
搭建環境測試
test.html代碼:
(1)獲取到該頁面完整url:
(2)進行重定向URL(no_key_is_here_forever.php不在根目錄下,在根目錄的下一級window.location_test目錄下,因此報錯)
總結:由上面測試可以看出,window.location="/no_key_is_here_forever.php",是將獲取到的完整的URL后,僅保留根目錄,也就是將no_key_is_here_forever.php替換根目錄后面的所有目錄,即最后重定向的URL為http://127.0.0.1:8008/no_key_is_here_forever.php
3.做CTF題時遇到的代碼
<script>window.location="./no_key_is_here_forever.php"; </script>上面的js代碼也是將頁面重定向到no_key_is_here_forever.php,只不過原先的/變成了./,這又是什么意思呢
于是我又在本地搭了個環境用做測試,環境搭建:
index.html:
search_key.php:
<script>window.location="./no_key_is_here_forever.php"; </script> key is : nctf{yougotit_script_now}no_key_is_here_forever.php:
<?php echo "這里真的沒有KEY,土土哥哥說的,土土哥哥從來不坑人,PS土土是閏土,不是譚神"; ?>上面index.html獲取當前頁面完整的URL也是http://127.0.0.1:8008/window.location_test/search_key.php,之后進行重定向,多了個./,我們來看看是個什么情況:
哎?它這里怎么沒有用no_key_is_here_forever.php替代除根目錄外的所有目錄,而是只替換了當前URL的最后一個目錄,最后重定向的URL為http://127.0.0.1:8008/window.location_test/no_key_is_here_forever.php,原來這就是./的作用!!
注:如果是window.location="no_key_is_here_forever.php",沒有/呢?經測試,沒有/和./效果一樣,都是只替換完整URL的最后一個目錄。
4.總結
window.location="/no_key_is_here_forever.php"是用no_key_is_here_forever.php替換完整路徑除根目錄外的所有目錄
window.location="./no_key_is_here_forever.php"和window.location="no_key_is_here_forever.php"是用no_key_is_here_forever.php替換完整路徑的最后一個目錄
注:
想要了解它的屬性的可以看以下幾個網址:
http://www.w3school.com.cn/js/js_window_location.asp
http://www.w3school.com.cn/jsref/dom_obj_location.asp
總結
以上是生活随笔為你收集整理的window点location(仅介绍window点location对象,不介绍属性,因标题不能含有非法字符,.用点来代替)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CG-CTF-Web-AAencode
- 下一篇: java信息管理系统总结_java实现科