第五节 模拟ecshop登录功能

来源:互联网 发布:买淘宝自动发货 编辑:程序博客网 时间:2024/06/03 17:11

一.准备

1.抓包工具Fiddler

2.下载并安装ecshop

3.注册ecshop帐号

二.抓去http信息

帐号:zhangsan
密码:1111aaaa

1.打开登录页面,输入帐号和密码,不要点击登录.

这里写图片描述

2.打开Fiddler

工具栏 ==>Rules =>Automatic Breakopints ==>Before Request(请求前设置断点抓取请求信息)
这里写图片描述

3.返回登录页面,点击登录

这里写图片描述

4.取消断点

这里写图片描述

5.找到请求信息

这里写图片描述


这里写图片描述

POST http://localhost/ecshop/upload/user.php HTTP/1.1Host: localhostUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateReferer: http://localhost/ecshop/upload/user.phpCookie: ECS[visit_times]=1; ECS_ID=583bd02660f7b7ae1f43b9602fd63cb2dcf969efConnection: keep-aliveUpgrade-Insecure-Requests: 1Content-Type: application/x-www-form-urlencodedContent-Length: 119username=zhangsan&password=1111aaaa&act=act_login&back_act=http%3A%2F%2Flocalhost%2Fecshop%2Fupload%2Findex.php&submit=

三.编写代码

login.php

$data=array(        'username'=>'zhangsan',        'password'=>'1111aaaa',        'act'     =>'act_login',        'back_act'=>'./index.php',        'submit'  =>'',    );$data=http_build_query($data);//①$fp = fsockopen('localhost',80,$errno,$errstr,5);//②$request='POST http://localhost/ecshop/upload/user.php HTTP/1.1Host: localhostUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateReferer: http://localhost/ecshop/upload/user.phpConnection: keep-aliveUpgrade-Insecure-Requests: 1Content-Type: application/x-www-form-urlencodedContent-Length: '.strlen($data).''.$data.';//③fwrite($fp,$request);//$str = '';while(!feof($fp)){    $str .=fgets($fp,1024);}file_put_contents('./user.html',$str);preg_match('/ECS_ID=(.*)?;/',$str,$match);//④setcookie("ECS_ID",$match[1],0,'/');//⑤fclose($fp);if(preg_match('/登录成功/',$str)){    echo 'ok';}else{    echo 'error';}

$data=http_build_query($data)
把数组生成一个经过 URL-encode 的请求字符串
输出格式为:
username=zhangsan&password=1111aaaa&act=act_login&back_act=.%2Findex.php&submit=
②fsockopen()
打开一个网络连接或者一个Unix套接字连接
fsockopen(主机,端口号,错误号,错误信息,链接超时时间)
③注意空行,把http请求信息粘贴到代码端中时,要把cookie的那行去掉
这里写图片描述
④正则匹配cookie信息
⑤设置cookie

四.刷新网页

执行脚本文件login.php
user.html代码
这里写图片描述


刷新前
这里写图片描述


刷新后
这里写图片描述

0 0
原创粉丝点击