Phorum.ro
Your Avatar Welcome to Phorum.ro!
If you haven't registered yet, click here!
Attention Visitor:
You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Du-te înapoi   Phorum.ro > Web Design & Web Development > Baze de date > MS SQL

MS SQL Programand in Microsoft(tm) SQL Server.

Răspunde
 
Thread Tools Moduri de afișare
Vechi 16.10.2006   #1
Tavicu
Beat in post!
 
Tavicu's Avatar
 
Data înregistrării: 26.11.2005
Mesaje: 321
Rep Power: 5
Tavicu is on a distinguished road
Trimite un mesaj prin Yahoo pentru Tavicu
Implicit Anti sql inject

Am cautat azi pe net un script care sa te protejeze inpotriva sql inject si m-am gandit sa postez si aici pentru ca poate aveti si voi probleme sau poate chiar va intereseaza

In primul rand avem pagina unde este input-ul care arata ceva de genu:
Cod:
    <form method="post" action="test.php"> 
    <input type="text" name="search" /> 
    <input type="submit" value="ok" /> 
    </form>

Al 2-lea fisier se numeste test.php care contine urmatorul script:

Cod:
function anti_injection( $search ) 
{ 


    $banlist = array 
        ( 
        "insert", "select", "update", "delete", "distinct", "having", "truncate", "replace", 
        "handler", "like", "as", "or", "procedure", "limit", "order by", "group by", "asc", "desc" 
        ); 

    if ( eregi ( "[a-zA-Z0-9]+", $search ) ) 
    { 
        $user = trim ( str_replace ( $banlist, '', strtolower ( $search ) ) ); 
    } 
    else 
    { 
        $user = NULL; 
    } 


    $array = array ( 'search' => $search ); 

    if ( in_array ( NULL, $array ) ) 
    { 
        die ( 'Hacking attempt. Go play someplace else, you script kiddie.' ); 
    } 
   else 
    { 
        return $_POST['search']; 
    } 
} 





print anti_injection ( $_POST['search'] );

Repet ...scriptul nu este facut de catre mine ci doar modificat


sper sa va fie de folos
Tavicu is offline   Reply With Quote
Sponsored Links
Vechi 10.10.2009   #2
tudalex
8-Bit Member
 
Data înregistrării: 25.10.2005
Mesaje: 6
Rep Power: 5
tudalex is on a distinguished road
Implicit

Misto scriptul ma gandeam sa imi scriu si eu unu. Desi cred ca ar fi prudent sa banezi si restu functiilor MSSQL (sau MySQL daca e folosit). Si totusi consider necesar ca dupa ce faci toate astea sa mai adaugi si mysql_escape_string() pe variabila returanata. Cel putin asa vei fi sigur ca nici un sql injection nu e posibil.
tudalex is offline   Reply With Quote
Vechi 11.10.2009   #3
Niku
16-Bit Member
 
Data înregistrării: 08.09.2005
Mesaje: 12
Rep Power: 5
Niku is on a distinguished road
Implicit

Si daca ai formularul de search la un site de programare, unde 100% userii trebuie sa caute despre insert, select, delete etc ce faci ?

Cred ca mysql_escape_string() isi face treaba bine, poate si o conditie sa citeasca numai litere si cifre .
Niku is offline   Reply With Quote
Vechi 11.10.2009   #4
Tavicu
Beat in post!
 
Tavicu's Avatar
 
Data înregistrării: 26.11.2005
Mesaje: 321
Rep Power: 5
Tavicu is on a distinguished road
Trimite un mesaj prin Yahoo pentru Tavicu
Implicit

Citat:
În prealabil postat de Adm1nuL
Si daca ai formularul de search la un site de programare, unde 100% userii trebuie sa caute despre insert, select, delete etc ce faci ?

Cred ca mysql_escape_string() isi face treaba bine, poate si o conditie sa citeasca numai litere si cifre .
asta e ce gasisem si eu pe net la vremea aia ...
Tavicu is offline   Reply With Quote
Vechi 11.10.2009   #5
Niku
16-Bit Member
 
Data înregistrării: 08.09.2005
Mesaje: 12
Rep Power: 5
Niku is on a distinguished road
Implicit

Eh nu m-am mai uitat la data la care ai postat tu )))
Niku is offline   Reply With Quote
Vechi 23.11.2009   #6
paul alexandru
16-Bit Member
 
Data înregistrării: 17.11.2009
Mesaje: 26
Rep Power: 1
paul alexandru is on a distinguished road
Implicit haha

si eu m-am uitat
paul alexandru is offline   Reply With Quote
Vechi 23.02.2010   #7
skreach
1024-Bit Member
 
skreach's Avatar
 
Data înregistrării: 10.11.2005
Locație: Constanța
Mesaje: 1.376
Rep Power: 10
skreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud of
Implicit

Cand o sa ajung la birou o sa va dau o functie pentru anti-sql injection, e destul de simpla.
skreach is offline   Reply With Quote
Vechi 26.02.2010   #8
skreach
1024-Bit Member
 
skreach's Avatar
 
Data înregistrării: 10.11.2005
Locație: Constanța
Mesaje: 1.376
Rep Power: 10
skreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud ofskreach has much to be proud of
Implicit

Cod:
function sql($sql) {
   $sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$sql);
   $sql = trim($sql);
   $sql = strip_tags($sql);
   $sql = addslashes($sql);
   return $sql;
}
Exemplu:
Cod:
sql($_POST['variabila']);

Last edited by skreach; 01.03.2010 at 03:38:56.
skreach is offline   Reply With Quote
Răspunde


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Moduri de afișare

Reguli de postare
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Pornit
emoticoanele sunt Pornit
Codul [IMG] este Pornit
Codul HTML este Oprit

Sări la...


Ora este GMT +3. Ora este acum 08:42:43.


Rulează cu: vBulletin Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Forum SEO by Zoints

XXXXXXXXXXXXXXXXXXX
Inactive Reminders By Icora Web Design