블로그 이미지
22Hz 22Hz

카테고리

분류 전체보기 (109)
모의해킹 침해대응 전문가 과정 (99)
리눅스 설정 (10)
Total
Today
Yesterday

달력

« » 2024.5
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

공지사항

태그목록

최근에 올라온 글

3일차

==============안내사항==============

첫날 줬던 제본 점검표 필요할때 가져와야함
1주일전 휴가계 작성해서 휴가를 사용
식당 굿모닝 쓰면 저렴 데스크에서 위치 등 확인
검색했을때 멀었던거 같았음 다른 굿모닝이 있나?
다음주에 자리배정 한다고 함 랜덤.. 가나다 나는 중간쯤?
내일 4시에 자리배정 새로??
대기시간에 4강의실에서 대기해도 됨 더우면 에어컨
컴퓨터 사용해도 되는데 나갈때 본체전원 꼭 끌것

\\172.16.13.1
soldesk / soldesksecurity1.

==============복습내용==============

whatis CMD 쓰려면 index 가 있어야 하는데 없으면 오류가 남
# makewhatis 를 입력해서 생성해야함

# whatis passwd (# makewhatis)

시스템 정보 확인할때 uname CMD

redhat, centos 등의 문서사이트 참고 많이 할 것

data CMD, rdate CMD (remote date, 원격 서버의 시간)

cd CMD 상대경로, 절대경로

디렉토리 관리 명령어
ls CMD, mkdir CMD, rmdir CMD
ls -altr

파일 관리 명령어
touch CMD, cp CMD, mv CMD, rm CMD
cp -p, cp -a
[참고] debugfs CMD

파일 내용 확인 명령어
cat CMD, more CMD, head CMD, tail CMD
cat -n
[참고] strings CMD

==============강의내용==============

1. 기타 관리용 명령어
 wc CMD
  [참고] Data Gathering
  # ps -ef | wc -l
  # rpm -qa | wc -l
  # cat /etc/passwd | wc -l

  # ps -ef | grep httpd | wc -l
  # df -k / | tail -1 | awk '{print $5}'
  # cat /var/log/messages | grep 'START: telnet' messages | grep 'Apr 14' | wc -l

 su CMD
  # su user01
  # su - user01
 id CMD
 groups CMD

 last CMD (/var/log/wtmp)
  # cd /var/log ; ls
  wtmp wtmp.0 wtmp.1 wtmp.2 wtmp.3 //1주일마다 하나씩
  # last -f wtmp.0

 lastlog CMD (/var/log/lastlog)
 lastb CMD (/var/log/btmp)
  [참고] watch CMD (# watch lastb)

 who CMD
 w CMD
  # while true
  do
   CMD
   sleep 2 //2초 딜레이
  done


==============실습내용==============

wc 명령어

[root@linux205 ~]# wc /etc/passwd
  42   61 1945 /etc/passwd
line count / word count / character count

[root@linux205 ~]# wc -l /etc/passwd
42 /etc/passwd
[root@linux205 ~]# wc -w /etc/passwd
61 /etc/passwd
[root@linux205 ~]# wc -c /etc/passwd
1945 /etc/passwd

실행중인 프로세스의 수 확인
# ps -ef | wc -l

설치된 패키지 수 확인
rpm -qa | wc -l

[root@linux205 ~]# service httpd
사용법: httpd {start|stop|restart|condrestart|reload|status|f
[root@linux205 ~]# service httpd start
httpd (을)를 시작 중:                                      [  OK  ]

[root@linux205 ~]# ps -ef | grep httpd | wc -l > apache.log
[root@linux205 ~]# cat apache.log
10

[root@linux205 ~]# df -k / | tail -1
/dev/sda1             37114672   3185492  32013432  10% /
[root@linux205 ~]# df -k / | tail -1 | awk '{print $5}'
10%
[root@linux205 ~]# df -k / | tail -1 | awk '{print $5}' > df.count
[root@linux205 ~]# cat df.count
10%

데이터 수집 Data Gathering

[root@linux205 /var/log]# grep 'START: telnet' messages
Apr 12 21:56:35 linux205 xinetd[19531]: START: telnet pid=19534 from=127.0.0.1
Apr 12 21:57:15 linux205 xinetd[19531]: START: telnet pid=19562 from=127.0.0.1
Apr 12 21:59:16 linux205 xinetd[19531]: START: telnet pid=19567 from=127.0.0.1
Apr 12 22:02:35 linux205 xinetd[19531]: START: telnet pid=19667 from=127.0.0.1
Apr 14 16:45:52 linux205 xinetd[3971]: START: telnet pid=4844 from=127.0.0.1
[root@linux205 /var/log]# grep 'START: telnet' messages | wc -l
5
[root@linux205 /var/log]# grep 'START: telnet' messages | grep 'Apr 14'
Apr 14 16:45:52 linux205 xinetd[3971]: START: telnet pid=4844 from=127.0.0.1

su CMD 사용저 전환 Switching User
일반사용자/user01 -> 다른 일반사용자/user02
일반사용자/user01 -> 관리자/root
관리자/root -> 일반사용자/user01

# su   [fedora]
[root@linux205 ~]# cd /etc
[root@linux205 /etc]# su fedora
[fedora@linux205 /etc]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[fedora@linux205 /etc]$ pwd
/etc
[fedora@linux205 /etc]$ echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

# su - [fedora]
[root@linux205 ~]# cd /etc
[root@linux205 /etc]# su - fedora
[fedora@linux205 ~]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[fedora@linux205 ~]$ pwd
/home/fedora
[fedora@linux205 ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/fedora/bin

[root@linux205 ~]# ssh fedora@localhost
fedora@localhost's password:
Last login: Tue Apr 12 21:56:43 2016 from linux205
[fedora@linux205 ~]$ cat /etc/shadow
cat: /etc/shadow: 허가 거부됨
[fedora@linux205 ~]$ ls -l /etc/shadow
-r-------- 1 root root 1275  4월 12 22:02 /etc/shadow
[fedora@linux205 ~]$ su - // su - root 와 동일
암호:
[root@linux205 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@linux205 ~]# cat /etc/shadow
root:$1$UKMNc7Ge$/gJRha8DberQjJGEThyKh1:16903:0:99999:7:::
bin:*:16902:0:99999:7:::
daemon:*:16902:0:99999:7:::
adm:*:16902:0:99999:7:::
lp:*:16902:0:99999:7:::
sync:*:16902:0:99999:7:::
shutdown:*:16902:0:99999:7:::
halt:*:16902:0:99999:7:::
mail:*:16902:0:99999:7:::
news:*:16902:0:99999:7:::
uucp:*:16902:0:99999:7:::
operator:*:16902:0:99999:7:::
games:*:16902:0:99999:7:::
gopher:*:16902:0:99999:7:::
ftp:*:16902:0:99999:7:::
nobody:*:16902:0:99999:7:::
distcache:!!:16902:0:99999:7:::
nscd:!!:16902:0:99999:7:::
vcsa:!!:16902:0:99999:7:::
apache:!!:16902:0:99999:7:::
rpc:!!:16902:0:99999:7:::
mailnull:!!:16902:0:99999:7:::
smmsp:!!:16902:0:99999:7:::
webalizer:!!:16902:0:99999:7:::
dovecot:!!:16902:0:99999:7:::
squid:!!:16902:0:99999:7:::
pcap:!!:16902:0:99999:7:::
ntp:!!:16902:0:99999:7:::
dbus:!!:16902:0:99999:7:::
avahi:!!:16902:0:99999:7:::
rpcuser:!!:16902:0:99999:7:::
nfsnobody:!!:16902:0:99999:7:::
named:!!:16902:0:99999:7:::
hsqldb:!!:16902:0:99999:7:::
sshd:!!:16902:0:99999:7:::
haldaemon:!!:16902:0:99999:7:::
avahi-autoipd:!!:16902:0:99999:7:::
xfs:!!:16902:0:99999:7:::
gdm:!!:16902:0:99999:7:::
sabayon:!!:16902:0:99999:7:::
fedora:$1$KLkGXiYJ$P.J2gxakySlsQqOdh23qM1:16903:0:99999:7:::
user01:$1$g7UnLTde$.Wa9v1IovkVxaWkzDPUfW0:16903:0:99999:7:::

[root@linux205 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

[root@linux205 ~]# groups
root bin daemon sys adm disk wheel
[root@linux205 ~]# groups fedora
fedora : fedora
[root@linux205 ~]# groups fedora root
fedora : fedora
root : root bin daemon sys adm disk wheel

last CMD : last, lastb 사용자들의 마지막 로그인한 기록 목록을 보여준다
사용자의 로그인, 로그아웃 시간을 출력하는 명령어

[root@linux205 ~]# tty
/dev/pts/2
[root@linux205 ~]# last
fedora   pts/3        linux205.example Thu Apr 14 17:21   still logged in  
fedora   pts/3        linux205.example Thu Apr 14 17:20 - 17:21  (00:01)   
root     pts/2        :0.0             Thu Apr 14 17:20   still logged in  
root     pts/1        :0.0             Thu Apr 14 17:15   still logged in  
fedora   pts/2        linux205.example Thu Apr 14 17:13 - 17:15  (00:02)   
root     pts/1        :0.0             Thu Apr 14 17:12 - 17:15  (00:02)   
root     pts/2        :0.0             Thu Apr 14 16:46 - 17:12  (00:26)   
root     pts/3        linux205         Thu Apr 14 16:45 - 16:46  (00:00)   
root     pts/2        :0.0             Thu Apr 14 16:45 - 16:46  (00:00)   
root     pts/1        :0.0             Thu Apr 14 16:12 - 17:12  (01:00)   
root     :0                            Thu Apr 14 16:11   still logged in  
root     :0                            Thu Apr 14 16:11 - 16:11  (00:00)   
reboot   system boot  2.6.18-194.el5   Thu Apr 14 16:10          (01:11)   
root     pts/3        :0.0             Tue Apr 12 22:10 - down   (00:11)   
root     pts/2        :0.0             Tue Apr 12 22:10 - down   (00:12)   
root     pts/1        :0.0             Tue Apr 12 22:10 - down   (00:12)   
user01   pts/3        linux205         Tue Apr 12 22:02 - 22:03  (00:00)   
root     pts/2        :0.0             Tue Apr 12 22:01 - 22:09  (00:08)   
root     pts/3        :0.0             Tue Apr 12 22:01 - 22:01  (00:00)   
root     pts/3        :0.0             Tue Apr 12 22:01 - 22:01  (00:00)   
root     pts/2        :0.0             Tue Apr 12 22:01 - 22:01  (00:00)   
root     pts/2        linux205         Tue Apr 12 21:59 - 21:59  (00:00)   
fedora   pts/2        linux205         Tue Apr 12 21:56 - 21:56  (00:00)   
root     pts/1        :0.0             Tue Apr 12 21:33 - 22:10  (00:36)   
root     pts/1        :0.0             Tue Apr 12 20:16 - 21:33  (01:17)   
root     pts/1        :0.0             Tue Apr 12 18:52 - 20:16  (01:24)   
root     pts/1        :0.0             Tue Apr 12 18:14 - 18:52  (00:37)   
fedora   pts/2        linux205.example Tue Apr 12 17:38 - 17:39  (00:00)   
root     pts/1        :0.0             Tue Apr 12 17:17 - 18:14  (00:57)   
root     pts/1        :0.0             Sun Aug 16 13:03 - 17:17 (2431+04:13)
root     pts/1        :0.0             Tue Apr 12 17:00 - 13:03 (-2431+-3:-5
root     pts/2        :0.0             Tue Apr 12 16:55 - 16:58  (00:02)   
root     pts/1        :0.0             Tue Apr 12 16:48 - 16:58  (00:10)   
root     :0                            Tue Apr 12 16:48 - down   (05:34)   
root     :0                            Tue Apr 12 16:48 - 16:48  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 16:47          (05:35)   
root     pts/1        :0.0             Tue Apr 12 16:34 - down   (00:11)   
fedora   pts/2        linux205.example Tue Apr 12 16:32 - 16:34  (00:01)   
root     pts/1        :0.0             Tue Apr 12 16:22 - 16:34  (00:12)   
root     pts/1        :0.0             Tue Apr 12 16:20 - 16:22  (00:02)   
root     :0                            Tue Apr 12 16:19 - down   (00:26)   
root     :0                            Tue Apr 12 16:19 - 16:19  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 16:19          (00:26)   
root     :0                            Tue Apr 12 16:11 - down   (00:06)   
root     :0                            Tue Apr 12 16:11 - 16:11  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 16:10          (00:06)   
root     pts/0        :0.0             Mon Apr 11 22:14 - down   (00:04)   
root     pts/0        :0.0             Mon Apr 11 22:14 - 22:14  (00:00)   
root     pts/0        :0.0             Mon Apr 11 22:08 - 22:14  (00:05)   
root     :0                            Mon Apr 11 22:04 - down   (00:13)   
root     :0                            Mon Apr 11 22:04 - 22:04  (00:00)   
reboot   system boot  2.6.18-194.el5   Mon Apr 11 22:03          (00:14)   
root     pts/1        :0.0             Mon Apr 11 21:49 - down   (00:09)   
root     :0                            Mon Apr 11 21:42 - down   (00:16)   
root     :0                            Mon Apr 11 21:42 - 21:42  (00:00)   
reboot   system boot  2.6.18-194.el5   Mon Apr 11 21:42          (00:16)   
root     pts/1        :0.0             Mon Apr 11 21:40 - down   (00:00)   
root     :0                            Mon Apr 11 21:39 - down   (00:01)   
root     :0                            Mon Apr 11 21:39 - 21:39  (00:00)   
root     tty1                          Mon Apr 11 21:38 - down   (00:02)   
root     pts/1        :0.0             Mon Apr 11 20:51 - 21:38  (00:46)   
root     :0                            Mon Apr 11 20:51 - 21:38  (00:47)   
root     :0                            Mon Apr 11 20:51 - 20:51  (00:00)   
reboot   system boot  2.6.18-194.el5   Mon Apr 11 20:50          (00:50)   
root     pts/2        :0.0             Mon Apr 11 20:19 - 20:19  (00:00)   
root     pts/2        :0.0             Mon Apr 11 20:16 - 20:16  (00:00)   
root     pts/2        :0.0             Mon Apr 11 20:16 - 20:16  (00:00)   
root     pts/1        :0.0             Tue Apr 12 05:02 - down   (-8:-13)  
root     :0                            Tue Apr 12 05:02 - down   (-8:-13)  
root     :0                            Tue Apr 12 05:02 - 05:02  (00:00)   
root     pts/1        :0.0             Tue Apr 12 04:46 - 05:02  (00:16)   
root     :0                            Tue Apr 12 04:45 - 05:02  (00:16)   
root     :0                            Tue Apr 12 04:45 - 04:45  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 04:45          (-7:-56)  
fedora   :0                            Tue Apr 12 04:41 - crash  (00:04)   
fedora   :0                            Tue Apr 12 04:41 - 04:41  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 04:39          (-7:-50)  
reboot   system boot  2.6.18-194.el5   Tue Apr 12 04:32          (00:05)   

wtmp begins Tue Apr 12 04:32:01 2016
[root@linux205 ~]#
[root@linux205 ~]# last -5
fedora   pts/3        linux205.example Thu Apr 14 17:21   still logged in  
fedora   pts/3        linux205.example Thu Apr 14 17:20 - 17:21  (00:01)   
root     pts/2        :0.0             Thu Apr 14 17:20   still logged in  
root     pts/1        :0.0             Thu Apr 14 17:15   still logged in  
fedora   pts/2        linux205.example Thu Apr 14 17:13 - 17:15  (00:02)   

wtmp begins Tue Apr 12 04:32:01 2016
[root@linux205 ~]# last | head -5
fedora   pts/3        linux205.example Thu Apr 14 17:21   still logged in  
fedora   pts/3        linux205.example Thu Apr 14 17:20 - 17:21  (00:01)   
root     pts/2        :0.0             Thu Apr 14 17:20   still logged in  
root     pts/1        :0.0             Thu Apr 14 17:15   still logged in  
fedora   pts/2        linux205.example Thu Apr 14 17:13 - 17:15  (00:02) 

[root@linux205 ~]# file /var/log/wtmp
/var/log/wtmp: data
[root@linux205 ~]# file /etc/passwd
/etc/passwd: ASCII text

last 명령어의 사용 예
개발자 요청내용 어제 파일(file.log)을 삭제한 사용자를 검색해 달라
정보1 어제 파일이 지워졌다
 # last | grep 'Jun 8'
정보2 지워진 파일의 이름 : file.log
 # cat ~/.bash_history
 # cat ~/.bash_history | grep 'file.log' | grep rm

[root@linux205 ~]# cd /test
[root@linux205 /test]# chmod 777 /test
[root@linux205 /test]# touch file.log
[root@linux205 /test]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.

    linux205.example.com (Linux release 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (3)

login: fedora
Password:
Last login: Thu Apr 14 17:21:35 from linux205.example.com
[fedora@linux205 ~]$ rm -rf /test/file.log
[fedora@linux205 ~]$ ls /test
[fedora@linux205 ~]$ exit
logout

[root@linux205 /test]# last | grep 'Apr 14'
fedora   pts/3        linux205         Thu Apr 14 17:33 - 17:34  (00:00)   
root     pts/2        :0.0             Thu Apr 14 17:33   still logged in  
root     pts/1        :0.0             Thu Apr 14 17:32   still logged in  
fedora   pts/3        linux205.example Thu Apr 14 17:21 - 17:32  (00:11)   
fedora   pts/3        linux205.example Thu Apr 14 17:20 - 17:21  (00:01)   
root     pts/2        :0.0             Thu Apr 14 17:20 - 17:32  (00:12)   
root     pts/1        :0.0             Thu Apr 14 17:15 - 17:32  (00:17)   
fedora   pts/2        linux205.example Thu Apr 14 17:13 - 17:15  (00:02)   
root     pts/1        :0.0             Thu Apr 14 17:12 - 17:15  (00:02)   
root     pts/2        :0.0             Thu Apr 14 16:46 - 17:12  (00:26)   
root     pts/3        linux205         Thu Apr 14 16:45 - 16:46  (00:00)   
root     pts/2        :0.0             Thu Apr 14 16:45 - 16:46  (00:00)   
root     pts/1        :0.0             Thu Apr 14 16:12 - 17:12  (01:00)   
root     :0                            Thu Apr 14 16:11   still logged in  
root     :0                            Thu Apr 14 16:11 - 16:11  (00:00)   
reboot   system boot  2.6.18-194.el5   Thu Apr 14 16:10          (01:24)   

[root@linux205 /test]# egrep -l "file.log" /home/*/.bash_history
/home/fedora/.bash_history
[root@linux205 /test]# egrep file.log /home/fedora/.bash_history
rm -rf /test/file.log

사용자 추적 완료!!

lastlog 가장 마지막에 로그인한 정보
[root@linux205 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.

    linux205.example.com (Linux release 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (2)

login: root
Password:
Last login: Thu Apr 14 16:45:57 from linux205
You have new mail.
[root@linux205 ~]# date
2016. 04. 14. (목) 17:41:40 KST

[root@linux205 ~]# lastlog
사용자명         포트     ~로부터          최근정보
root             pts/2    linux205         목  4월 14 17:41:26 +0900 2016
bin                                        **한번도 로그인한 적이 없습니다**
daemon                                     **한번도 로그인한 적이 없습니다**
adm                                        **한번도 로그인한 적이 없습니다**
lp                                         **한번도 로그인한 적이 없습니다**
sync                                       **한번도 로그인한 적이 없습니다**
shutdown                                   **한번도 로그인한 적이 없습니다**
halt                                       **한번도 로그인한 적이 없습니다**
mail                                       **한번도 로그인한 적이 없습니다**
news                                       **한번도 로그인한 적이 없습니다**
uucp                                       **한번도 로그인한 적이 없습니다**
operator                                   **한번도 로그인한 적이 없습니다**
games                                      **한번도 로그인한 적이 없습니다**
gopher                                     **한번도 로그인한 적이 없습니다**
ftp                                        **한번도 로그인한 적이 없습니다**
nobody                                     **한번도 로그인한 적이 없습니다**
distcache                                  **한번도 로그인한 적이 없습니다**
nscd                                       **한번도 로그인한 적이 없습니다**
vcsa                                       **한번도 로그인한 적이 없습니다**
apache                                     **한번도 로그인한 적이 없습니다**
rpc                                        **한번도 로그인한 적이 없습니다**
mailnull                                   **한번도 로그인한 적이 없습니다**
smmsp                                      **한번도 로그인한 적이 없습니다**
webalizer                                  **한번도 로그인한 적이 없습니다**
dovecot                                    **한번도 로그인한 적이 없습니다**
squid                                      **한번도 로그인한 적이 없습니다**
pcap                                       **한번도 로그인한 적이 없습니다**
ntp                                        **한번도 로그인한 적이 없습니다**
dbus                                       **한번도 로그인한 적이 없습니다**
avahi                                      **한번도 로그인한 적이 없습니다**
rpcuser                                    **한번도 로그인한 적이 없습니다**
named                                      **한번도 로그인한 적이 없습니다**
hsqldb                                     **한번도 로그인한 적이 없습니다**
sshd                                       **한번도 로그인한 적이 없습니다**
haldaemon                                  **한번도 로그인한 적이 없습니다**
avahi-autoipd                              **한번도 로그인한 적이 없습니다**
xfs                                        **한번도 로그인한 적이 없습니다**
gdm                                        **한번도 로그인한 적이 없습니다**
sabayon                                    **한번도 로그인한 적이 없습니다**
fedora           pts/3    linux205         목  4월 14 17:33:41 +0900 2016
user01           pts/3    linux205         화  4월 12 22:02:40 +0900 2016

lastb 접속실패로그를 출력해준다 /var/log/btmp

(전제조건) user01 사용자가 있어야 한다
[root@linux205 ~]# cat /etc/passwd | grep user01
user01:x:501:501::/home/user01:/bin/bash

없으면 # useradd user01, # passwd user01

[root@linux205 ~]# ssh user01@localhost
user01@localhost's password:
Permission denied, please try again.
user01@localhost's password:
Permission denied, please try again.
user01@localhost's password:
Permission denied (publickey,gssapi-with-mic,password).
[root@linux205 ~]# lastb
user01   ssh:notty    linux205.example Thu Apr 14 17:45 - 17:45  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)  

watch lastb 예제 사진파일1

[root@linux205 ~]# lastb -5
fedora   ssh:notty    linux205.example Thu Apr 14 17:46 - 17:46  (00:00)   
fedora   ssh:notty    linux205.example Thu Apr 14 17:46 - 17:46  (00:00)   
fedora   ssh:notty    linux205.example Thu Apr 14 17:46 - 17:46  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:45 - 17:45  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   

btmp begins Thu Apr 14 17:44:41 2016
[root@linux205 ~]# lastb - grep user01
user01   ssh:notty    linux205.example Thu Apr 14 17:45 - 17:45  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   

btmp begins Thu Apr 14 17:44:41 2016
[root@linux205 ~]# lastb | grep user01 | wc -l
5

who 명령어, w 명령어
who : 현재 서버에 로그인 한 사용자 확인
/var/run/utmp 의 내용을 보여줌

[root@linux205 ~]# who
root     :0           2016-04-14 16:11
root     pts/1        2016-04-14 17:38 (:0.0)
fedora   pts/2        2016-04-14 18:18 (linux205)
root     pts/3        2016-04-14 18:18 (:0.0)
[root@linux205 ~]# who
root     :0           2016-04-14 16:11
root     pts/1        2016-04-14 17:38 (:0.0)
root     pts/3        2016-04-14 18:18 (:0.0)

현재 로그인되어있는 사용자들 확인

[root@linux205 ~]# ssh 172.16.9.252
ssh_exchange_identification: Connection closed by remote host
[root@linux205 ~]# ssh 172.16.9.252
The authenticity of host '172.16.9.252 (172.16.9.252)' can't be established.
RSA key fingerprint is e2:f0:f8:a2:47:3b:b4:7c:ae:65:38:0e:31:bf:1f:84.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.9.252' (RSA) to the list of known hosts.
root@172.16.9.252's password:
Last login: Thu Apr 14 18:21:16 2016 from 172.16.6.204
[linux252@~]#  id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[linux252@~]#  tty
/dev/pts/17
[linux252@~]#  who
root     :0           2016-04-07 18:43
root     pts/1        2016-04-07 18:44 (:0.0)
root     pts/8        2016-04-14 18:20 (172.16.6.227)
root     pts/10       2016-04-14 18:21 (172.16.6.201)
root     pts/2        2016-04-14 18:20 (172.16.6.249)
root     pts/3        2016-04-14 18:20 (172.16.6.203)
root     pts/4        2016-04-14 18:20 (172.16.6.211)
root     pts/12       2016-04-14 18:21 (172.16.6.223)
root     pts/7        2016-04-14 18:20 (172.16.6.225)
root     pts/5        2016-04-14 18:20 (172.16.6.228)
root     pts/6        2016-04-14 18:20 (172.16.6.202)
root     pts/9        2016-04-14 18:20 (172.16.6.212)
root     pts/11       2016-04-14 18:21 (172.16.9.238)
root     pts/13       2016-04-14 18:21 (172.16.6.221)
root     pts/14       2016-04-14 18:21 (172.16.6.213)
root     pts/15       2016-04-14 18:21 (172.16.6.215)
root     pts/16       2016-04-14 18:21 (172.16.6.204)
root     pts/17       2016-04-14 18:21 (172.16.6.205)
root     pts/18       2016-04-14 18:21 (172.16.6.206)
root     pts/19       2016-04-14 18:21 (172.16.6.220)
root     pts/20       2016-04-14 18:21 (172.16.6.219)
root     pts/21       2016-04-14 18:21 (172.16.6.200)
root     pts/22       2016-04-14 18:21 (172.16.6.214)

w : work 실행되고 있는 명령어들 확인
[root@linux205 ~]# w
 18:24:14 up  2:14,  3 users,  load average: 0.05, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       -                16:11   ?xdm?  29.55s  0.23s /usr/bin/gnome-session
root     pts/1    :0.0             17:38    4:01   0.06s  0.06s bash
root     pts/3    :0.0             18:18    0.00s  0.03s  0.00s w

putty 프로그램 사용해서 리눅스 서버에 접속

[root@linux205 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:F7:F6:B8 
          inet addr:172.16.6.205  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fec0:1234::20c:29ff:fef7:f6b8/64 Scope:Site
          inet6 addr: fe80::20c:29ff:fef7:f6b8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:89960 errors:0 dropped:0 overruns:0 frame:0
          TX packets:777 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7751095 (7.3 MiB)  TX bytes:60878 (59.4 KiB)
          Interrupt:67 Base address:0x2024

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2565 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2565 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2471336 (2.3 MiB)  TX bytes:2471336 (2.3 MiB)

putty 옵션 만들어서 접속

악의적 사용자(user01 vim /etc/passwd) 모니터링

모니터링 하는 방법 while ~ do ~ done
[root@linux205 ~]# while true
> do
> w user01
> sleep 2
> done
 18:42:12 up  2:32,  7 users,  load average: 0.10, 0.06, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    5:21   0.14s  0.08s vim /etc/passwd
 18:42:14 up  2:32,  7 users,  load average: 0.10, 0.05, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    5:23   0.14s  0.08s vim /etc/passwd
 18:42:16 up  2:32,  7 users,  load average: 0.10, 0.05, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    5:25   0.14s  0.08s vim /etc/passwd

[root@linux205 ~]# while true
> do
> echo "----------`date`----------"
> w user01
> sleep 2
> done
----------2016. 04. 14. (목) 18:43:28 KST----------
 18:43:28 up  2:33,  7 users,  load average: 0.03, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    6:37   0.14s  0.08s vim /etc/passwd
----------2016. 04. 14. (목) 18:43:30 KST----------
 18:43:30 up  2:33,  7 users,  load average: 0.03, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    6:39   0.14s  0.08s vim /etc/passwd
----------2016. 04. 14. (목) 18:43:32 KST----------
 18:43:32 up  2:34,  7 users,  load average: 0.03, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    6:41   0.14s  0.08s vim /etc/passwd
----------2016. 04. 14. (목) 18:43:34 KST----------
 18:43:34 up  2:34,  7 users,  load average: 0.02, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    6:43   0.14s  0.08s vim /etc/passwd

user01 의 로그인쉘을 종료시키면 하위쉘 다 종료시킬수 있음
악성유저의 배쉬쉘의 PID 번호를 kill

[root@linux205 ~]# ps -fu user01
UID        PID  PPID  C STIME TTY          TIME CMD
user01    5972  5971  0 18:36 pts/5    00:00:00 -bash
user01    5995  5972  0 18:36 pts/5    00:00:00 vim /etc/passwd
[root@linux205 ~]# kill -9 5972

모니터링창에서는 아래와 같이 나옴
----------2016. 04. 14. (목) 18:46:42 KST----------
 18:46:42 up  2:37,  7 users,  load average: 0.00, 0.02, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
----------2016. 04. 14. (목) 18:46:44 KST----------
 18:46:44 up  2:37,  7 users,  load average: 0.00, 0.02, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
----------2016. 04. 14. (목) 18:46:46 KST----------
 18:46:46 up  2:37,  7 users,  load average: 0.00, 0.02, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT

[참고] 원격서버에 접속시 접속한 서버의 이름, 사용자, 작업 디렉토리 꼭 확인
# hostname
# id
# pwd

[참고] 관리서버에 접속시 오늘 로그인/로그아웃 사용자 정보 확인
# last
# who
# w

현재 서버에 붙어있는 사용자가 몇명인지 2초마다 확인
[root@linux205 ~]# ps -ef | grep httpd | wc -l
10
[root@linux205 ~]# while true
> do
> ps -ef | grep httpd | wc -l
> sleep 2
> done
10
10
10

[root@linux205 ~]# while true
> do
> echo "-----`date`-----"
> df -h /data1 /home
> sleep 2
> done
-----2016. 04. 14. (목) 19:47:27 KST-----
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda3             487M   11M  451M   3% /home
-----2016. 04. 14. (목) 19:47:29 KST-----
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda3             487M   11M  451M   3% /home

[root@linux205 ~]# while true
> do
> clear //이런식으로도 활용가능
> echo "----------`date`----------"
> df -h
> sleep 2
> done

----------2016. 04. 14. (목) 19:48:06 KST----------
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final

vi Visual Editor (/bin/vi)
vim Visual Editor Improved (/usr/bin/vim)

vi 에서 이동 명령어
h좌 j하 k상 l우
x한글자, dd한줄
i입력모드
shift + :, /, ? save & quit //최하위행(라인) 모드 라스트라인(Last Line Mode)
wq write & quit

: set number (: set nu)
: set nonumber (: set nonu)

: 30 (30G) nG //줄이동

w : word 다음 단어
b : back word 이전 단어
0(^) : 라인의 처음
$ : 라인의 끝
Ctrl + F : 다음페이지
Ctrl + B : 이전페이지
H, M, L : 출력된 페이지에서 하이 미들 로우 줄로 이동
G, nG, 1G : 소문자g 첫줄, 대문자G 마지막줄

삭제
x : 현재커서 삭제
dw : delete word 워드 단위로 삭제
d0, d$ : 커서 위치부터 라인처음까지 삭제, 라인끝까지 삭제
dd : 커서위치한 라인전부 삭제
ndd : 3dd 현재커서라인 포함해서 아래로 3라인 삭제, n라인 삭제, 잘 안쓴다고 함
:1,3d : 1번라인부터 3번라인까지 삭제
dG : 끝라인까지 다 삭제
d1G : 첫라인까지 다 삭제

i : insert 커서 앞부분에 insert
I : 커서 위치한 라인의 제일 첫칸에 삽입모드
a : append 커서 뒷부분에 insert
A : 커서 위치한 라인의 제일 마지막칸에 삽입모드
o : open line 현재 커서 아래에 빈줄삽입 후 삽입(i)모드
O : 현재 커서 위에 빈줄삽입 후 삽입(i) 모드

소문자는 아래, 대문자는 위

u undo 실행취소
u 바로 이전에 상태로 되돌림
U 라인 전체에 대해 이전 상태로 되돌림

J 현재라인에 아래 라인 붙이기

r 현재 글자를 대치 (워드에 수정모드)
R ESC 키를 누르기 전까지 현재 글자 대치

복사 Copy = Yank / 붙이기 Paste
yy 현재 라인 복사
p 현재 커서 아래쪽에 붙이기
P 현재 커서 위쪽에 붙이기
3yy(3Y) 현재 커서가 있는 라인 포함에서 아래로 3줄 복사

:1,3 copy 5 (:1,3 co 5) 1번라인~3번라인 복사해서 5번라인 아래에 붙이기
:1,3 m 5 1번라인~3번라인을 5번라인 아래로 이동하기

검색하기
/New(검색어), n다음 or N이전 현재 커서라인부터 찾으려는 문자열 검색
?New 문서의 마지막부터 찾기

치환작업
검색/바꾸기(Search & Replace)
:%s/<찾을문자열>/<바꿀문자열>/g

:5,10s/^/#/   /* 주석처리 */
:5,10s/^#//   /* 주석해제 */
:5,10s/^/ / (4 blank character) /* 들여쓰기 */
:5,10s/^ //   /* 내어쓰기 */

:w 저장하기
:w filename 다른이름으로 저장하기
:w! (root use) 강제적으로 저장하기
:w! filename
:q 종료
:q! 저장안하고 종료
:wq 저장하고 종료
:wq! (root use) 강제적으로 저장하고 종료
:!CMD vi 편집기를 빠져나가지 않은 상태로 쉘 커맨드 수행
:! bash 를 많이 쓰게될것임

[참고] 저장하고 빠져나가기
:x
:wq
ZZ

파일의 종류
파일의 구조
filename = inode + Data Block

일반파일(Ordinary File)
[root@linux205 /test]# echo 1111 > file1
[root@linux205 /test]# ls -l file1
-rw-r--r-- 1 root root 5  4월 14 21:45 file1 //inode
[root@linux205 /test]# cat file1
1111     //Data Block
[root@linux205 /test]# ls -i
5330754 file1    //5330754 = inode 번호

디렉토리파일(Directory File)
Data Block
. //현재 디렉토리의 inode 번호
.. //현재 디렉토리의 상위 디렉토리의 inode 번호
file1
dir2

[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# ls -a dir1
.  ..
[root@linux205 /test]# touch dir1/file1
[root@linux205 /test]# mkdir dir1/dir2
[root@linux205 /test]# ls -a dir1
.  ..  dir2  file1
[root@linux205 /test]# tree
.
`-- dir1
    |-- dir2
    `-- file1

2 directories, 1 file
[root@linux205 /test]# ls -ia dir1
5330754 .  5330753 ..  5330756 dir2  5330755 file1

링크파일(Link File) - 하드링크 / 심볼링크(소프트링크)
하드링크 Hard Link
# ln file1 file2
심볼링크 Symbolic Link
# ln -s file1 file2

[root@linux205 /test]# touch file1
[root@linux205 /test]# ls -l file1
-rw-r--r-- 1 root root 0  4월 14 21:56 file1 //하드링크카운트 1
파일에 대한 하드링크 수는 1이다

[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# ls -ld dir1
drwxr-xr-x 2 root root 4.0K  4월 14 21:57 dir1 //하드링크카운트 2
디렉토리 안에 들어있는 디렉토리의 개수가 하드링크 수이다 (., ..)

[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# ls -l

drwxr-xr-x 2 root root 4.0K  4월 14 21:58 dir1
[root@linux205 /test]# mkdir dir1/dir2
[root@linux205 /test]# ls -l

drwxr-xr-x 3 root root 4.0K  4월 14 21:59 dir1
[root@linux205 /test]# mkdir dir1/dir3
[root@linux205 /test]# ls -l

drwxr-xr-x 4 root root 4.0K  4월 14 21:59 dir1
[root@linux205 /test]# touch dir1/file1
[root@linux205 /test]# ls -l

drwxr-xr-x 4 root root 4.0K  4월 14 21:59 dir1
[root@linux205 /test]# mkdir dir1/dir2/dir4
[root@linux205 /test]# ls -l

drwxr-xr-x 4 root root 4.0K  4월 14 21:59 dir1

[root@linux205 /test]# tree
.
`-- dir1
    |-- dir2
    |   `-- dir4
    |-- dir3
    `-- file1

4 directories, 1 file

[root@linux205 /test]# ls -l /
...
drwxr-xr-x 108 root root  12K  4월 14 16:11 etc
...
이 경우에는 etc 라는 디렉토리는 .과 ..을 제외한 하위디렉토리가 106개가 있다

하드링크 실습
[root@linux205 /test]# echo 1111 > file1
[root@linux205 /test]# ls -l file1
-rw-r--r-- 1 root root 5  4월 14 22:03 file1
[root@linux205 /test]# cat file1
1111
[root@linux205 /test]# ln file1 file2
[root@linux205 /test]# ls -li
합계 8.0K
5330754 -rw-r--r-- 2 root root 5  4월 14 22:03 file1
5330754 -rw-r--r-- 2 root root 5  4월 14 22:03 file2
[root@linux205 /test]# echo 2222 >> file2
[root@linux205 /test]# cat file2
1111
2222
[root@linux205 /test]# cat file1
1111
2222

파일 이름은 다르지만 동일한 inode 를 사용하는 같은 내용의 파일이다
하드링크카운트가 2인 이유는 하나의 inode에 2개의 filename이 있기 때문이다

file1 = inode1 + 11112222
file2 = inode1 + 11112222

[root@linux205 /test]# rm file1
rm: remove 일반 파일 `file1'? y 
[root@linux205 /test]# cat file2
1111
2222

파일을 삭제하는 경우에는 파일이름만 지우기 때문에 내용은 남아있다

[root@linux205 /test]# ls -l
합계 4.0K
-rw-r--r-- 1 root root 10  4월 14 22:05 file2

하드링크카운트가 1이 된것을 볼 수 있다


심볼링크 실습
[root@linux205 /test]# ln -s file2 file3
[root@linux205 /test]# ls -li
합계 4.0K
5330754 -rw-r--r-- 1 root root 10  4월 14 22:05 file2
5330755 lrwxrwxrwx 1 root root  5  4월 14 22:10 file3 -> file2 //file3이 file2를 포인트하고있다 터미널상에서는 파란색

inode 속성정보 다 다르다

f2 = inode1 + 11112222
f3 = inode2 + f2(inode1)

[root@linux205 /test]# echo 3333 >> file3
[root@linux205 /test]# cat file3
1111
2222
3333
[root@linux205 /test]# cat file2
1111
2222
3333
[root@linux205 /test]# echo 4444 >> file2
[root@linux205 /test]# cat file2
1111
2222
3333
4444
[root@linux205 /test]# cat file3
1111
2222
3333
4444

[root@linux205 /test]# rm file2
rm: remove 일반 파일 `file2'? y
[root@linux205 /test]# cat file3
cat: file3: 그런 파일이나 디렉토리가 없음

file3이 포인트하는 file2가 없어지면 file3은 의미가 없어진다

[root@linux205 /test]# ls -li
합계 0
5330755 lrwxrwxrwx 1 root root 5  4월 14 22:10 file3 -> file2 //터미널상에서는 빨간색

색상의 차이는 2번 그림파일

하드링크와 심볼링크의 차이점
1) 파일시스템을 넘어서 링크를 걸 수 있는가?? 하드링크는 불가 심볼링크는 가능
2) 디렉토리에 링크를 걸 수 있는가?? 하드링크는 불가 심볼링크는 가능
 => 하드링크에는 한계가 있다
 => 작업에 편의를 위해서 심볼릭링크를 사용한다

[참고] 심볼릭 링크 = 윈도우 바로가기 아이콘(바로가기는 파일이지만 디렉토리에 링크를 걸수있음)



'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160419 리눅스 기초  (0) 2016.04.20
20160418 리눅스 기초  (0) 2016.04.19
20160415 리눅스 기초  (0) 2016.04.15
20160412 리눅스 기초  (0) 2016.04.13
20160411 리눅스 기초  (0) 2016.04.12
Posted by 22Hz
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함