tags:

views:

47

answers:

1

I've been working on writing a script which automatically logs me into my school's network, checks if the classes I'm trying to get into are no longer completely full, and if a spot has opened up, registers the class for me. However, I've hit a big snag in just the logging-in process.

Basically, I've been looking at the headers that are sent when I log in and try to replicate them. The problem is I keep getting an error saying "HTTP/1.1 400 Bad Request Content-Type: text/html Date: Sat, 23 Oct 2010 18:42:20 GMT Connection: close Content-Length: 42 Bad Request (Invalid Header Name)".

I'm guessing it has something to do with Host parameter I'm setting being different from what it really is (I set it so it is elion.psu.edu, but when looking at the headers from my script it has changed back to grantbachman.com, where the script is hosted). I guess it'll be best just to show you. The beginning of the header I'm trying to create:

https://elion.psu.edu/cgi-bin/elion-student.exe/submit

POST /cgi-bin/elion-student.exe/submit HTTP/1.1
Host: elion.psu.edu

The beginning of the header which shows up when I run my script:

http://myDomain.com/myScriptName.php

GET /elionScript.php HTTP/1.1
Host: myDomain.com

Basically, the first line is different, the Host name is different, and it says I'm sending my info with a GET variable instead of a POST variable (even though I set curlopt_post to true). I'm basically looking for any help with altering this info such that the server accepts my script. I'm fresh out of ideas. Thanks.

Oh here's the code I'm using:

$data = array(
    "$userIDName" => '********',
    "$passName" => '********',
    "$submitName" => 'Login+to+eLion',
    'submitController' => '',
    'forceUnicode' => '%D0%B4%D0%B0',
    'sessionKey' => "$sessionValue",
    'pageKey' => "$pageKeyValue",
    'shopperID' => '');

$contentLength = strlen($userIDName . '=*********&' . $passName . '=********&' . $submitName .'=Login+to+eLion&submitController=&forceUnicode=%D0%B4%D0%B0&sessionKey=' . $sessionValue . '&pageKey=' . $pageKeyValue . '&shopperID=');

$ch = curl_init("https://elion.psu.edu/cgi-bin/elion-student.exe/submit");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIE,'sessionKey="$sessionValue";pageKey="$pageKeyValue";BIGipServerelion_prod_pool="$prodPoolValue"');
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
    'Host: elion.psu.edu',
    'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10',
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language: en-us,en;q=0.5','Accept-Encoding: gzip,deflate',
    'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
    'Keep-Alive: 115',
    'Referer: https://elion.psu.edu/cgi-bin/elion-student.exe/launch/ELionMainGUI/Student',
    "Cookie: sessionKey=$sessionValue; pageKey=$pageKeyValue; BIGipServerelion_prod_pool=$prodPoolValue", 'Content-Type: application/x-www-form-urlencoded',
    "Content-Length: $contentLength"));
$contents2 = curl_exec ($ch);

I't also probably important to note that when I run the script, none of the information below the 'Keep-Alive: 115' line is displayed when I view the header.

A: 

Hello David,

Seems it missing some code in your question but try this :

1- Save your certificate on your server

2- Try this code

$pg = curl_init();
// Set the form data for posting the login information
$postData = array();
$postData["username"] = $username;
$postData["password"] = $password;

$postText = "";

foreach( $postData as $key => $value ) {
$postText .= $key . "=" . $value . "&";
}

curl_setopt( $pg, CURLOPT_URL, $YOUR_URL );
curl_setopt( $pg, CURLOPT_POST, true );
curl_setopt( $pg, CURLOPT_POSTFIELDS, $postText );
curl_setopt( $pg, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $pg, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $pg, CURLOPT_CAINFO, getcwd() . '/web'); //web is the exported certificate


//curl_setopt( $pg, CURLOPT_VERBOSE, true ); // for debug 
//curl_setopt( $pg, CURLOPT_RETURNTRANSFERT, true); // if you want a ouput
curl_setopt( $pg, CURLOPT_COOKIEJAR, "cookies.txt" );
curl_setopt( $pg, CURLOPT_COOKIEFILE, "cookies.txt" );
curl_setopt( $pg, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)" );
curl_setopt( $pg, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $pg, CURLOPT_COOKIE, session_name() . '=' . session_id() );

if( ( $response = curl_exec( $pg ) ) === false ) {
        echo '*Curl erro' . curl_error($pg) . "\n";
}

curl_close($pg)

$YOUR_URL:https://elion.psu.edu/cgi-bin/elion-student.exe/launch/ELionMainGUI/Student

The form using dynamic name so its not simple like "username" and "password". Check on the website to know a "good" one.

Do not forget to add others hidden field like you did in the postData array and update the cookie section too.

racar
Thanks for your help so far, but I've ran into another problem. I've never messed with certificates or sessions before, but I visited the site and downloaded the certificate to my server. However, I'm getting this error:"SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed". I went the easier way and just set VERIFYPEER to false. This worked, but I keep hitting their Session Expired page. Do you know what would cause it to behave this way, or am I doing something wrong?
Grant David Bachman
Well i assume you're doing something wrong , because its aint working. From my side , i can't do some test because i don't have access , and its seems like senstive content so , this will be hard for me to help you more.
racar