file_get_contents中的动态站点

时间:2016-03-07 14:01:11

标签: php captcha

问题,在动态网站中穿越CAPTCHA .. :( https://edu.uast.ac.ir中的问题链接操作表单.. 抱歉,我的英语不好。

请测试我的代码:

我的源代码:

a.php只会

<?php
echo file_get_contents("https://edu.uast.ac.ir");
?>

b.php

<?php
$a  =  $_POST["captcha_first_page"];

$postdata = http_build_query(
    array(
        'captcha_first_page' => $a
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);    
$result = file_get_contents('https://edu.uast.ac.ir/user/user_manage/userLogin/', false, $context);
echo $result;
?>

请帮帮我

1 个答案:

答案 0 :(得分:0)

您还必须替换表单操作,因为如果没有提交的表单想要发布到您的b.php。

<强>验证码-a.php只会

<?php

$content = file_get_contents("https://edu.uast.ac.ir");
$content = str_replace('https://edu.uast.ac.ir/user/user_manage/userLogin/','captcha-b.php', $content);
echo $content;

<强>验证码-b.php

<?php
function redirect_post($url, array $data, array $headers = null) {
    $params = array(
        'http' => array(
            'method' => 'POST',
            'content' => http_build_query($data)
        )
    );

    // replace
    $headers['Host'] = "edu.uast.ac.ir";
    $headers['Origin'] = "https://edu.uast.ac.ir";
    $headers['Referer'] = "https://edu.uast.ac.ir";

    if (!is_null($headers)) {
        $params['http']['header'] = '';
        foreach ($headers as $k => $v) {
            $params['http']['header'] .= "$k: $v\n";
        }
    }
    $ctx = stream_context_create($params);
    $fp = fopen($url, 'rb', false, $ctx);
    if ($fp) {
        return stream_get_contents($fp);
    } else {
        // Error
        throw new Exception("Error loading '$url', $php_errormsg");
    }
}

setlocale(LC_ALL, "en_US.UTF8");
echo redirect_post("https://edu.uast.ac.ir/user/user_manage/userLogin/" ,$_POST, getallheaders());

这应该是一个很好的起点。不知道它是否有效,因为我不能说阿拉伯语。