如何使用脚本模仿登陆过程

2018-09-07 12:28

阅读:415

  查看他的登陆页面的代码,看他提交到哪个页面,变量是什么。
复制代码 代码如下:
<formmethod=postaction=login.jsp>
<tablealign=centerwidth=40%style=FONT-SIZE:12pxborder=0cellpadding=0cellspacing=2>
<tr>
<tdwidth=30%align=rightbgcolor=#0073AAstyle=FONT-SIZE:12px;color:#ffffff>name:</td>
<tdwidth=70%><inputtype=textsize=30name=username></td>
</tr>
<tr>
<tdwidth=30%align=rightbgcolor=#0073AAstyle=FONT-SIZE:12px;color:#ffffff>password:</td>
<tdwidth=70%><inputtype=passwordsize=32name=passwd></td>
</tr>
<tr>
<tdcolspan=2align=right>
<inputtype=submitname=submitvalue=Login>
<inputtype=buttonname=submitvalue=regestonclick=location.href=regest.jsp>
</td>
</tr>
</table>
</form>

很明显,如果你要登陆,你需要把username,passwd,submit这几个变量post到login.jsp,而且submit=Login
用以下代码:
复制代码 代码如下:
<?php
$postData=username=your_name&password=your_password&Submit=Login;
$posturl=

$postUrl=parse_url($posturl);
$host=$postUrl[host]?$postUrl[host]:;
$port=$postUrl[port]?$postUrl[port]:80;
$path=$postUrl[path]?$postUrl[path]:/;



$fsp=fsockopen($host,$port,&$errno,&$errstr,30);
if(!$fsp){
print\nopensocketfailed\n;
}else{
fwrite($fsp,POST.$path.HTTP/1.1\r\n);
fwrite($fsp,Accept:image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/x-shockwave-flash,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/msword,*/*\r\n);
fwrite($fsp,Accept-Language:zh-cn\r\n);
fwrite($fsp,Content-Type:application/x-
fwrite($fsp,User-Agent:Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1;Maxthon)\r\n);
fwrite($fsp,Host:.$host.\r\n);
fwrite($fsp,Content-Length:.strlen($postData).\r\n\r\n);
fwrite($fsp,$postData);

$resp=;
do{
if(strlen($out=fread($fsp,1024))==0)break;
$resp.=$out;
}while(true);

echo<br><br>.nl2br($resp);

fclose($fsp);

}
?>


评论


亲,登录后才可以留言!