접근 통제 시스템 Access Control System

Download Report

Transcript 접근 통제 시스템 Access Control System

접근 통제 시스템
Access Control System
홍석범 ([email protected])
`접근 통제 시스템의 분류
1. 내부 통제 (Permission 조정)
(1) Permission or Owner
(2) Read Only File (or System)
(3) Limit Available Resource
2. 외부 통제 (Client IP에 대해)
(1) Inetd (Xinetd)
(2) StandAlone 데몬별 제한
(3) IPTABLES(IPCHAINS) 및 라우터등
(1.1) Permission
-rw-r--r-permission
root
user
root
group
test
file
user , group, other(all)
r(4) : 읽기 권한 (디렉토리의 경우 하부 파일 리스팅)
w(2): 쓰기 권한 (파일을 덮어쓰거나 삭제할 수 있다.)
x(1) : 실행 권한 (CGI 나 스크립트 실행시 필요하다)
▶ /tmp (1777)  sticky bit
drwxrwxrwt
root
root tmp/
: 누구나 쓰고 읽을 수 있지만 다른 유저가 생성한 파일은
삭제가 불가능하다.
Permission (Suid)
▶ Setuid(4511) = 4(4+1)11
-r-s--x--x
root
root
/usr/bin/passwd
이 파일을 실행 당시에는 root 가 되어야만이 root만이 읽을 수
있는 /etc/shadow 파일을 일반 유저가 변경할 수 있다.
▶ SetGid (2755)
-rwxr-sr-x
1 root
man
/usr/bin/man*
suid 속성을 이용한 응용(1)
-rwsr-x--- 1 root
wheel
/bin/su*
/etc/group 에 wheel::10:root,kissec 와 같이 추가.
wheel 그룹에 속한 유저만이 system 명령어 사용이 가능하게 된다.
Permission (suid, umask)
▶ suid 속성을 이용한 응용(2)
# cp /bin/sh /tmp/.hack
# chmod 4755 /tmp/.hack
-rwsr-xr-x root
root
$ /tmp/.hack
# id
uid=0(root) gid=0(root)
/tmp/.hack*
SUID 의 특성을 이용한 가상 고전적인 백도어 방법이다.
▶ Umask
파일이나 디렉토리 생성시 기본적으로 777(또는 666, 이는 시스템마다
다소 다르다.) 에서 뺀 퍼미션으로 설정된다. Umask 가 022일 경우
기본 퍼미션은 777-022= 755 가 된다. /etc/profile 에 정의되어 로긴
하는 모든 유저에 적용된다.
# find / -type f \( -perm -4000 -o -perm -2000 \) \-exec
ls -al {} \;
SUID 나 SGID 가 설정된 파일을 찾아준다.
# chmod a-s /usr/sbin/traceroute 또는
chmod 700 /usr/sbin/traceroute 으로 suid 설정해제.
# find / -type f \( -perm -2 -o -perm -20 \) -exec ls -lg {} \;
World Writable File 을 찾는다.
# find / -type d \( -perm -2 -o -perm -20 \) -exec ls -ldg {} \;
World Writable Directory 를 찾는다.
(2.1) chattr
1. Read Only File (or File System) 설정
▶ developed by Remy Card(ext2 fs developer)
사용법 : chattr +-= [ASacdisu] filename
“+” : 지정한 옵션 추가
“ –“ : 지정한 옵션 삭제
“=” : 초기화
A : atime (Access time)속성이 변경되지 않는다.
atime 속성은 stat file 로 확인 가능하다.
a: append(추가)만이 가능하다.
주로 로그 파일에 적당하다.
i : Immutable 로 추가, 변경, 삭제 등이 불가능하다.
chattr의 사용예
# touch test
# ls -la test
-rw-r--r-- 1 root
root
test
# lsattr test
-------- test
# chattr +i test
# lsattr test
----i--- test
# rm test
rm: remove write-protected file `test'? y
rm: cannot unlink `test': Operation not permitted
# chattr -i test
chattr의 사용예
# lsattr test
-------- test
# rm test
rm: remove `test'? y
#
# stat test
File: "test"
Size: 0
Filetype: Regular File
Mode: (0644/-rw-r--r--)
Uid: ( 0/ root) Gid: (
Device: 8,8 Inode: 288657 Links: 1
Access: Sat Aug 25 17:10:26 2001(00000.00:03:31)
Modify: Sat Aug 25 17:11:01 2001(00000.00:02:56)
Change: Sat Aug 25 17:11:01 2001(00000.00:02:56)
0/
root)
(2.2) File System
▶
설정 가능한 옵션(/etc/fstab 에서 설정)
defaults : 모든 기능을 허용한다.(quota, read-write, suid등)
noquota : user의 quota 설정을 하지 않는다.
nosuid : SUID나 SGID의 설정을 허용하지 않는다.
nodev : 문자나 특별한 장치(디바이스)를 허용하지 않는다.
noexec : 어떠한 실행 파일에 대해서도 실행을 허용하지 않는다
quota
: 유저들의 quota 설정을 허용한다.
ro
: 현재의 파티션을 읽기 전용(read-only) 으로 마운트한다.
rw : 현재의 파티션을 읽고 쓰기(read-write) 모드로 마운트한다.
suid
: SUID나 SGID의 사용을 허가한다.
File System 옵션 변경하기
▶ /etc/fstab 에서 filesystem 설정 변경
변경전)
/dev/sda11
/dev/sda6
/tmp
ext2 defaults 1 2
/home ext2 defaults 1 2
변경후)
/dev/sda11 /tmp
ext2 defaults,rw,nosuid,nodev,noexec 1 2
/dev/sda6 /home ext2 defaults,rw,nosuid,nodev 1 2
▶ 파일 시스템을 다시 마운트하기.
# mount /home -oremount
# mount /tmp –oremoun
# cat /proc/mounts
/dev/sda8
/home ext2 rw,nosuid 0 0
/dev/sda13
/tmp
ext2 rw,noexec,nosuid 0 0 로 확인.
(3) Limit Available Resource
▶ Kernel 레벨에서의 System Limit 설정
. 유저당 생성할 수 있는 프로세스의 수
. 유저당 open 할 수 있는 파일의 수등
 커널 튜닝을 통해 변경 가능.
▶ 커널튜닝 방법
(1)하드레벨 커널 튜닝 : 커널 소스의 수정후 커널 컴파일
(2)소프트 레벨 커널 튜닝 : 부팅후 /proc 파일 시스템의
파라미터 변경을 통해
▶ parameter 변경예
# echo 8192 > /proc/sys/fs/file-max
# sysctl -w fs.file-max=8192
ulimit 를 이용한 제한
▶
Shell logging user 에 대한 제한 (자세한 설명은 “help ulimit” )
/etc/profile 에 설정시 로그인하는 모든 유저에 적용 (root 포함)
if [ $LOGNAME != "root" ];
then
ulimit -Su 10
# 유저가 생성 가능한 프로세스수 10개로 제한
ulimit -Sv 20000 # 유저가 사용 가능한 메모리 20M로 제한
ulimit –Sf 5000 # 생성할 수 있는 한 파일의 사이즈 5M로 제한
fi
5M 이상의 파일을 복사하려고 할 때 아래와 같이 에러가 나게 됨.
[user@kisec ~]$ cp /tmp/larger_file .
파일 크기 제한을 초과함
[user@kisec ~]$
/etc/security/limits.conf
(PAM) 를 이용한 설정.
참고: http://www.kernel.org/pub/linux/libs/pam/
/etc/pam.d/login 파일의 하단에
session required /lib/security/pam_limits.so 추가 후
/etc/security/limits.conf 파일에 아래와 같이 설정
(superuser인 root 에는 적용되지 않는다.)
*
hard
core
0
# CORE 파일 생성하지 않는다.
*
*
hard
hard
rss
nproc
*
hard
maxlogins 4 # 동시접속을 4개로 제한
5000 # 사용 메모리 5M 로 제한
20 # 생성 프로세스 20개로 제한
PAM 을 이용한 접근 제한
▶ PAM(Pluggable Authentication Modules) 은 공유 라이브러리로 구
성되어 있는데, PAM 을 이용하여 응용 프로그램이 어떤 방법으로 사
용자를 인증할 것인지 설정할 수 있다.
PAM 모듈의 설정파일은 /etc/pam.d/ 에, 모듈(공유 라이브러리) 파일
들은 /lib/security 디렉토리에 위치한다.
/etc/pam.d/login 에
account required /lib/security/pam_access.so 추가.
▶ /etc/security/access.conf 파일 편집
-:ALL EXCEPT root admin:ALL
root 와 admin 을 제외한 모든 유저에 대해 콘솔과 원격접근 차단.
-:ALL EXCEPT root admin:192.168.1.2
root와 admin 에 대해서 특정한 IP 에서만 접근이 가능하도록 한다.
-:ALL:LOCAL
콘솔을 통해서는 모든 접근을 불허한다.
PAM 을 이용한 접근시간 제한
▶ pam_time.so 모듈이 제공하는 time.conf 파일을 이용
/etc/pam.d/login 파일에
account required /lib/security/pam_time.so 추가
/etc/security/time.conf
login ; tty* & !ttyp* ; !root !admin ; !Al0000-2400
root 와 admin 이라는 계정을 제외한 모든 유저에 대해
언제나 콘솔로의 로긴을 제한한다.
login ; * ; !admin ; !Wd0000-2400 !Tu0800-1800
admin 이라는 계정은 모든 접근이 허용되며 단, 주말과 화요일에 오전 8시부터
오후 6시까지만 콘솔 접근이 불가한다.
PAM 을 이용한 접근 제한
▶ ftp 는 열고 telnet은 막는법
(1) /etc/pam.d/login 파일에
auth required /lib/security/pam_listfile.so item=user
sense=allow file=/etc/telnetusers onerr=succeed 추가
/etc/telnetusers 파일에 telnet 접근을 허용할 ID 추가
특정 사용자만 접근을 막으려면 allow->deny 로 변경.
(2) /etc/passwd 파일에
frog:*:1003:999:The Frog:/home/frog:/bin/nologin 추가
# cat /bin/nologin
#!/bin/sh
echo "You can not log in!"
exit 0
PAM 을 이용한 접근 제한
▶ 특정 계정에 대해 telnet 접근 제한
/etc/security/access.conf 파일에서 설정
permission : users : origins
permission에서는 "+" (허용) "-" (불가)이 가능.
-:user1 xyz77 :ALL
user1, xyz77 에 대해서는 계정 접근 금지
▶ root 에 대해 telnet 접속허용
/etc/pam.d/login 파일에서
"auth required /lib/security/pam_securetty.so" 주석처리
/etc/securetty 파일에 ttyp1 등 접근 가능한 터미널을 추가.
2. 외부 통제
2.1 Inetd(Xinetd)
주의점: Max. server instances per minute is 60
pop-3 stream tcp
nowait.150 root /usr/sbin/tcpd
ipop3d
Instance 를 default 60에서 150으로 설정함.
해당 서비스 : pop3, telnet 등
Inetd 의 경우 Tcp Wrapper 와 함께 설정되어 접근 통제
(통상적으로 hosts.deny 에서 차단후 hosts.allow에서 허용).
Tcp Wrapper 는 /etc/hosts.deny 와 /etc/hosts.allow 파일을
통해 적절히 설정
▶ Only Inetd
pop-3 stream tcp nowait root
Client -
/usr/sbin/ipop3d
ipop3d
----- Service
Inetd ----- Service
------ Service
▶ Tcp_Wrapper 를 통한 Inetd
pop-3 stream tcp nowait root /usr/sbin/tcpd
----- Service
Client  Tcpd --- Inetd ----- Service
----- Service
ipop3d
▶ Wrapper 설정:daemon_list : client_list [ : shell_command ]
/etc/hosts.deny
all : 131.155. # 131.155.x.x 에 대해 접근 차단
/etc/hosts.allow
in.telnetd : 131.156.72.0/255.255.255.0
# 131.156.72.0 대역에 대해 telnet 접근 허용.
ipop3d: ALL: (/some/where/safe_finger -l @%h | \
/usr/ucb/mail -s %d-%h root) &
와 같이 shell 명령어를 사용할 수도 있다.
Xinetd
참고사이트: http://www.xinetd.org/
service pop3
{
socket_type = stream
wait = no
user = root
server = /usr/sbin/ipop3d
only_from = 0.0.0.0/0
no_access = 207.35.78.10 128.138.204.0
# Allows every client
# Deny from
instances = 30
log_on_success += USERID
log_on_failure += USERID
access_times = 2:00-9:00 12:00-24:00
# 접근 가능한 시간대를 제한
rlimit_as
= 8M
# 사용 가능한 메모리를 8M로 제한
nice = -2
}
2.2 Standalone 서버 제어
sendmail
http://www.sendmail.org/
/etc/mail/access 파일에서 제어
[email protected]
REJECT
abc.com
REJECT
[email protected] OK
203.34
REJECT
211.47.64
RELAY
작성후 /etc/mail 에서 ./makemap.sh access 로 DB 화.
Sendmail 에서 SMTP 인증
▶ /etc/pam.d/smtp 생성후 아래 라인 추가
auth
required
/lib/security/pam_listfile.so item=user \
sense=allow file=/etc/mail/smtpauth onerr=succeed
auth
required
/lib/security/pam_stack.so service=system-auth
account required
/lib/security/pam_stack.so service=system-auth
/etc/mail/smtpauth 에 SMTP 인증을
허용할 유저를 한 줄에 하나씩 추가
httpd.conf 나 .htaccess 를 이용한 웹접근 제어
▶ httpd.conf 이용시
<Directory /home/abc/>
Order deny, allow
Deny from all
Allow from 211.47.64 211.47.65
</Directory>
 211.47.64. 와 211.47.65. 대역만 접근가능.
이외 IP 대역에서 접근시 404 Forbidden 에러.
.htaccess 파일을 이용한 접근제어
AuthName "Members Only."
AuthType Basic
AuthUserFile /home/private/public_html/.htpasswd
AuthGroupFile /dev/null
ErrorDocument 401 " ABC 직원만 접근 가능합니다.
<Limit GET POST>
require valid-user
Satisfy all
order deny,allow
allow from 192.168.1
allow from 210.60.58.217
deny from all
</Limit>
Satisfy all  두조건 모두 적합해야 함.
any  하나만 적합하면 됨.
미설정시 all 이 기본 설정값
Webzip, Teleport 등 일부 agent 프로그램 차단
BrowserMatch "WebZIP" go_out
BrowserMatch "Teleport" go_out
BrowserMatch "GetRight" go_out
<Directory />
Options ExecCGI
AllowOverride AuthConfig
Order allow,deny
Allow from all
Deny from env=go_out
</Directory>
외부에서 임의 데이터 링크 차단법
<VirtualHost domain.co.kr>
ServerAdmin [email protected]
DocumentRoot /home/domain/public_html
ServerName domain.co.kr
ServerAlias www.domain.co.kr
SetEnvIf Referer domain\.co\.kr go_in
SetEnvIf Referer www\.domain\.co\.kr go_in
SetEnvIf Referer ^$ go_in
<FilesMatch ".(mpg|asf|wmv)$">
Order Deny,Allow
Allow from env=go_in
Deny from all
</FilesMatch>
</VirtualHost>
Proftpd의 접근 통제
▶ proftpd.conf 에 아래 설정 추가.
<Limit LOGIN>
Order allow,deny
Allow from 211.47.64.
Allow from 211.47.65.
Deny from all
</Limit>
http://proftpd.net/
211.47.64.x 와 211.47.65.x 대역에서만 접근 허가
DNS 에서의 접근통제(named.conf)
options {
directory "/var/named";
allow-transfer {localhost; }; // Zone Transfer를 제한한다.
allow-recursion {211.47.64.0/24; 211.47.65.0/24; };
// recursion을 제
한한다.
};
zone "bind" chaos {
type master;
file "db.bind";
allow-query {
none;
};
allow-transfer {
none;
};
};
/var/named/db.bind 파일의 내용
$TTL 1D
$ORIGIN bind.
@
CHAOS SOA localhost. root.localhost. (
2000081201
3H
1H
1W
1D )
CHAOS
NS
localhost.
; serial
; refresh
; retry
; expiry
; minimum
// dig @ns.yahoo.co.kr txt chaos version.bind | grep VERSION
// 과 같은 bind 의 버전정보 요청에 대해 차단한다.
dig @kuccgx.korea.ac.kr korea.ac.kr axfr 를 막기 위한 방법은 ?
 Zone Transfer 차단.
. IPTABLES(ipchains) 를 이용한 패킷 필터링
참고사이트: http://netfilter.samba.org/
IPCHAINS (Kernel 2.2.x 이하) 와 IPTABLES (Kernel 2.4.x) 는
Kernel Level 에서 작동하며 패킷 헤더에 있는 소스IP : PORT와
목적지 IP:PORT 등의 정보를 이용하여 접근을 허용할 서비스를 제외한
접근을 필터링한다.
▶ 기본적으로 DROP 할 패킷
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
iptables
–A INPUT –s 255.255.255.255/32 –j DROP
–A INPUT –s 10.0.0.0/8 –j DROP
-A INPUT -s 0.0.0.0/8 -j DROP
-A INPUT -s 127.0.0.0/8 -j DROP
-A INPUT -s 169.254.0.0/16 -j DROP
-A INPUT -s 192.0.2.0/24 -j DROP
-A INPUT -s 224.0.0.0/3 -j DROP
-A INPUT -s 224.0.0.0/3 -j DROP
–A INPUT –s (Local.Network.Range) –j DROP
TCP/IP 3 Way Hand-Shaking
▶ TCP/IP 의 기본 통신 방식
본격적인 데이터 교환을 하기전에
서버와 클라이언트간에
SYN, SYN+ACK, ACK 를 주고 받는다.
따라서 서버와 클라이언트간 통신을
위해서는 이 관계를 고려하여 필터링
규칙을 세워야 한다.
메일 서버에서의 패킷 필터링 예
▶ SMTP 서버로 들어오는 메일 허용
iptables –A INPUT –p tcp ! –sport 0:1023 –dport 25 –j ACCEPT
iptables –A OUTPUT –p tcp –sport 25 –j ACCEPT
▶ 외부의 SMTP로 나가는 메일 허용
iptables –A OUTPUT –p tcp –dport 25 –j ACDCEPT
iptables –A INPUT –p tcp ! –syn –sport 25 ! –dport 0:1023 –j
ACCEPT
메일 서버에서의 패킷 필터링 예
▶ POP3 서버로 들어오는 접속 허용
Iptables –A INPUT –p tcp ! –sport 0:1023 –dport 110 –j ACCEPT
Iptables –A OUTPUT –p tcp –sport 110 –j ACCEPT
▶
클라이언트에서 POP3 서버로 나가는 접속
iptables –A OUTPUT –p tcp –dport 110 –j ACCEPT
iptables –A INPUT –p tcp ! –syn –sport 110 ! –dport 0:1023 –j
ACCEPT
허용 하여야 하는 연결이외 나머지는 모두 접근 차단(DROP).
패킷 필터링 규칙을 설정할 때 ftp 의 Passive Mode와
Normal Mode 의 차이를 잘 인식하고 규칙을 세워야 한다.
라우터에서의 접근 제어
▶모든 패킷이 가장 먼저 통과하는 관문이므로 가장 중요하고
가장 효과적인 보안 설정이 필요한 곳이다.
일반적인 라우터와 방화벽의 위치
(1) snmp community 재설정 및 접근제어
access-list 7 permit 211.100.14.200
snmp-server community xsnahs6x RO 7
라우터에서의 접근 제어
(2) 라우터에 telnet 접근제어
access-list 8 permit 211.100.14.200
access-list 8 deny any
line vty 0 4
access-class 8 in
(3) Virtual 패스워드를 암호화
Central(config)# service password-encryption
(4) 기타 서비스 제어
Central(config)#
Central(config)#
Central(config)#
Central(config)#
Central(config)#
no cdp enable
no service udp-small-servers
no service tcp-small-servers
no ip finger
no ip http server
라우터에서의 접근 제어
(5) access-list filtering
interface serial3/0
ip access-group 101 in
ip access-group 110 out
access-list
access-list
access-list
access-list
access-list
access-list
access-list
access-list
access-list
access-list
access-list
access-list
access-list
access-list
101
101
101
101
101
101
101
101
101
101
101
110
110
110
deny ip host 0.0.0.0 any
deny ip 127.0.0.0 0.255.255.255 any
deny ip 10.0.0.0 0.255.255.255 any
deny ip 172.16.0.0 0.15.255.255 any
deny ip 192.0.2.0 0.0.0.255 any
deny ip 169.254.0.0 0.0.255.255 any
deny ip 192.168.0.0 0.0.255.255 any
deny ip 240.0.0.0 15.255.255.255 any
deny ip 211.2.2.0 0.0.0.255 any
deny tcp any any range 12345 12346
permit ip any any
permit ip 211.2.2.0 0.0.0.255 any
permit ip 211.2.3.0 0.0.0.255 any
deny ip any any log-input