Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Make a perl client fake a GET containing a cookie

Posted on 2000-05-09
6
Medium Priority
?
227 Views
Last Modified: 2010-03-05
Let's say I execute the following code and it doesn't work because the server
doesn't believe I have cookies enabled.  The server returns "Cannot Identify
User. You must allow cookies in  your browser so that PINVAL can identify you after
Login".

My code follows.  It works agains other http's that don't need a cookie.  I'm basically grabbing .HTML and dumping it to the disk.

     use LWP::UserAgent;
     $user_agent = new LWP::UserAgent;
     $request = new HTTP::Request ('GET','http://www.this.com/pinVAL/XS.ISA?Action=GETINSTSTD&ID=951692');
     $response = $user_agent->request($request);

     open FILEHANDLE, ">file.txt";
     print FILEHANDLE $response->content;
     close FILEHANDLE;

What can I do before hand to force the server to recognize my cookie?

I don't know much about the server, but when I sniff the transmission (during a IE 4.0 browser transmission) I see the following during a SEND.

GET /finVAL/Images/developed.jpg HTTP/1.1
Accepted: */*
Referer: http://www.this.com/finVAL/XS.ISA?Action=STCON
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt; version.dll)
Host: www.this.com
Connection: Keep-Allive
Cookie: PINXZZZ=MYACCT; PINDDDID=MYACCT-46158x19377x781178x50891218
0
Comment
Question by:cwoodwar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:tgoetze
ID: 2795638
You can add the cookie in the GET request by sending an optional third parameter to HTTP::Request.

For example:


use LWP::UserAgent;
use HTTP::Headers;

$h = new HTTP::Headers();
$h->header('Cookie' => 'PINXZZZ=MYACCT; PINDDDID=MYACCT-46158x19377x781178x50891218');

     $user_agent = new LWP::UserAgent;
     $request = new HTTP::Request ('GET','http://www.this.com/pinVAL/XS.ISA?Action=GETINSTSTD&ID=951692',$h);
     $response = $user_agent->request($request);

     open FILEHANDLE, ">file.txt";
     print FILEHANDLE $response->content;
     close FILEHANDLE;



You can also check out the HTTP::Cookies module if you want to store new cookies as you go.

0
 

Author Comment

by:cwoodwar
ID: 2795953
You mentioned the following.

"You can also check out the HTTP::Cookies module if you want to store new cookies as you go"

How do I do this.  I need to check the cookie so I can plug in the values.

How do I do this?

0
 
LVL 3

Expert Comment

by:tgoetze
ID: 2800954
You already have a way of transmitting the request with the approrpiate header (once you know the cookie content). If you can find where IE stores the cookie, you can just grab it and put it in the program. Often times the cookie value doesn't change very often. Look in: c:\windows\Profiles\user_name\Cookies for your cookies.

Alternatively, you can try to have Perl do everything for you. Two ways you can do this. (1) Write a script that does the original registration through the web page and consequently grabs the cookie when it is originally created. This requies a decent sized effort and good understanding of the site you are going to and LWP.

Here's an alternative:
(2) Use Netscape to establish your account originally. Then you can have HTTP::Cookies::Netscape share Netscape's cookies. Here's an example:

use LWP::UserAgent;
use HTTP::Cookies::Netscape;

     $user_agent = new LWP::UserAgent;
     $request = new HTTP::Request ('GET','http://www.this.com/pinVAL/XS.ISA?Action=GETINSTSTD&ID=951692',$h);
     $cookie_jar = HTTP::Cookies::Netscape->new(
                     File => 'C:\netscape\cookies', #CHANGE THIS TO POINT TO YOUR LOCATION
                     Autosave => 1
                   );
     $cookie_jar->add_cookie_header($request); # adds the header to the request, this is
                                               #  what I showed you how to do previously
     $response = $user_agent->request($request);

     #If you think the cookie might have changed, you can:
     $cookie_jar->extract($response);
     $cookie_jar->save();

     open FILEHANDLE, ">file.txt";
     print FILEHANDLE $response->content;
     close FILEHANDLE;



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
tgoetze earned 400 total points
ID: 2800982
I didn't clean up properly in the last code pasting. Try this as the code sample from in the previous post:

use LWP::UserAgent;
use HTTP::Cookies::Netscape;

     $user_agent = new LWP::UserAgent;
     $request = new HTTP::Request ('GET','http://www.this.com/pinVAL/XS.ISA?Action=GETINSTSTD&ID=951692');
     $cookie_jar = HTTP::Cookies::Netscape->new(
                     File => 'C:\netscape\cookies', #CHANGE THIS TO POINT TO YOUR LOCATION
                     Autosave => 1
                   );
     $cookie_jar->add_cookie_header($request); # adds the header to the request, this is
                                               #  what I showed you how to do previously
     $response = $user_agent->request($request);

     #If you think the cookie might have changed, you can:
     $cookie_jar->extract($response);
     $cookie_jar->save();

     open FILEHANDLE, ">file.txt";
     print FILEHANDLE $response->content;
     close FILEHANDLE;





0
 

Author Comment

by:cwoodwar
ID: 2800999
I'll give this a try when I get back to my other lab.

Please stand by.

Charles
0
 

Author Comment

by:cwoodwar
ID: 2802970
We nolonger have access to the target machine.  Therefore I can't 100% validate the answer.

Looking at the code I believe this definitely the answer.

Therefore I give tgoetze 95% out of a 100%.

Thank you very much.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question