Masterslave
08-10-2007, 06:42 PM
Hello all,
I've a big problem.
I have a public guestbook.
And some spambots can leave posts in my guestbook.
I don't know how they do it.
Does anyone know how to avoid spambots (a non CAPCHA way)?
<?php
//part of the guestbook script
$strip_tags = strip_tags( $_POST['content'] );
if( !preg_match('/http:\/\/(localhost)|' . '(www\.trefnology\.nl)/i',$_SERVER['HTTP_REFERER']) )
{
die("Wegens veiligheidsredenen kun je niet het gastenboek bekijken zonder dat je al op een pagina bent geweest van Trefnology.");
}
else
{
if ( isset( $_SESSION["guestbook"] ) || $_SESSION["guestbook"] )
{
if( isset( $_POST['submit'] ) )
{
if( !empty( $_POST['hidden'] ) )
{
die();
}
else
{
if (trim(empty($_POST['name'])) || trim(empty($_POST['content'])))
{
$error = "<br /><strong>Je dient je naam en bericht op te geven om een bericht te plaatsen.</strong>";
}
if( $strip_tags != $_POST['content'] )
{
die("Het is verboden om HTML tags te gebruiken in het gastenboek. Ga terug naar het gastenboek om het opnieuw te proberen.");
}
else
{
$commentInsert = " INSERT INTO
$guestbooktable
(
name,
email,
website,
content,
ip,
host
)
VALUES
(
'" . mysql_real_escape_string($_POST['name']) . "',
'" . mysql_real_escape_string($_POST['email']) . "',
'" . mysql_real_escape_string($_POST['website']) . "',
'" . mysql_real_escape_string($_POST['content']) . "',
'" . mysql_real_escape_string($_POST['ip']) . "',
'" . mysql_real_escape_string($_POST['host']) . "'
)";
$result = mysql_query($commentInsert) or die (mysql_error());
header("Location: guestbook.php");
}
}
}
}
else
{
die();
}
}?>
How can the spammers breakthrough my security?
Is my script above not right, tell me.
Thanks for your help.
Attached a screenshot from PHPmyadmin and a part of the log file from apache.
Log:
81.177.22.198 - - [07/Aug/2007:20:34:42 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 121 "http://www.valdosta.edu/~tthompson/syllabi/sys.php?amateur.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:42 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 121 "http://www.valdosta.edu/~tthompson/syllabi/sys.php?amateur.html" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.22.198 - - [07/Aug/2007:20:34:43 +0200] "GET / HTTP/1.0" 200 10025 "http://www.trefnology.nl/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:43 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5288 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:45 +0200] "POST /guestbook.php?page=6 HTTP/1.0" 302 5288 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:45 +0200] "GET / HTTP/1.0" 200 10025 "http://www.trefnology.nl/" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.22.198 - - [07/Aug/2007:20:34:46 +0200] "GET /guestbook.php HTTP/1.0" 200 7973 "http://www.trefnology.nl/guestbook.php" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:46 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5561 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.22.198 - - [07/Aug/2007:20:34:46 +0200] "POST /guestbook.php?page=6 HTTP/1.0" 302 5561 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.22.198 - - [07/Aug/2007:20:34:46 +0200] "GET /guestbook.php HTTP/1.0" 200 10558 "http://www.trefnology.nl/guestbook.php" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.23.136 - - [07/Aug/2007:20:50:15 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 121 "http://www.valdosta.edu/~tthompson/syllabi/sys.php?teen.html" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:50:15 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 121 "http://www.valdosta.edu/~tthompson/syllabi/sys.php?teen.html" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:50:15 +0200] "GET / HTTP/1.0" 200 10025 "http://www.trefnology.nl/" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:50:15 +0200] "GET / HTTP/1.0" 200 10025 "http://www.trefnology.nl/" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:50:55 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:50:55 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:51:35 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5449 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:51:35 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5449 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:51:35 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:51:35 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:51:36 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:51:36 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:52:16 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:52:16 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:52:16 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:52:16 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:52:55 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5449 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:52:55 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5449 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
<form method="post" action="<?=htmlentities($_SERVER['REQUEST_URI'])?>" onsubmit="return checkform(this);">
<label for="name">Naam:</label>
<input type="text" name="name" id="name" /><br />
<label for="email">Email:</label>
<input type="text" name="email" id="email" /><br />
<label for="website">Website:</label>
<input type="text" name="website" id="website" /><br />
<label for="comment">Bericht:</label>
<textarea name="content" id="comment"></textarea><br />
<input type="hidden" value="<?=$_SERVER['REMOTE_ADDR'];?>" name="ip" />
<input type="hidden" value="<?=gethostbyaddr($_SERVER['REMOTE_ADDR']);?>" name="host" />
<input type="text" name="hidden" id="hidden_field"/>
<input type="submit" name="submit" value="Plaats reactie" class="button" />
</form>
I've added the new PHP code for the guestbook, which includes Len Whistler way.
I've a big problem.
I have a public guestbook.
And some spambots can leave posts in my guestbook.
I don't know how they do it.
Does anyone know how to avoid spambots (a non CAPCHA way)?
<?php
//part of the guestbook script
$strip_tags = strip_tags( $_POST['content'] );
if( !preg_match('/http:\/\/(localhost)|' . '(www\.trefnology\.nl)/i',$_SERVER['HTTP_REFERER']) )
{
die("Wegens veiligheidsredenen kun je niet het gastenboek bekijken zonder dat je al op een pagina bent geweest van Trefnology.");
}
else
{
if ( isset( $_SESSION["guestbook"] ) || $_SESSION["guestbook"] )
{
if( isset( $_POST['submit'] ) )
{
if( !empty( $_POST['hidden'] ) )
{
die();
}
else
{
if (trim(empty($_POST['name'])) || trim(empty($_POST['content'])))
{
$error = "<br /><strong>Je dient je naam en bericht op te geven om een bericht te plaatsen.</strong>";
}
if( $strip_tags != $_POST['content'] )
{
die("Het is verboden om HTML tags te gebruiken in het gastenboek. Ga terug naar het gastenboek om het opnieuw te proberen.");
}
else
{
$commentInsert = " INSERT INTO
$guestbooktable
(
name,
email,
website,
content,
ip,
host
)
VALUES
(
'" . mysql_real_escape_string($_POST['name']) . "',
'" . mysql_real_escape_string($_POST['email']) . "',
'" . mysql_real_escape_string($_POST['website']) . "',
'" . mysql_real_escape_string($_POST['content']) . "',
'" . mysql_real_escape_string($_POST['ip']) . "',
'" . mysql_real_escape_string($_POST['host']) . "'
)";
$result = mysql_query($commentInsert) or die (mysql_error());
header("Location: guestbook.php");
}
}
}
}
else
{
die();
}
}?>
How can the spammers breakthrough my security?
Is my script above not right, tell me.
Thanks for your help.
Attached a screenshot from PHPmyadmin and a part of the log file from apache.
Log:
81.177.22.198 - - [07/Aug/2007:20:34:42 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 121 "http://www.valdosta.edu/~tthompson/syllabi/sys.php?amateur.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:42 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 121 "http://www.valdosta.edu/~tthompson/syllabi/sys.php?amateur.html" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.22.198 - - [07/Aug/2007:20:34:43 +0200] "GET / HTTP/1.0" 200 10025 "http://www.trefnology.nl/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:43 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5288 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:45 +0200] "POST /guestbook.php?page=6 HTTP/1.0" 302 5288 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:45 +0200] "GET / HTTP/1.0" 200 10025 "http://www.trefnology.nl/" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.22.198 - - [07/Aug/2007:20:34:46 +0200] "GET /guestbook.php HTTP/1.0" 200 7973 "http://www.trefnology.nl/guestbook.php" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"
81.177.22.198 - - [07/Aug/2007:20:34:46 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5561 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.22.198 - - [07/Aug/2007:20:34:46 +0200] "POST /guestbook.php?page=6 HTTP/1.0" 302 5561 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.22.198 - - [07/Aug/2007:20:34:46 +0200] "GET /guestbook.php HTTP/1.0" 200 10558 "http://www.trefnology.nl/guestbook.php" "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"
81.177.23.136 - - [07/Aug/2007:20:50:15 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 121 "http://www.valdosta.edu/~tthompson/syllabi/sys.php?teen.html" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:50:15 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 121 "http://www.valdosta.edu/~tthompson/syllabi/sys.php?teen.html" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:50:15 +0200] "GET / HTTP/1.0" 200 10025 "http://www.trefnology.nl/" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:50:15 +0200] "GET / HTTP/1.0" 200 10025 "http://www.trefnology.nl/" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:50:55 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:50:55 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:51:35 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5449 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:51:35 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5449 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:51:35 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:51:35 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:51:36 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:51:36 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:52:16 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:52:16 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:52:16 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:52:16 +0200] "GET /index.php HTTP/1.0" 200 10025 "http://www.trefnology.nl/index.php" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
81.177.23.136 - - [07/Aug/2007:20:52:55 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5449 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/1.22 (compatible; MSIE 2.0d; Windows NT)"
81.177.23.136 - - [07/Aug/2007:20:52:55 +0200] "GET /guestbook.php?page=6 HTTP/1.0" 200 5449 "http://www.trefnology.nl/guestbook.php?page=6" "Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0"
<form method="post" action="<?=htmlentities($_SERVER['REQUEST_URI'])?>" onsubmit="return checkform(this);">
<label for="name">Naam:</label>
<input type="text" name="name" id="name" /><br />
<label for="email">Email:</label>
<input type="text" name="email" id="email" /><br />
<label for="website">Website:</label>
<input type="text" name="website" id="website" /><br />
<label for="comment">Bericht:</label>
<textarea name="content" id="comment"></textarea><br />
<input type="hidden" value="<?=$_SERVER['REMOTE_ADDR'];?>" name="ip" />
<input type="hidden" value="<?=gethostbyaddr($_SERVER['REMOTE_ADDR']);?>" name="host" />
<input type="text" name="hidden" id="hidden_field"/>
<input type="submit" name="submit" value="Plaats reactie" class="button" />
</form>
I've added the new PHP code for the guestbook, which includes Len Whistler way.