Notice
Recent Posts
Recent Comments
«   2025/07   »
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
07-09 12:13
Today
Total
관리 메뉴

해킹공주의 일상

[AWS 보안진단] Key Pair 관리 본문

사이드 프로젝트/클라우드

[AWS 보안진단] Key Pair 관리

7.3.7 2023. 5. 16. 16:19

Overview

가이드에 따르면, 계정 관리 항목은 다음과 같다. 본문에서 살펴볼 내용은 굵은 글씨로 표기해두었다.
 

계정관리
1 사용자 계정 관리 
2 IAM 사용자 계정 단일화 관리 
3 IAM 사용자 계정 식별 관리 
4 IAM 그룹 사용자 계정 관리 
5 Key Pair 접근 관리 
6 Key Pair 보관 관리 
7 Admin Console 관리자 정책 관리 
8 Admin Console 계정 Access Key 활성화 및 사용주기 관리 
9 MFA (Multi-Factor Authentication) 설정 
10 AWS 계정 패스워드 정책 관리 

점검내용 

Key Pair 사용 및 저장 관리

항목분석

Key Pair
AWS에서 EC2 인스턴스에 접근할때 사용되는 키 쌍이다. EC2 인스턴스를 생성할때 Key Pair를 선택하면 해당 Key Pair의 공개키가 인스턴스에 배치되고, 나한테 발급된 비공개 키 파일을 이용해 EC2에 접근이 가능하다. 
 
Key Pair 방법을 사용하면 이 키 파일이 있어야 접근이 가능하고, 없으면 일반 패스워드로 접근하도록 설정된다. 보안상 키파일을 사용하는게 안전하다. 또한 키파일이 안전한곳에 저장되어있는 것이 중요하다.
 

키페어 등록

왜 Admin console은 Access Key를 지우라고 하면서 EC2는 키페어를 등록하라고 하나요?
이런 의문이 갑자기 들어서 확인해봤는데, 음.. 아직 잘모르겠다 ㅎㅎ 아는 분있으면 답글달아주세요
 

보안위협 

1. 비인가자의 무단접근
2. 키 유출을 통한 비인증 액세스 발생

Assessment

점검 기준 및 방법

아래는 EC2 인스턴스에 대해서 키페어가 있는지 확인하는 스크립트이다.

# 🌈✨ 7-3-7@tistory.com 23-05-16 ✨🌈
import boto3
from prettytable import PrettyTable

# AWS region
REGION = boto3.Session().region_name

# Create EC2 client
ec2 = boto3.client('ec2', region_name=REGION)

# Create pretty table object to print EC2 instances information
instance_table = PrettyTable()
instance_table.field_names = ['Name', 'Key Name', 'Instance ID', 'Instance Type', 'State']

# Get all running instances
instances = ec2.describe_instances(Filters=[{'Name': 'instance-state-name', 'Values': ['running']}])

# Iterate over each instance and get its information
for reservation in instances['Reservations']:
    for instance in reservation['Instances']:
        # Get instance id, instance type and instance state
        instance_id = instance['InstanceId']
        instance_type = instance['InstanceType']
        instance_state = instance['State']['Name']
        
        # Get the value of the 'Name' tag, if available
        name_tag = next((tag['Value'] for tag in instance['Tags'] if tag['Key'] == 'Name'), '-')
        
        # Check if instance uses a key pair
        key_name = instance.get('KeyName', '-')
        
        # Add instance information to the table
        instance_table.add_row([name_tag, key_name, instance_id, instance_type, instance_state])

# Print the table
print(instance_table)

 
아래는 스크립트 결과이다. 키값이 설정 되지않은 인스턴스는 키페어가 없는 인스턴스이다.

+----------+----------+---------------------+---------------+---------+
|   Name   | Key Name |     Instance ID     | Instance Type |  State  |
+----------+----------+---------------------+---------------+---------+
| sub_Web  |    -     | i-09a6f4750b58e2c07 |    t2.micro   | running |
| main_Web | 737_key  | i-009dc8617190e052c |    t2.micro   | running |
| sub2_Web | 737_key  | i-094f01931e8a7aba5 |    t2.micro   | running |
+----------+----------+---------------------+---------------+---------+

 
5 Key Pair 접근 관리
- Key Pair(PEM)를 통해 EC2 인스턴스에 접근할 경우
: 결과 값 확인
 
6 Key Pair 보관 관리
- Key Pair(PEM)를 안전한 곳 (퍼블릭 S3, EC2 “Admin Console(/)” 디렉터리 등이 아닌 곳)에 보관하고 있을 경우
: 담당자 확인 필요

Countermeasure

- EC2 인스턴스에 대해서 각각 키페어 등록
- 상세 설정 방법은 SK 쉴더스에서 작성한 '2023 클라우드 보안 가이드' 참조

 
※ 본 블로그에서 작성하는 AWS 보안 관련 가이드는 SK 쉴더스에서 작성된 가이드를 기반으로 작성된 글입니다.

Comments