Script permettant de décoder le password SOAP de WebSphere.

  • Prendre le password SOAP de la version WebSphere installé.

  • #!/usr/bin/perl
    
    use warnings;
    use strict;
    use Getopt::Long qw(:config pass_through);
    use File::Basename;
    use Pod::Usage;
    
    my $password;           
    
    
    # Programme, nom et version
    my $PROGNAME   = lc basename($0);
    my $CVSVERSION = '$Revision: 1.8 $';
    
    # Prend les options --help and --man
    if ( @ARGV == 0 )               { &usage; };
    GetOptions(   "help"    =>  sub { &usage; },
                  "man"     =>  sub { pod2usage( -exitval =>  0, -verbose => 2); },
               );
    
    
    $password=$ARGV[0];
    
    # On décode si la chaine est encodée, on encode si c'est une chaine de caractère
    if ($password =~ s/{xor}(.*)/$1/)
    	{ print decode($password); }
    else
    	{ print encode($password); };
    
    exit 0;
    
    
    
    
    
    sub encode
    {
        my (@data)  = @_;
        my $string  = $data[0];
        my $eol     = $data[1];
    
        my $res;
        my $padding;
    
        $eol        = "\n" unless defined $eol;
    
        $string     = ibmxor($string);
    
        $res        = pack("u", $string);
    
        # Remove first character of each line, remove newlines
        $res        =~ s/^.//mg;
        $res        =~ s/\n//g;
        $res        =~ tr|` -_|AA-Za-z0-9+/|;               # `
    
        # fix padding at the end
        $padding    =   (3 - length($string) % 3) % 3;
        $res        =~  s/.{$padding}$/'=' x $padding/e if $padding;
    
        # break encoded string into lines of no more than 76 characters each
        if (length $eol)
        {
            $res =~ s/(.{1,76})/$1$eol/g;
        };
    
        return "{xor}",$res;
    }
    
    
    
    
    sub decode
    	{
    	my ($string) = @_;
    	my $len;
    	my $tempstring;
    	my @chars;
    
    	# basic uudecode, la variable string ne doit pas excèder 86 octets
    	$string	=~ tr#A-Za-z0-9+/##cd;
    	$string =~ tr#A-Za-z0-9+/# -_#;
    	$len	=  pack("c", 32 + 0.75*length($string));
    	$tempstring =  unpack("u", $len . $string);
    
    	return ibmxor($tempstring)."\n";
    	};
    
    
    
    sub ibmxor
    {
        my ($string) = @_;
        my @chars;
    
        @chars = unpack('C*', $string);
        for my $cnt (0 .. $#chars) { $chars[$cnt] ^= 0x5f; };
    
        return pack('C*', @chars);
    };
    
    sub usage
    {
        my ($version) = $CVSVERSION =~ /(\d\S+)/;
        print "$PROGNAME $version\n\n";
        pod2usage( -exitval =>  0, -verbose =>  1);
        return 0;
    };