line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Cisco; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
65838
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
10
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
938
|
|
15
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'subs' => [qw( cisco_encrypt cisco_decrypt )], ); |
16
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{$EXPORT_TAGS{'subs'}} ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Cisco's XOR key |
21
|
|
|
|
|
|
|
my @xlat = ( |
22
|
|
|
|
|
|
|
0x64, 0x73, 0x66, 0x64, 0x3B, 0x6B, 0x66, 0x6F, 0x41, 0x2C, 0x2E, 0x69, |
23
|
|
|
|
|
|
|
0x79, 0x65, 0x77, 0x72, 0x6B, 0x6C, 0x64, 0x4A, 0x4B, 0x44, 0x48, 0x53, |
24
|
|
|
|
|
|
|
0x55, 0x42, 0x73, 0x67, 0x76, 0x63, 0x61, 0x36, 0x39, 0x38, 0x33, 0x34, |
25
|
|
|
|
|
|
|
0x6E, 0x63, 0x78, 0x76, 0x39, 0x38, 0x37, 0x33, 0x32, 0x35, 0x34, 0x6B, |
26
|
|
|
|
|
|
|
0x3B, 0x66, 0x67, 0x38, 0x37 |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $warn = sprintf |
30
|
|
|
|
|
|
|
"\n" . |
31
|
|
|
|
|
|
|
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" . |
32
|
|
|
|
|
|
|
"'password_*' subs are deprecated.\n" . |
33
|
|
|
|
|
|
|
"They will be removed from a future release." . |
34
|
|
|
|
|
|
|
"Instead, use 'cisco_*'\n" . |
35
|
|
|
|
|
|
|
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" . |
36
|
|
|
|
|
|
|
"\n"; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
################################################## |
39
|
|
|
|
|
|
|
# Start Public Module |
40
|
|
|
|
|
|
|
################################################## |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub password_decrypt { |
43
|
0
|
|
|
0
|
1
|
0
|
warn($warn); |
44
|
0
|
|
|
|
|
0
|
return cisco_decrypt(@_); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub cisco_decrypt { |
48
|
53
|
|
|
53
|
1
|
676
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
53
|
|
|
|
|
56
|
my $passwd; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Call as sub |
53
|
53
|
50
|
|
|
|
84
|
if ( $self =~ /^Crypt::Cisco/ ) { |
54
|
0
|
|
|
|
|
0
|
($passwd) = @_; |
55
|
|
|
|
|
|
|
} else { |
56
|
53
|
|
|
|
|
58
|
$passwd = $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
53
|
50
|
33
|
|
|
196
|
if ( ( $passwd =~ /^[\da-f]+$/i ) and ( length($passwd) > 2 ) ) { |
60
|
53
|
50
|
|
|
|
82
|
if ( !( length($passwd) & 1 ) ) { |
61
|
53
|
|
|
|
|
60
|
my $dec = ""; |
62
|
53
|
|
|
|
|
138
|
my ( $s, $e ) = ( $passwd =~ /^(..)(.+)/o ); |
63
|
|
|
|
|
|
|
|
64
|
53
|
|
|
|
|
109
|
for ( my $i = 0; $i < length($e); $i += 2 ) { |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# If we move past the end of the XOR key, reset |
67
|
265
|
100
|
|
|
|
450
|
if ( $s > $#xlat ) { $s = 0 } |
|
4
|
|
|
|
|
5
|
|
68
|
265
|
|
|
|
|
609
|
$dec .= sprintf "%c", |
69
|
|
|
|
|
|
|
hex( substr( $e, $i, 2 ) ) ^ $xlat[$s++]; |
70
|
|
|
|
|
|
|
} |
71
|
53
|
|
|
|
|
136
|
return $dec; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
0
|
carp("Invalid password `$passwd'"); |
75
|
0
|
|
|
|
|
0
|
return ""; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub password_encrypt { |
79
|
0
|
|
|
0
|
1
|
0
|
warn($warn); |
80
|
0
|
|
|
|
|
0
|
return cisco_decrypt(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub cisco_encrypt { |
84
|
3
|
|
|
3
|
1
|
791
|
my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
|
|
5
|
my ( $cleartxt, $index ); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Call as sub |
89
|
3
|
50
|
|
|
|
8
|
if ( $self =~ /^Crypt::Cisco/ ) { |
90
|
0
|
|
|
|
|
0
|
( $cleartxt, $index ) = @_; |
91
|
|
|
|
|
|
|
} else { |
92
|
3
|
|
|
|
|
3
|
$cleartxt = $self; |
93
|
3
|
|
|
|
|
19
|
($index) = @_; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
3
|
|
|
|
|
6
|
my $start = 0; |
97
|
3
|
|
|
|
|
4
|
my $end = $#xlat; |
98
|
|
|
|
|
|
|
|
99
|
3
|
100
|
|
|
|
6
|
if ( defined $index ) { |
100
|
2
|
100
|
|
|
|
10
|
if ( $index =~ /^\d+$/ ) { |
101
|
1
|
50
|
33
|
|
|
5
|
if ( ( $index < 0 ) or ( $index > $end ) ) { |
102
|
0
|
|
|
|
|
0
|
carp("Index out of range 0-$#xlat: $index"); |
103
|
0
|
|
|
|
|
0
|
return ""; |
104
|
|
|
|
|
|
|
} else { |
105
|
1
|
|
|
|
|
2
|
$start = $end = $index; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} else { |
109
|
1
|
|
|
|
|
25
|
$start = $end = int( rand( $#xlat + 1 ) ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
4
|
my @passwds; |
113
|
3
|
|
|
|
|
8
|
for ( my $j = $start; $j <= $end; $j++ ) { |
114
|
55
|
|
|
|
|
89
|
my $encrypt = sprintf "%02i", $j; |
115
|
55
|
|
|
|
|
66
|
my $s = $j; |
116
|
|
|
|
|
|
|
|
117
|
55
|
|
|
|
|
86
|
for ( my $i = 0; $i < length($cleartxt); $i++ ) { |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# If we move past the end of the XOR key, reset |
120
|
275
|
100
|
|
|
|
394
|
if ( $s > $#xlat ) { $s = 0 } |
|
4
|
|
|
|
|
5
|
|
121
|
275
|
|
|
|
|
555
|
$encrypt .= sprintf "%02X", |
122
|
|
|
|
|
|
|
ord( substr( $cleartxt, $i, 1 ) ) ^ $xlat[$s++]; |
123
|
|
|
|
|
|
|
} |
124
|
55
|
|
|
|
|
134
|
push @passwds, $encrypt; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
3
|
|
|
|
|
5
|
my $ret = \@passwds; |
128
|
3
|
100
|
|
|
|
8
|
if ( $#passwds == 0 ) { |
129
|
2
|
|
|
|
|
3
|
$ret = $passwds[0]; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
3
|
50
|
|
|
|
7
|
if ( wantarray ) { |
133
|
0
|
|
|
|
|
0
|
return @passwds; |
134
|
|
|
|
|
|
|
} else { |
135
|
3
|
|
|
|
|
12
|
return $ret; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
################################################## |
140
|
|
|
|
|
|
|
# End Public Module |
141
|
|
|
|
|
|
|
################################################## |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |