Hi!
I have a radius auth. related problem. Beleive me before posting here i looked everywhere and still couldn't find any information about it (except on www.mavetju.org there is a script but the functions it uses are not valid for my version of php 4.3 on freebsd)
So it's like this i'm using it to authenticate users I attached a file containing the script i use..It is a modyfied script from mavetju.org so i'm just using it to connect and send the information to radius. My main problem is that when i check the logs on the server i get the following error:
WARNING: Malformed RADIUS packet from host 127.0.0.1: Invalid attribute
--- Walking the entire request list ---
Nothing to do. Sleeping until we see a request.
WARNING: Malformed RADIUS packet from host 127.0.0.1: Invalid attribute
--- Walking the entire request list ---
Nothing to do. Sleeping until we see a request.
WARNING: Malformed RADIUS packet from host 127.0.0.1: Invalid attribute
--- Walking the entire request list ---
Nothing to do. Sleeping until we see a request.
It means that i'm not sending the packet properly otherwise radius would be able to interpret it.. Does anyone have any experience on this subject?? i've been working 3 days on it and no success..so any pointers would be appreciated
Here's the script
$username = "testuser";
$password = "testpass";
$sharedsecret = "secret";
//$ip= "localhost";
//$radiushost="127.0.0.1";
$SERVER_ADDR = $radiushost;
$radiushost="aaa.bbb.ccc.ddd";
$SERVER_ADDR = $radiushost;
$nasIP=explode(".",$SERVER_ADDR); //is being used in the encrypt function
$ip=gethostbyname($radiushost);
$radiusport = 1812;
$sock = socket_create (AF_INET, SOCK_DGRAM, getprotobyname("UDP"));
//$sock=socket_create(AF_INET,SOCK_DGRAM,17);
echo "socket created<br>";
$retval=socket_connect($sock,$ip,$radiusport);
echo "<br>...connected to socket<br>";
//function to encrypt data
function Encrypt($password,$key,$RA) {
//global $debug;
$keyRA=$key.$RA;
if ($debug)
echo "<br>key: $key<br>password: $password<hr>\n";
$md5checksum=md5($keyRA);
$output="";
for ($i=0;$i<=15;$i++) {
if (2*$i>strlen($md5checksum)) $m=0; else $m=hexdec(substr($md5checksum,2*$i,2));
if ($i>strlen($keyRA)) $k=0; else $k=ord(substr($keyRA,$i,1));
if ($i>strlen($password)) $p=0; else $p=ord(substr($password,$i,1));
$c=$m^$p;
$output.=chr($c);
}
return $output;
}//end of encrypt function
//prepare data to send
$RA=pack("CCCCCCCCCCCCCCCC", // auth code
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255,
1+rand()%255, 1+rand()%255, 1+rand()%255, 1+rand()%255);
$encryptedpassword=Encrypt($password,$sharedsecret,$RA);
$length=4+ // header
16+ // auth code
6+ // service type
2+strlen($username)+ // username
2+strlen($encryptedpassword)+ // userpassword
6+ // nasIP
6; // nasPort
$thisidentifier=rand()%256;
// v v v v v v v v
$data=pack("CCCCa*CCCCCCCCa*CCa*CCCCCCCCCCCC",
1,$thisidentifier,$length/256,$length%256, // header
$RA, // authcode
6,6,0,0,0,1, // service type
1,2+strlen($username),$username, // username
2,2+strlen($encryptedpassword),$encryptedpassword, // userpassword
4,6,$nasIP[0],$nasIP[1],$nasIP[2],$nasIP[3], // nasIP
5,3,0,0,0,0 // nasPort
);
//$data = "data i'm sending is not too short";
//$length = 66;
//socket_write($sock,$data,$length);
socket_write($sock,$data);
echo "<strong>SOCK: </strong>".$sock."<br>";
echo "<strong>DATA being SENT: </strong>".$data."<br>";
echo "<strong>Length of packet: </strong>".$length."<br>";