본문 바로가기

DF

[Python] Timestamp Convert

  시간 데이터는 디지털포렌식에서 중요한 정보로 활용됩니다.

  이메일, 데이터베이스, 파일시스템 등에서 많은 시간 정보를 획득할 수 있으므로 사건의 사실 여부를 증명하는데 활용할 수 있기 때문입니다.

 

  이렇게 특정한 시각을 나타내는 문자열을 바로 타임스탬프 (Timestamp)라고 합니다.

디지털포렌식에서 타임스탬프를 활용하여 분석을 수행할 경우 주의해야할 점이 있는데 운영체제 혹은 언어마다 타임스탬프의 기준시와 단위가 달라집니다.

 

  아래는 RFC 822, ISO 8601, Unix/Epoch, FILETIME, Microsoft, Mac 타임스탬프 등 다양한 방식으로 표현된 시간 정보입니다. 다양한 방식으로 시간을 표현하지만 모두 같은 날짜 및 시간을 의미합니다.

  • Tue, 07 Apr 2020 07:03:36 +0000 (RFC 822)
  • 2020-04-07T07:03:36+00:00 (ISO 8601)
  • 1586243016 (Unix/Epoch)
  • 132307166160000000 (FILETIME)
  • 43928.294166667 (Microsoft)
  • 3669087816 (Mac)

  또한, 주로 시간 정보는 UTC 기준으로 기록되어 있습니다. 그러나, 대한민국에서 사용된 PC를 조사할 때에는 UTC로 기록된 데이터를 그대로 사용해선 안됩니다. 대한민국 시간은 UTC 시간보다 9시간 빠르기 때문입니다.

 

  따라서, 이와 같이 다양한 기준시와 단위로 표현된 타임스탬프를 사람이 이해하기 쉽게 변경하여야 하고, 각 국가에 맞는 날짜와 시간으로 인식하여 분석해야 합니다.

 

  이 포스트를 통해서 Python을 통해 위의 예시와 같은 타임스탬프를 로컬 시간대로 사용자가 보기 쉽게끔 알려주는 코드를 꾸준히 작성해보려 합니다.

 

Unix/Epoch Timestamp


Unix/Epoch 타임스탬프는 1907년 1월 1일 (UTC) 이후 경과한 시간을 초 (seconds) 단위로 나타냅니다. 

이는 seconds(10자리), millisecons(13자리), microseconds(16자리) 단위로 표현될 수 있습니다.

 

#unix/epoch timestamp to local timestamp

from time import localtime, strftime

def Unix_Epoch_Converter():
    #1970-01-01 seconds
	t=int(input('>> Please input Unix or Epoch timestamp: '))
	t_len=len(str(t))
	if t_len == 10: local=localtime(t)
	elif t_len == 13: local=localtime((t/1000))
	elif t_len == 16: local=localtime((t/1000000))
	time_format='%Y-%m-%d %H:%M:%S'
	result= strftime(time_format, local)
	print("   "+ t + "  =>  " + result)

 

LDAP/FILETIME Timestamp


Active Directory, win32 FILETIME, SYSTEMTIME, NTFS 파일시스템의 타임스탬프는 1601년 1월 1일 (UTC) 이후 경과한 시간을 100 나노 초 (100-nanoseconds) 단위로 나타냅니다. 

Unix/Epoch 시간과는 11644473600 초 차이가 납니다.

 

#LDAP/FILETIME timestamp to local timestamp

from time import localtime, strftime
def LDAP_FILETIME_Converter():
        #1601-01-01 100-nanosecond(18)
        #Active Directory, Wn32 FILETIME, SYSTEMTIME, NTFS file time
	t=int(input('>> Please input LDAP or FILETIME timestamp: '))
	local=localtime((t/10000000)-11644473600)
	time_format='%Y-%m-%d %H:%M:%S'
	result= strftime(time_format, local)
	print(result)

 

WebKit/Chrome Timestamp


Apple Safari(WebKit), Google Chrome, Opera 타임스탬프는 1601년 1월 1일(UTC) 이후 경과한 시간을 마이크로초 (microseconds) 단위로 나타냅니다.

Unix/Epoch 시간과는 11644473600 초 차이가 납니다.

 

#webkit/chrome/opera timestamp to local timestamp

from time import localtime, strftime
def WebKit_Chrome_Converter():
        #1601-01-01 microseconds(17)
        #Apple Safari(WebKit), Google Chrome, Opera
	t=int(input('>> Please input WebKit or Chrome timestamp: '))
	local=localtime((t/1000000)-11644473600)
	time_format='%Y-%m-%d %H:%M:%S'
	result= strftime(time_format, local)
	print(result)

 

Apple Cocoa Core Data Timestamp


iOS, OS X 어플리케이션은 Apple cocoa Core Data 타임스탬프를 사용합니다.

Apple cocoa Core Data 타임스탬프는 2001년 1월 1일 이후 경과한 시간을 초 (seconds) 혹은 나노초 (nanoseconds) 단위로 나타냅니다.

이는 Unix/Epoch 시간과 978307200  차이가 납니다.

#Apple cocoa Core Data timestamp to local timestamp

from time import localtime, strftime
def Apple_Cocoa_CoreData_Converter():
        #2001-01-01 seconds(9) or nanoseconds(18)
        #iOS, OS X applications
        t=int(input('>> Please input Apple Cocoa Core Data timestamp: '))
        t_len=len(str(t))
        if t_len == 9: local=localtime(t+978307200)
        elif t_len == 18: local=localtime((t/1000000000)+978307200)
        time_format='%Y-%m-%d %H:%M:%S'
        result= strftime(time_format, local)
        print(result)

 

Mac HFS+ Timestamp


애플 iPod, Palm OS, JMP/JSL는 mac HFS+ 파일시스템 타임스탬프를 사용합니다.

mac HFS+ 파일시스템 타임스탬프는 1904년 1월 1일 이후 경과한 시간을 초 (seconds) 단위로 나타냅니다.

이는 Unix/Epoch 시간과 2082844800  차이가 납니다.

#mac HFS+ filesystem timestamp to local timestamp

from time import localtime, strftime
def Mac_HFS_plus_Converter():
        #1904-01-01 seconds(10)
        #Apple iPod's, Palm OS, JMP/JSL
        t=int(input('>> Please input Mac HFS+ timestamp: '))
        local=localtime((t-2082844800))
        time_format='%Y-%m-%d %H:%M:%S'
        result= strftime(time_format, local)
        print(result)

 

'DF' 카테고리의 다른 글

디스크 인터페이스 간략 정리 (정리중)  (0) 2020.06.03
Windows 10 Timeline Forensics  (0) 2020.03.11
Cuckoo Sandbox 구축  (1) 2020.03.04