blib/lib/WWW/Honeypot/httpBL.pm

filter: Statementstmt 21.7% 23 / 106 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 43 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 33.3% 7 / 21 Podpod 77.7% 7 / 9 totaltotal 15.6% 37 / 237 CC 33 SCAR 33.4
CC
33
Cov
12%
fetch
72.0
is_suspicious
42.0
is_harvester
42.0
CRAP 28.3
↑ Summary
1 package WWW::Honeypot::httpBL;
2  
3 3 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Net::hostent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use constant 'LOOKUP_DOMAIN' => 'dnsbl.httpbl.org';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 our $VERSION = '0.01';
14  
15 3 my $search_engines = {
16 '0' => 'Undocumented',
17 '1' => 'Alta Vista',
18 '2' => 'Ask',
19 '3' => 'Baidu',
20 '4' => 'Excite',
21 '5' => 'Google',
22 '6' => 'Looksmart',
23 '7' => 'Lycos',
24 '8' => 'MSN',
25 '9' => 'Yahoo',
26 '10' => 'InfoSeek',
27 '11' => 'Miscellaneous'
28 };
29  
30 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
31 0 my $pkg = shift;
32  
33 0 my $self = {};
34 0 bless $self, $pkg;
35  
36 0 ▶ if (! $self->_init(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_init(@_)) 0 0 0
37 0 return undef;
38 }
39  
40 0 return $self;
41 }
42  
43 0 ▶sub _init {
Subroutine _init: not called CC=2 SCAR=17.9
44 0 my $self = shift;
45 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
46  
47 0 $self->{'_debug'} = $args->{'debug'};
48 0 $self->{'_key'} = $args->{'access_key'};
49 0 $self->{'_current_ip'} = '';
50 0 $self->{'_current_response'} = '';
51 0 $self->{'_current_response_octets'} = [];
52  
53 0 return 1;
54 }
55  
56 0 ▶sub access_key {
Subroutine access_key: not called CC=2 SCAR=17.9
Pod undocumented
57 0 my $self = shift;
58 0 my $key = shift;
59  
60 0 ▶ if ($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) 0 0 0
61 0 $self->{'_key'} = $key;
62 }
63  
64 0 return $self->{'_key'};
65 }
66  
67 0 ▶sub fetch {
Subroutine fetch: not called CC=8 SCAR=42.8
Pod documented
68 0 my $self = shift;
69 0 my $ip = shift;
70  
71 0 $self->_reset();
72  
73 0 ▶ carp("No Access Key!") && return unless $self->access_key();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->access_key 0 0 0
Condition0%0/5
$self->access_key || carp('No Access Key!') && (return)
l!l&&r!l&&!r
000
carp("No Access Key!") and return
!ll
00
MC/DC0%0/2
$self->access_key || carp('No Access Key!') && (return)
$self->access_key carp("No Access Key!")
Truth table0%0/3
A || B
A= $self->access_keyB= carp("No Access Key!")
ABresult
1X1
011
000
74 0 ▶ carp("Nothing to fetch!") && return unless $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip 0 0 0
Condition0%0/5
$ip || carp('Nothing to fetch!') && (return)
l!l&&r!l&&!r
000
carp("Nothing to fetch!") and return
!ll
00
MC/DC0%0/2
$ip || carp('Nothing to fetch!') && (return)
$ip carp("Nothing to fetch!")
Truth table0%0/3
A || B
A= $ipB= carp("Nothing to fetch!")
ABresult
1X1
011
000
75  
76 0 ▶ unless ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) 0 0 0
77 0 my $err_str = "That doesn't look like an IP address!";
78 0 ▶ carp($err_str) && return $err_str;
Branch: 1 branch
BranchTrueFalseTotal
carp($err_str) and return $err_str 0 0 0
79 }
80  
81 0 $self->_lookup($self->_reverse_IP($ip));
82
83 0 ▶ return $self->{_current_response} ? ($self->_parse_response()) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_current_response'} ? : 0 0 0
84 }
85  
86 0 ▶sub threat_score {
Subroutine threat_score: not called CC=3 SCAR=24.8
Pod documented
87 0 my $self = shift;
88  
89 return ( $self->{_current_response} && !$self->is_search_engine() ) ?
90 0 ▶ ${$self->{_current_response_octets}}[2] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_current_response'} && !$self->is_search_engine ? : 0 0 0
Condition0%0/3
$self->{"_current_response"} and not $self->is_search_engine
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_current_response"} and not $self->is_search_engine
$self->{"_current_response"} not $self->is_search_engine
Truth table0%0/3
A and not(B)
A= $self->{"_current_response"}B= not $self->is_search_engine
ABresult
0X0
100
111
91 }
92  
93 0 ▶sub days_since_last_actvity {
Subroutine days_since_last_actvity: not called CC=3 SCAR=24.8
Pod documented
94 0 my $self = shift;
95  
96 return ( $self->{_current_response} && !$self->is_search_engine() ) ?
97 0 ▶ ${$self->{_current_response_octets}}[1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_current_response'} && !$self->is_search_engine ? : 0 0 0
Condition0%0/3
$self->{"_current_response"} and not $self->is_search_engine
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_current_response"} and not $self->is_search_engine
$self->{"_current_response"} not $self->is_search_engine
Truth table0%0/3
A and not(B)
A= $self->{"_current_response"}B= not $self->is_search_engine
ABresult
0X0
100
111
98 }
99  
100 0 ▶sub is_search_engine {
Subroutine is_search_engine: not called CC=3 SCAR=24.8
Pod documented
101 0 my $self = shift;
102  
103 0 ▶ return undef unless $self->{_current_response};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_current_response"} 0 0 0
104  
105 0 ▶ if ( ${$self->{_current_response_octets}}[3] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { $$self{'_current_response_octets'} }->[3] == 0) { } 0 0 0
106 0 my $serial_number = ${$self->{_current_response_octets}}[2];
107 0 return $search_engines->{$serial_number};
108 } else {
109 0 return;
110 }
111 }
112  
113 0 ▶sub is_suspicious {
Subroutine is_suspicious: not called CC=6 SCAR=37.4
Pod documented
114 0 my $self = shift;
115  
116 0 ▶ return undef unless $self->{_current_response};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_current_response"} 0 0 0
117  
118 0 my $c = ${$self->{_current_response_octets}}[3];
119 0 ▶ if ($c == 1 || $c == 3 || $c == 5 || $c == 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == 1 or $c == 3 or $c == 5 or $c == 7) { } 0 0 0
Condition0%0/9
$c == 1 or $c == 3 or $c == 5 or $c == 7
l!l&&r!l&&!r
000
$c == 1 or $c == 3 or $c == 5
l!l&&r!l&&!r
000
$c == 1 or $c == 3
l!l&&r!l&&!r
000
MC/DC0%0/4
$c == 1 or $c == 3 or $c == 5 or $c == 7
$c == 1 $c == 3 $c == 5 $c == 7
Truth table0%0/5
A or B or C or D
A= $c == 1B= $c == 3C= $c == 5D= $c == 7
ABCDresult
1XXX1
01XX1
001X1
00011
00000
120 0 return 1;
121 } else {
122 0 return undef;
123 }
124 }
125  
126 0 ▶sub is_harvester {
Subroutine is_harvester: not called CC=6 SCAR=37.4
Pod documented
127 0 my $self = shift;
128  
129 0 ▶ return undef unless $self->{_current_response};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_current_response"} 0 0 0
130  
131 0 my $c = ${$self->{_current_response_octets}}[3];
132 0 ▶ if ($c == 2 || $c == 3 || $c == 6 || $c == 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == 2 or $c == 3 or $c == 6 or $c == 7) { } 0 0 0
Condition0%0/9
$c == 2 or $c == 3 or $c == 6 or $c == 7
l!l&&r!l&&!r
000
$c == 2 or $c == 3 or $c == 6
l!l&&r!l&&!r
000
$c == 2 or $c == 3
l!l&&r!l&&!r
000
MC/DC0%0/4
$c == 2 or $c == 3 or $c == 6 or $c == 7
$c == 2 $c == 3 $c == 6 $c == 7
Truth table0%0/5
A or B or C or D
A= $c == 2B= $c == 3C= $c == 6D= $c == 7
ABCDresult
1XXX1
01XX1
001X1
00011
00000
133 0 return 1;
134 } else {
135 0 return undef;
136 }
137 }
138  
139 0 ▶sub is_comment_spammer {
Subroutine is_comment_spammer: not called CC=6 SCAR=37.4
Pod documented
140 0 my $self = shift;
141  
142 0 ▶ return undef unless $self->{_current_response};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_current_response"} 0 0 0
143  
144 0 my $c = ${$self->{_current_response_octets}}[3];
145  
146 0 ▶ if ($c == 4 || $c == 5 || $c == 6 || $c == 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == 4 or $c == 5 or $c == 6 or $c == 7) { } 0 0 0
Condition0%0/9
$c == 4 or $c == 5 or $c == 6 or $c == 7
l!l&&r!l&&!r
000
$c == 4 or $c == 5 or $c == 6
l!l&&r!l&&!r
000
$c == 4 or $c == 5
l!l&&r!l&&!r
000
MC/DC0%0/4
$c == 4 or $c == 5 or $c == 6 or $c == 7
$c == 4 $c == 5 $c == 6 $c == 7
Truth table0%0/5
A or B or C or D
A= $c == 4B= $c == 5C= $c == 6D= $c == 7
ABCDresult
1XXX1
01XX1
001X1
00011
00000
147 0 return 1;
148 } else {
149 0 return undef;
150 }
151 }
152  
153 # Internal methods below
154  
155 0 ▶sub _lookup {
Subroutine _lookup: not called CC=2 SCAR=17.9
156 0 my $self = shift;
157 0 my $reversed_ip = shift;
158  
159 0 my $str = join('.', $self->access_key(), $reversed_ip, LOOKUP_DOMAIN);
160  
161 0 my $h = gethost($str);
162  
163 0 ▶ return unless $h;
Branch: 1 branch
BranchTrueFalseTotal
unless $h 0 0 0
164  
165 0 $self->{_current_response} = inet_ntoa($h->addr);
166 }
167  
168 0 ▶sub _reverse_IP {
Subroutine _reverse_IP: not called CC=1 SCAR=6.9
169 0 my $self = shift;
170 0 my $ip = shift;
171  
172 0 my @parts = split(/\./, $ip);
173 0 return join('.', reverse(@parts));
174 }
175  
176 0 ▶sub _parse_response {
Subroutine _parse_response: not called CC=1 SCAR=6.9
177 0 my $self = shift;
178  
179 0 my @octets = split(/\./, $self->{_current_response});
180 0 push(@{$self->{_current_response_octets}}, @octets);
181 0 return @octets;
182 }
183  
184 0 ▶sub _reset {
Subroutine _reset: not called CC=1 SCAR=6.9
185 0 my $self = shift;
186  
187 0 $self->{'_current_ip'} = '';
188 0 $self->{'_current_response'} = '';
189 0 $self->{'_current_response_octets'} = [];
190 }
191  
192 3 1;
193 __END__
↑ Summary