perl http编程

来源:互联网 发布:java 计算bmi 编辑:程序博客网 时间:2024/06/05 05:02

Burp Proxy抓包,观察数据流过程

1. GET获取SessionID

2. Post username&password


>>perl a.pl http://localhost/login.asp

ASPSESSIONIDQSRSDQQT=JNIJLIKDNHMDAGCFLGEOGIDC; AJSTAT_ok_pages=1; AJSTAT_ok_times=1


>>cat a.pl


#!/usr/bin/perl -lw


use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use strict;
use warnings;


my $ua       = new LWP::UserAgent;
my $cookie   = undef;
my $host     = $1 if ($ARGV[0] =~ /www.(.*)\/.*/);
my $origin   = 'http://'.$host;
my $ok_page  = '; AJSTAT_ok_pages=1';
my $ok_times = '; AJSTAT_ok_times=1';
my $action   = '?Acton=ok';
my $post_url = $ARGV[0].$action;
###############################################################################
# 1. Get cookie for next step
###############################################################################
#$ua->agent('Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36');
$ua->default_header('User-Agent' => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36');
$ua->default_header('Accept-Encoding' => 'gzip,deflate,sdch');
$ua->default_header('Accept-Language' => 'zh-CN,zh');
$ua->default_header('Accept' => 'textml,application/xhtml+xml,application/xml');
$ua->default_header('Host'   => $host);
$ua->default_header('Referer' => $ARGV[0]);


my $request = new HTTP::Request('GET', $ARGV[0]);
my $response = $ua->request($request);
if ($response->is_success) {
$cookie = $response->header('Set-Cookie');
} else {
print $response->error_as_HTML;
}


###############################################################################
# 2. Setup the cookie
###############################################################################
if($cookie =~ /(.*)\;/){
$cookie = $1;
}else{
die "Error COOKIE: $cookie";
}
$cookie = $cookie.$ok_page.$ok_times;
print $cookie;


###############################################################################
# 3. Login using the password
###############################################################################
$ua = undef;
$ua = new LWP::UserAgent;
#$ua->agent('Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36');
$ua->default_header('Accept-Encoding' => 'gzip,deflate,sdch');
$ua->default_header('Accept-Language' => 'zh-CN,zh');
$ua->default_header('Accept' => 'textml,application/xhtml+xml,application/xml');
$ua->default_header('Host'   => $host);
$ua->default_header('Referer' => $ARGV[0]);
$ua->default_header('Proxy-Connection' => 'keep-alive');
$ua->default_header('Cookie' => $cookie);
$ua->default_header('Content-Length' => '89');
$ua->default_header('Content-Type'   => 'application/x-www-form-urlencoded');
$ua->default_header('Origin' => $origin);
$ua->default_header('User-Agent' => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36');
$request = new HTTP::Request('POST', $post_url);


$request->content('username=jgjguyguj+&password=11111&cookietime=1&loginsubmit=+%B5%C7+%C2%BC+&action=login');
$response = $ua->request($request);
if ($response->is_success) {
print $response->content;
} else {
        print $response->error_as_HTML;
}

原创粉丝点击