45일차

45일차

홈으로 돌아가기

이메일 로그 확인 
IP확보
이메일 서버에 있는 악성코드 해시값 확보
해커 IP 확보
해커 PC에서 전달된 악성코드 발견

1) 서버의 로그 기록 확보
> auth.log에 본인의 접속 IP가 있는가?
2) RSYSLOG의 데이터 기록 전체 확보후 각자 분석
> RSYSLOG데이터에 본인의 접속 IP가 있는가?
3) 이메일 파일 확보후 분석
> 이메일 로그에 본인의 IP가 있는가?
> 각자 관리자 한테 보낸 악성 코드 어디에 있는지 찾기
> 인코딩되어 있지만 디코딩 후 해시값 분석 일치

서과장 하드디스크 복구

bootstrapcode
disk serial number
reserved 
partition 1, 2, 3, 4
signature

디스크의 첫번째 섹터
MBR > 각각의 파티션 위치
8~11 : 파티션의 위치 
12~15 : 파티션의 크기

00 08 00 00 > 00 00 00 00
헥사를 십진수로 읽을려면 거꾸로 읽어야함
00 00 08 00 > 2048 > NTFS + 시그니처(55AA) = VBR 
십진수 : 2048

NTFS의 백업본은 맨 밑에 만듬

FAT32의 백업본은 6섹터 밑에 만듬

서과장
Partition1 > 63
Partition2 > 41945715

pip install pywin32


import os
import ctypes
import struct
import win32file
import win32con

# NTFS 시그니처: 0x4E 0x54 0x46 0x53 (ASCII "NTFS")
NTFS_SIGNATURE = b'NTFS'

# 섹터 크기 (512바이트)
SECTOR_SIZE = 512

def find_ntfs_partition(disk_path):
    """디스크에서 NTFS 파티션을 찾아 그 시작 위치를 섹터 단위로 반환"""
    try:
        with open(disk_path, 'rb') as f:
            offset = 0
            while True:
                # 512바이트씩 읽기
                chunk = f.read(SECTOR_SIZE)
                if not chunk:
                    break  # 더 이상 읽을 데이터가 없으면 종료

                # NTFS 시그니처가 있는지 확인
                ntfs_index = chunk.find(NTFS_SIGNATURE)
                if ntfs_index != -1:
                    # NTFS 시그니처를 찾았으면 그 위치를 반환
                    partition_start = offset + ntfs_index
                    print(f"NTFS 파티션 발견! 위치: {partition_start} 바이트")
                    return partition_start // SECTOR_SIZE  # 섹터 단위로 변환
                offset += SECTOR_SIZE

        print("NTFS 파티션을 찾을 수 없습니다.")
        return None
    except Exception as e:
        print(f"디스크 검색 중 오류 발생: {e}")
        return None

def write_partition_start(disk_path, partition_start_sector):
    """MBR에 파티션 시작 위치를 기록"""
    try:
        # 디스크에 접근하기 위해 관리자 권한 확인
        hDevice = win32file.CreateFile(
            disk_path,
            win32con.GENERIC_READ | win32con.GENERIC_WRITE,
            0,
            None,
            win32con.OPEN_EXISTING,
            0,
            None
        )
        
        # 파티션 시작 위치 기록
        win32file.SetFilePointer(hDevice, 446 + (partition_start_sector * SECTOR_SIZE), os.SEEK_SET)

        partition_start_bytes = struct.pack(" 바이트로 변환: {partition_start_bytes}")
        
        win32file.WriteFile(hDevice, partition_start_bytes)
        print(f"파티션 시작 위치 기록 완료")

        print(f"파티션 시작 위치 {partition_start_sector} 섹터을(를) MBR에 기록했습니다.")
        win32file.CloseHandle(hDevice)
        print(f"디스크 핸들 닫기 완료")
        
    except Exception as e:
        print(f"파티션 시작 위치 기록 중 오류 발생: {e}")

def main():
    # 관리자 권한 확인
    if not ctypes.windll.shell32.IsUserAnAdmin():
        print("관리자 권한이 필요합니다.")
        return

    disk_path = '\\\\.\\PhysicalDrive2'  # 디스크 2 (Windows에서 PhysicalDriveX 형식)
    print(f"디스크 경로: {disk_path}")
    
    # 1. NTFS 파티션 찾기
    partition_start_sector = find_ntfs_partition(disk_path)
    
    if partition_start_sector is not None:
        print(f"NTFS 파티션 시작 섹터: {partition_start_sector}")
        # 2. 파티션 시작 위치를 MBR에 기록
        write_partition_start(disk_path, partition_start_sector)
    else:
        print("NTFS 파티션을 찾을 수 없어 MBR에 기록할 수 없습니다.")

if __name__ == "__main__":
    main()


파티션2 주소
73 0A 80 02

NTFS는 파티션 마지막 부분에 복구용 섹터를 생성
FAT32는 6섹터 밑에 복구용 섹터를 생성