가상머신이란 특정 물리적 컴퓨터 위에 물리자원을 가상화한 컴퓨터 환경을 구축하여 어떤 운영체제라도 설치할 수 있게하는 소프트웨어를 말한다. 하나의 물리적 자원 위에 다수의 운영체제를 설치하는 식으로 서버용 컴퓨터를 보다 효율적으로 사용하기 위해 주로 사용한다. VM외에 Docker로 대표되는 컨테이너라는 개념도 있다.
가상머신을 설치하기 앞서 하이퍼바이저(Hypervisor) 라는 개념을 알아야 한다. 하이퍼바이저는 실제 물리자원을 가상화 하고 이를 가상머신이 사용할 수 있도록 중간에서 매개체 역할을 하는 소프트웨어이다.
AppArmor(Application Armor) 은 시스템 관리자가 프로그램 프로필 별로 프로그램 보안을 세팅할 수 있게 해주는 리눅스 커널 보안 모듈이다.
Mandatory Access Control(MAC)로 관리자가 특정 프로그램에 대한 네트워크, 소켓, 입출력 등에 대한 접근을 제한할 수 있도록 한다.
프로필들은 네트워크 엑세스, raw 소켓 엑세스 그리고 파일의 읽기, 쓰기, 실행 같은 능력을 허용할 수 있다. AppArmor은 강제적 접근 통제 (MAC)을 제공하면서 전통적인 유닉스 임의적 접근 통제 (DAC) 모델을 지원한다.
DAC(Discretionary Access Control)은 임의 접근 통제로 시스템 객체에서 접근을 사용자나 그룹의 신분을 기준으로 제한하는 방법이다.
sudo ufw status verbose
systemctl status ssh
hostnamectl
The subject requests that a user with the login of the evaluated student is present on the virtual machine. Check that it has been added and that it belongs to the "sudo" and "user42" groups.
(대상은 평가되는 학생의 로그인을 가진 사용자가 가상 머신에 존재하도록 요청합니다. 추가되었고 "sudo" 및 "user42" 그룹에 속하는지 확인합니다.)
id <username>
Make sure the rules imposed in the subject concerning the password policy have been put in place by following the following steps.
(다음 단계에 따라 비밀번호 정책과 관련하여 주제에 부과된 규칙이 적용되었는지 확인 하십시오.)
sudo vi /etc/pam.d/common-password
retry=3 : 암호입력 3회까지
minlen=10 : 암호 최소 길이는 10
difok=7 : 기존 패스워드와 달라야 하는 문자수는 7
ucredit=-1 : 대문자 한 개 이상
lcredit=-1 : 소문자 한 개 이상
dcredit=-1 : 숫자 한 개 이상
reject_username: username이 그대로 뒤집혀서 새 패스워드에 들어있는지 검사하고, 들어있다면 거부
enforce_for_root : root 사용자가 패스워드를 바꾸려고 한느 경우에도 위의 조건을 적용
First, create a new user. Assign it a password of your choice, respecting the subject ruels. The evaluated student must now explain to you how he was able to set up the rules requested in the subject on their virtual machine.
(저 새 사용자를 만듭니다. 주제 규칙을 준수하여 선택한 암호를 할당하십시오. 평가 중인 학생은 이제 가상 머신에서 주제에서 요청한 규칙을 어떻게 설정할 수 있었는지 설명해야 합니다.)
adduser [username]
Normally there should be one or two modified files. If there is any problem, the evaluation stops here.
(일반적으로 하나 또는 두 개의 수정된 파일이 있어야 합니다. 문제가 있으면 여기에서 평가를 중지합니다.)
sudo groupadd [evaluating] : evaluating이라는 그룹 추가
sudo usermod -aG evaluating [username] : username을 eval에 할당
usermod -aG sudo,user42 <username>
-> 그룹에 유저를 추가해주는 명령어, 그룹이 여러개인 경우 공백없이 콤마로 구분한다.
usermod -g user42 <username> 명령어를 통해 user42그룹이 primary group이 되도록 한다..
G 옵션 :
gid 그룹들을 제외하고 명령어에 나열된 그룹만 추가가 되며, ㅁ여령어에 나열되어 있지 않지만 유저가 속해있는 그룹은 전부 탈퇴된다.
a 옵션:
G옵션에서만 함께 쓰일 수 있고, G옵션만 붙었을 때와 달리, 유저가 속해있지만 명령어에 나열되어있지 않은 그룹에 관하여 탈퇴처리 되지 않는다.
id <username>을 통해 해당 user가 어떤 그룹에 속해있는지 확인 가능하다.
Finally, ask the student evaluated to explain the advantages of this password policy, as well as the adcantages and disadvantages of its implementation. Of course, answering that it is because the subject asks for it does not count.
(마지막으로 평가를 받는 학생에게 이 암호 정책의 장점과 구현의 장점과 단점을 설명하도록 요청합니다. 물론 피험자가 요구하기 때문이라고 답하는 것은 포함하지 않는다.)
-> password 정책의 장점 말하기
-> password 정책을 이행하는데 있어 장단점 말하기
비밀번호 정책으로 인하여 강력한 비밀번호를 생성해야 하므로 보안성은 높아졌지만, 30일 주기로 매번 다른 비밀번호를 생성해야 하는 불편함이 생김
hostnamectl
hostnamectl set-hostname <hostname>
If on restart, the hostname has not been updated, the evaluation stops here.
(다시 시작할 때 호스트 이름이 업데이트되지 않은 경우 평가는 여기서 중지됩니다.)
You can now restore the machine to the original hostname.
(이제 시스템을 원래 호스트 이름으로 복원할 수 있습니다.)
Ask the student evaluated how to view the partitions for this for this virtual machine.
(평가 중인 학생에게 이 가상 머신의 파티션을 보는 방법을 묻습니다.)
lsblk
This part is an opportunity to discuss the scores! The student being evaluated should give you a brief explanation of how LVM works and what it is all about.
(이 부분은 점수를 토론할 수 있는 기회입니다! 평가를 받는 학생은 LVM이 어떻게 작동하고 무엇에 관한 것인지에 대해 간략하게 설명해야 합니다.)
LVM (Logical Volume Manager)은 리눅스의 저장 공간을 효율적이고 유연하게 관리하기 위한 커널의 한 부분이다.
LVM이 아닌 기존 방식의 경우, 하드디스크를 파티셔닝한 후 OS영역에 마운트 하여 read/write작업을 수행한다.
이 경우 저장 공간의 크기가 고정되어서 증설/축소가 어렵다.
이를 보완하기 위한 방법으로 LVM을 구성할 수 있다.
LVM은 파티션 대신에 volume이라는 단위로 저장 장치를 다룬다.
스토리지의 확장, 변경에 유연하며, 크기를 변경할 때 기존 데이터의 이전이 필요없다.
물리적 볼륨 / PV (Physical Volume)
참조
https://greencloud33.tistory.com/41
dpkg -l sudo
sudo usermod -aG sudo <새로운 사용자 명>
In a second step, it must show you the implementation of the rules imposed by the subject.
(두 번째 단계에서는 주제에 의해 부과된 규칙의 구현을 보여주어야 합니다.)
sudo visudo
sudo vim /var/log/sudo/
Finally, try to run a command via sudo. See if the file in the "/var/log/sudo/" folder have been updated.
(마지막으로 sudo를 통해 명령을 실행해 보십시오.
"/var/log/sudo/" 폴더의 파일이 업데이트되었는지 확인합니다.)
sudo ufw status verbose
aduo aa-status : 상태확인
sudo aa-enabled : 활성화 여부 확인
sudo ufw status numbered
sudo vim /etc/ssh/sshd_config -> Port 8080추가
sudo ufw allow 8080
sudo ufw status numbered
sudo ufw delete 8080
sudo ufw status numbered
apt search openssh-server
systemctl status ssh
-> 새로운 사용자로 terminal에서 접근하기
SSH(Secure Shell)은 원격으로 public network를 통해 호스트 컴퓨터와 통신을 할 때 보안을 위해 사용되는 프로토콜이다. 기존의 텔넷(telnet) 이 취약했기에 암호화 기능을 추가한 보안 프로토콜이다. 개인키-공개키 쌍의 비대칭키 방식을 사용한다. 쉘로 원격접속하기 때문에 기본적으로 CLI로 실행하며 기본 포트는 22번이다.
-> 4242포트 말고 다른 포트로 진입되는지 확인
ssh <username>@127.0.0.1 -p [portnum]
To do this, you can use a key or a simple password.
(이렇게 하려면 키 또는 간단한 암호를 사용할 수 있습니다.)
It will depend on the student being evaluated.
(그것은 평가받는 학생에 따라 달라질 것이다.)
Of course, you have to make sure that you cannot use SSH with the "root" user as stated in the subject.
(물론 제목에 명시된 "root" 사용자와 SSH를 함께 사용할 수 없는지 확인해야 합니다.)
-> root로 터미널에 연결되는지 확인
ssh root@127.0.0.1 -p [port num]
The student evaluated should explain to you simply:
(평가된 학생은 다음과 같이 간단히 설명해야 합니다.)
#!/bin/bash
printf "#Architecture: "
uname -a
printf "#CPU physical : "
nproc --all
printf "#vCPU : "
cat /proc/cpuinfo | grep processor | wc -l
printf "#Memory Usage: "
free -m | grep Mem |awk '{printf"%d/%dMB (%.2f%%)\n", $3, $2, $3/$2 * 100}'
printf "#Disk Usage: "
df -a -BM | grep /dev/map | awk '{sum+=$3}END{print sum}' | tr -d '\n'
printf "/"
df -a -BM | grep /dev/map | awk '{sum+=$4}END{print sum}' | tr -d '\n'
printf "MB ("
df -a -BM | grep /dev/map | awk '{sum1+=$3 ; sum2+=$4 }END{printf "%d", sum1 / sum2 * 100}' | tr -d '\n'
printf "%%)\n"
printf "#CPU load: "
mpstat | grep all | awk '{printf "%.2f%%\n", 100-$13}'
printf "#Last boot: "
who -b | awk '{printf $3" "$4"\n"}'
printf "#LVM use: "
if [ "$(lsblk | grep lvm | wc -l)" -gt 0 ] ; then printf "yes\n" ; else printf "no\n" ; fi
printf "#Connections TCP : "
ss | grep -i tcp | wc -l | tr -d '\n'
printf " ESTABLISHED\n"
printf "#User log: "
who | wc -l
printf "#Network: IP "
hostname -I | tr -d '\n'
printf "("
ip link show | awk '$1 == "link/ether" {print $2}' | sed '2, $d' | tr -d '\n'
printf ")\n"
printf "#Sudo : "
journalctl _COMM=sudo | wc -l | tr -d '\n'
printf " cmd\n"
exit 0
Once the correct functioning of the script has been verified, the student evaluated should ensure that this script runs every 30s.
(스크립트의 올바른 기능이 확인되면 평가 대상 학생은 이 스크립트가 1분마다 실행되는지 확인해야 합니다.)
sduo crontab -e
*/10 * * * * /root/monitoring.sh | wall
초단위 컨트롤시 sleep[]; command
-> */1 * * * * sleep 30; /root/monitoring.sh | wall
You can run whatever you want to make sure the script stop running when the server starts up, but without modifying the script.
(스크립트를 수정하지 않고 서버가 시작될 때 스크립트 실행을 중지하도록 원하는 대로 실행할 수 있습니다.)
service cron stop : Pause
service cron restart : Restart
service cron status : Check
머신 껐다 켜야함
To check this point, you will have to restart the server one last time.
(이 점을 확인하려면 서버를 마지막으로 다시 시작해야 합니다.)
At startup, it will be necessary to check that the script still exists in the same place, that its rights have remained unchanged, and that it has not been modified.
(시작할 때 스크립트가 동일한 위치에 여전히 존재하는지, 해당 권한이 변경되지 않았는지, 수정되지 않았는지 확인해야 합니다.)