un spammer nos impide el envío de eventos

3 views
Skip to first unread message

webmaster libroblanco

unread,
Oct 14, 2009, 1:22:30 AM10/14/09
to Libroblanco del software libre
Habréis observado que al enviar eventos os proporciona un error. No es
que no queramos la participación de los usuarios, sino que tenemos una
vulnerabilidad que todavía no hemos sabido corregir, y hay un spammer
que se dedica a aprovecharla.

el spammer viene de estos dominios

gt56.lawn6careforu.com

caboodle.caboodle.com

termserv.sloboda.net

atom2.vapournet.com

121.96.179.27.bti.net.ph

y probablemente de este también

217-162-98-26.dclient.hispeed.ch



Aquí está el codigo del fichero vulnerable en cuestión por si alguien
nos puede dar alguna pista

se produce con las opciones op=addevent&copyevent=0
Gracias por adelantado, cualquier pista será muy agradecida.

<?php

##########################################################################

# Please refer to the README file for licensing and contact
information.

#

# This file has been updated for version 1.7.20070707

#

# If you like this application, do support me in its development

# by sending any contributions at www.calendarix.com.

#

#

# Copyright \Uffffffff 2002-2007 Vincent Hor

##########################################################################



include_once ("cal_utils.php") ;

include_once ("cal_taboo.php") ;

// Cache posted items

ob_start(); // to allow cookies resetting

cacheEvent(false);

include ("cal_popheader.inc.php");



if (file_exists("FCKeditor/fckeditor.php")) { include("FCKeditor/
fckeditor.php") ; $useFCKEditor = 1; }

else $useFCKEditor = 0;



/*****************/

/* back function */

/*****************/



function back(){

echo "<div align=center><a class=menufont
href=javascript:history.back()>".translate("Back")."</a></div>";

}



/*************/

/* add event */

/*************/



// revalidate to prevent posting of events when addevent window is
open and user is logout



if (!isset($_GET['copyevent']))

$copyevent = 0;

else

$copyevent = $_GET['copyevent'];



if ($UVIEW[0]==1) {

if (!isset($_SESSION["login"])) { header ("location:
cal_login.php"); exit(); }

}



if ($op == "addevent" || $op == "upevent"){

if ($op == "addevent"){

$repeat = $_POST['repeat'];

$rtype = $_POST['rtype'];

$rtimes = $_POST['rtimes'];

$rday = $_POST['rday'];

$fday = $_POST['fday'];

$fmonth = $_POST['fmonth'];

$fyear = $_POST['fyear'];

$tday = $_POST['tday'];

$tmonth = $_POST['tmonth'];

$tyear = $_POST['tyear'];

}



$title = $_POST['title'];

$description = $_POST['description'];

$location = $_POST['location'];

$fee = $_POST['fee'];

$email = $_POST['email'];

$url = $_POST['url'];

$cat = $_POST['cat'];

$scope = $_POST['scope'];

$bday = $_POST['bday'];

$bmonth = $_POST['bmonth'];

$byear = $_POST['byear'];

$idgroup = $_POST['idgroup'];

$notify = $_POST['notify'];



if ($DTCONFIG[0]==0) {

$starttimehr = $_POST['starttimehr'];

$starttimemin = $_POST['starttimemin'];

$endtimehr = $_POST['endtimehr'];

$endtimemin = $_POST['endtimemin'];

if ($DTCONFIG[1]==1) {

$startperiod = $_POST['startperiod'] ;

$endperiod = $_POST['endperiod'] ;

}

}



if ($op=="addevent")

{

if ($DTCONFIG[0]==0) {

if ($DTCONFIG[1]==1) {

addevent($title,$description,$location,$fee,$email,$url,$cat,
$scope,$repeat,$bday,$bmonth,$byear,$rday,$rtimes,$rtype,$starttimehr,
$starttimemin,$endtimehr,$endtimemin,$startperiod,$endperiod,$notify,
$fday,$fmonth,$fyear,$tday,$tmonth,$tyear); }

else {

addevent($title,$description,$location,$fee,$email,$url,$cat,
$scope,$repeat,$bday,$bmonth,$byear,$rday,$rtimes,$rtype,$starttimehr,
$starttimemin,$endtimehr,$endtimemin,"--","--",$notify,$fday,$fmonth,
$fyear,$tday,$tmonth,$tyear); }

}

else {

addevent($title,$description,$location,$fee,$email,$url,$cat,
$scope,$repeat,$bday,$bmonth,$byear,$rday,$rtimes,$rtype,

"--","--","--","--","am","am",$notify,$fday,$fmonth,$fyear,$tday,
$tmonth,$tyear);

}

}

else if ($op=="upevent")

{

if ($DTCONFIG[1]==1) {

upevent($id,$title,$description,$location,$fee,$url,
$email,$cat,$scope,$bday,$bmonth,$byear,

$starttimehr,$starttimemin,$endtimehr,$endtimemin,$startperiod,
$endperiod,$notify,$idgroup); }

else {

upevent($id,$title,$description,$location,$fee,$url,$email,
$cat,$scope,$bday,$bmonth,$byear,

$starttimehr,$starttimemin,$endtimehr,$endtimemin,"--","--",
$notify,$idgroup); }

}

}



/****************************************/

/* Check for event entry in same time */

/****************************************/

function checkTimeEntry($eventid,$cat,$stime,$etime,$cday,$cmonth,
$cyear)

{

global $EVENTS_TB,$ALLOWVIEW;

$found = 0;

if ($ALLOWVIEW[9]==1) return 0;

if (($stime=="")&&($etime=="")) return 0 ;

$query = "select id,day,month,year,cat,starttime,endtime,approved
from ".$EVENTS_TB." where cat='".$cat."' and day='".$cday."' and
month='".$cmonth."' and year='".$cyear."' and approved=1 " ;

if ($ALLOWVIEW[10]==0)

$query = "select id,day,month,year,cat,starttime,endtime,approved
from ".$EVENTS_TB." where day='".$cday."' and month='".$cmonth."' and
year='".$cyear."' and approved=1 " ;



$result = mysql_query($query);

while ($row = mysql_fetch_object($result)) {

if (($eventid<>0)&&($row->id==$eventid)) continue ;

if ($stime!="") {

if (intval(substr($stime,0,2).substr($stime,3,2))>=intval(substr
($row->endtime,0,2).substr($row->endtime,3,2))) ;

elseif (($etime!="")&&

(intval(substr($etime,0,2).substr($etime,3,2))<=intval
(substr($row->starttime,0,2).substr($row->starttime,3,2)))) ;

elseif ($etime=="") {

if (intval(substr($stime,0,2).substr($stime,3,2))<intval(substr
($row->starttime,0,2).substr($row->starttime,3,2))) ;

else $found++;

}

else $found++ ;

}

}

return $found;

}



/****************/

/* Validation */

/****************/

function validationAdd($id,$title,$description,$cat,$fee,$repeat,$bday,
$bmonth,$byear,$fday,$fmonth,$fyear,$tday,$tmonth,$tyear,$stime,
$etime)

{

global $ALLOWVIEW;

$canadd = false;

if ((!$title)||(CheckTaboo($title)!='')) { echo "<div class=normalfont
align=center>".translate("notitle")."</div><br/>" ; back(); }

elseif ((!$description)||(CheckTaboo($description)!='')) { echo "<div
class=normalfont align=center>".translate("nodescription")."</div><br/
>" ; back(); }

elseif (!$cat) { echo "<div class=normalfont align=center>".translate
("nocat")."</div><br/>" ; back(); }

elseif (($ALLOWVIEW[7])&&($fee!="")&&(!is_numeric($fee))) {

echo "<div class=normalfont align=center>".translate("nofee")."</
div><br/>" ; back();

}

else if ($repeat=="one") {

if (!$bday) { echo "<div class=normalfont align=center>".translate
("noday")."</div><br/>" ; back(); }

elseif (!$bmonth) { echo "<div class=normalfont
align=center>".translate("nomonth")."</div><br/>"; back(); }

elseif (!$byear) { echo "<div class=normalfont
align=center>".translate("noyear")."</div><br/>"; back(); }

elseif (checkTimeEntry(0,$cat,$stime,$etime,$bday,$bmonth,$byear)>0)
{ echo "<div class=normalfont align=center>".translate("Events in
conflict")."</div><br/>"; back(); }

else $canadd = true ;

}

else if ($repeat=="more") {

if (!$fday) { echo "<div class=normalfont align=center>".translate
("noday")."</div><br/>" ; back(); }

elseif (!$fmonth) { echo "<div class=normalfont
align=center>".translate("nomonth")."</div><br/>"; back(); }

elseif (!$fyear) { echo "<div class=normalfont
align=center>".translate("noyear")."</div><br/>"; back(); }

elseif (!$tday) { echo "<div class=normalfont
align=center>".translate("noday")."</div><br/>" ; back(); }

elseif (!$tmonth) { echo "<div class=normalfont
align=center>".translate("nomonth")."</div><br/>"; back(); }

elseif (!$tyear) { echo "<div class=normalfont
align=center>".translate("noyear")."</div><br/>"; back(); }

elseif ((intval($tyear)<intval($fyear))||((intval($tyear)==intval
($fyear))&&(intval(date("z",mktime(0,0,0,$fmonth,$fday,$fyear)))
>=intval(date("z",mktime(0,0,0,$tmonth,$tday,$tyear)))))) { echo "<div
class=normalfont align=center>".translate("invaliddates")."</div><br/
>"; back() ; }

elseif (checkTimeEntry(0,$cat,$stime,$etime,$fday,$fmonth,$fyear)>0)
{ echo "<div class=normalfont align=center>".translate("Events in
conflict")."</div><br/>"; back(); }

else $canadd = true ;

}

return $canadd;

}



function validateUpdate($id,$title,$description,$cat,$fee,$bday,
$bmonth,$byear,$stime,$etime)

{

global $ALLOWVIEW;

$canadd = false;

$foundnum = 0;

if ((!$title)||(CheckTaboo($title)!='')) { echo "<div class=normalfont
align=center>".translate("notitle")."</div><br/>" ; back(); }

elseif ((!$description)||(CheckTaboo($description)!='')) { echo "<div
class=normalfont align=center>".translate("nodescription")."</div><br/
>" ; back(); }

elseif (!$cat) { echo "<div class=normalfont align=center>".translate
("nocat")."</div><br/>" ; back(); }

elseif (($ALLOWVIEW[7])&&($fee!="")&&(!is_numeric($fee))) {

echo "<div class=normalfont align=center>".translate("nofee")."</
div><br/>" ; back();

}

elseif (!$bday) { echo "<div class=normalfont align=center>".translate
("noday")."</div><br/>" ; back(); }

elseif (!$bmonth) { echo "<div class=normalfont
align=center>".translate("nomonth")."</div><br/>"; back(); }

elseif (!$byear) { echo "<div class=normalfont align=center>".translate
("noyear")."</div><br/>"; back(); }

elseif (checkTimeEntry($id,$cat,$stime,$etime,$bday,$bmonth,$byear)>0)
{

echo "<div class=normalfont align=center>".translate("Events in
conflict")."</div><br/>"; back();

}

else $canadd = true ;

return $canadd;

}



/***************/

/* Add Event */

/*********** ***/

function addevent($title,$description,$location,$fee,$email,$url,$cat,
$scope,$repeat,$bday,$bmonth,$byear,$rday,$rtimes,$rtype,

$starttimehr,$starttimemin,$endtimehr,$endtimemin,$startperiod,
$endperiod,$notify,$fday,$fmonth,$fyear,$tday,$tmonth,$tyear){

global $EVENTS_TB,$CAT_TB,$USER_TB,$APPR,$POPVIEW,$UVIEW,$DTCONFIG,
$MAILCFG,$CURRENCY,$ALLOWVIEW,$mth,$week,$copyevent,

$id,$PROTOCOL,$useFCKEditor;



$fee = trim($fee) ;

$goadd = false ;



echo $stime = '' ;

echo $etime = '' ;



if ($DTCONFIG[0]==0) {

if ($starttimehr!="--") {

if ($DTCONFIG[1]==1) {

$stime = convert12to24($starttimehr,$startperiod).":".
$starttimemin ;

}

else

$stime = $starttimehr.":".$starttimemin ;

}

if ($endtimehr!="--") {

if ($DTCONFIG[1]==1)

$etime = convert12to24($endtimehr,$endperiod).":".$endtimemin ;

else

$etime = $endtimehr.":".$endtimemin ;

}

}



// Validation

$goadd = validationAdd($id,$title,$description,$cat,$fee,$repeat,$bday,
$bmonth,$byear,$fday,$fmonth,$fyear,$tday,$tmonth,$tyear,$stime,
$etime);



if ($goadd) {

cacheEvent(true);

$title = addslashes($title);

if ($useFCKEditor) $description = addslashes($description);

else $description = addslashes(nl2br($description));

$location = addslashes($location);

// for compatibility with up to 1.4 version

if ((trim($url)<>"")&&(strtolower(substr($url,0,4))<>"http")) $url =
$PROTOCOL."://".$url;



$approve = !$APPR[0];

$nobody = '' ;

$insertuser = '';

if ($UVIEW[0]==1) {

if (isset($_SESSION["login"])) {

$insertuser = $_SESSION["login"] ;

$nobody = $insertuser ;

}

}

// else if (($UVIEW[0]==0)&&($UVIEW[1]==0)) $nobody = 'nobody';



// get the correct timezone offset for timestamping of event entries

$timestamp = correctTime("YmdHis") ;



// trim fee to make clean entry

$fee = trim($fee);



if ($repeat=="one") {

$query = "insert into ".$EVENTS_TB." values

(null,'$timestamp','$title','$description','$location','$url','$email','$cat','$stime','$etime','$bday','$bmonth','$byear','$approve','$fee','$scope','$insertuser','','')";

$result = mysql_query($query);

}



// Mail portion

if (($MAILCFG[0]==1)||($MAILCFG[2]==1)) {



$catquery = "select cat_name from ".$CAT_TB." where cat_id=$cat" ;

$catresult = mysql_query($catquery);

$catrow = mysql_fetch_object($catresult) ;



$mailhead = translate("Date").": ".$bday." ".$mth[$bmonth]." ".
$byear ;

$mailhead = $mailhead."\r\n".translate("From").": " ;

$mailhead = $mailhead.show12hour($stime) ;

$mailhead = $mailhead." ".translate("To").": " ;

$mailhead = $mailhead.show12hour($etime) ;

$mailhead = $mailhead."\r\n".translate("Category").": ".stripslashes
($catrow->cat_name) ;

if ($ALLOWVIEW[8]==1)

$mailhead = $mailhead."\r\n".translate("Location").": ".stripslashes
(stripslashes($location)) ;

$mailhead = $mailhead."\r\n".translate("Event Title").": ".stripslashes
(stripslashes($title)) ;

$mailhead = $mailhead."\r\n".translate("Event Description").": \r\n\r
\n" ;

if ($ALLOWVIEW[7]==1) {

$maildesc = "\r\n\r\n".translate("Fee").": ".$CURRENCY." ".$fee ;

$maildesc = $maildesc."\r\n".translate("Email").": ".$email ;

}

else $maildesc = "\r\n\r\n".translate("Email").": ".$email ;

$maildesc = $maildesc."\r\n".translate("More info").": ".$url ;

if ($repeat=="more") {

$maildesc = "\r\n\r\n".translate("Event repeated")." ".translate
("between")." " ;

$maildesc = $maildesc.$fday." ".$mth[$fmonth]." ".$fyear."
".translate("and")." " ;

$maildesc = $maildesc.$tday." ".$mth[$tmonth]." ".$tyear." " ;

if ($rtype==0) {

if ($rday==0)

$maildesc = $maildesc.translate("every")." ".$rtimes."
".translate("Day")." \r\n" ;

elseif ($rday<8)

$maildesc = $maildesc.translate("every")." ".$rtimes." ".$week
[$rday]." \r\n" ;

elseif ($rday==8)

$maildesc = $maildesc.translate("every")." ".$rtimes."
".translate("Month")." \r\n" ;

elseif ($rday==9)

$maildesc = $maildesc.translate("every")." ".$rtimes."
".translate("Year")." \r\n" ;

}

else {

switch ($rtype){

case 1: {

$maildesc = $maildesc.translate("every")." ".translate
("1st")." ".$week[$rday]." \r\n" ;

break; }

case 2: {

$maildesc = $maildesc.translate("every")." ".translate
("2nd")." ".$week[$rday]." \r\n" ;

break; }

case 3: {

$maildesc = $maildesc.translate("every")." ".translate
("3rd")." ".$week[$rday]." \r\n" ;

break; }

case 4: {

$maildesc = $maildesc.translate("every")." ".translate
("4th")." ".$week[$rday]." \r\n" ;

break; }

case 5: {

$maildesc = $maildesc.translate("every")." ".translate
("last")." ".$week[$rday]." \r\n" ;

break; }

default: {

$maildesc = $maildesc.translate("every")." ".$rtimes." ".
$week[$rday]." \r\n" ;

break; }

}

}

}

$mailrecpt = $MAILCFG[1] ;

if (trim($insertuser)!='') {

$mailquery = "select email from ".$USER_TB." where
username='$insertuser'" ;

$mailresult = mysql_query($mailquery);

$mailrow = mysql_fetch_object($mailresult) ;

if (mysql_num_rows($mailresult)>0) {

if (trim($mailrow->email)!="") $nobody = $mailrow->email ;

}

}





if ($MAILCFG[0]==1) {

mail($mailrecpt, "Event added - ".stripslashes(stripslashes
($title))." (".$bday." ".$mth[$bmonth]." ".$byear.") ",
$mailhead.stripslashes(stripslashes($description)).$maildesc,

"From: ".$nobody."\r\n"

."Reply-To: ".$nobody."\r\n");

}



$notify = trim($notify) ;

if (($MAILCFG[2]==1)&&($notify!="")) {

$mailrecpt = $notify ;

mail($mailrecpt, "Event added - ".stripslashes(stripslashes
($title))." (".$bday." ".$mth[$bmonth]." ".$byear.") ",
$mailhead.stripslashes(stripslashes($description)).$maildesc,

"From: ".$nobody."\r\n"

."Reply-To: ".$nobody."\r\n");

}

}



if ($repeat=="more"){

$rangeok = FALSE ;

$egrpid = uniqid(rand(),1); // event group id

if (($fday!=0)&&($fmonth!=0)&&($fyear!=0)&&($tday!=0)&&($tmonth!=0)
&&($tyear!=0)) $rangeok = TRUE ;

$repeatset = false ;

$rcount = intval($rtimes) ;

if (($rtype>0)&&($rangeok)) {

$monthset = FALSE ; // to flag if the current month has been
set

$inrange = FALSE ;

if (intval($tyear)>intval($fyear)) $inrange = TRUE ;

elseif ((intval($tyear)==intval($fyear))&&(intval(date("z",mktime
(0,0,0,$fmonth,$fday,$fyear)))<=intval(date("z",mktime(0,0,0,$tmonth,
$tday,$tyear))))) $inrange = TRUE ;



while ($inrange) {

// run through a day at a time until correct day found then flag
to set with repeatset

$mdate = date("d-m-Y", mktime(0,0,0,$fmonth,$fday,$fyear)) ;

$testday = intval(date("w",mktime(0,0,0,$fmonth,$fday,$fyear)))
+1;

$testmonth = intval(substr("$mdate",3,2));

if (substr("$testmonth",0,1) == "0")

$testmonth = str_replace("0","",$testmonth);

// 5 = repeat LAST day of month

if ($rtype==5 && $rday==$testday) {

if ((date("n", mktime(0,0,0,$fmonth,$fday+7,$fyear)))<>(date
("n", mktime(0,0,0,$fmonth,$fday,$fyear)))) {

$repeatset = true;

$monthset = TRUE; // to increment to next month for next
search

}

}

else if ($rtype<5 && $rday==$testday) {

$wkcnt = 1 ;

for ($i=4;$i>0;$i--) { // check which week number it is

if ((date("n", mktime(0,0,0,$fmonth,$fday-($i*7),$fyear)))==

(date("n", mktime(0,0,0,$fmonth,$fday,$fyear))))

$wkcnt++;

}

if ($wkcnt==$rtype) {

$monthset = TRUE ;

if ($fday<=($rtype*7)) { // ensure the first repeat is
set after 'from' range

$repeatset = true ;

}

}

}

if ($repeatset) {

$fday = substr("$mdate",0,2);

if (substr("$fday",0,1) == "0") $fday = str_replace("0","",
$fday);

$fmonth = substr("$mdate",3,2);

if (substr("$fmonth",0,1) == "0") $fmonth = str_replace("0","",
$fmonth);

$fyear = substr("$mdate",6,4);

$query = "insert into ".$EVENTS_TB." values
(null,'$timestamp','$title','$description','$location','$url','$email','$cat','$stime','$etime','$fday','$fmonth','$fyear','$approve','$fee','$scope','$insertuser','','$egrpid')";

$result = mysql_query($query);

$repeatset = false ;

}

if ($monthset) { // to go to next month if week number
exceeded

$monthset = FALSE ;

$fmonth++;

if ($fmonth>12) {

$fyear++;

$fmonth=1;

}

$fday = 0;

}

$fday++ ;

if (intval($tyear)>intval($fyear)) $inrange = TRUE ;

elseif ((intval($tyear)==intval($fyear))&&(intval(date("z",mktime
(0,0,0,$fmonth,$fday,$fyear)))<=intval(date("z",mktime(0,0,0,$tmonth,
$tday,$tyear))))) $inrange = TRUE ;

else $inrange = FALSE ;

} // end while ($inrange)

}

else if (($rday<8)&&($rangeok)) {

$inrange = FALSE ;

if (intval($tyear)>intval($fyear)) $inrange = TRUE ;

elseif ((intval($tyear)==intval($fyear))&&(intval(date("z",mktime
(0,0,0,$fmonth,$fday,$fyear)))<=intval(date("z",mktime(0,0,0,$tmonth,
$tday,$tyear))))) $inrange = TRUE ;

while ($inrange) {

// run through a day at a time until correct day found then flag
to set with repeatset

$mdate = date("d-m-Y", mktime(0,0,0,$fmonth,$fday,$fyear)) ;

if ($rday==0) {

if ($rcount==$rtimes) {

$repeatset = true ;

}

$rcount-- ;

if ($rcount==0) $rcount = $rtimes ;

}

else if ($rday==(intval(date("w",mktime(0,0,0,$fmonth,$fday,
$fyear)))+1)){

if ($rcount==$rtimes) {

$repeatset = true ;

}

$rcount-- ;

if ($rcount==0) $rcount = $rtimes ;

}

if ($repeatset) {

$fday = substr("$mdate",0,2);

if (substr("$fday",0,1) == "0"){

$fday = str_replace("0","",$fday);

}

$fmonth = substr("$mdate",3,2);

if (substr("$fmonth",0,1) == "0"){

$fmonth = str_replace("0","",$fmonth);

}

$fyear = substr("$mdate",6,4);

$query = "insert into ".$EVENTS_TB." values

(null,'$timestamp','$title','$description','$location','$url','$email','$cat','$stime','$etime','$fday','$fmonth','$fyear','$approve','$fee','$scope','$insertuser','','$egrpid')";

$result = mysql_query($query);

$repeatset = false ;

}

$fday++ ;

if (intval($tyear)>intval($fyear)) $inrange = TRUE ;

elseif ((intval($tyear)==intval($fyear))&&(intval(date("z",mktime
(0,0,0,$fmonth,$fday,$fyear)))<=intval(date("z",mktime(0,0,0,$tmonth,
$tday,$tyear))))) $inrange = TRUE ;

else $inrange = FALSE ;

}

}

elseif ($rangeok) {

$inrange = FALSE ;

if (intval($tyear)>intval($fyear)) $inrange = TRUE ;

elseif ((intval($tyear)==intval($fyear))&&(intval(date("z",mktime
(0,0,0,$fmonth,$fday,$fyear)))<=intval(date("z",mktime(0,0,0,$tmonth,
$tday,$tyear))))) $inrange = TRUE ;

$firstrep = TRUE ; // to allow from date range to be done first

$rcount = $rtimes ;

while ($inrange) {

$can = false ;

if ($rday==8) {

// add 1 month each time

if (!$firstrep) $fmonth++ ;

if ($rcount==$rtimes) {

$can = true ;

}

$rcount-- ;

if ($rcount==0) $rcount = $rtimes ;

if (!(date("t",mktime(0,0,0,$fmonth,1,$fyear))>=$fday)) $can =
false ; // to handle 29 February

}

elseif ($rday==9) {

// add 1 year each time

if (!$firstrep) $fyear++ ;

if ($rcount==$rtimes) {

$can = true ;

}

$rcount-- ;

if ($rcount==0) $rcount = $rtimes ;

}

if (intval($tyear)>intval($fyear)) $inrange = TRUE ;

elseif ((intval($tyear)==intval($fyear))&&(intval(date("z",mktime
(0,0,0,$fmonth,$fday,$fyear)))<=intval(date("z",mktime(0,0,0,$tmonth,
$tday,$tyear))))) $inrange = TRUE ;

else { $inrange = FALSE ; $can = false ; }

if ($can) {

$mdate = date("d-m-Y", mktime(0,0,0,$fmonth,$fday,$fyear)) ;

$fday = substr("$mdate",0,2);

if (substr("$fday",0,1) == "0"){

$fday = str_replace("0","",$fday);

}

$fmonth = substr("$mdate",3,2);

if (substr("$fmonth",0,1) == "0"){

$fmonth = str_replace("0","",$fmonth);

}

$fyear = substr("$mdate",6,4);

if ((intval(correctTime("Y"))+$DTCONFIG[5])<(intval
($fyear))) break ;

$query = "insert into ".$EVENTS_TB." values

(null,'$timestamp','$title','$description','$location','$url','$email','$cat','$stime','$etime','$fday','$fmonth','$fyear','$approve','$fee','$scope','$insertuser','','$egrpid')";

$result = mysql_query($query);

}

$firstrep = FALSE ;

}

}

}



if ($APPR[0]==1) {

echo "<div class=normalfont align=center>".translate
("thankyou")."<br/><br/>";

}

else {

echo "<div class=normalfont align=center>".translate
("thankyoupost")."<br/><br/>";

}



if (($copyevent)&&($POPVIEW[0]==1)) {

echo "<br/><a class=menufont href=\"Javascript:void(0);\"
onclick='Javascript:self.window.close
();top.opener.window.location.href=\"cal_popup.php?reload=y&op=view&id=
$id\";'>".translate("Close")."</a></div>\n" ;


}

else echo "<br/><a class=menufont href=\"Javascript:void(0);\"
onclick='Javascript:self.window.close
();top.opener.window.location.reload();'>".translate("Close")."</a></
div>\n" ;


}

ob_end_flush(); // to enable cookie resetting

echo "<p align=\"center\"> QUE ES </P>";
echo " <div class=normalfont >El Calendario Hispano de Eventos
Abiertos es una iniciativa sin animo de lucro para ayudar a difundir
los eventos que sobre software libre, open source y conocimiento
abierto se celebran en mundo hispano<br><br></div>";

echo "<p align=\"center\"> QUE DIFUSIÓN TENDRÁS </P>";
echo "<div class=normalfont>La informacion de eventos que se nos
envia (ya hemos superado los 1000 eventos registrados, en 21 paises)
se retransmite a traves de cualquiera de los <a href=\"http://
libroblanco.com/cms/index.php/Red-Calendarios/Red-Calendarios/
\">calendarios</a> que incluyen mas de 80 webs , los casi 200
suscriptores del usuario de twitter <a href=\"http://www.twitter.com/
eventosabiertos\">eventosabiertos</a>, a traves de un <a href=\"http://
www.libroblanco.com/cms/index.php/Google-calendar.html\">google
calendar</a> y en la <a href=\"http://libroblanco.com\">página</a></
div> ";

echo "<p align=\"center\"> AYUDANOS A MEJORAR </P>";
echo "<div class=normalfont >Cualquier comentario o sugerencia
sobre nuestra pagina o como podriamos ayudar envianos un correo a <A
href=\"mailto:webm...@libroblanco.com\">webmaster @ libroblanco.com</
a></div>";

echo "<p align=\"center\"> PON ESTOS EVENTOS EN TU WEB</P>";
echo "<div class=normalfont align=center>Finalmente existe la
posibilidad de incluir el calendario en una página web o blog con esta
linea de javascript<br>";
echo "<b>&lt;script type='text/javascript'\" src='http://
www.libroblanco.com/calendario/calenjs.php'> <script&gt;</b></div>";

echo "<p align=\"center\"> QUE CRITERIOS HAN DE CUMPLIR LOS
EVENTOS </P>";
echo " <div class=normalfont >Los criterios de inclusión en este
calendario son (a cumplir todos ellos): <br>";
echo "1. Deben ser eventos presenciales relacionados con
tecnologias abiertas (P.e. Software libre, software de fuentes
abiertas, conocimientos libres, hardware libre, etc)<br>";
echo "2. Deben tener un sitio en internet donde se refleje la
actividad a realizar<br>";
echo "3. Deben ser públicos o tener interés para el público y de
asistencia gratuita o de coste simbólico.<br>";
echo "4. Deben tener como idioma principal el español o ser de
interés para la comunidad hispanohablante.</div>";


}



/****************/

/* update event */

/****************/



function upevent($id,$title,$description,$location,$fee,$url,$email,
$cat,$scope,$bday,$bmonth,$byear,

$starttimehr,$starttimemin,$endtimehr,$endtimemin,$startperiod,
$endperiod,$notify,$idgroup){

global $EVENTS_TB,$CAT_TB,$USER_TB,$DTCONFIG,$MAILCFG,$CURRENCY,
$ALLOWVIEW,$POPVIEW,$mth,$PROTOCOL,$useFCKEditor ;



$title = addslashes($title);

if ($useFCKEditor) $description = addslashes($description);

else $description = addslashes(nl2br($description));

$location = addslashes($location);

// for compatibility with up to 1.4 version

if ((trim($url)<>"")&&(strtolower(substr($url,0,4))<>"http")) $url =
$PROTOCOL."://".$url;



// get the correct timezone offset for timestamping of event entries

$timestamp = correctTime("YmdHis") ;



$query = "update ".$EVENTS_TB." set
timestamp='$timestamp',title='$title',description='$description',location='$location',fee='$fee',url='$url',email='$email',cat='$cat',priority='$scope'
";

if ($idgroup=="") $query =
$query.",day='$bday',month='$bmonth',year='$byear' " ;



echo $stime = '' ;

echo $etime = '' ;



if ($DTCONFIG[0]==0) {

if ($starttimehr!="--") {

if ($DTCONFIG[1]==1) {

$stime = convert12to24($starttimehr,$startperiod).":".
$starttimemin ;

$query = $query.",starttime='".convert12to24($starttimehr,
$startperiod).":".$starttimemin."' " ;

}

else {

$stime = $starttimehr.":".$starttimemin ;

$query = $query.",starttime='".$starttimehr.":".$starttimemin."'
" ;

}

}

else { $query = $query.",starttime='' " ; }

if ($endtimehr!="--") {

if ($DTCONFIG[1]==1) {

$etime = convert12to24($endtimehr,$endperiod).":".$endtimemin ;

$query = $query.",endtime='".convert12to24($endtimehr,
$endperiod).":".$endtimemin."' " ;

}

else {

$etime = $endtimehr.":".$endtimemin ;

$query = $query.",endtime='".$endtimehr.":".$endtimemin."' " ;

}

}

else { $query = $query.",endtime='' " ; }

}

else {

$query = $query.",starttime='' ".",endtime='' " ; }



if ($idgroup=="")

$query = $query." where id='$id'";

else

$query = $query." where idgroup='$idgroup'";



// Validation

//$goadd = false ;

$goadd = validateUpdate($id,$title,$description,$cat,$fee,$bday,
$bmonth,$byear,$stime,$etime);

if ($goadd)

{

cacheEvent(true);

$result = mysql_query($query);

if ($starttimehr!="--") {

$startdatetime = date ("Y-m-d H:i:s",mktime(intval(convert12to24
($starttimehr,$startperiod)),intval($starttimemin),0,intval
($bmonth),intval($bday),intval($byear)));

remupdate($id,$startdatetime);

}

}

else

exit();



// Mail portion

if ($MAILCFG[2]==1) {



$catquery = "select cat_name from ".$CAT_TB." where cat_id=$cat" ;

$catresult = mysql_query($catquery);

$catrow = mysql_fetch_object($catresult) ;



$mailhead = translate("Date").": ".$bday." ".$mth[$bmonth]." ".
$byear ;

$mailhead = $mailhead."\r\n".translate("From").": " ;

$mailhead = $mailhead.show12hour($stime) ;

$mailhead = $mailhead." ".translate("To").": " ;

$mailhead = $mailhead.show12hour($etime) ;

$mailhead = $mailhead."\r\n".translate("Category").": ".stripslashes
($catrow->cat_name) ;

if ($ALLOWVIEW[8]==1)

$mailhead = $mailhead."\r\n".translate("Location").": ".stripslashes
(stripslashes($location)) ;

$mailhead = $mailhead."\r\n".translate("Event Title").": ".stripslashes
(stripslashes($title)) ;

$mailhead = $mailhead."\r\n".translate("Event Description").": \r\n\r
\n" ;

if ($ALLOWVIEW[7]==1) {

$maildesc = "\r\n\r\n".translate("Fee").": ".$CURRENCY." ".$fee ;

$maildesc = $maildesc."\r\n".translate("Email").": ".$email ;

}

else $maildesc = "\r\n\r\n".translate("Email").": ".$email ;

$maildesc = $maildesc."\r\n".translate("More info").": ".$url ;



$nobody = '' ;

if (isset($_SESSION["login"]))

$nobody = $_SESSION["login"] ;

$notify = trim($notify) ;

if (($MAILCFG[2]==1)&&($notify!="")) {

$mailquery = "select email from ".$USER_TB." where
username='$nobody'" ;

$mailresult = mysql_query($mailquery);

$mailrow = mysql_fetch_object($mailresult) ;

if (mysql_num_rows($mailresult)>0) {

if (trim($mailrow->email)!="") $nobody = $mailrow->email ;

}

$mailrecpt = $notify ;

mail($mailrecpt, "Event updated - ".stripslashes(stripslashes
($title))." (".$bday." ".$mth[$bmonth]." ".$byear.") ",
$mailhead.stripslashes(stripslashes(strip_tags
($description,'<a><b><i><u><img>'))).$maildesc,

"From: ".$nobody."\r\n"

."Reply-To: ".$nobody."\r\n");

}

}



echo "<script language=\"JavaScript\">\n" ;

echo "<!--\n" ;

if ($POPVIEW[0]==1)

echo "self.window.close();top.opener.window.location.href=
\"cal_popup.php?reload=y&op=view&id=$id\";\n" ;

else

echo "self.window.close();top.opener.window.location.reload();
\n" ;

echo "</script>\n" ;

}



?>

</body>

</html>

Alfonso Moratalla

unread,
Oct 14, 2009, 4:29:10 AM10/14/09
to libro...@googlegroups.com
Es mucho codigo y no he podido revisarlo bien, aunque parece que no
filtra muy bien las variables del post y pueda haber algun sql
injection o se salte algunas restricciones.

Pero antes de analizarlo mas en profundidad creo que se deberia probar
a actualizarlo, estan disponibles las versiones 1.8.20081228 (de pago)
y 0.8.20080808 (basico), que lo mismo ya de por si han corregido estos
fallos.

Un saludo,

Alfonso Moratalla

2009/10/14 webmaster libroblanco <alberto...@gmail.com>:

alberto

unread,
Oct 14, 2009, 8:33:05 AM10/14/09
to libro...@googlegroups.com
El mié, 14-10-2009 a las 10:29 +0200, Alfonso Moratalla escribió:
Es mucho codigo y no he podido revisarlo bien, aunque parece que no
filtra muy bien las variables del post y pueda haber algun sql
injection o se salte algunas restricciones.
parece que hace un post con los datos de variables que el spammer quiere, pero no le hecha al no venir del fichero adecuado.

¿Se puede poner un código en el fichero de forma que si no es llamado por uno en concreto lo mande al güano?



Pero antes de analizarlo mas en profundidad creo que se deberia probar
a actualizarlo, estan disponibles las versiones 1.8.20081228 (de pago)
y 0.8.20080808 (basico), que lo mismo ya de por si han corregido estos
fallos.

Muchas gracias alfonso, pero es la versión de pago del 20080808 lo que el fichero es el mismo. ;-D

Igor Zubiaurre

unread,
Oct 14, 2009, 9:25:36 AM10/14/09
to libro...@googlegroups.com
El 14 de octubre de 2009 14:33, alberto <webmasterl...@gmail.com> escribió:
El mié, 14-10-2009 a las 10:29 +0200, Alfonso Moratalla escribió:
¿Se puede poner un código en el fichero de forma que si no es llamado por uno en concreto lo mande al güano?
Si las llamadas son públicas no tardará en re-descubrirlo. ¿Se ejecuta todo en un solo paso? ¿Si no es así se podría poner un control en php que no se vea en el html?
 
¿Cual es problema exáctamente? ¿Qué hace el spammer? ¿Sobrecargar la lista de eventos pendientes de aprobar? ¿?
Pero antes de analizarlo mas en profundidad creo que se deberia probar
a actualizarlo, estan disponibles las versiones 1.8.20081228 (de pago)
y 0.8.20080808 (basico), que lo mismo ya de por si han corregido estos
fallos.
Muchas gracias alfonso, pero es la versión de pago del 20080808 lo que el fichero es el mismo. ;-D
 
Revísalo porque no cuadran las fechas: agosto vs diciembre

Alfonso Moratalla

unread,
Oct 14, 2009, 11:03:46 AM10/14/09
to libro...@googlegroups.com
2009/10/14 alberto <webmasterl...@gmail.com>:
> El mié, 14-10-2009 a las 10:29 +0200, Alfonso Moratalla escribió:
>
> Es mucho codigo y no he podido revisarlo bien, aunque parece que no
> filtra muy bien las variables del post y pueda haber algun sql
> injection o se salte algunas restricciones.
>
> parece que hace un post con los datos de variables que el spammer quiere,
> pero no le hecha al no venir del fichero adecuado.
>
> ¿Se puede poner un código en el fichero de forma que si no es llamado por
> uno en concreto lo mande al güano?
>

Si claro, si se esta saltando el captcha o es porque es capaz de
resolverlo o estan mandando directamente la peticion a la pagina
siguiente, que como es conocida sera lo mas probable.

Tocando un pelin el codigo hay muchas formas de evitar que el spam se
cuele, sobretodo porque dejaria de ser el codigo original que es el
que conocen. Si tuviera acceso a los ficheros puedo hacerlo en un
momento, es que en la web solo puedes bajar el basico.

>
> Pero antes de analizarlo mas en profundidad creo que se deberia probar
> a actualizarlo, estan disponibles las versiones 1.8.20081228 (de pago)
> y 0.8.20080808 (basico), que lo mismo ya de por si han corregido estos
> fallos.
>
> Muchas gracias alfonso, pero es la versión de pago del 20080808 lo que el
> fichero es el mismo. ;-D
>

Vi 2007 en el fichero que pegaste y pense que seria esa version.

alberto

unread,
Oct 14, 2009, 11:20:20 AM10/14/09
to libro...@googlegroups.com
te adjunto los dos ficheros de marras.

El cal_addevent_new.php es el que registra el evento y el cal_postevent.php el que lo debe de grabar cuando es llamado con las opciones op=addevent&copyevent=0.

thanks
cal_addevent_new.php
cal_postevent.php

Alfonso Moratalla

unread,
Oct 14, 2009, 12:12:50 PM10/14/09
to libro...@googlegroups.com
Ya he encontrado por donde entran, el captcha funciona ocultando el
boton de enviar y hasta que no pulsamos el check con el resultado
correcto no lo muestra, pero el codigo esta ahi con visibility:hidden
que es ignorado por los bot y ejecutan el submit tal cual.

Voy a implementar algo sencillo que compruebe el captcha en el otro
fichero al recibir la peticion y solucionado.

Ahora en un rato lo mando.

Un saludo,

Alfonso Moratalla

2009/10/14 alberto <webmasterl...@gmail.com>:

Alfonso Moratalla

unread,
Oct 14, 2009, 1:34:58 PM10/14/09
to libro...@googlegroups.com
2009/10/14 alberto <webmasterl...@gmail.com>:

> te adjunto los dos ficheros de marras.
>
> El cal_addevent_new.php es el que registra el evento y el cal_postevent.php
> el que lo debe de grabar cuando es llamado con las opciones
> op=addevent&copyevent=0.
>
> thanks


He puesto el tipico token para comprobar la peticion y aunque se puede hacer de mil formas lo he hecho de tal manera que la web externamente siguiera exactamente igual.

Los cambios que hay que hacer, en cal_addevent_new.php:

Modificar la funcion del captcha para que los valores de a y b los tengamos disponibles en la parte de PHP y al input ponerle un name para que lo envie junto con el formulario, los cambios van en negrita asi que puedes usar lo que no esta en negrita para buscar donde hay que insertar el codigo, no mando los ficheros enteros para que no haya duda de si he tocado otra parte y porque los he tenido que modificar para ejecutarlos en local para probar el tema:

<script type="text/javascript">
   <?php
         $a = rand(1,9);
         $b = rand(1,9);
   ?>


   var a = <?php echo $a; ?>;
   var b = <?php echo $b; ?>;
   var c = a + b
   function DrawBotBoot()
   {
       document.write("¿Cuanto es "+ a + " + " + b +"? ");
       document.write("<input id='BotBootInput' name='BotBootInput' type='text' maxlength='2' size='2'/>");
   }
   function ValidBotBoot(){
       var d = document.getElementById('BotBootInput').value;
       if (d == c) return true;........
       return false;
    }
</script>

Y al final del todo:

if (!$edit) {

$clave = "qwerty123456"; // cambiar a algo igual o mas largo y secreto
$captcha = $a + $b;
$token = sha1($clave.$captcha);
echo "<input type=\"hidden\" name=\"token\" value=\"$token\">";


echo "Adivina la suma y aparecerá el botón para enviar el evento<br />"

Y en el fichero cal_postevent.php:

$clave = "qwerty123456"; // la misma que en el otro fichero
$input = $_POST['BotBootInput'];
$token = $_POST['token'];

if ($token != sha1($clave.$input)) { die(); }


include_once ("cal_utils.php") ;
include_once ("cal_taboo.php") ;

Con eso debe bastar para mantener a los bot alejados, es la forma mas simple a obligar a calcular el captcha correctamente ya que calcular el token es mas dificil, pero la seguridad sigue residiendo en el captcha nada mas.

Se le pueden hacer muchas mejoras como sacar la clave a un fichero externo, añadir un include o sustituir ese die por escribir en un registro las peticiones fallidas para revisarlas o pasar el token por session para evitar que reenvien resultados conocidos de captcha/token ... no se, le puedo echar otro rato un dia si quereis añadir algo mas, pero dudo que nadie se moleste en programar los bot para que funcione solo con este formulario.

Un saludo,

Alfonso Moratalla

alberto

unread,
Oct 15, 2009, 9:50:35 AM10/15/09
to libro...@googlegroups.com
muchísimas gracias, esta misma noche voy a ver si lo implemento en el site.

THANKS
THANKS

alberto

unread,
Oct 16, 2009, 8:26:41 PM10/16/09
to libro...@googlegroups.com
Gracias Alfonso, ya está implementado, funciona perfecto, ahora solo hace falta que no nos encuentren otro hueco por donde colarnos spam.

thanks


Reply all
Reply to author
Forward
0 new messages