Changeset 3437


Ignore:
Timestamp:
10/29/10 10:14:12 (13 years ago)
Author:
rafaelraymundo
Message:

Ticket #990 - Vulnerabilidades no Anti robo Captcha do Login.

Location:
branches/2.2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/login.php

    r1742 r3437  
    11<?php 
    2 //Valida a existencia do cookie, antes de grava-lo 
    3 if(isset($_COOKIE['contador'])) { 
    4         $valor_cookie = $_COOKIE['contador']; 
    5         if( isset( $_POST['user'] ) && isset( $_POST['passwd'] ) ) 
    6                 { 
    7                 $valor_cookie = $valor_cookie + 1; 
    8                 setcookie("contador", $valor_cookie,0); 
    9                 } 
    10         } 
    11         //Cookie inexistente: tenta gravar um 
    12         else 
    13         { 
    14         if (setcookie("contador", 1,0)) 
    15                 //echo "OK, cookie gravado."; 
    16                 $valor_cookie = 1; 
    17                 else 
    18                 //echo "Nao gravou o cookie"; 
    19                 $valor_cookie = "9999"; // forca captcha 
    20         } 
    21 // logout, inicia contador novamente..... 
    22 if( ( isset( $_GET[ 'cd' ] ) && ( $_GET['cd']=='1' || $_GET['cd'] == 10 ) ) || ( isset( $_COOKIE['sessionid'] ) ) ) 
    23         { 
    24         $valor_cookie = 1; 
    25         setcookie("contador", 1,0); 
    26         } 
    27  
    282        /**************************************************************************\ 
    293        * eGroupWare login                                                         * 
     
    12599                $GLOBALS['phpgw']->session->phpgw_setcookie('serverID', $GLOBALS['phpgw_info']['server']['use_frontend_id']); 
    126100        } 
    127  
     101if($GLOBALS['phpgw_info']['server']['captcha']==1) 
     102  { 
     103    $key_convert = md5_file($_SERVER["DOCUMENT_ROOT"].'header.inc.php'); 
     104    if(!$key_convert) 
     105        { 
     106            echo '<b>' . lang('Error in access. Please, alert the Administrator.') . '</b>'; 
     107            exit(); 
     108        } 
     109    session_name('ZABX'); 
     110    if($_COOKIE['ZABX'] && $key_convert) 
     111        { 
     112            $aux = session_convert(base64_decode($_COOKIE['ZABX']),$key_convert); 
     113            if(substr($aux,0,32) == $key_convert) 
     114                { 
     115                    session_id(substr($aux,32)); 
     116                } 
     117            else 
     118                { 
     119                    $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5')); 
     120                } 
     121        } 
     122     session_start(); 
     123  } 
    128124include(personalize_include_path('phpgwapi','login')); 
    129125?> 
  • branches/2.2/phpgwapi/inc/common_functions.inc.php

    r1681 r3437  
    707707 
    708708        /*! 
     709         @function session_convert 
     710         @abstract cipher/decipher session id. 
     711         @Include by Serpro ( Antonio Carlos da Silva). 
     712         @discussion This function cipher/decipher session id to captcha. 
     713         */ 
     714        function session_convert($str,$ky='') 
     715        { 
     716            if($ky=='') return $str; 
     717            $ky=str_replace(chr(32),'',$ky); 
     718            if(strlen($ky)<8) return ''; 
     719            $kl=strlen($ky)<32?strlen($ky):32; 
     720            $k=array(); 
     721            for($i=0;$i<$kl;$i++) 
     722                { 
     723                    $k[$i]=ord($ky{$i})&0x1F; 
     724                } 
     725            $j=0; 
     726            for($i=0;$i<strlen($str);$i++) 
     727                { 
     728                    $e=ord($str{$i}); 
     729                    $str{$i}=$e&0xE0?chr($e^$k[$j]):chr($e); 
     730                    $j++;$j=$j==$kl?0:$j; 
     731                } 
     732            return $str; 
     733        } 
     734 
     735        /*! 
    709736         @function CreateObject 
    710737         @abstract Load a class and include the class file if not done so already. 
  • branches/2.2/phpgwapi/templates/default/login_default.php

    r3243 r3437  
    1212        \**************************************************************************/ 
    1313 
    14         function check_logoutcode($code) 
     14function check_logoutcode($code) 
    1515        { 
    1616                switch($code) 
     
    5656                } 
    5757        } 
    58          
     58         
    5959        /* Program starts here */ 
    6060 
     
    104104                unset($sslattributes); 
    105105        } 
    106         session_start();  
     106 
     107        if( isset( $_GET[ 'cd' ] ) && ( $_GET['cd']=='1' || $_GET['cd'] == 10 ) ) 
     108        { 
     109            $_SESSION['contador'] = 0; 
     110        } 
     111 
    107112        if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit) 
    108113        { 
    109  
    110         // Primeiro testa o captcha....se houver...... 
    111         if( $GLOBALS['phpgw_info']['server']['captcha']==1) 
    112                 { 
    113                 if(isset($_POST['codigo'])) 
    114                         { 
    115                         if ($_SESSION['CAPTCHAString'] != strtoupper($_POST['codigo'])) 
    116                                 { 
    117                                         $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=200')); 
    118                                 } 
    119                         unset($_SESSION['CAPTCHAString']); 
    120                         } 
    121                 } 
     114         
     115            // Primeiro testa o captcha....se houver...... 
     116            if($GLOBALS['phpgw_info']['server']['captcha']==1) 
     117              { 
     118                if(!$_COOKIE['ZABX']) 
     119                    { 
     120                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=5')); 
     121                    } 
     122                if($_SESSION['contador'] > $GLOBALS['phpgw_info']['server']['num_badlogin']) 
     123                    { 
     124                        if ($_SESSION['CAPTCHAString'] != trim(strtoupper($_POST['codigo']))) 
     125                                { 
     126                                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=200')); 
     127                                } 
     128                        unset($_SESSION['CAPTCHAString']); 
     129                    } 
     130              } 
    122131                if($_POST['user']) { 
    123132                        if($GLOBALS['phpgw_info']['server']['use_prefix_organization']) { 
     
    197206        else 
    198207        { 
     208            $valor_contador = $_SESSION['contador']; 
     209            $valor_contador = $valor_contador + 1; 
     210            $_SESSION['contador'] = $valor_contador; 
    199211                // !!! DONT CHANGE THESE LINES !!! 
    200212                // If there is something wrong with this code TELL ME! 
     
    402414        $tmpl->set_var('autocomplete', ($GLOBALS['phpgw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : '')); 
    403415 
    404 $aux_captcha = ''; 
    405416// soh mostra o captcha se for login sem certificado.... 
    406417if($GLOBALS['phpgw_info']['server']['captcha'] && $_GET['cd']!='300' ) 
    407         { 
    408                 if($valor_cookie > $GLOBALS['phpgw_info']['server']['num_badlogin']) 
    409                         { 
    410                                 $aux_captcha = '<div class="login_label" > 
    411  <input type="hidden" name="' . session_name() .'" value="' . session_id() . '" >  
    412  <img src="./security/captcha.php?xsid='.session_id().'" title="'.lang('Security code').'" alt="'.lang('Security code').'" style="width:60;">   
    413 <br /> 
    414                 <input class="input" type="text" maxlength="50" size="20" name="codigo" id="codigo" value="" > 
    415               </div>'; 
    416                                 $tmpl->set_var('captcha',$aux_captcha); 
    417                         } 
    418         } 
    419  
     418    { 
     419        $aux_captcha = ''; 
     420        setcookie(session_name(),base64_encode(session_convert($key_convert . session_id(),$key_convert)),0); 
     421        if($valor_contador > $GLOBALS['phpgw_info']['server']['num_badlogin']) 
     422            { 
     423                $aux_captcha = '<div class="login_label" > 
     424                   <img src="./security/captcha.php" title="'.lang('Security code').'" alt="'.lang('Security code').'" style="width:60;"><br/> 
     425                   <input class="input" type="text" maxlength="50" size="20" name="codigo" id="codigo" value="" > 
     426                   </div>'; 
     427                $tmpl->set_var('captcha',$aux_captcha); 
     428            } 
     429    } 
     430     
    420431// Testa se deve incluir applet para login com certificado...... 
    421432if ($_GET['cd']=='300' && $GLOBALS['phpgw_info']['server']['certificado']==1) 
    422433        { 
    423434                //Zera o Cookie contador, responsavel pelo captcha 
    424                 $valor_cookie = 1; 
    425                 setcookie("contador", 1,0); 
    426  
     435                $_SESSION['contador'] = 0; 
     436                $valor_contador = 0; 
    427437                $link_alterna_login = '<img border=0 style="padding: 0px 5px 0px 0px" src="phpgwapi/templates/default/images/warning.gif"/><a href="login.php" style="margin: 0px; padding: 0px; text-decoration:none;"><font color="#ffffff" face="Verdana, Arial, Helvetica, sans-serif" size="1">' . lang('Access without Digital Certificate') . '</a>'; 
    428438                $tmpl->set_var('show','none'); 
  • branches/2.2/security/captcha.php

    r3018 r3437  
    106106  
    107107 // ************  Fim da Classe  ************************* 
    108   
    109   
    110   //Cria o CAPTCHA( gera o string e a imagem ... 
     108 
     109function session_convert($str,$ky='') 
     110    { 
     111        if($ky=='') return $str; 
     112        $ky=str_replace(chr(32),'',$ky); 
     113        if(strlen($ky)<8) return ''; 
     114        $kl=strlen($ky)<32?strlen($ky):32; 
     115        $k=array(); 
     116        for($i=0;$i<$kl;$i++) 
     117            { 
     118                $k[$i]=ord($ky{$i})&0x1F; 
     119            } 
     120        $j=0; 
     121        for($i=0;$i<strlen($str);$i++) 
     122            { 
     123                $e=ord($str{$i}); 
     124                $str{$i}=$e&0xE0?chr($e^$k[$j]):chr($e); 
     125                $j++;$j=$j==$kl?0:$j; 
     126            } 
     127        return $str; 
     128    } 
     129 
     130  $key_convert = md5_file($_SERVER["DOCUMENT_ROOT"].'header.inc.php'); 
     131  //Cria o CAPTCHA,  gera o string e a imagem ... 
    111132  $GLOBALS['captcha'] = new captcha; 
    112133  // Guarda o string do captcha na session... 
    113   session_id($_REQUEST['xsid']);  
     134  session_name('ZABX'); 
     135  session_id(substr(session_convert(base64_decode($_REQUEST['ZABX']),$key_convert),32)); 
    114136  session_start();  
    115137  $_SESSION['CAPTCHAString'] = $GLOBALS['captcha'] ->GetCaptchaString(); 
Note: See TracChangeset for help on using the changeset viewer.