| 1 | package WWW::TamperData; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use XML::Simple; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use HTTP::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | WWW::TamperData - Replay tamper data XML files | ||||||||||
| 13 | |||||||||||
| 14 | =head1 VERSION | ||||||||||
| 15 | |||||||||||
| 16 | Version 0.09 | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | # Globals | ||||||||||
| 21 | 2 | our $VERSION = '0.09'; | |||||||||
| 22 | 2 | our $AUTHOR = 'Eldar Marcussen - http://www.justanotherhacker.com'; | |||||||||
| 23 | 2 | our $_tamperagent; | |||||||||
| 24 | 2 | our $_tamperxml; | |||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | use WWW::TamperData; | ||||||||||
| 29 | |||||||||||
| 30 | my $foo = WWW::TamperData->new(transcript => "myfile.xml"); | ||||||||||
| 31 | my %data = $foo->replay(); | ||||||||||
| 32 | |||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||
| 34 | Tamperdata is a firefox extension that lets you intercept or inspect browser requests and the server responses. WWW::TamperData can replay | ||||||||||
| 35 | requests exported to an XML file from Tamperdata. | ||||||||||
| 36 | |||||||||||
| 37 | =head1 SUBROUTINES/METHODS | ||||||||||
| 38 | |||||||||||
| 39 | =head2 new | ||||||||||
| 40 | |||||||||||
| 41 | Initializes the new object, it takes some options; | ||||||||||
| 42 | |||||||||||
| 43 | =over 4 | ||||||||||
| 44 | |||||||||||
| 45 | =item WWW::TamperData->new(%options); | ||||||||||
| 46 | |||||||||||
| 47 | KEY DEFAULT USE | ||||||||||
| 48 | --------------- ----------------- -------------------------------------------------- | ||||||||||
| 49 | transcript undef Filename to read tamperdata xml from | ||||||||||
| 50 | timeout 60 LWP connection timeout | ||||||||||
| 51 | requestfilter undef Name of function to call before making the request | ||||||||||
| 52 | responsefilter undef Name of function to call after making the request | ||||||||||
| 53 | |||||||||||
| 54 | =back | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=5 SCAR=19.5
Pod
documented
| |||||||||||
| 59 | 1 | my ($class, %options) = @_; | |||||||||
| 60 | 1 | my $self = {}; | |||||||||
| 61 | |||||||||||
| 62 | 1 | ▶ | if ($options{'transcript'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $self->{'transcript'} = $options{'transcript'}; | |||||||||
| 64 | 0 | $_tamperxml = XMLin($self->{'transcript'}); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | $self->{'timeout'} = $options{'timeout'} ? $options{'timeout'} : 60; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | |||||||||||
| 69 | 1 | ▶ | if ($options{'requestfilter'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | $self->{requestfilter}{module} = caller; | |||||||||
| 71 | 0 | $self->{requestfilter}{function} = $options{'requestfilter'}; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 1 | ▶ | if ($options{'responsefilter'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 0 | $self->{responsefilter}{module} = caller; | |||||||||
| 76 | 0 | $self->{responsefilter}{function} = $options{'responsefilter'}; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 1 | $_tamperagent = LWP::UserAgent->new; | |||||||||
| 80 | 1 | $_tamperagent->timeout($self->{'timeout'}); | |||||||||
| 81 | 1 | return bless $self, $class; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | =head2 replay | ||||||||||
| 85 | |||||||||||
| 86 | This function will replay all the requests provided in the xml file in sequential order. | ||||||||||
| 87 | |||||||||||
| 88 | =cut | ||||||||||
| 89 | |||||||||||
| 90 | #TODO: Add delay between requests | ||||||||||
| 91 | 0 | ▶ | sub replay { | ||||||||
|
Subroutine
replay: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 92 | 0 | my $self = shift; | |||||||||
| 93 | 0 | ▶ | if (ref($_tamperxml->{tdRequest}) eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | for my $x (0..scalar $_tamperxml->{tdRequest}) { | |||||||||
| 95 | 0 | $self->_make_request($_tamperxml->{tdRequest}->[$x]); | |||||||||
| 96 | |||||||||||
| 97 | } | ||||||||||
| 98 | } else { | ||||||||||
| 99 | 0 | $self->_make_request($_tamperxml->{tdRequest}); | |||||||||
| 100 | } | ||||||||||
| 101 | 0 | return 1; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | =head2 requestfilter | ||||||||||
| 105 | |||||||||||
| 106 | Callback function that allows inspection/tampering of the uri and parameters before the request is performed. | ||||||||||
| 107 | |||||||||||
| 108 | =cut | ||||||||||
| 109 | |||||||||||
| 110 | 0 | ▶ | sub requestfilter { | ||||||||
|
Subroutine
requestfilter: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 111 | 0 | my ($self, $callback) = @_; | |||||||||
| 112 | 0 | $self->{requestfilter}{module} = caller; | |||||||||
| 113 | 0 | $self->{requestfilter}{function} = $callback; | |||||||||
| 114 | 0 | return 1; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | =head2 responsefilter | ||||||||||
| 118 | |||||||||||
| 119 | Callback function that allows inspection of the response object. | ||||||||||
| 120 | |||||||||||
| 121 | =cut | ||||||||||
| 122 | |||||||||||
| 123 | 0 | ▶ | sub responsefilter { | ||||||||
|
Subroutine
responsefilter: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 124 | 0 | my ($self, $callback) = @_; | |||||||||
| 125 | 0 | $self->{responsefilter}{module} = caller; | |||||||||
| 126 | 0 | $self->{responsefilter}{function} = $callback; | |||||||||
| 127 | 0 | return 1; | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | # Internal functions | ||||||||||
| 131 | |||||||||||
| 132 | 0 | ▶ | sub _make_request { | ||||||||
|
Subroutine
_make_request: not called CC=7 SCAR=40.3
| |||||||||||
| 133 | 0 | my ($self, $uriobj) = @_; | |||||||||
| 134 | # TODO: Make this _process_request_filter() & support multiple filters | ||||||||||
| 135 | 0 | ▶ | if ($self->{requestfilter}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 0 | my $rqfclass = $self->{requestfilter}{module}; | |||||||||
| 137 | 0 | my $rqfmethod = $self->{requestfilter}{function}; | |||||||||
| 138 | 0 | eval { $rqfclass->$rqfmethod($uriobj); }; | |||||||||
| 139 | 0 | ▶ | carp "Request filter errors:\n $@" if ($@); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 140 | } | ||||||||||
| 141 | 0 | $uriobj->{uri} =~ s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/gei; | |||||||||
| 142 | 0 | my $request = HTTP::Request->new($uriobj->{tdRequestMethod} => "$uriobj->{uri}"); | |||||||||
| 143 | 0 | my $request_headers = $uriobj->{tdRequestHeaders}{tdRequestHeader}; | |||||||||
| 144 | 0 | foreach my $header (keys %{$request_headers} ) { | |||||||||
| 145 | 0 | $request_headers->{$header}{content} =~ s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/gei; | |||||||||
| 146 | 0 | $request->push_header($header => $request_headers->{$header}{content}); | |||||||||
| 147 | } | ||||||||||
| 148 | 0 | my $response = $_tamperagent->request($request); | |||||||||
| 149 | # TODO: Make this into _process_response_filter() & support multiple filters | ||||||||||
| 150 | 0 | ▶ | if ($self->{responsefilter}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 151 | 0 | my $rpfclass = $self->{responsefilter}{module}; | |||||||||
| 152 | 0 | my $rpfmethod = $self->{responsefilter}{function}; | |||||||||
| 153 | 0 | eval { $rpfclass->$rpfmethod($uriobj, $response); }; | |||||||||
| 154 | 0 | ▶ | carp "Response filter errors:\n $@\n" if ($@); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 155 | } | ||||||||||
| 156 | 0 | ▶ | if (!$response->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 0 | croak $response->status_line; | |||||||||
| 158 | } | ||||||||||
| 159 | 0 | return $response; | |||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | 0 | ▶ | sub _process_request_filter { | ||||||||
|
Subroutine
_process_request_filter: not called CC=1 SCAR=0.0
| |||||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | 0 | ▶ | sub _process_response_filter { | ||||||||
|
Subroutine
_process_response_filter: not called CC=1 SCAR=0.0
| |||||||||||
| 166 | } | ||||||||||
| 167 | |||||||||||
| 168 | |||||||||||
| 169 | |||||||||||
| 170 | =head1 AUTHOR | ||||||||||
| 171 | |||||||||||
| 172 | Eldar Marcussen, C<< <japh at justanotherhacker.com> >> | ||||||||||
| 173 | |||||||||||
| 174 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 175 | |||||||||||
| 176 | Please report any bugs or feature requests to C<bug-www-tamperdata at rt.cpan.org>, or through | ||||||||||
| 177 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-TamperData>. I will be notified, and then you'll | ||||||||||
| 178 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 179 | |||||||||||
| 180 | =head1 SUPPORT | ||||||||||
| 181 | |||||||||||
| 182 | You can find documentation for this module with the perldoc command. | ||||||||||
| 183 | |||||||||||
| 184 | perldoc WWW::TamperData | ||||||||||
| 185 | |||||||||||
| 186 | |||||||||||
| 187 | You can also look for information at: | ||||||||||
| 188 | |||||||||||
| 189 | =over 4 | ||||||||||
| 190 | |||||||||||
| 191 | =item * RT: CPAN's request tracker | ||||||||||
| 192 | |||||||||||
| 193 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-TamperData> | ||||||||||
| 194 | |||||||||||
| 195 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 196 | |||||||||||
| 197 | L<http://annocpan.org/dist/WWW-TamperData> | ||||||||||
| 198 | |||||||||||
| 199 | =item * CPAN Ratings | ||||||||||
| 200 | |||||||||||
| 201 | L<http://cpanratings.perl.org/d/WWW-TamperData> | ||||||||||
| 202 | |||||||||||
| 203 | =item * Search CPAN | ||||||||||
| 204 | |||||||||||
| 205 | L<http://search.cpan.org/dist/WWW-TamperData> | ||||||||||
| 206 | |||||||||||
| 207 | =back | ||||||||||
| 208 | |||||||||||
| 209 | |||||||||||
| 210 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 211 | |||||||||||
| 212 | Copyright 2009 Eldar Marcussen, all rights reserved. | ||||||||||
| 213 | |||||||||||
| 214 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 215 | under the same terms as Perl itself. | ||||||||||
| 216 | |||||||||||
| 217 | |||||||||||
| 218 | =cut | ||||||||||
| 219 | |||||||||||
| 220 | 2 | 1; # End of WWW::TamperData | |||||||||