Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
smradius
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shail
smradius
Commits
b5318455
Commit
b5318455
authored
15 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
* Fixed handling of ident in return packet
* Fixed Magic1 and Magic2 arrays * Few cosmetic changes
parent
ac1dee39
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smradius/modules/authentication/mod_auth_mschap.pm
+41
-22
41 additions, 22 deletions
smradius/modules/authentication/mod_auth_mschap.pm
with
41 additions
and
22 deletions
smradius/modules/authentication/mod_auth_mschap.pm
+
41
−
22
View file @
b5318455
...
...
@@ -31,6 +31,7 @@ use warnings;
# Modules we need
use
smradius::
attributes
;
use
smradius::
constants
;
use
smradius::
logging
;
use
Crypt::
DES
;
...
...
@@ -41,9 +42,6 @@ use Digest::MD4 qw( md4 );
# Don't use unicode
use
bytes
;
use
Data::
Dumper
;
# Exporter stuff
require
Exporter
;
...
...
@@ -173,11 +171,13 @@ sub authenticate
# Pull off challenge & response
my
$challenge
=
@
{
$rawChallenge
}[
0
];
my
$ident
=
unpack
("
C
",
substr
(
@
{
$rawResponse2
}[
0
],
0
,
1
));
my
$response
=
substr
(
@
{
$rawResponse2
}[
0
],
2
);
# print(STDERR "RECEIVED\n");
# print(STDERR "Challenge: len = ".length($challenge).", hex = ".unpack("H*",$challenge)."\n");
# print(STDERR "Reponse : len = ".length($response).", hex = ".unpack("H*",$response)."\n");
# print(STDERR "Ident : $ident\n");
# print(STDERR "Response : len = ".length($response).", hex = ".unpack("H*",$response)."\n");
# print(STDERR "\n\n");
...
...
@@ -186,19 +186,34 @@ sub authenticate
# Grab peer challenge and response
my
$peerChallenge
=
substr
(
$response
,
0
,
16
);
my
$NtResponse
=
substr
(
$response
,
24
,
24
);
# print(STDERR "Challenge: len = ".length($peerChallenge).", hex = ".unpack("H*",$peerChallenge)."\n");
# print(STDERR "NTRespons: len = ".length($NtResponse).", hex = ".unpack("H*",$NtResponse)."\n");
# print(STDERR "
Peer
Challenge: len = ".length($peerChallenge).", hex = ".unpack("H*",$peerChallenge)."\n");
# print(STDERR "NTRespons
e
: len = ".length($NtResponse).", hex = ".unpack("H*",$NtResponse)."\n");
# print(STDERR "\n\n");
# print(STDERR "TEST\n");
# Generate our challenge and our response
my
$ourChallenge
=
ChallengeHash
(
$peerChallenge
,
$challenge
,
$username
);
my
$ourResponse
=
NtChallengeResponse
(
$ourChallenge
,
$unicodePassword
);
# print(STDERR "Calculate: len = ".length($ourResponse).", hex = ".unpack("H*",$ourResponse)."\n");
# print(STDERR "OurChallenge: len = ".length($ourChallenge).", hex = ".unpack("H*",$ourChallenge)."\n");
# print(STDERR "OurResponse: len = ".length($ourResponse).", hex = ".unpack("H*",$ourResponse)."\n");
# print(STDERR "\n\n");
# Check response match
if
(
$NtResponse
eq
$ourResponse
)
{
# Generate authenticator response
my
$authenticatorResponse
=
pack
("
C
",
$ident
)
.
GenerateAuthenticatorResponse
(
$unicodePassword
,
$ourResponse
,
$peerChallenge
,
$challenge
,
$username
);
# print(STDERR "Authenticator Response: len = ".length($authenticatorResponse).
# ", hex = ".unpack("H*",$authenticatorResponse)."\n");
setReplyVAttribute
(
$server
,
$user
->
{'
ReplyVAttributes
'},
{
'
Vendor
'
=>
311
,
'
Name
'
=>
'
MS-CHAP2-Success
',
'
Operator
'
=>
"
:=
",
'
Value
'
=>
$authenticatorResponse
});
return
MOD_RES_ACK
;
}
...
...
@@ -487,30 +502,32 @@ sub GenerateAuthenticatorResponse
my
(
$Password
,
$NTResponse
,
$PeerChallenge
,
$AuthenticatorChallenge
,
$UserName
)
=
@_
;
# "Magic" constants used in response generation
# "Magic" constants used in response generation
- this is in hex
my
@Magic1
=
(
0x
4D
,
0x
61
,
0x
67
,
0x
69
,
0x
63
,
0x
20
,
0x
73
,
0x
65
,
0x
72
,
0x
76
,
0x
65
,
0x
72
,
0x
20
,
0x
74
,
0x
6F
,
0x
20
,
0x
63
,
0x
6C
,
0x
69
,
0x
65
,
0x
6E
,
0x
74
,
0x
20
,
0x
73
,
0x
69
,
0x
67
,
0x
6E
,
0x
69
,
0x
6E
,
0x
67
,
0x
20
,
0x
63
,
0x
6F
,
0x
6E
,
0x
73
,
0x
74
,
0x
61
,
0x
6E
,
0x
74
);
(
"
4D
"
,
"
61
"
,
"
67
"
,
"
69
"
,
"
63
"
,
"
20
"
,
"
73
"
,
"
65
"
,
"
72
"
,
"
76
"
,
"
65
"
,
"
72
"
,
"
20
"
,
"
74
"
,
"
6F
"
,
"
20
"
,
"
63
"
,
"
6C
"
,
"
69
"
,
"
65
"
,
"
6E
"
,
"
74
"
,
"
20
"
,
"
73
"
,
"
69
"
,
"
67
"
,
"
6E
"
,
"
69
"
,
"
6E
"
,
"
67
"
,
"
20
"
,
"
63
"
,
"
6F
"
,
"
6E
"
,
"
73
"
,
"
74
"
,
"
61
"
,
"
6E
"
,
"
74
"
);
my
@Magic2
=
(
0x
50
,
0x
61
,
0x
64
,
0x
20
,
0x
74
,
0x
6F
,
0x
20
,
0x
6D
,
0x
61
,
0x
6B
,
0x
65
,
0x
20
,
0x
69
,
0x
74
,
0x
20
,
0x
64
,
0x
6F
,
0x
20
,
0x
6D
,
0x
6F
,
0x
72
,
0x
65
,
0x
20
,
0x
74
,
0x
68
,
0x
61
,
0x
6E
,
0x
20
,
0x
6F
,
0x
6E
,
0x
65
,
0x
20
,
0x
69
,
0x
74
,
0x
65
,
0x
72
,
0x
61
,
0x
74
,
0x
69
,
0x
6F
,
0x
6E
);
(
"
50
"
,
"
61
"
,
"
64
"
,
"
20
"
,
"
74
"
,
"
6F
"
,
"
20
"
,
"
6D
"
,
"
61
"
,
"
6B
"
,
"
65
"
,
"
20
"
,
"
69
"
,
"
74
"
,
"
20
"
,
"
64
"
,
"
6F
"
,
"
20
"
,
"
6D
"
,
"
6F
"
,
"
72
"
,
"
65
"
,
"
20
"
,
"
74
"
,
"
68
"
,
"
61
"
,
"
6E
"
,
"
20
"
,
"
6F
"
,
"
6E
"
,
"
65
"
,
"
20
"
,
"
69
"
,
"
74
"
,
"
65
"
,
"
72
"
,
"
61
"
,
"
74
"
,
"
69
"
,
"
6F
"
,
"
6E
"
);
# Hash the password with MD4
my
$PasswordHash
=
NtPasswordHash
(
$Password
);
# Now hash the hash
my
$PasswordHashHash
=
HashNtPasswordHash
(
$PasswordHash
);
# SHA encryption
my
$sha
=
Digest::
SHA1
->
new
();
$sha
->
add
(
$PasswordHashHash
);
$sha
->
add
(
$NTResponse
);
$sha
->
add
(
@Magic1
);
foreach
my
$item
(
@Magic1
)
{
$sha
->
add
(
pack
("
H*
",
$item
));
}
my
$Digest
=
$sha
->
digest
();
my
$Challenge
=
ChallengeHash
(
$PeerChallenge
,
$AuthenticatorChallenge
,
$UserName
);
...
...
@@ -518,11 +535,13 @@ sub GenerateAuthenticatorResponse
$sha
=
Digest::
SHA1
->
new
();
$sha
->
add
(
$Digest
);
$sha
->
add
(
$Challenge
);
$sha
->
add
(
@Magic2
);
foreach
my
$item
(
@Magic2
)
{
$sha
->
add
(
pack
("
H*
",
$item
));
}
$Digest
=
$sha
->
digest
();
# Encode digest and return response
my
$AuthenticatorResponse
=
"
S=
"
.
unpack
("
H*
",
$Digest
);
# Encode digest and return response
, UPPERCASE response
my
$AuthenticatorResponse
=
"
S=
"
.
uc
(
unpack
("
H*
",
$Digest
)
)
;
return
$AuthenticatorResponse
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment