HTTP_Proxy_IMP/IMP/Example/changeTarget.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 53 CC 1 SCAR 6.9
CC
1
Cov
0%
RTYPES
2.0
new_analyzer
2.0
request_hdr
2.0
CRAP 2.0
1 # sample IMP plugin to change target host by replacing request header
2 # for this example it get changed to spiegel.de - whatever we want to access
3 # THIS IS JUST A SILLY EXAMPLE!!!!
4  
5 use strict;
6 use warnings;
7 package App::HTTP_Proxy_IMP::IMP::Example::changeTarget;
8 use base 'Net::IMP::HTTP::Request';
9  
10 use Net::IMP;
11 use Net::IMP::Debug;
12  
13 my $target = 'www.spiegel.de';
14 sub RTYPES { ( IMP_PASS,IMP_REPLACE,IMP_DENY ) }
15  
16 sub new_analyzer {
17 my ($class,%args) = @_;
18 my $self = $class->SUPER::new_analyzer(%args);
19 $self->run_callback(
20 # we don't need to look at response
21 [ IMP_PASS,1,IMP_MAXOFFSET ],
22 );
23 return $self;
24 }
25  
26  
27 sub request_hdr {
28 my ($self,$hdr) = @_;
29 my $len = length($hdr) or return;
30 $hdr =~s{\A(\S+\s+http://)([^\s/]+)}{$1$target}; # first line absoluteURI
31 $hdr =~s{^Host:\s*(.*)}{Host: www.spiegel.de}mi; # host header
32 $self->run_callback(
33 [ IMP_REPLACE,0,$len,$hdr ], # replace header
34 [ IMP_PASS,0,IMP_MAXOFFSET ], # pass thru everything else
35 );
36 }
37  
38 # will not be called
39 sub request_body {}
40 sub response_hdr {}
41 sub response_body {}
42 sub any_data {}
43  
44 1;
45  
46 __END__