简体   繁体   English

如何阻止Bot提交Web表单

[英]How to stop bots from submitting web forms

I'm making a website that requires the user to sign up and log in. My friend keeps making bots with mechanize . 我正在建立一个要求用户注册并登录的网站。我的朋友一直在用机械化制作机器人。 The bot signs up for the site multiple times. 该漫游器会多次注册该站点。 When the bot makes tonnes of users, the users are added to a database table. 当漫游器产生大量用户时,会将用户添加到数据库表中。

I've made a program to stop an entry that has example in it since the bot just has a variable like: 我已经编写了一个程序来停止其中包含示例的条目,因为该机器人只有一个变量,例如:

name = 0

and keeps adding 1 to the name variable. 并继续在name变量上加1。

I think he has a while loop like this: 我认为他有一个while循环,如下所示:

import mechanize
br = mechanize.Browser()
br.open("http://www.example.com/")
br.set_handle_robots(False) # Ignores the robots.txt file

name = 0
person = 'example',name

while True:
    br.select_form( 'signup' )
    br.form[ 'fullname' ] = person
    br.submit()
    name = name + 1

So he basically has this program running non stop until the program crashes. 因此,他基本上使该程序不停地运行,直到程序崩溃为止。

I want to be able to stop this with either javascript or php. 我希望能够使用javascript或php停止此操作。

I've searched for an answer to this but all of the methods that I've tried have failed. 我一直在寻找答案,但是我尝试过的所有方法都失败了。 I've tried making a timer to see how long the person was on the page since a bot is only on a webpage for about a second. 我已经尝试制作一个计时器,以查看该人在页面上停留了多长时间,因为漫游器仅在网页上停留了大约一秒钟。 I've made the timer in php and javascript and they both failed. 我已经在php和javascript中设置了计时器,但它们都失败了。

I've considered captcha but the bot can still send private messages and I don't think the user will stay on the site if they have to fill in a captcha everytime they want to message a friend. 我已经考虑过验证码,但是该机器人仍然可以发送私人消息,并且我认为用户每次要向朋友发送消息时都必须填写验证码,因此用户不会留在网站上。 And I don't want to have a captcha on the sign up form because it doesn't look to attractive. 而且我不想在注册表格上输入验证码,因为它看上去并不吸引人。

I've ran out of ideas to stop this. 我已经没有足够的想法来阻止这种情况了。 It's been going on for a couple ofmonths and it's really slowed downthe development of the site as i have to keep checking for any entries that my program may have missed. 它已经进行了几个月,并且确实减慢了网站的开发速度,因为我必须不断检查程序可能错过的所有条目。

Does anyone know of any other ways to stop a bot. 有谁知道停止机器人的任何其他方法。

Add email confirmation on sign-up, along with a unique email address constraint in your application or persistence layer. 在注册时添加电子邮件确认,并在应用程序或持久层中添加唯一的电子邮件地址约束。

Combine this with adeneo's suggestion of using a hidden field and you'll reduce bot registrations. 将其与adeneo建议使用隐藏字段的建议结合使用,您将减少机器人注册。 Note, you can use a unique field name + value each time, making it more difficult to attack. 请注意,您每次都可以使用唯一的字段名+值,这使得攻击更加困难。

Note, many of the suggestions given so far are to foil generic attacks. 注意,到目前为止给出的许多建议都是为了阻止通用攻击。 It's a different thing altogether to deal with somebody specifically attacking your site by evaluating its weaknesses. 通过评估网站的弱点来专门攻击您的网站是完全不同的。

The simplest solution to me would seem to be to implement login with a third party such as Facebook and don't offer a standard login form at all. 对我来说,最简单的解决方案似乎是实现与第三方(如Facebook)的登录,而根本不提供标准的登录表单。

Alternatively, you could implement a system to store a user's IP address when they create an account, together with a counter, and if more than a certain number of accounts get created from that IP address within a certain time period, then take corrective action, such as suspending those accounts. 或者,您可以实施一个系统来存储用户创建帐户时的IP地址以及一个计数器,如果在一定时间段内从该IP地址创建了多个帐户,则可以采取纠正措施,例如暂停这些帐户。

I have a feeling it might also be possible to create a custom filter using fail2ban that would do the job - that way if a user tried to sign up too many times in a certain period they could be blocked for a given length of time. 我有一种感觉,也许还可以使用fail2ban创建一个自定义过滤器来完成这项工作-这样,如果用户尝试在特定时期内注册过多次,则在给定的时间长度内可能会被阻止。

Google have released their new "reCAPTHA" technology, which with a mere check of a box. 谷歌已经发布了他们的新“ reCAPTHA”技术,仅需勾选即可。 Bots can get around this, but it's very difficult to do so. 机器人可以解决这个问题,但这很难做到。 By using this, you can reduce the risk of your friend's bot. 通过使用此功能,您可以减少朋友机器人的风险。 To the extent of my knowledge, Mechanize does not currently have a way around this. 就我所知,Mechanize目前尚无解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM