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
|
|
13206
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#use Net::SNMP qw(:asn1); |
12
|
1
|
|
|
1
|
|
453
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
649
|
|
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
|
1084
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
53
|
|
|
|
|
40
|
my $passwd; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Call as sub |
43
|
53
|
50
|
|
|
|
125
|
if ($self =~ /^Cisco::SNMP/) { |
44
|
53
|
|
|
|
|
67
|
($passwd) = @_ |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
|
|
|
|
0
|
$passwd = $self |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
53
|
50
|
33
|
|
|
255
|
if (($passwd =~ /^[\da-f]+$/i) && (length($passwd) > 2)) { |
50
|
53
|
50
|
|
|
|
81
|
if (!(length($passwd) & 1)) { |
51
|
53
|
|
|
|
|
48
|
my $dec = ""; |
52
|
53
|
|
|
|
|
130
|
my ($s, $e) = ($passwd =~ /^(..)(.+)/o); |
53
|
|
|
|
|
|
|
|
54
|
53
|
|
|
|
|
130
|
for (my $i = 0; $i < length($e); $i+=2) { |
55
|
|
|
|
|
|
|
# If we move past the end of the XOR key, reset |
56
|
265
|
100
|
|
|
|
371
|
if ($s > $#xlat) { $s = 0 } |
|
4
|
|
|
|
|
6
|
|
57
|
265
|
|
|
|
|
720
|
$dec .= sprintf "%c",hex(substr($e,$i,2))^$xlat[$s++] |
58
|
|
|
|
|
|
|
} |
59
|
53
|
|
|
|
|
121
|
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
|
1386
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
4
|
my ($cleartxt, $index); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Call as sub |
72
|
3
|
50
|
|
|
|
14
|
if ($self =~ /^Cisco::SNMP/) { |
73
|
3
|
|
|
|
|
6
|
($cleartxt, $index) = @_ |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
0
|
$cleartxt = $self; |
76
|
0
|
|
|
|
|
0
|
($index) = @_ |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
4
|
my $start = 0; |
80
|
3
|
|
|
|
|
7
|
my $end = $#xlat; |
81
|
|
|
|
|
|
|
|
82
|
3
|
100
|
|
|
|
36
|
if (defined $index) { |
83
|
2
|
100
|
|
|
|
13
|
if ($index =~ /^\d+$/) { |
|
|
50
|
|
|
|
|
|
84
|
1
|
50
|
33
|
|
|
9
|
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
|
|
|
|
|
3
|
$start = $index; |
89
|
1
|
|
|
|
|
3
|
$end = $index |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} elsif ($index eq "") { |
92
|
|
|
|
|
|
|
# Do them all - currently set for that. |
93
|
|
|
|
|
|
|
} else { |
94
|
1
|
|
|
|
|
5
|
my $random = int(rand($#xlat + 1)); |
95
|
1
|
|
|
|
|
2
|
$start = $random; |
96
|
1
|
|
|
|
|
1
|
$end = $random |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
3
|
my @passwds; |
101
|
3
|
|
|
|
|
10
|
for (my $j = $start; $j <= $end; $j++) { |
102
|
55
|
|
|
|
|
73
|
my $encrypt = sprintf "%02i", $j; |
103
|
55
|
|
|
|
|
48
|
my $s = $j; |
104
|
|
|
|
|
|
|
|
105
|
55
|
|
|
|
|
80
|
for (my $i = 0; $i < length($cleartxt); $i++) { |
106
|
|
|
|
|
|
|
# If we move past the end of the XOR key, reset |
107
|
275
|
100
|
|
|
|
365
|
if ($s > $#xlat) { $s = 0 } |
|
4
|
|
|
|
|
7
|
|
108
|
275
|
|
|
|
|
608
|
$encrypt .= sprintf "%02X", ord(substr($cleartxt,$i,1))^$xlat[$s++] |
109
|
|
|
|
|
|
|
} |
110
|
55
|
|
|
|
|
121
|
push @passwds, $encrypt |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
return \@passwds |
113
|
3
|
|
|
|
|
12
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
################################################## |
116
|
|
|
|
|
|
|
# End Public Module |
117
|
|
|
|
|
|
|
################################################## |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |