Skip to content

Instantly share code, notes, and snippets.

@korjavin
Created March 20, 2013 11:54
Show Gist options
  • Select an option

  • Save korjavin/5204096 to your computer and use it in GitHub Desktop.

Select an option

Save korjavin/5204096 to your computer and use it in GitHub Desktop.
auth_req_verify
use utf8;
use Digest::MD5;
sub auth_req_verify {
my ( $packet, $secret, $prauth ) = @_;
return 1
if Digest::MD5::md5(
substr( $packet, 0, 4 ) . $prauth . substr( $packet, 20 ) . $secret )
eq substr( $packet, 4, 16 );
return;
}
sub unpack_hex_to_byte {
my $string=shift;
my @hex = ($string =~ /(..)/g);
my @dec = map { hex($_) } @hex;
my @bytes = map { pack('C', $_) } @dec;
return join '',@bytes;
}
$secret="ssnet00";
$req_authenticator=unpack_hex_to_byte ('a98edf153fa3ed70fa6825c6026006a4');
$data=unpack_hex_to_byte ('0244006bfd4f8e9f12f7b72c29b1cae61713bddf1a2000000009651a683332332d6372656469742d616d6f756e743d3130302e301a1d000000096617683332332d6372656469742d74696d653d313830301a1a000000096714683332332d72657475726e2d636f64653d30');
print "bill ok \n" if auth_req_verify($data, $secret, $req_authenticator);
print $data;
$secret="testing123";
$req_authenticator=unpack_hex_to_byte ('a98edf153fa3ed70fa6825c6026006a4');
$data=unpack_hex_to_byte ('024a00316625677bb44de5fdf0230765768bae4d1a1d000000096617683332332d6372656469742d74696d653d31353230');
print "freeradius ok \n" if auth_req_verify($data, $secret, $req_authenticator);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment