Jump to content

Php Curl Login Asp.net Website Help


bgold

Recommended Posts

I am trying create a php script to that logins to a specific site that does a __doPostBack to submit the form.

 

If I run the script I get an output of the form as if I had not sent any post data. I know I have to do something with the view state and the event val but I'm just so confused.

 

I honestly have tried a whole bunch of different CURL scenarios I don't know what to post here. If anyone could give me an example of what I need so it at least recognizes that I am trying to POST data that would be awesome.

 

Any help would be greatly appreciated.

 

<?php
$url="https://www.domain.com/Default.aspx";
				 $header = array("POST /Default.aspx HTTP/1.1",
												 "Host: www.domain.com",
												 "Connection: close",
												 "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
												 "Accept-Encoding: gzip",
												 "Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7",
												 "Cache-Control: no",
												 "Accept-Language: de,en;q=0.7,en-us;q=0.3",
												 "Referer: https://www.domain.com/Default.aspx",
												 "Content-type: application/x-www-form-urlencoded",
												 "Content-length: 0"
												 );


$regexViewstate = '/__VIEWSTATE\" value=\"(.*)\"/i';
$regexEventVal = '/__EVENTVALIDATION\" value=\"(.*)\"/i';


function regexExtract($text, $regex, $regs, $nthValue)
{
if (preg_match($regex, $text, $regs)) {
$result = $regs[$nthValue];
}
else {
$result = "";
}
return $result;
}



curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data=curl_exec($ch);


$viewstate = regexExtract($data,$regexViewstate,$regs,1);
$eventval = regexExtract($data, $regexEventVal,$regs,1);

 $post = "ctl00%24cb%24txtSiteLoginName=asd&ctl00%24cb%24txtSitePassword=123123&__VIEWSTATE=$viewstate&__EVENTVALIDATION=$eventval";

				 $ch = curl_init();
				 curl_setopt($ch, CURLOPT_URL, $url);
				 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)');
				 curl_setopt($ch, CURLOPT_HEADER, 1);
				 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
				 curl_setopt($ch, CURLOPT_VERBOSE,1);
				 curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
				 curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
				 curl_setopt($ch, CURLOPT_POST, 1);
				 curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
				 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
				 curl_setopt($ch, CURLOPT_FAILonerror, 1);
				 curl_setopt($ch, CURLOPT_REFERER, 'https://www.domain.com/Default.aspx');
				 //curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
				 $curlres = curl_exec($ch);
?>

 

I have attached a html of the page and the POST data that I received from Chrome Web Developer when I log into the site.

 

test.html

data.txt

Link to comment
https://forums.phpfreaks.com/topic/268702-php-curl-login-aspnet-website-help/
Share on other sites

I think this may be the appropriate post data but I'm not sure

 

$postData = "__LASTFOCUS=&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=$viewstate&__VIEWSTATEENCRYPTED=&__EVENTVALIDATION=$eventvalidation&ctl00%24txtSearch=&ctl00%24cb%24txtSiteLoginName=$username&ctl00%24cb%24txtSitePassword=$password&ctl00%24cb%24btnLogin.x=30&ctl00%24cb%24btnLog.y=14&ctl00%24cb%24txtLoginName=&ctl00%24cb%24txtPassword=&ctl00%24cb%24txtTransactionid=";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.