0
I want to do some tests of sql Injection. For this, I created a db called person and a table called users. I am passing some sql statements to test the ingestion of sql. Gives error, but does not execute the query:
connection file with the bank:
php connection.
$server="localhost";
$user="root";
$password="";
$database="pessoa";
//conexao com servidor de banco
$connect = mysql_connect($server, $user, $password) or print(mysql_error());
//se a conexao falhar
if (!$connect) {
echo "Conexão com servidor errou";
}
else {
//usar database
$selectDB = mysql_select_db($database, $connect);
//se database falhar
if (!$selectDB) {
echo "Conexão com o banco errou";
}
}
index file.html
<html>
<body>
<form name="buscar" id="buscarId" action="server.php" method="post">
<label for="Nome">Nome</label>
<input type="text" name="nome" id="nomeId">
<input type="submit" value="Buscar">
</form> >
</body>
</html>
php server file.
<?php
include('connect.php');
buscar();
function buscar() {
echo "<p>";
$select = "select * from usuarios where nome='$_POST[nome]'";
$query = mysql_query($select);
$rows=mysql_num_rows($query);
if ($rows==0) {
echo "Nome não encontrado";
} else {
while ($dados=mysql_fetch_array($query)) {
print_r($dados);
}
}
}
?>
In the form that searches by name, instead of giving the name, I put a query:
select * from users
of course this is not a command for the bank, it is a search because it is in single or double quotes:
select * from usuarios
makes the mistake:
( ! ) Warning: mysql_num_rows() expects Parameter 1 to be Resource, Boolean Given in path folder.
I’ve already done:
$select = "select * from usuarios where nome='.$_POST[nome].'";
threshing gets:
select * from usuarios where nome='.select * from usuarios.', ou seja, não executa o que está em $_POST;
And I also made:
$select = 'select * from usuarios where nome=$_POST[nome]';
Também não funciona. Só não entendi porque tem que concatenar.
Required link: http://xkcd.com/327/
– Oralista de Sistemas