安全中国首页 > 文章中心 > 其他漏洞研究
 
安全中国网友投稿专用上传FTP空间:
Ftp服务器:download.anqn.com
Ftp端口:21
用户名:anqn
密 码:anqn.com
 

我所知道的管理员在上传方面的部分设计漏洞

更新时间:2007-11-21 10:44:38
责任编辑:阿loosen
热 点:
实都很简单,都和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’)或者直接?*晃猚heckFileUpload(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不是早就完蛋翘了。

 
相关文章
一日一文章
 
一日一软件
一日一动画