Radius 프로토콜을 통해서 요청이 들어오면

Radius Server는 이를 받아서 Tomcat 쪽에 인증, 인가 요청을 하고그 결과를

Radius Server 가 다시 받아서 전송하는 방법이다.

제가 한것은 아니고
류지철님께서 도움을 주셔서 저는 정리만......


* 소스 설치 centos 6.6
- Tomcat이 다운되어 있는 경우 reject을 바로 넘김

1 iptable 설정
 UDP 1812, 1813 포트를 열어줘야 함
 -A INPUT -p udp -m state --state NEW -m udp --dport 1812 -j ACCEPT
 -A INPUT -p udp -m state --state NEW -m udp --dport 1813 -j ACCEPT

2 소스 다운
 http://freeradius.org/download.html 에서 freeradius-server-3.0.10.tar.gz 다운
3 사전 작업
 yum install libtalloc-devel -y
 openssl version
 OpenSSL 1.0.1e-fips 11 Feb 2013
 yum -y update openssl

3 설치
 cd /tools
 [root@52 tools]# tar -zxf freeradius-server-3.0.10.tar.gz
 [root@52 tools]# cd freeradius-server-3.0.10
 ./configure --prefix=/tools/freeradius
 make
 make install
 
4 openssl 관련 수정
 cd /tools/freeradius/etc/raddb
 vi radiusd.conf
 allow_vulnerable_openssl = yes
 
5 서비스 시작
 freeradius 압축 푼 디렉토리 redhat 디렉토리에 보면 아래 파일이 있는데 이걸 복사
 [root@52 redhat]# cp freeradius-radiusd-init /etc/init.d/radiusd
 vi /etc/init.d/radiusd
 exec=${exec:=/tools/freeradius/sbin/$prog}
 config_dir=${config_dir:=/tools/freeradius/etc/raddb}
 config=${config:=$config_dir/radiusd.conf}
 pidfile=${pidfile:=/var/run/$prog/$prog.pid}
 lockfile=${lockfile:=/var/lock/subsys/radiusd}
 
 service radiusd stop/start
 stop은 이상하게 안된다. kill -9 으로 죽여야 죽는다.
 나중에 확인하자.

6 perl 모듈 추가
 1) mode-enabled
  mods-enabled 디렉토리에 심볼링 링크 추가 및 수정
  cd /tools/freeradius/etc/raddb/mods-enabled
  [root@52 mods-enabled]# ln -s ../mods-available/perl perl
  vi perl
  filename = ${modconfdir}/${.:instance}/perl.pl
 2) perl.pl 파일 수정
  cd /tools/freeradius/etc/raddb/mods-config/perl
  mv example.pl perl.pl
  authorize, authenticate 부분을 수정
  vi perl.pl
 
  sub authorize {
      # 테스트 부분을 주석 처리
      #&test_call;
      return RLM_MODULE_OK;
  }

  sub authenticate {
     my $userName = $RAD_REQUEST{'User-Name'};
    my $userPassword = $RAD_REQUEST{'User-Password'};
    my $ipAddress = $RAD_REQUEST{'NAS-IP-Address'};
    my $identifier = $RAD_REQUEST{'NAS-Identifier'};
    my $userId = 'userId='.$userName;
    my $password = 'password='.$userPassword;
    my $clientIp = 'clientIp=';
    if (defined $ipAddress and length $ipAddress) {
        $clientIp = 'clientIp='.$ipAddress;
    }
    my $requestType= 'requestType=';
    if (defined $identifier and length $identifier) {
        $requestType = 'requestType='.$identifier;
    }

    my $query = 'https://127.0.0.1:7777/api/callRadius.do';
    my $result = qx{curl --insecure --silent $query --data-urlencode $userId --data-urlencode $password --data-urlencode $clientIp --data-urlencode $requestType};
    if ( $result eq 'OK' ) {
        return RLM_MODULE_OK;
    } elsif ( $result eq 'NOTFOUND' ) {
        $RAD_REPLY{'Reply-Message'} = 'invalid User-Name and User-Password By OTP Server';
        return RLM_MODULE_NOTFOUND;
    } else {
        $RAD_REPLY{'Reply-Message'} = "Denied access by OTP Server";
        return RLM_MODULE_REJECT;
    }
  }
 
 3) radiusd.conf 파일 수정
  주석 처리 하면 클라이언트에서 서버 요청이 불가능
  $INCLUDE clients.conf
  따로 특별히 수정할 부분은 없음
 4) clients.conf 파일 수정
  client ip 대역대를 추가해 주었다. 안해줄 경우 서버 요청 불가능. secret 코드가 관건이다.
  client 192.xxx.1.0/24 {
      secret      = gt1000
      nastype     = other
  }
  client 192.xxx.0.0/24 {
      secret      = gt1000
      nastype     = other
  }
  5) sites-enabled/ 파일 수정
  cd /tools/freeradius/etc/raddb/sites-enabled
  inner-tunnel 파일은 local 서비스내 내부 tunnel 이다.
  다른 용도가 없기 때문에 default 파일의 authorize, authenticate 부분만 동일하게 처리해 주었음
  vi default
  authorize, authenticate 에 아래 내용들 추가
  authorize {
      .... 생력 ....
      perl
          if (ok || updated) {
              update control {
                  Auth-Type := Perl
              }
          }
      .... 생력 ....
  }
  authenticate {
      .... 생력 ....
      Auth-Type Perl {
          perl
      }
      .... 생력 ....
  }
 
  authorize 부분에서 preprocess 를 주석 처리 하지 않으면 아래 오류가 발생함
  sanitizing 과 같은 악성 공격 관련인거 같은데.... 일단 주석 처리 했음
  (0) perl: ERROR: Failed to create pair request:Event-Timestamp = 10월 10 2015 21:58:46 KST
 
  authorize 부분에서 pap 를 주석 처리 하지 않으면 아래 경고가 발생함
  (0) pap: WARNING: No "known good" password found for the user.  Not setting Auth-Type
  (0) pap: WARNING: Authentication will fail unless a "known good" password is available
  authorize 부분에서 sql, ldap도 주석 처리 해 버렸음
 
7 테스트
 cd /tools/freeradius/bin
 이건 내부 inner-tunnel을 통해서 테스트 하는것이고
 ./radtest {username} {password} {hostname} 10 {radius_secret}
 ./radtest testing test123 localhost 0 testing123
 
 이건 테스트 하는 것
 echo "User-Name=testing,User-Password=test123,Framed-Protocol=PPP " | /tools/freeradius/bin/radclient 192.xxx.x.xxx:1812 auth testing123
 
 클라이언트 테스트 툴
 NTRadPing
 완전 좋음
 
 

'오픈소스' 카테고리의 다른 글

Kibana 로깅 관련  (0) 2015.10.24
태틀(Tattle), 서버 모니터링 관련  (0) 2015.10.24
오픈 소스 OTP  (0) 2015.10.09
업무 모니터링 관련  (0) 2015.03.06
JavaMelody 무료 무니터링 툴  (0) 2015.01.23
Posted by gt1000

블로그 이미지
gt1000

태그목록

공지사항

어제
오늘

달력

 « |  » 2024.3
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함