moubik Posted October 18, 2007 Report Share Posted October 18, 2007 am implementat intr-un site aceste functii.functie ce poate fi folosita la filtrare impotriva xss.daca observa ca unul dintre caracterele 'evil' a fost filtrat face si logare.function filterCross($filterMe){ $tempMe = $filterMe; $filterMe = str_replace("<", "<", $filterMe); $filterMe = str_replace(">", ">", $filterMe); $filterMe = str_replace("(", "(", $filterMe); $filterMe = str_replace(")", ")", $filterMe); $filterMe = str_replace("#", "#", $filterMe); $filterMe = str_replace("&", "&", $filterMe); $filterMe = str_replace("\"", "", $filterMe); $filterMe = str_replace("\'", "", $filterMe); if (strcmp($tempMe,$filterMe)) { logHacker(); } return $filterMe;}functia care log-eaza request-ul unui user, preferabil hacker:function logHacker(){ $link = mysql_real_escape_string($_SERVER['PHP_SELF']); $useragent = mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']); $referrer = mysql_real_escape_string(getenv ('HTTP_REFERER')); $ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']); $env = mysql_real_escape_string(var_export($_ENV, true)); $cookie = mysql_real_escape_string(var_export($_COOKIE, true)); $get = mysql_real_escape_string(var_export($_GET, true)); $post = mysql_real_escape_string(var_export($_POST, true)); $session = mysql_real_escape_string(var_export($_SESSION, true)); $globals = mysql_real_escape_string(var_export($GLOBALS, true)); $date = time(); $queryInsertHacker = "INSERT INTO hackers " ."(link, useragent, referrer, ip, env, cookie, get, post, session, globals, date) " ."VALUES ('".$link."', '".$useragent."', '".$referrer."', '".$ip."', '".$env."', '".$cookie."', '".$get."', '".$post."'," ."'".$session."', '".$globals."', '".$date."')"; mysql_query($queryInsertHacker);}sql pentru crearea tabelei 'hackers'CREATE TABLE IF NOT EXISTS `hackers` ( `ID` bigint(20) NOT NULL auto_increment, `link` text NOT NULL, `useragent` text NOT NULL, `referrer` text NOT NULL, `ip` varchar(15) NOT NULL default '', `env` longtext NOT NULL, `cookie` longtext NOT NULL, `get` longtext NOT NULL, `post` longtext NOT NULL, `session` longtext NOT NULL, `globals` longtext NOT NULL, `date` bigint(20) NOT NULL, PRIMARY KEY (`ID`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=151 ;ca sa scapi de sql inject poti sa faci:$_GET = array_map("mysql_real_escape_string", $_GET);$_POST = array_map("mysql_real_escape_string", $_POST);ca sa folositi functia filterCross pe tot $_GET si $_POST puteti sa faceti:$_GET = array_map("filterCross", $_GET);$_POST = array_map("filterCross", $_POST);sau doar pentru o variabila:$variabila = filterCross($variabila);deci este atat de simplu.bineinteles, uneori vrei sa fie lasate unele caractere sa treaca Quote Link to comment Share on other sites More sharing options...
michee Posted October 25, 2007 Report Share Posted October 25, 2007 intrebare:Nu e suficient daca in functia crossFilter faci doar un strip_tags?Fara acele str_replace-uri?Intreb si eu sunt mai incepator... Quote Link to comment Share on other sites More sharing options...
moubik Posted October 25, 2007 Author Report Share Posted October 25, 2007 si eu sunt tot incepator, dar din testele pe care le-am facut eu strip_tags nu te-ar scapa de"+onmouseover="javascript:alert(1)"+ Quote Link to comment Share on other sites More sharing options...
michee Posted October 25, 2007 Report Share Posted October 25, 2007 stai putin ca nu inteleg ce-i cu + -urile alea.in ce context ar veni asta? Quote Link to comment Share on other sites More sharing options...
moubik Posted October 25, 2007 Author Report Share Posted October 25, 2007 poti sa faci xss cu onmouseovervezi ca am postat unul aici.http://rstcenter.com/forum/post47984.rst#47984 Quote Link to comment Share on other sites More sharing options...
michee Posted October 26, 2007 Report Share Posted October 26, 2007 m-am uitat dar nu mai merge...daca am inteles eu bine....modifici ce e in interior-ul unui tag <input......... >folosind js? Adik + -ul acela e operatorul de concatenare?si folosind-ul inchizi value="" (cu ghilemelee care le adaugi tu) si apoi adaugi xss-ul cu onmouseover...?am inteles bine? Quote Link to comment Share on other sites More sharing options...
moubik Posted October 26, 2007 Author Report Share Posted October 26, 2007 cred ca ai inteles bine vezi ca inca merge xss-ul ala trebuie sa-l deschizi cu un browser care stie javascript (firefox, opera, ie) si sa duci mouse-ul deasupra obiectului modificat.in cazul acesta, chiar casuta de editare.incearca, si uite-te la sursa, fa teste, o sa simti mai bine vulnerabilitatea asta Quote Link to comment Share on other sites More sharing options...
michee Posted October 28, 2007 Report Share Posted October 28, 2007 i'm back:)se pare ca nu merge pf FF 2.0.0.8 xss-ul ala cu onmouseover.....pe IE 6.0 XP cu sp2 mi-a mers......e al 2lea xss postat pe aici ca nu merge pe FF 2.0.0.8, dupa cel cu paypal postat recent de nemessis....ps:m-am uitat in sursa paginii la FF si vad ceva de genul<input name="textfield" type="text" class="prettysearch" value="" onmouseover "javascript alert 1 " "" style="width:330px;">se pare ca FF face strip automat la (), <>, :,= .... gresesc cu ceva? Nu a mai patit nimeni? Quote Link to comment Share on other sites More sharing options...
michee Posted October 28, 2007 Report Share Posted October 28, 2007 si tot nu inteleg ce este cu acel + din atack....daca rolul lui este purs si simplu de a delimita ultima " de la value de onmouseover la fel de bine poti folosit spatiu(%20) ca de exemplu.http://search.dir.bg/index.php?Cat=0&Forum=All_Forums&Match=Entire%20Phrase&Old=allposts&textfield="%20onmouseover="javascript:alert(1)">&x=0&y=0Am eliminat o mare parte din link deoarece celelalte input-uri am observat ca iau aceeasi valoare din textinput, inainte de a se da submit la forma printr-o functie submit.ps: Am descoperit de ce nu mergea pe FF 2.0.0.8 la mine. Se pare ca de la extensia NOSCRIPT care are rolul de a proteja de atacurile XSS:)......se pare ca era setata sa sanitizeze automat requesturile dubioase. Deci ca tot vorbeam de metode de protectie asupra XSS....cred ca ar merge si aceasta extensie NOSCRIPT. Quote Link to comment Share on other sites More sharing options...
moubik Posted December 7, 2007 Author Report Share Posted December 7, 2007 da, dar vezi tu, noscript e la nivel de user. in site tot apar xssurile.(sorry for bumping) Quote Link to comment Share on other sites More sharing options...