Security



OpenSSH 인증

vi  /etc/ssh/sshd_config
    Port  21122                         #--- 서비스 Port 변경
    Protocol  2                         #--- SSH v2만 허용
    PubkeyAuthentication  yes           #--- yes. SSH Key 기반 인증 허용
    PasswordAuthentication  no          #--- no. 비빌번호로 인증 차단
    PermitEmptyPasswords  no            #--- no. 비어 있는 비밀번호는 허용하지 않음
    MaxAuthTries  3                     #--- 최대 로그인 시도 횟수
    LoginGraceTime  2m                  #--- 로그인 대기 시간(초)
    
    PermitRootLogin  no                 #--- no. root 로그인 비활성화
    AllowUsers  obcon01  obcon02        #--- 특정 사용자만 접속 허용
    AllowUsers  obcon03@129.222.34.29   #--- 특정 IP로 접속한 특정 사용자만 접속 허용

firewall-cmd  --add-port  21122/tcp
firewall-cmd  --add-port  21122/tcp  --permanent
firewall-cmd  --reload

systemctl  restart  sshd.service


ssh-keygen                              #--- SSH Key 생성

#--- 특정 사용자에게 접속 허용
vi  ~/.ssh/config
    Host  obconServer
        User  obcon01
        HostName  10.33.44.23
        Port  22
        IdentityFile  ~/.ssh/id_rsa
        Protocol  2

    Host  obconServer2
        User  obcon02
        HostName  10.33.23.23
        Port  22
        IdentityFile  ~/.ssh/id_rsa
        Protocol  2
        
#--- 특정 IP에서의 접근만 허용
vi  /etc/hosts.deny
    sshd: ALL
    
vi  /etc/hosts.allow
    sshd: IP1, IP2, IP3

fail2ban 인증

로그 파일을 스캔해서 로그인 암호 실패를 한 IP 주소들을 방화벽 도구를 이용해 차단

#--- 모니터링 : 로그 파일
tail  -f  /var/log/secure | grep -i password

#--- fail2ban 구성
yum  -y  install  fail2ban  fail2ban-systemd

cd  /etc/fail2ban
cp  jail.conf  jail.local
vi  /etc/fail2ban/jail.local
    [DEFAULT]
    ignoreip = 127.0.0.1/8 172.27.0.20/16 211.251.236.86
    bantime = 6000                      #--- 차단시간(초), -1. 무제한
    findtime = 600                      #--- 600초 동안 5번 실패하면 차단 한다.    
    maxretry = 5 
    
    [sshd]
    enabled = true
    port      = ssh
    logpath  = %(sshd_log)s
    backend = %(sshd_backend)s
    maxretry = 3

    [sshd-ddos]
    enabled = true
    port      = ssh
    logpath  = %(sshd_log)s
    backend = %(sshd_backend)s
    
    [php-url-fopen]
    enabled = true
    port    = http,https
    logpath = %(nginx_access_log)s

    [sendmail-auth]
    enabled = true
    port    = submission,465,smtp
    logpath = %(syslog_mail)s
    backend = %(syslog_backend)s

    [sendmail-reject]
    enabled = true
    port     = smtp,465,submission
    logpath  = %(syslog_mail)s
    backend  = %(syslog_backend)s

vi  /etc/fail2ban/paths-common.conf
    [DEFAULT]
    default_backend = polling

vi  /etc/systemd/system/fail2ban.service.d/limits.conf
    [Service]
    LimitNOFILE=2048
systemctl  daemon-reload

vi  /etc/logrotate.d/fail2ban
    /var/log/fail2ban.log {
        daily                           #--- 로그 파일은 1일 단위로 로테이션 한다.
        rotate 7
        missingok
        compress
        notifempty
        postrotate
          /usr/bin/fail2ban-client flushlogs >/dev/null || true
        endscript
    }

#--- fail2ban 서비스 시작
systemctl  enable  firewalld.service
systemctl  start   firewalld.service

systemctl  enable  fail2ban.service
systemctl  start   fail2ban.service

#--- CLI
fail2ban-client  status
fail2ban-client  status  sshd
fail2ban-client  set  sshd  unbanip  IP주소                  #--- 차단 해제

iptables  -L  |  more
tail  -f  /var/log/fail2ban.log

GeoIP 인증

IP를 사용하지 지리적 위치(예, 국가)를 확인하고 이를 인증을 강화하는데 사용 한다.

yum  -y  install  GeoIP

#--- 국가별 IP 대역폭이 정리된 파일 다운로드
wget http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
unzip GeoIPCountryCSV.zip

iptables  -N  GeoIP-China
iptables  -A  GeoIP-China  -j  Drop

#--- GeoIPCountryCSV 파일을 참조하여 차단할 IP 범위를 지정 한다.
iptables  -I  INPUT  -p  all  -m  iprange  --src-range  ${IP범위}  -j  GeoIP-China

iptables  -L  |  grep  China

BlackIP로 인증

Black IP로 신고된 IP를 사용하여 차단 한다.

#--- blackip.txt 파일 생성
git  clone  --depth=1  https://github.com/maravento/blackip.git
cd  blackip
tar  xvfz  blackip.tar.gz

iptables  -N  BlackIP
iptables  -A  BlackIP  -j  DROP

iptables  -I  INPUT  -p  all  -s ${IP}  -j  BlackIP

Google Authenticator 인증

Google OTP (One-Time-Password)를 사용하여 인증을 강화 한다.

yum  -y  install  google-authenticator

#--- PAM (Pluggable Authentication Modules) 설정
vi  /etc/pam.d/sshd
    auth    required    pam_google_authenticator.so nullok
    
vi  /etc/ssh/sshd_config
    PasswordAuthentication  no
    PermitEmptyPasswords  no
    
    #--- yes. 2FA (Twoo Factor Authentication)를 위해서 설정
    ChallengeResponseAuthentication  yes
    UsePAM  yes
    
systemctl  restart  sshd.service  

google-authenticator
    Do you want authenticatin tokens to be time-based (y/n)  y
    #--- Secret key, verification code, emergency scratch codes가 표시됨
    
vi  ~/.google_authenticator               #--- 이 파일이 자동 생성되어 있다.

#--- 핸드폰에서 Google OTP를 설치하여 사용 한다.
#---     Secret Key로 등록 한다.

HTTPS 서비스

SecureSign 사이트에서 서버 인증서를 발급 한다.

  • RootChain/ca-chain-bundle.pem : CA crt
  • ~.crt.pem : Server crt
  • ~.key.pem : Server key

Nginx 설정

  • obcon.crt : ~.crt.pem + RootChain/ca-chain-bundle.pem
  • obcon.key : ~.key.pem
#--- nginx  -t 
    server {
        listen       80;
        listen       [::]:80;
        return 301 https://www.obcon.biz$request_uri;
    }
    
    server {
        listen       443 ssl;
        listen       [::]:443 ssl;
        
        ssl_certificate         /etc/nginx/obcon.crt;
        ssl_certificate_key     /etc/nginx/obcon.key;
        ssl_session_timeout     10m;
        ssl_session_cache       shared:SSL:1m;
        ssl_protocols           SSLv3 TLSv1; # SSLv2
        ssl_ciphers             ALL:!aNull:!eNull:!SSLv2:!kEDH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+EXP:@STRENGTH;
        # ssl_ciphers             HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
    }

Mediawiki 설정

vi  LocalSettings.php
    $wgServer = "https://www.jopenbusiness.com";
    $wgLogo = "https://www.jopenbusiness.com/mediawiki/logo.jpg";

WordPress 설정

#--- "설정 > 일반" 메뉴에서
#--- 워드프레스 주소와 사이트 주소를 변경 한다.
SELECT * 
  FROM obcon_options 
 WHERE option_name = 'siteurl' 
    OR option_name = 'home';

UPDATE obcon_options 
   SET option_value = 'https://www.obcon.biz/wordpress' 
 WHERE option_name = 'siteurl' 
    OR option_name = 'home';

SuiteCRM 설정

vi  config_override.php
    $sugar_config['site_url'] = 'https://www.obcon.biz/crm';

OBCon_~ 설정

vi  config_~_override.js
    conf.homepage = 'https://www.jopenbusiness.com/';
    conf.helppage = 'https://www.obcon.biz/cms/OBCon_SCADA/README.md';
     
    conf.http.baseUrl = 'https://www.jopenbusiness.com/';
    # conf.ThingPlug.appServer = 'http://www.obcon.biz/scada/thingplugs?action=receive';
최종 수정일: 2022-10-24 19:17:33

이전글 :
다음글 :
상단 menu
arrow_back_ios
arrow_forward_ios