Target UBI
→ 010editor로 살펴본 결과 squash fs시그니처가 존재하고 이 부분들을 뽑으면 된다.
→ binwalk로 파일 시스템 추출이 잘 안됌.
→ 깨져있는 UBI 헤더가 포함되어 있어서 UBI헤더부분들을 복구해보려다가, UBI의 헤더부분들을 제외하고 데이터 부분들을 모아서 binwalk 사용하기로 함.
→ UBI헤더가 가리키는 데이터 오프셋은 UBI_EC_HDR_ubi_ec_hdr_.data_offset 만큼에 있다.
→ UBI헤더로부터 데이터가 있는 영역 전까지는 UBI
로 시작하는 헤더와 \xff 의 더미값들로 이뤄져 있어서 이 부분들을 뺀 새로운 파일들을 만듦.
→ ex.py && binwalk -e ./output_file.bin
def filter_data(input_file, output_file):
with open(input_file, 'rb') as infile, open(output_file, 'wb') as outfile:
chunk_size = 16
while True:
chunk = infile.read(chunk_size)
if not chunk:
break
# # 첫 번째 조건: "\xff"*0x10와 "\x00"*0x10이 아닌 경우에만 파일로 다시 쓰기
if b"UBI" in chunk:
print(f"UBI in chunk {chunk}")
infile.read(0x30)
continue
if chunk != b"\xff"*chunk_size: #and chunk != b"\x00"*chunk_size:
outfile.write(chunk)
if __name__ == "__main__":
input_file_path = "target_ubi.bin" # 입력 파일 경로 입력
output_file_path = "output_file.bin" # 출력 파일 경로 입력
filter_data(input_file_path, output_file_path)
print("필터링이 완료되었습니다.")
Python
복사