GithubHelp home page GithubHelp logo

freeradius-demo's Introduction

freeradius-demo

freeradius eap-peap dynamic vlan + mac auth example

describe

In this project, FreeRADIUS server is portability. Validation has been conducted only on Ubuntu 20.04, Ubuntu 22.04, and Kali Linux. There might be errors related to missing library packages in other environments.

deploy

scripts/deploy.sh

#start in background
scripts/start.sh

# Start in debug mode
scripts/start.sh c

database

create database and create a operator account

create database raddb;
create user radius@"%" identified by "Rad@123!";
grant all privileges on raddb.* to raddb;

use raddb;
#  When importing the system database, make sure to use the correct path.
srouce mods-config/sql/main/mysql/schema.sql;

freeradius

Below are the modifications to the default configuration file. The file is located at a relative path.

  1. raddb/clients.conf
client private-network-1 {
        ipaddr          = 192.168.8.0/24
        secret          = testing123
}
  1. raddb/mods-enabled/eap

Due to the fact that EAP packets of PEAP and TTLS types are handled by the inner-tunnel section, it is necessary to set 'copy_request_to_tunnel' and 'use_tunneled_reply' to 'yes'.

default_eap_type = peap
copy_request_to_tunnel = yes
use_tunneled_reply = yes
  1. Enabling and Configuring the SQL Module
# Symbolic links must use absolute paths. Please write the path according to your actual situation.
ln -s  /.../etc/raddb/mods-available/sql  /.../etc/raddb/mods-enabled/

edit raddb/mods-available/sql

dialect = "mysql"
#       driver = "rlm_sql_null"
driver = "rlm_sql_${dialect}"

mysql {
               # If you're not using a TLS connection for the data, please remove the TLS-related configuration within the block.
                warnings = auto
}
# 
server = "localhost"
port = 3306
login = "radius"
password = "Rad@123!"
radius_db = "raddb"
  1. raddb/sites-available/default

Enable the SQL module.

# Uncomment the SQL section, change "-sql" to "sql," or remove the '#' symbol in front of it.
authorize {
.
.
.
sql
.
.
.
}
session {
.
.
.
sql
}
.
.
.

SQL Script

insert group

insert into radgroupreply (groupname, attribute, op, value) values ('VLAN8', 'Tunnel-Type', '=', '13');   	# Tunnel Type VLAN
insert into radgroupreply (groupname, attribute, op, value) values ('VLAN8', 'Tunnel-Medium-Type', '=', '6');   # Protocol Field  IEEE 802
insert into radgroupreply (groupname, attribute, op, value) values ('VLAN8', "Tunnel-Private-Group-Id", '=', '8');  # Dynamic VLAN ID sent to the client.

insert into radgroupreply (groupname, attribute, op, value) values ('VLAN9', 'Tunnel-Type', '=', '13');    
insert into radgroupreply (groupname, attribute, op, value) values ('VLAN9', 'Tunnel-Medium-Type', '', '6');
insert into radgroupreply (groupname, attribute, op, value) values ('VLAN9', 'Tunnel-Private-Group-Id', '=', '9');

insert user

INSERT INTO radcheck (username, attribute, op, value) VALUES('zhangsan', 'Cleartext-Password', ':=', 'Aa123456');
INSERT INTO radusergroup (username, groupname, priority) values ('zhangsan', 'VLAN8', 10);   # User 'zhangsan' is bound to the groupname 'VLAN8'.

INSERT INTO radcheck (username, attribute, op, value) VALUES('lisi', 'Cleartext-Password',":=","Aa123456");
INSERT INTO radusergroup (username, groupname, priority) values ('lisi', 'VLAN9', 10);  # User 'lisi' is bound to the groupname 'VLAN9'.

eapol_test

the eapol_test path is raddb/test ,If the eapol_test output ends with "SUCCESS," the test is successful, indicating that the RADIUS server is operational. test command

./eapol_test -c conf -a 192.168.xx.xxx  -s testing123

conf

network={
  phase1="tls_disable_tlsv1_0=1 tls_disable_tlsv1_1=1 tls_disable_tlsv1_2=0 tls_disable_tlsv1_3=1 peapver=0"
  key_mgmt=WPA-EAP
  eap=PEAP
  identity="lisi"
  password="Aa123456"
  phase2="eapauth=MSCHAPV2 mschapv2_retry=0"
}

802.1x + mac auth

In many cases, we require both MAC address and 802.1x authentication to ensure that an account can only be logged in on specific devices.

  1. Create a 'macauth' table in the 'raddb' database.
CREATE TABLE raddb.macauth (
	id INT auto_increment NULL,
	username varchar(100) NULL,
	macaddr varchar(100) NULL,
	CONSTRAINT macauth_PK PRIMARY KEY (id)
)
  1. Add MAC address checking action in 'post-auth'.

site-available/default

post-auth {
.
.
.
if("%{sql:SELECT COUNT(macaddr) FROM macauth  WHERE username ='%{User-Name}' and macaddr='%{Calling-Station-ID}'}" > 0){
                 ok
   }
   else{
                reject
   }
.
.
.
}

Generate certificates

cd  raddb/certs
sed -i 's/FR/CN/g' *.cnf
sed -i 's/Radius/Sichuan/g' *.cnf
sed -i 's/Somewhere/Chengdu/g' *.cnf
sed -i 's#Example Inc.#MyOrg#g' *.cnf
sed -i 's/Example Certificate Authority/radius.xxx.com/g' *.cnf 
grep 60 -r *.cnf  
sed -i 's/60/3650/g' *.cnf     #  Set the certificate validity period to 10 years.
make

Edit mods-available/eap to apply the certificates generated earlier.

#  Please modify to use absolute paths !
private_key_file = .../certs/rsa/server.key  
certificate_file = .../certs/server.pem    
ca_file = .../certs/ca.pem                                                 
ca_path = certs/rsa
dh_file = ${certdir}/dh   

freeradius-demo's People

Contributors

hcye avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.