SQL Injection

Gestart doorDylan10 reacties90 weergaven

11 berichten · pagina 1 van 1

Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Hoi.
Ik heb dit:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] filter[COLOR= #007700]([/COLOR][COLOR= #0000BB]$var[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/get_magic_quotes_gpc"]get_magic_quotes_gpc[/URL][COLOR= #007700]()) {[/COLOR]
        [COLOR= #0000BB]$var[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$var[/COLOR][COLOR= #007700]);
    }[/COLOR]
    [URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR]htmlspecialchars[COLOR= #007700]([/COLOR][COLOR= #0000BB]$var[/COLOR][COLOR= #007700])));
}[/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]".."[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"//"[/COLOR][COLOR= #007700], ..[/COLOR][COLOR= #DD0000]") or die(mysql_error());
mysql_select_db("[/COLOR][COLOR= #FF8000]//") or die(mysql_error());[/COLOR]


[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR][COLOR= #007700].[/COLOR]filter[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR][COLOR= #007700].[/COLOR]filter[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
?>


URL: http://localhost/sql.php?id=6
Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 6 at line 1


nu is SQL injection gewoon mogelijk? Terwijl filter() wel erbij staat?
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Localhost kunnen wij niet bekijken emo
Wrm striptags en htmlspecialchars? Striptags haalt alle html dingen weg.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Sevvlor schreef:
Localhost kunnen wij niet bekijken emo
Wrm striptags en htmlspecialchars? Striptags haalt alle html dingen weg.
HTML dingen weg halen is voor XSS.
En van localhost, heb je een ideetje wat ik achter ?id= heb gezet
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Dylanh schreef:
Eerdere citaten tonen
Sevvlor schreef:
Localhost kunnen wij niet bekijken emo
Wrm striptags en htmlspecialchars? Striptags haalt alle html dingen weg.

HTML dingen weg halen is voor XSS.
En van localhost, heb je een ideetje wat ik achter ?id= heb gezet
Je doet het nu dubbel.... Htmlspecialchars heeft nu geen functie, ook moet je die pas gebruiken bij het echoën

toevoeging op 19 juli 2012, 12:42:46:
Zet de connect eens boven de functie.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"x"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"x"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"x"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"x"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());
function[/COLOR] filter[COLOR= #007700]([/COLOR][COLOR= #0000BB]$var[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/get_magic_quotes_gpc"]get_magic_quotes_gpc[/URL][COLOR= #007700]()) {[/COLOR]
        [COLOR= #0000BB]$var[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$var[/COLOR][COLOR= #007700]);
    }[/COLOR]
    [URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR]htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$var[/COLOR][COLOR= #007700]));
}[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR][COLOR= #007700].[/COLOR]filter[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR][COLOR= #007700].[/COLOR]filter[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
?>


mysql_real_escape_string werkt gewoon niet?
0
Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
dan moet je addslashes gebruiken
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
addslashes() is onnodig, je helpt daarmee je data om zeep.

toevoeging op 19 juli 2012, 15:38:37:

[COLOR= #0000BB]<?php
$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
?>


Zo, dat is beter....
Voor de rest mag je zelf fatsoenlijke foutafhandeling toevoegen....
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Aarclay schreef:
addslashes() is onnodig, je helpt daarmee je data om zeep.
toevoeging op 19 juli 2012, 15:38:37:

[COLOR= #0000BB]<?php
$result[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
?>


Zo, dat is beter....
Voor de rest mag je zelf fatsoenlijke foutafhandeling toevoegen....

Dus ik kan de functie filter() niet gebruiken?sadley
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Ik vind het onnodig.... je kan het anders direct in je code toepassen na je mysql_real_escape_string..
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je kan eventueel wel je functie filter gebruiken, ookal staat er enkel mysql_real_escape_string in smilefilter() is korter dan mysql_real_escape_string biggrin
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Maartenl schreef:
Je kan eventueel wel je functie filter gebruiken, ookal staat er enkel mysql_real_escape_string in smile
filter() is korter dan mysql_real_escape_string biggrin
En alsnog blijft het onzinnig, je staat een hele functie onnodig aan te maken.

En of het korter is? Bij een gemiddelde IDE/editor is het geen probleem dankzij auto-complete.....
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren