cURL login page in ASP does not authenticate

1

I've searched everywhere on the web, but so far I can not understand what's going wrong with my code.

I'm trying to access my student's portal from my college, using cURL, my interest is to get the grades of each student to be served to other means.

My problem is when I log in because I am passing the user data and password, but it is not authenticated and it seems to me that it is not generating an authentication cookie.

I put the code I'm using and then image the head of the college page and the page running locally.

What I want to receive is the page that displays the notes, but I can not even pass the login page.

$url="http://179.189.22.226/corpore.net/Login.aspx"; 
$cookie="cookie.txt"; 

$postdata = "txtUser=aquiUsuario&txtPass=aquiSenha&ddlAlias=CorporeRM&btnLogin=Acessar"; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 
curl_setopt($ch, CURLOPT_URL, 'http://179.189.22.226/corpore.net/Main.aspx?ShowMode=2&SelectedMenuIDKey=');

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

echo $result;  
curl_close($ch);

    
asked by anonymous 19.04.2015 / 07:28

1 answer

2

Since I did this I had to pass these variables underline and I used a class that I found on the internet to make the requisitions, because I was not able to control the request correctly with the curl.

Follow the code snippet:

<?php

include 'HttpClient.class.php';

$email = $_REQUEST['email'];
$password = $_REQUEST['password'];

$client = new HttpClient('intranet.somedomain.com.br');
$client->cookie_host = 'intranet.somedomain.com.br';
$client->persist_cookies = true;

$client->get('/Login.aspx');

preg_match('/<[^>]*value="(?<__VIEWSTATE>\/[a-z0-9]+)"[^>]*>/i', $client->getContent(), $params);

$client->post('/Login.aspx', array(
    '__EVENTTARGET' => "",
    '__EVENTARGUMENT' => "",
    '__VIEWSTATE' => $params['__VIEWSTATE'],
    'txtUsuario' => $email,
    'txtsenha' => $password,
    'txtNewPasswd' => '',
    'txtReenterNewPasswd' => '',
    'txtEmailLembrarSenha' => '',
    'btnLogin' => 'Entrar',
    'hdnAlteraSenha' => '0' 
));


$client->get('/engine.aspx?pg=42');

The lib I used was this: link

As you are doing a prototype, if it works well, I did not bother with the lib being outdated.

In this example I passed, I access the login page of the application, get the value of the variable view state and make the request.

    
19.04.2015 / 14:34