line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::Password; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
58236
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#use Net::SNMP qw(:asn1); |
12
|
1
|
|
|
1
|
|
395
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
517
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Cisco's XOR key |
19
|
|
|
|
|
|
|
my @xlat = ( |
20
|
|
|
|
|
|
|
0x64, 0x73, 0x66, 0x64, 0x3B, 0x6B, 0x66, 0x6F, 0x41, 0x2C, |
21
|
|
|
|
|
|
|
0x2E, 0x69, 0x79, 0x65, 0x77, 0x72, 0x6B, 0x6C, 0x64, 0x4A, |
22
|
|
|
|
|
|
|
0x4B, 0x44, 0x48, 0x53, 0x55, 0x42, 0x73, 0x67, 0x76, 0x63, |
23
|
|
|
|
|
|
|
0x61, 0x36, 0x39, 0x38, 0x33, 0x34, 0x6E, 0x63, 0x78, 0x76, |
24
|
|
|
|
|
|
|
0x39, 0x38, 0x37, 0x33, 0x32, 0x35, 0x34, 0x6B, 0x3B, 0x66, |
25
|
|
|
|
|
|
|
0x67, 0x38, 0x37 |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
################################################## |
29
|
|
|
|
|
|
|
# Start Public Module |
30
|
|
|
|
|
|
|
################################################## |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Override with empty new() |
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
1
|
0
|
return bless {}, __PACKAGE__ |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub password_decrypt { |
38
|
53
|
|
|
53
|
1
|
940
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
53
|
|
|
|
|
61
|
my $passwd; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Call as sub |
43
|
53
|
50
|
|
|
|
115
|
if ($self =~ /^Cisco::SNMP/) { |
44
|
53
|
|
|
|
|
79
|
($passwd) = @_ |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
|
|
|
|
0
|
$passwd = $self |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
53
|
50
|
33
|
|
|
187
|
if (($passwd =~ /^[\da-f]+$/i) && (length($passwd) > 2)) { |
50
|
53
|
50
|
|
|
|
91
|
if (!(length($passwd) & 1)) { |
51
|
53
|
|
|
|
|
66
|
my $dec = ""; |
52
|
53
|
|
|
|
|
133
|
my ($s, $e) = ($passwd =~ /^(..)(.+)/o); |
53
|
|
|
|
|
|
|
|
54
|
53
|
|
|
|
|
102
|
for (my $i = 0; $i < length($e); $i+=2) { |
55
|
|
|
|
|
|
|
# If we move past the end of the XOR key, reset |
56
|
265
|
100
|
|
|
|
420
|
if ($s > $#xlat) { $s = 0 } |
|
4
|
|
|
|
|
5
|
|
57
|
265
|
|
|
|
|
692
|
$dec .= sprintf "%c",hex(substr($e,$i,2))^$xlat[$s++] |
58
|
|
|
|
|
|
|
} |
59
|
53
|
|
|
|
|
134
|
return $dec |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
0
|
$Cisco::SNMP::LASTERROR = "Invalid password `$passwd'"; |
63
|
0
|
|
|
|
|
0
|
return(0) |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub password_encrypt { |
67
|
3
|
|
|
3
|
1
|
1097
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
8
|
my ($cleartxt, $index); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Call as sub |
72
|
3
|
50
|
|
|
|
13
|
if ($self =~ /^Cisco::SNMP/) { |
73
|
3
|
|
|
|
|
7
|
($cleartxt, $index) = @_ |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
0
|
$cleartxt = $self; |
76
|
0
|
|
|
|
|
0
|
($index) = @_ |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
5
|
my $start = 0; |
80
|
3
|
|
|
|
|
5
|
my $end = $#xlat; |
81
|
|
|
|
|
|
|
|
82
|
3
|
100
|
|
|
|
7
|
if (defined $index) { |
83
|
2
|
100
|
|
|
|
9
|
if ($index =~ /^\d+$/) { |
|
|
50
|
|
|
|
|
|
84
|
1
|
50
|
33
|
|
|
6
|
if (($index < 0) || ($index > $#xlat)) { |
85
|
0
|
|
|
|
|
0
|
$Cisco::SNMP::LASTERROR = "Index out of range 0-$#xlat: $index"; |
86
|
0
|
|
|
|
|
0
|
return(0) |
87
|
|
|
|
|
|
|
} else { |
88
|
1
|
|
|
|
|
2
|
$start = $index; |
89
|
1
|
|
|
|
|
2
|
$end = $index |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} elsif ($index eq "") { |
92
|
|
|
|
|
|
|
# Do them all - currently set for that. |
93
|
|
|
|
|
|
|
} else { |
94
|
1
|
|
|
|
|
4
|
my $random = int(rand($#xlat + 1)); |
95
|
1
|
|
|
|
|
2
|
$start = $random; |
96
|
1
|
|
|
|
|
2
|
$end = $random |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
5
|
my @passwds; |
101
|
3
|
|
|
|
|
8
|
for (my $j = $start; $j <= $end; $j++) { |
102
|
55
|
|
|
|
|
98
|
my $encrypt = sprintf "%02i", $j; |
103
|
55
|
|
|
|
|
71
|
my $s = $j; |
104
|
|
|
|
|
|
|
|
105
|
55
|
|
|
|
|
87
|
for (my $i = 0; $i < length($cleartxt); $i++) { |
106
|
|
|
|
|
|
|
# If we move past the end of the XOR key, reset |
107
|
275
|
100
|
|
|
|
422
|
if ($s > $#xlat) { $s = 0 } |
|
4
|
|
|
|
|
5
|
|
108
|
275
|
|
|
|
|
623
|
$encrypt .= sprintf "%02X", ord(substr($cleartxt,$i,1))^$xlat[$s++] |
109
|
|
|
|
|
|
|
} |
110
|
55
|
|
|
|
|
139
|
push @passwds, $encrypt |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
return \@passwds |
113
|
3
|
|
|
|
|
12
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
################################################## |
116
|
|
|
|
|
|
|
# End Public Module |
117
|
|
|
|
|
|
|
################################################## |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |