4
I want to develop a security system, which serves both for contact form and login, the intention is that it is an additional to the use of CAPTCHA, or in some cases a substitute. The logic is as follows:
The user can access at most 4 times during intervals of 7 seconds, if he access more than 4 times that given data sending page within 7 seconds, the system understands as a bot and redirects the user to another location to "divert" traffic or performs another security measure.
This was the experimental code I developed with some friends.
OBS 1: I am not an expert in PHP, I am always in constant learning, so tips and methodologies are always welcome.
OBS 2: The idea is to redirect bots to avoid sending spam or even attacks like Brut force, then it is a Generic code for use in several cases
<?php
// Detecta BOT
session_start();
$maxTempoLim = 7; //Tempo Limite
$maxVezesLim = 4; //Numero de Vezes possiveis dentro do tempo limite
if ( ! isset($_SESSION['temp_bot'])) {
$_SESSION['temp_bot'] = time();
$_SESSION['conta_vezbot'] = 1;
}
$diferenTime = time() - $_SESSION['temp_bot'];
if ($diferenTime <= $maxTempoLim) {
$_SESSION['conta_vezbot']++;
if ($_SESSION['conta_vezbot'] > $maxVezesLim) {
session_destroy();
header('Location: spam_detectado.php'); //redireciona
// ou colocar outra ação ao invés de redirecionar
exit;
}
}
The idea arose from a situation where they tried to send spam to a contact form on my page and from some customers, both I added a CAPTCHA and it worked very well, only I didn’t want to force the user to type the CAPTCHA, would like to create something that detects that is a bot or any other type of system accessing uninterruptedly, and through the amount of access per second, or for a period of time that for an ordinary user would be impossible, redirect traffic.
the idea for using this algorithm is quite varied, including to avoid Brute force in logins, among other applications, where it does not allow access for the mentioned period, but I do not know if something of this type that I did would solve, or would apply the same "shot in the foot" what you said about spam in all the solutions I intend to apply
– Gabriel Masson
My answer was an explanation for the cases of SPAM, as you mentioned. For the case of login, you can adopt a pattern of X attempts. Add the cases to the question.
– Papa Charlie
Or create a new question, after all each question should have only one subject and should not invalidate existing answers.
– Maniero
You could also see the subject here: http://answall.com/questions/32533/algoritimo-contrabrute-force. I think you already have a little help :D
– Cold
@Cold I had read, but do not agree with some points, so did not Linkei. The problem is the paranoia is great - and rightly - and can end up making security a terrible experience for the user. Block access after X attempts, not good.
– Papa Charlie
Really, I didn’t think about how usability would look in the case of login, thanks for alerting me, but in the question of sending data from some contact form? would that help? I have no advanced knowledge of the functioning of bots, I never got a chance to see the code of a
– Gabriel Masson
I did an update on the code, take a look
– Gabriel Masson
@Gabrielmasson [...]contact form? would it help?[...] It’s like I said, the chance to pass SPAM is great. Only logged in users can submit the form?
– Papa Charlie
no, they are from institutional websites, the intention is to decrease their flow, because until those days I received 1 spam every 3 secondswith Loren ipson
– Gabriel Masson
then, I put Captcha and it worked, however the user have to type Captcha every time you send it is complicated
– Gabriel Masson
@Gabrielmasson, the link that Cold posted above has some suggestions that may be interesting. Take a look and if you think it’s worth it I can propose some other ideas.
– Papa Charlie
@Gabrielmasson Papacharlie’s answer is relevant to the problem ahead. If you have no experience it will be difficult. Have you thought for example what happens if the session is renewed on the third try? With this say that Cold put a link that should read. An effective response to your problem also involves the resources at your disposal.
– chambelix