论坛: 黑客进阶 标题: 我所知道的管理员在上传方面的部分设计漏洞 复制本贴地址    
作者: a_one [a_one]    论坛用户   登录


实都很简单,都和JS有关。





例子1:
一个文档上传处:
--------code begin---------
function Checkvalue(the){
var yes=true;
if( the.username.value==\"\" || the.password.value==\"\" || the.primarykey.value==\"\"){
alert(\"表单中标示 * 的项目必须填写完整 !\");
yes=false;}
var fileext=the.primarykey.value.substring(the.primarykey.value.length-4,the.primarykey.value.length)
fileext=fileext.toLowerCase()
if (!(fileext=='.doc' || fileext=='.txt' || fileext=='.dat'))
{alert(\"对不起,不正确的文件位置,必须为.doc、.txt或.dat !\");
the.primarykey.focus();
yes=false;
}
return yes;
}
--------code end---------
他只用javascript做限制,而没有从PHP环境下改正。
直接把那个网页当到本地后,改了改原代码。
他当中的if (!(fileext=='.doc' || fileext=='.txt' || fileext=='.dat'))
修改成
if ((fileext=='.doc' || fileext=='.txt' || fileext=='.dat'))
并且修改FORM里头的地址从upload.php改为http://IP/upload.php



例子2:
一个网站的上传处:
--------code begin---------
function getFileExtension(filePath) { //v1.0
fileName = ((filePath.indexOf('/') > -1) ? filePath.substring(filePath.lastIndexOf('/')+1,filePath.length) : filePath.substring(filePath.lastIndexOf('\\\\')+1,filePath.length));
return fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);
}



function checkFileUpload(form,extensions) { //v1.0
document.MM_returnValue = true;
if (extensions && extensions != '') {
for (var i = 0; i field = form.elements[i];
if (field.type.toUpperCase() != 'FILE') continue;
if (field.value == '') {
alert('文件框中必须保证已经有文件被选中!');
document.MM_returnValue = false;field.focus();break;
}
if (extensions.toUpperCase().indexOf(getFileExtension(field.value).toUpperCase()) == -1) {
alert('这种文件类型不允许上传!.\\n只有以下类型的文件才被允许上传: ' + extensions + '.\\n请选择别的文件并重新上传.');
document.MM_returnValue = false;field.focus();break;
} } }
}
--------code end---------
初看觉得,没有上面提到的那样白痴的问题,当时我们接着来
--------code begin---------




--------code end---------



上面这句话让他死的很难看,把checkFileUpload(this,'zip,gtp,gp3');checkFileUpload(this,'zip')改成checkFileUpload(this,'asp,gtp,gp3');checkFileUpload(this,'asp')或者直接?*晃�checkFileUpload(this,'asp'),呵呵,一样可以随便传东西上去喽!
不过记的前面的action中的地址要改成绝对地址http://ip/upload/webpage/upload/upl...?GP_upload=true



例子3:
这个是17173的一个图片上传的地方:
--------code begin---------
function form1_onsubmit(theForm) {
if(theForm.file1.value == \"\")
{
alert(\"选择照片\");
return(false);
}



if (theForm.title.value == \"\")
{
alert(\"请输入照片名称\");
theForm.title.focus();
return (false);
}
if (theForm.gameid.value == \"\")
{
alert(\"请输入您在游戏中的ID\");
theForm.gameid.focus();
return (false);
}



if (theForm.onlinetime.value == \"\")
{
alert(\"请输入您的上线时间\");
theForm.onlinetime.focus();
return (false);
}
if (theForm.author.value == \"\")
{
alert(\"请输入您的名字\");
theForm.author.focus();
return (false);
}
if (theForm.webgame.value == \"\")
{
alert(\"您是哪个网络游戏服务器的玩家??\");
theForm.webgame.focus();
return (false);
}
if(theForm.email.value == \"\")
{
alert(\"请输入您的email\");
theForm.email.focus();
return(false);
}
if(theForm.other.value == \"\")
{
alert(\"请输入简介\");
theForm.other.focus();
return(false);
}



if (theForm.title.value.length > 20)
{
alert(\"非法名称\");
theForm.title.focus();
return (false);
}



if(theForm.catalogid.value == \"0\")
{
alert(\"选择类别\");
return(false);
}



if (theForm.author.value.length > 20)
{
alert(\"非法作者名字\");
theForm.author.focus();
return (false);
}




var checkOK = \"@.\";
var checkStr = theForm.email.value;
var allValid = true;
for (i = 0; i < checkOK.length; i++)
{
j=checkStr.indexOf(checkOK.charAt(i));



if ( (j==-1) && (checkStr!=\"\") )



{



alert(\"非法电子邮件\");
theForm.email.focus();
return (false);
}
}
var fname = document.form1.file1.value;
var ftype = fname.substring(fname.length-3,fname.length);
if(ftype!='jpg' && ftype!='gif' && ftype!='tif' && ftype!='zip' && ftype!='asp')
{
alert(\"图片格式必须是:*.jpg,*.gif,*.tif\");
return(false);
}
theForm.filetype.value = theForm.file1.value.substr(theForm.file1.value.length-3,3) ;



return (true);
}
--------code end---------
不难看出
if(ftype!='jpg' && ftype!='gif' && ftype!='tif' && ftype!='zip' && ftype!='asp')这句话证明了他只对文件后缀做限制
把他改成if(ftype!='jpg' && ftype!='gif' && ftype!='tif' && ftype!='zip' && ftype!='asp')
再把ACTION里头的地址改改,可以上传了,不过结果没预料的那么好,我们读取不到文件,呵呵,如果都被读取了,那么17173不是早就完蛋翘了。




地主 发表时间: 04-06-10 15:00

回复: letmein [letmein]   论坛用户   登录
现在好多程序员都只为达到目的,至于写出的代码的安全性实在不敢恭维,不知这样下去会有什么后果~~~~~・

B1层 发表时间: 04-06-14 16:04

回复: drckness [drckness]   论坛用户   登录
既然和JS有关把IE的JS支持给关了,嘻嘻,不就ok了!

B2层 发表时间: 04-06-15 14:23

回复: a_one [a_one]   论坛用户   登录


B3层 发表时间: 04-06-16 18:00

回复: a_one [a_one]   论坛用户   登录
有些网站用别人的代码不该数据库路径。比如http://www.tx-info.com/gbook/gbook.asp
里什么账号密码一览无余

B4层 发表时间: 04-06-17 17:41

回复: lijingxi [lijingxi]   见习版主   登录
高! 不错!

B5层 发表时间: 04-06-18 12:40

回复: lgf [lgf]   论坛用户   登录
呵呵

B6层 发表时间: 04-06-18 18:26

论坛: 黑客进阶

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号