본문 바로가기

Learning/└◆리눅스 서버 보안

01_사용자/그룹이 없는 파일에 대해서

<!--[if !supportEmptyParas]--> <!--[endif]-->

사용자/그룹이 없는 파일에 대해서

<!--[if !supportEmptyParas]--> <!--[endif]-->

<!--[if !supportEmptyParas]--> <!--[endif]-->

<!--[if !supportEmptyParas]--> <!--[endif]-->

사용시스템

- linux200

<!--[if !supportEmptyParas]--> <!--[endif]-->

<!--[if !supportEmptyParas]--> <!--[endif]-->

[실습] 사용자/그룹이 없는 파일 생성

<!--[if !supportEmptyParas]--> <!--[endif]-->

실습용 사용자(nouser) 생성 및 확인

# useradd nouser

# echo nouser | passwd --stdin nouser

Changing password for user nouser.

passwd: all authentication tokens updated successfully.

<!--[if !supportEmptyParas]--> <!--[endif]-->

useradd 명령어 수행

() /etc/passwd 파일 내용 추가(# grep nouser /etc/passwd)

() /etc/shadow 파일 내용 추가(# grep nouser /etc/shadow)

() /home/nouser 디렉토리 생성(# ls -l /etc/skel/*)

() /etc/group 파일 내용 추가 (# grep nouser /etc/group)

() MAIL BOX 설정(# ls -l /var/spool/mail/$USER)

<!--[if !supportEmptyParas]--> <!--[endif]-->

# grep nouser /etc/passwd

nouser:x:504:504::/home/nouser:/bin/bash

<!--[if !supportEmptyParas]--> <!--[endif]-->

# cd /home

# ls -l

total 17

drwx------ 3 hacker hacker 1024 Sep 16 09:28 hacker

drwx------ 2 root root 12288 Jul 4 05:17 lost+found

drwx------ 3 nouser nouser 1024 Sep 16 09:28 nouser

drwx------ 3 user01 user01 1024 Dec 30 2014 user01

drwx------ 3 user02 user02 1024 Dec 30 2014 user02

drwx------ 3 user03 user03 1024 Dec 30 2014 user03

<!--[if !supportEmptyParas]--> <!--[endif]-->

/etc/passwd 파일 백업 및 /etc/passwd 파일 편집

# cp -p /etc/passwd /etc/passwd.old

# vi /etc/passwd

..... (중략) .....

user01:x:500:500::/home/user01:/bin/bash

user02:x:501:501::/home/user02:/bin/bash

user03:x:502:502::/home/user03:/bin/bash

hacker:x:503:503::/home/hacker:/bin/bash

nouser:x:504:504::/home/nouser:/bin/bash

-> nouser 라인 삭제

<!--[if !supportEmptyParas]--> <!--[endif]-->

# ls -l

total 17

drwx------ 3 hacker hacker 1024 Sep 16 09:28 hacker

drwx------ 2 root root 12288 Jul 4 05:17 lost+found

drwx------ 3 504 nouser 1024 Sep 16 09:28 nouser

drwx------ 3 user01 user01 1024 Dec 30 2014 user01

drwx------ 3 user02 user02 1024 Dec 30 2014 user02

drwx------ 3 user03 user03 1024 Dec 30 2014 user03

누구 소유인지 모를 때 숫자로 형성 (/etc/passwd에서 삭제했기 때문에)

<!--[if !supportEmptyParas]--> <!--[endif]-->

<!--[if !supportEmptyParas]--> <!--[endif]-->

<!--[if !supportEmptyParas]--> <!--[endif]-->

nouser 파일들 목록 점검

# find / -nouser 2>/dev/null

/home/nouser

/home/nouser/.bash_logout

/home/nouser/.bash_profile

/home/nouser/.mozilla

/home/nouser/.mozilla/extensions

/home/nouser/.mozilla/plugins

/home/nouser/.bashrc

/home/nouser/.emacs

/var/spool/mail/nouser

<!--[if !supportEmptyParas]--> <!--[endif]-->

# find / -nouser -ls 2>/dev/null

1 drwx------ 3 504 nouser 1024 Sep 16 09:28 /home/nouser

77523 1 -rw-r--r-- 1 504 nouser 33 Sep 16 09:28 /home/nouser/.bash_logout

77527 1 -rw-r--r-- 1 504 nouser 176 Sep 16 09:28 /home/nouser/.bash_profile

77524 1 drwxr-xr-x 4 504 nouser 1024 Sep 16 09:28 /home/nouser/.mozilla

77525 1 drwxr-xr-x 2 504 nouser 1024 Sep 16 09:28 /home/nouser/.mozilla/extensions

77526 1 drwxr-xr-x 2 504 nouser 1024 Sep 16 09:28 /home/nouser/.mozilla/plugins

77528 1 -rw-r--r-- 1 504 nouser 124 Sep 16 09:28 /home/nouser/.bashrc

77522 1 -rw-r--r-- 1 504 nouser 515 Sep 16 09:28 /home/nouser/.emacs

6431634 0 -rw-rw---- 1 504 mail 0 Sep 16 09:28 /var/spool/mail/nouser

<!--[if !supportEmptyParas]--> <!--[endif]-->

# find / -nouser -exec rm -rf {} \;

# find / \( -nouser -o -nogroup \) -ls 2>/dev/null

<!--[if !supportEmptyParas]--> <!--[endif]-->

# find / -perm -2 2>/dev/null

# find / -perm -0002 2>/dev/null

# find / -perm -o=w 2>/dev/null

-2 => 0002 => -o=w => other => w권한

<!--[if !supportEmptyParas]--> <!--[endif]-->

(예제) (파일 ) -rw-r--rw- ..... file1

(디렉토리) -rwxr-xrwx ..... dir1

<!--[if !supportEmptyParas]--> <!--[endif]-->

내용중 불필요한 파일이 있다면 삭제한다.

<!--[if !supportEmptyParas]--> <!--[endif]-->

/etc/passwd 파일 복원작업 검색된

# cp -f /etc/passwd.old /etc/passwd

# ls -l /home

-> /home/nouser 파일의 디렉토리 속성 정보 확인

<!--[if !supportEmptyParas]--> <!--[endif]-->

<!--[if !supportEmptyParas]--> <!--[endif]-->