强智科技教务处模拟登录

通过对教务处登录进行抓包分析,发现登录教务处只需要两个操作

  1 将username和password两个的值post到http://202.114.242.21/whkjdx/Logon.do?method=logon

  2 通过1的操作以后,页面会跳转到http://202.114.242.21/whkjdx/index.jsp,接着我们post一个空表单到http://202.114.242.21/whkjdx/Logon.do?method=logonBySSO,这样才算完全登录成功,如果没有第二步,会提示权限错误

 

接下来给出具体的代码,有两种实现方法,一个是用curl来实现,一个是用snoopy.class.php来实现

 登录过程是:

访问index.jsp(获得cookie,这是后面操作的基础)->向Logon.do?method=logon提交用户名和密码->自动跳转页面到main.jsp->由main.jsp发起Logon.do?method=logonBySSO的请求->登录过程完成->访问xszqcjglAction.do?method=queryxscj获得成绩

用curl来实现

php
$login_url = 'http://202.114.242.21/whkjdx/index.jsp';


//cookie文件存放在网站根目录的temp文件夹下
$cookie_file = tempnam('./temp','cookie');

//从首页获取session的密码
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);



//准备提交数据登录
$send_url='http://202.114.242.21/whkjdx/Logon.do?method=logon';
$post_fields='USERNAME=你的用户名&PASSWORD=你的密码&useDogCode=&useDogCode=&x=39&y=10';

$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_REFERER, 'http://202.114.242.21/whkjdx/');
$contents = curl_exec($ch);
curl_close($ch);


$send_url='http://202.114.242.21/whkjdx/framework/main.jsp';
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_REFERER, 'http://202.114.242.21/whkjdx/Logon.do?method=logon');
curl_exec($ch);
curl_close($ch);


$send_url='http://202.114.242.21/whkjdx/Logon.do?method=logonBySSO';
$post_fields='';
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_REFERER, 'http://202.114.242.21/whkjdx/framework/main.jsp');
curl_exec($ch);
curl_close($ch);


//查询成绩
$send_url='http://202.114.242.21/whkjdx/xszqcjglAction.do?method=queryxscj';
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);

//输出页面的内容
print_r($contents);
?>

 

用snoopy.class.php来实现

php   
include "Snoopy.class.php";
$snoopy = new Snoopy; 
$snoopy->expandlinks=true;  
$formvars["USERNAME"] = "你的用户名";   
$formvars["PASSWORD"] = "你的密码";   
    
$action = "http://202.114.242.21/whkjdx/Logon.do?method=logon";//表单提交地址
$snoopy->fetch("http://202.114.242.21/whkjdx/index.jsp");
$snoopy->setcookies();//留下cookie,这个很重要

$snoopy->submit($action,$formvars);//$formvars为提交的数组 $snoopy->fetch("http://202.114.242.21/whkjdx/framework/main.jsp");

$formvars=NULL; $action="http://202.114.242.21/whkjdx/Logon.do?method=logonBySSO"; $snoopy->submit($action,$formvars); $snoopy->fetch('http://202.114.242.21/whkjdx/xszqcjglAction.do?method=queryxscj'); echo $snoopy->results; ?>

ps:查询成绩,只要登录成功以后,访问http://202.114.242.21/whkjdx/xszqcjglAction.do?method=queryxscj就可以了

转载于:https://www.cnblogs.com/geqianst/p/3286027.html

你可能感兴趣的:(强智科技教务处模拟登录)