找回密码
 加入
搜索
查看: 14854|回复: 8

[网络通信] 【已解决】POST登录论坛失败

  [复制链接]
发表于 2014-9-26 12:48:14 | 显示全部楼层 |阅读模式
本帖最后由 vigiles 于 2014-9-28 14:17 编辑

想做个论坛登录用的,目标论坛 http://www.unitymanual.com/

从论坛看到了这个 http://www.autoitx.com/forum.php?mod=viewthread&tid=35273&highlight=POST%2B%B5%C7%C2%BC 能够轻松登录咱们本AutoItX,

尝试修改:
$UserName = '用户名'
$password = '密码'

;---- 登录信息填写页
$userInfoPage = 'http://www.unitymanual.com/home.php?mod=space&uid=11336'

;---- POST地址
$PostPage = 'http://www.unitymanual.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=' & 'LTG7d' & '&inajax=1'

;---- 检测帐号登录情况页
$CheckPage = 'http://www.unitymanual.com/index.php'

#cs ;;~~~~~~~~~~~~~~~~~MSXML2.XMLHTTP.3.0~~~~~~~~~~~~~~~~~~~~
        属性:
        onreadystatechange* 指定当readyState属性改变时的事件处理句柄。只写
        readyState          返回当前请求的状态,只读.
        responseBody        将回应信息正文以unsigned byte数组形式返回.只读
        responseStream      以Ado Stream对象的形式返回响应信息。只读
        responseText        将响应信息作为字符串返回.只读
        responseXML         将响应信息格式化为Xml Document对象并返回,只读
        status              返回当前请求的http状态码.只读
        statusText          返回当前请求的响应行状态,只读
        方法:
        abort                  取消当前请求
        getAllResponseHeaders  获取响应的所有http头
        getResponseHeader      从响应信息中获取指定的http头
        open                   创建一个新的http请求,并指定此请求的方法、URL以及验证信息(用户名/密码)
        send                   发送请求到http服务器并接收回应
        setRequestHeader       单独指定请求的某个http头
#ce ;
$xmlHttpReq = ObjCreate("MSXML2.XMLHTTP.3.0") ;;;;;;;;;; 1.创建 HTTP请求与接收器

#cs
        下列代码段用于检查之前帐号有无退出。因为如果没有退出的话,就获取不到Post数据中的formhash值。。。。。。。。。。。。。。。。。。。。。。。。
#ce
$xmlHttpReq.open("GET", $CheckPage, False) ;;;;;;;;;;;;; 2.创建一个GET请求(全大写英文方法,地址,验证)

$xmlHttpReq.send() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3.发送请求

$Content = BinaryToString($xmlHttpReq.responseBody, 1) ; 4.将回应信息正文以unsigned byte数组形式返回.只读

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 5.从返回的信息提取登录信息,;存在此段网页代码则说明帐号已经登录。
If StringRegExp($Content, 'href="home.php?mod=space&uid=11336" target="_blank"') Then

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 6.从返回的信息提取登录信息,;获取退出时所要使用的formhash值
        $FormHash11 = StringRegExp($Content, 'formhash=(.*?)">退出</a>', 3)        ;member.php?mod=logging&action=logout&formhash=2626f083

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 7.如果已经登录,退出
        $xmlHttpReq.open("GET", 'http://www.unitymanual.com/member.php?mod=logging&action=logout&formhash=' & $FormHash11[0] & '', False)

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 8.发送退出请求
        $xmlHttpReq.send()
EndIf
$xmlHttpReq.abort()

#cs
        下列代码段用于获取POST数据中的formhash值以及提交POST数据登录。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
#ce
;; ~~~~~~~~~~~~~~~~~~~~ 后台登录页面
$loginhashpage = 'http://www.unitymanual.com/member.php?mod=logging&action=login'
;; ~~~~~~~~~~~~~~~~~~~~ 访问页面
$xmlHttpReq.open("GET", $loginhashpage, False)
;; ~~~~~~~~~~~~~~~~~~~~ 执行
$xmlHttpReq.send()
$Content = BinaryToString($xmlHttpReq.responseBody, 1)

;; .1.提取页面里的关键字
$formHashIndex = StringInStr ($Content, "formhash=")        ;; formhash=d237dcd9
;; .2.提取loginhash
$formhash = StringMid ($Content, $formHashIndex + 9, 8)

;; 1.提取页面里的关键字
$loginhashIndex = StringInStr ($Content, "loginhash=")        ;; loginhash=LBdVy
;; 2.提取loginhash
$loginhash = StringMid ($Content, $loginhashIndex + 10, 5)
;; 3.创建可用登录路径
$PostPage = 'http://www.unitymanual.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=' & $loginhash & '&inajax=1'

If @error = 0 Then
        $xmlHttpReq.open("POST", $PostPage, False)
        ;; 4.必须的POST请求头
        $xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

        ;; 5.数据
        $xmlHttpReq.send('formhash=' & $formhash & '&referer=http://www.unitymanual.com/&loginfield=username&username=' & $UserName & '&password=' & $password & '&questionid=0&answer=&cookietime=2592000')
        $Content = BinaryToString($xmlHttpReq.responseBody, 1)

        If StringRegExp($Content, '欢迎您回来', 0) Then
                MsgBox(0, "", "登录成功!")
        Else
                MsgBox(0, "", "登录失败!")
        EndIf
EndIf
$xmlHttpReq.abort()
一直登录失败,个人感觉问题出在“5.数据”这一步。

登录抓包数据:
Request URL:http://www.unitymanual.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=Ly5r3&inajax=1
Request Method:POST
Status Code:200 OK

Request Headers--------------------------------------------------------
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:179
Content-Type:application/x-www-form-urlencoded
Cookie:Hm_lvt_ed4c8a2e6028cd3b6a7d3cfe18415af0=1411467221,1411588736,1411603258,1411666071; Hm_lpvt_ed4c8a2e6028cd3b6a7d3cfe18415af0=1411731150; 8ZMk_2132_saltkey=Qmm29CCC; 8ZMk_2132_lastvisit=1411702377; 8ZMk_2132_sendmail=1; 8ZMk_2132_nofocus_portal=1; 8ZMk_2132_sid=CIO56y; CNZZDATA4924487=cnzz_eid%3D1436773829-1411637341-%26ntime%3D1411705974; 8ZMk_2132_lastact=1411706052%09member.php%09logging
Host:www.unitymanual.com
Origin:http://www.unitymanual.com
Referer:http://www.unitymanual.com/member.php?mod=logging&action=login
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.27 (KHTML, like Gecko) Chrome/26.0.1388.0 Safari/537.27

Query String Parameters-------------------------------------------------
mod:logging
action:login
loginsubmit:yes
loginhash:Ly5r3
inajax:1

Form Data---------------------------------------------------------------
formhash:bbbd6975
referer:http://www.unitymanual.com/
loginfield:username
username:用户名
password:密码
questionid:0
answer:
cookietime:2592000
loginsubmit:true

Response Headers---------------------------------------------------------
Cache-Control:no-store, private, post-check=0, pre-check=0, max-age=0
Connection:keep-alive
Content-Type:text/xml; charset=utf-8
Date:Fri, 26 Sep 2014 04:34:31 GMT
Expires:-1
Pragma:no-cache
Server:nginx/1.0.12
Set-Cookie:8ZMk_2132_activationauth=deleted; expires=Thu, 26-Sep-2013 04:34:29 GMT; path=/
Set-Cookie:8ZMk_2132_lastact=1411706070%09member.php%09logging; expires=Sat, 27-Sep-2014 04:34:30 GMT; path=/
Set-Cookie:8ZMk_2132_ulastactivity=57ca7FetE2Ql4Us1L22cvQYVlnZTzA4b0m0ZVmjXXgRohnW46ydL; expires=Sat, 26-Sep-2015 04:34:30 GMT; path=/
Set-Cookie:8ZMk_2132_sid=CIO56y; expires=Sat, 27-Sep-2014 04:34:30 GMT; path=/
Set-Cookie:8ZMk_2132_auth=19ack4veB7ZWCzK0YX2jNh%2FuPTmM9oOb1IGZONLdqm6TtdJS07cECSAa94zlz7G4PiBEqp70tYW6Q67EDWfg%2BnJspQ; expires=Sun, 26-Oct-2014 04:34:30 GMT; path=/; httponly
Set-Cookie:8ZMk_2132_loginuser=deleted; expires=Thu, 26-Sep-2013 04:34:29 GMT; path=/
Set-Cookie:8ZMk_2132_security_cookiereport=c7d5FWLidi2T5z4s93rT2c3dxJlAPxNk910HMnxKxRwHEKJLFLog; expires=Fri, 26-Sep-2014 16:34:30 GMT; path=/
Set-Cookie:8ZMk_2132_pmnum=deleted; expires=Thu, 26-Sep-2013 04:34:29 GMT; path=/
Set-Cookie:8ZMk_2132_lastcheckfeed=11336%7C1411706070; expires=Sat, 26-Sep-2015 04:34:30 GMT; path=/
Set-Cookie:8ZMk_2132_checkfollow=1; expires=Fri, 26-Sep-2014 04:35:00 GMT; path=/
Set-Cookie:8ZMk_2132_lip=120.193.154.46%2C1411704653; path=/
Transfer-Encoding:chunked
X-Powered-By:PHP/5.2.17p1
请各位A友不吝赐教!

----------------------------------------------------------------------------
感谢A友haijie1223的热切交流。网上论坛那么多,此贴针对其中一个。各个论坛的登录请求地址不尽相同,使用Autoit做出通用的登录程序还有难度。多抓包,多测试,积累经验很重要。此贴虽结,革命尚未程序,同志仍须努力!
发表于 2014-9-26 21:00:44 | 显示全部楼层
前段时间一直想学习post,只可惜基础太差,所以一直还在学习基础知识。正好今天遇到楼主提问,就硬着头皮试试。。。照着葫芦画个瓢
看到原帖中用的是xml对象,不过觉得还是换成http函数更好。
Global $UserName, $password
Global $LoginPage, $PostPage, $CheckPage
Global $xmlhttp, $sValue, $Formhash
$UserName = 'username'
$password = 'password'
$LoginPage = 'http://www.unitymanual.com/space-uid-46847.html'
$PostPage = 'http://www.unitymanual.com/member.php?mod=logging&action=login&loginsubmit=yes'
$CheckPage = 'http://www.unitymanual.com/index.php'
;===========以下是检测帐号是否登录,如果登陆就先退出==============
$xmlhttp = ObjCreate("MSXML2.XMLHTTP.3.0")
$xmlhttp.open("GET", $CheckPage, False)
$xmlhttp.send()
$sValue = BinaryToString($xmlhttp.responseBody, 4)
If StringInStr($sValue, 'title="访问我的空间">' & $UserName & '</a>') Then
        $Formhash = StringRegExp($sValue, 'formhash=(.*?)"', 3)
        $xmlhttp.open("GET", 'http://www.unitymanual.com/member.php?mod=logging&action=logout&formhash=' & $Formhash[0] & '', False)
        $xmlhttp.send()
EndIf
$xmlhttp.abort()
;============以下是发送post数据,并检测登录是否成功================
$xmlhttp.open("GET", $LoginPage, False)
$xmlhttp.send()
$sValue = BinaryToString($xmlhttp.responseBody, 4)
$Formhash = StringRegExp($sValue, 'name="formhash" value="(.*?)\"', 3)
If @error = 0 Then
        $xmlhttp.open("POST", $PostPage, False)
        $xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        $xmlhttp.send('formhash=' & $Formhash[0] & '&loginfield=username&username=' & $UserName & '&password=' & $password & '&questionid=0&answer=')
        $sValue = BinaryToString($xmlhttp.responseBody, 4)
        If StringInStr($sValue, '访问我的空间') Then
                MsgBox(0, "", "登录成功!")
        Else
                MsgBox(0, "", "登录失败!")
        EndIf
EndIf
$xmlhttp.abort()
 楼主| 发表于 2014-9-27 14:09:33 | 显示全部楼层
回复 2# haijie1223
--------------------------------------------------------------------------------
非常感谢,我抓包的请求路径是
http://www.unitymanual.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=Ly5r3&inajax=1
你是如何得知
http://www.unitymanual.com/member.php?mod=logging&action=login&loginsubmit=yes
这个路径就可以的
发表于 2014-9-28 08:34:36 | 显示全部楼层
回复 3# vigiles
你的观点是正确的,因为第一次写post代码,2楼的代码基本上是照葫芦画瓢,一半是按照你给的示例写的。
今天又重新抓包分析了一下,觉得以下这个代码比较靠谱。
对于post我也是新手,在给你回帖的同时,也希望能起到抛砖引玉的作用,能让post高手能指点一下。


Global $UserName, $password
Global $LoginPage, $PostPage, $CheckPage
Global $xmlhttp, $bodytext
Global $PostData, $sValue, $Formhash, $loginhash, $cookietime

$UserName = 'username'
$password = 'password'

$CheckPage = 'http://www.unitymanual.com/'
$LoginPage = "http://www.unitymanual.com/member.php?mod=logging&action=login"
$xmlhttp = ObjCreate("MSXML2.XMLHTTP.3.0")


;===========以下是检测帐号是否登录,如果登陆就先退出==============
$xmlhttp.open("GET", $CheckPage, False)
$xmlhttp.send()
$sValue = BinaryToString($xmlhttp.responseBody, 4)
If StringInStr($sValue, 'title="访问我的空间">' & $UserName & '</a>') Then
        $Formhash = StringRegExp($sValue, 'formhash=(.*?)"', 3)
        $xmlhttp.open("GET", 'http://www.unitymanual.com/member.php?mod=logging&action=logout&formhash=' & $Formhash[0] & '', False)
        $xmlhttp.send()
EndIf
$xmlhttp.abort()

;=============以下是获取loginhash\$cookietime\$Formhash的值==============================
$xmlhttp.open("GET", $LoginPage, False)
$xmlhttp.send()
$bodytext = BinaryToString($xmlhttp.responseBody, 4)
$loginhash = StringRegExp($bodytext, 'loginhash=(.*?)"', 3)
If Not @error Then $PostPage = 'http://www.unitymanual.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=' & $loginhash[0] & '&inajax=1'
$cookietime = StringRegExp($bodytext, 'name="cookietime".*?value="(.*?)"', 3)
$Formhash = StringRegExp($sValue, 'formhash=(.*?)"', 3)
If Not @error Then $PostData = 'cookietime=' & $cookietime[0] & 'formhash=' & $Formhash[0] & '&loginfield=username&username=' & $UserName & '&password=' & $password & '&questionid=0&answer='

;============以下是发送post数据,并检测登录是否成功================

$xmlhttp.open("POST", $PostPage, False)
$xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
$xmlhttp.setRequestHeader('referer', 'http://www.unitymanual.com/')
$xmlhttp.send($PostData)
$sValue = BinaryToString($xmlhttp.responseBody, 4)
ConsoleWrite($sValue)
If StringInStr($sValue, '欢迎您回来') Then
        MsgBox(0, "", "登录成功!")
Else
        MsgBox(0, "", "登录失败!")
EndIf

$xmlhttp.abort()
 楼主| 发表于 2014-9-28 10:44:56 | 显示全部楼层
回复 4# haijie1223
---------------------

受教了,非常感谢!
发表于 2014-9-28 12:50:52 | 显示全部楼层
回复 5# vigiles

重新写了一个登录ACN的代码,http://autoitx.com/thread-45432-1-1.html

评分

参与人数 1金钱 +20 收起 理由
vigiles + 20 支持,顶起!

查看全部评分

 楼主| 发表于 2014-10-10 22:50:27 | 显示全部楼层
回复 6# haijie1223


    兄台帮忙整整这个百度分享破解
#include <array.au3>

$PostPage = "http://pan.baidu.com/share/init?shareid=3398908431&uk=3460319131"
; $PostPage = "http://pan.baidu.com/share/verify?shareid=3398908431&uk=3460319131&t=1412971332418&channel=chunlei&clienttype=0&web=1"

$xmlhttp = ObjCreate("MSXML2.XMLHTTP.3.0")

$xmlhttp.open("POST", $PostPage, False)
$xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

$a = "aaaabcdefghijklmnopqrstuvwxyz0123456789999"

; 拆分字符串为若干子串( "字符串", "分隔符" [, 标志 = 2 = 禁用返回表示元素数量的第一个元素] )
$b = StringSplit($a, "", 2)                ; 直接将上面的字符串拆为一个数组,每个索引一个字符

; 从选定的一维数组返回一组元素的重组合数组(目标数组,重组合的大小,结果字符串分隔符)
$c = _ArrayCombinations($b, 4)        ; 将目标数组的每4个索引组合成本数组的一个元素

For $i In $c
        ConsoleWrite("步骤:" & $i & @CRLF)

        $xmlhttp.send("pwd=" & $i)
        $sValue = BinaryToString($xmlhttp.responseBody, 4)
        ConsoleWrite($sValue & @CRLF)

        If StringInStr($sValue, "保存至网盘") Then
                MsgBox(0, "", "破解成功!" & $i)
                ExitLoop
        EndIf
Next

$xmlhttp.abort()
 楼主| 发表于 2014-11-21 16:10:01 | 显示全部楼层
post请求技术性还是很高的,留着备用吧
http://pan.baidu.com/share/init?shareid=608190992&uk=1766870370
发表于 2019-2-27 14:28:29 | 显示全部楼层
谢谢分享      认真学习POST
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-16 04:23 , Processed in 0.087643 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表