Authen-Perl-NTLM

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

#!/usr/bin/perl

use ExtUtils::MakeMaker;
eval "require Crypt::DES && require Digest::MD4";
if ($@) {
    WriteMakefile(
	'NAME'	    => 'Authen::Perl::NTLM',
	'VERSION_FROM'  => 'lib/Authen/Perl/NTLM.pm',
	'PREREQ_PM'     => {
			       Crypt::DES_PP => 1.00,
			       Digest::Perl::MD4 => 1.0, 
			   }
    );
}
else {
    WriteMakefile(
	'NAME'		=> 'Authen::Perl::NTLM',
	'VERSION_FROM'	=> 'lib/Authen/Perl/NTLM.pm',
	'PREREQ_PM'     => {
			   Crypt::DES => 2.03,
			   Digest::MD4 => 1.1, 
			   }
);
}

README  view on Meta::CPAN

    responses.

    This module was written without the knowledge of Mark Bush's (MARKBUSH)
    NTLM implementation. It was used by Yee Man Chan to implement a Perl
    DCOM client.

DEPENDENCIES
    To use this module, please install the one of the following two sets of
    DES and MD4 modules:

    1) Crypt::DES module by Dave Paris (DPARIS) and Digest::MD4 module by
    Mike McCauley (MIKEM) first. These two modules are implemented in C.

    2) Crypt::DES_PP module by Guido Flohr (GUIDO) and Digest::Perl::MD4
    module by Ted Anderson (OTAKA). These two modules are implemented in
    Perl.

    The first set of modules will be preferred by NTLM because they are
    supposedly faster.

TO-DO
    1) A function to parse NTLM negotiation packet for DCE RPC.

    2) A function to parse NTLM response packet for DCE RPC.

README  view on Meta::CPAN

BUGS
    Nothing known.

AUTHOR
    This implementation was written by Yee Man Chan (ymc@yahoo.com).
    Copyright (c) 2002 Yee Man Chan. All rights reserved. This program is
    free software; you can redistribute it and/or modify it under the same
    terms as Perl itself.

SEE ALSO
    Digest::MD4(3), Crypt::DES(3), perl(1), m4(1).

lib/Authen/Perl/NTLM.pm  view on Meta::CPAN

# I will add the corresponding server side functions in the next version.
#

package Authen::Perl::NTLM;

use strict;
use POSIX;
use Carp;
$Authen::Perl::NTLM::PurePerl = undef; # a flag to see if we load pure perl 
                                       # DES and MD4 modules
eval "require Crypt::DES && require Digest::MD4";
if ($@) {
    eval "require Crypt::DES_PP && require Digest::Perl::MD4";
    if ($@) {
	die "Required DES and/or MD4 module doesn't exist!\n";
    }
    else {
        $Authen::Perl::NTLM::PurePerl = 1;
    }
}
else {
    $Authen::Perl::NTLM::PurePerl = 0;
}

if ($Authen::Perl::NTLM::PurePerl == 1) {
    require Crypt::DES_PP;
    Crypt::DES_PP->import;
    require Digest::Perl::MD4;
    import Digest::Perl::MD4 qw(md4);
}
else {
    require Crypt::DES;
    Crypt::DES->import;
    require Digest::MD4;
    import Digest::MD4;
}
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;
require DynaLoader;

*import = \&Exporter::import;

@ISA = qw (Exporter DynaLoader);
@EXPORT = qw ();
@EXPORT_OK = qw (nt_hash lm_hash calc_resp);
$VERSION = '0.12';

# Stolen from Crypt::DES.
sub usage {
    my ($package, $filename, $line, $subr) = caller (1);
    $Carp::CarpLevel = 2;
    croak "Usage: $subr (@_)";
}

# These constants are stolen from samba-2.2.4 and other sources
use constant NTLMSSP_SIGNATURE => 'NTLMSSP';

# NTLMSSP Message Types

lib/Authen/Perl/NTLM.pm  view on Meta::CPAN

    my $cipher1;
    my $cipher2;
    my $magic = pack("H16", "4B47532140232425"); # magical string to be encrypted for the LM password hash
    while (length($passwd) < 14) {
	$passwd .= chr(0);
    }
    my $lm_pw = substr($passwd, 0, 14);
    $lm_pw = uc($lm_pw); # change the password to upper case
    my $key = convert_key(substr($lm_pw, 0, 7)) . convert_key(substr($lm_pw, 7, 7));
    if ($Authen::Perl::NTLM::PurePerl) {
	$cipher1 = Crypt::DES_PP->new(substr($key, 0, 8));
	$cipher2 = Crypt::DES_PP->new(substr($key, 8, 8));
    }
    else {
	$cipher1 = Crypt::DES->new(substr($key, 0, 8));
	$cipher2 = Crypt::DES->new(substr($key, 8, 8));
    }
    return $cipher1->encrypt($magic) . $cipher2->encrypt($magic) . pack("H10", "0000000000");
} 

##########################################################################
# nt_hash calculates the NT hash to be used to calculate the NT response #
# It takes a password and return the 21 bytes NT password hash.          #
##########################################################################
sub nt_hash($)
{

lib/Authen/Perl/NTLM.pm  view on Meta::CPAN

###########################################################################
sub calc_resp($$)
{
    my ($key, $nonce) = @_;
    my $cipher1;
    my $cipher2;
    my $cipher3; 
    usage("key must be 21-bytes long") unless length($key) == 21;
    usage("nonce must be 8-bytes long") unless length($nonce) == 8;
    if ($Authen::Perl::NTLM::PurePerl) {
	$cipher1 = Crypt::DES_PP->new(convert_key(substr($key, 0, 7)));
	$cipher2 = Crypt::DES_PP->new(convert_key(substr($key, 7, 7)));
	$cipher3 = Crypt::DES_PP->new(convert_key(substr($key, 14, 7)));
    }
    else {
	$cipher1 = Crypt::DES->new(convert_key(substr($key, 0, 7)));
	$cipher2 = Crypt::DES->new(convert_key(substr($key, 7, 7)));
	$cipher3 = Crypt::DES->new(convert_key(substr($key, 14, 7)));
    }
    return $cipher1->encrypt($nonce) . $cipher2->encrypt($nonce) . $cipher3->encrypt($nonce);
}

#########################################################################
# un_unicodify takes a unicode string and turns it into an ASCII string.
# CAUTION: This function is intended to be used with unicodified ASCII
# strings.
#########################################################################
sub un_unicodify

lib/Authen/Perl/NTLM.pm  view on Meta::CPAN


This module was written without the knowledge of Mark Bush's (MARKBUSH)
NTLM implementation. It was used by Yee Man Chan to implement a Perl
DCOM client.

=head1 DEPENDENCIES

To use this module, please install the one of the following two sets of
DES and MD4 modules:

1) Crypt::DES module by Dave Paris (DPARIS) and Digest::MD4 module by 
Mike McCauley (MIKEM) first. These two modules are implemented in C.

2) Crypt::DES_PP module by Guido Flohr (GUIDO) and Digest::Perl::MD4
module by Ted Anderson (OTAKA). These two modules are implemented
in Perl.

The first set of modules will be preferred by NTLM because they are
supposedly faster.

=head1 TO-DO

1) A function to parse NTLM negotiation packet for DCE RPC. 

lib/Authen/Perl/NTLM.pm  view on Meta::CPAN


=head1 AUTHOR

This implementation was written by Yee Man Chan (ymc@yahoo.com).
Copyright (c) 2002 Yee Man Chan. All rights reserved. This program 
is free software; you can redistribute it and/or modify it under 
the same terms as Perl itself. 

=head1 SEE ALSO

Digest::MD4(3), Crypt::DES(3), perl(1), m4(1).

=cut

Local Variables:
mode: perl
perl-indent-level: 4
perl-continued-statement-offset: 4
perl-continued-brace-offset: 0
perl-brace-offset: -4
perl-brace-imaginary-offset: 0



( run in 0.246 second using v1.01-cache-2.11-cpan-9a3d99fc6dc )