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