Curl login page in ASP does not authenticate

Asked

Viewed 449 times

1

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

The thing is, I’m trying to access the student portal of my college, using Curl, my interest is to take each student’s grades to be served to other means.

My problem is at the time of logging in, because I am passing the username and password data, but it does not authenticate and it seems to me that it is not generating authentication cookie.

I’ll put the code q 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’m not even able to 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);

Login efetuado com sucesso no site normal

Login dando errado, header retorno

1 answer

2

The time I did this I had to pass these variables with underline and I used a class I found on the internet to make the requests, because I was not able to properly control the request with Curl.

Follows 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: http://scripts.incutio.com/httpclient/

As this making a prototype, if it works was already good, I did not worry much about the lib being outdated.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.