История изменений
Исправление rtxtxtrx, (текущая версия) :
https://gist.github.com/bmaupin/a9d29f5fdc831d1d0164
Можно и башем, но питон универсальнее. После сигнатуры должно следовать что-то еще чтобы отделить всякий мусор которого будет очень много…
Это универсальнее:
#!/usr/bin/env python
import argparse
import itertools
import sys
# Sector size in bytes (usually 512 bytes)
SECTOR_SIZE = 512
# File system signatures
FILE_SYSTEM_SIGNATURES = {
b"\x53\xef": "EXT 2/3/4",
b"\x58\x46\x53\x42": "Btrfs",
b"\xfd\x37\x7a\x58\x5a\x00": "ZFS",
b"\xeb\x3c\x90\x28": "FAT",
b"\xeb\x52\x90\x4e": "NTFS",
}
def find_partitions(device_path):
try:
# Open the device for reading
with open(device_path, "rb") as device:
for sector_offset in itertools.count():
# Read one sector
sector_data = device.read(SECTOR_SIZE)
if not sector_data:
break
# Check if the sector starts with any file system signature
for signature, fs_name in FILE_SYSTEM_SIGNATURES.items():
if sector_data.startswith(signature):
print(
f"Found {fs_name} partition at sector offset {sector_offset}."
)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
# Create argument parser
parser = argparse.ArgumentParser(
description="Search for all occurrences of file system signatures on a device."
)
parser.add_argument(
"device", type=str, help="Path to the device (e.g., /dev/sda)"
)
args = parser.parse_args()
find_partitions(args.device)
Но все равно мусора много:
~/workspace/hacking
(.venv) ❯ sudo ./find_partitions.py /dev/nvme0n1
[sudo] password for sergey:
Found EXT 2/3/4 partition at sector offset 236473.
Found EXT 2/3/4 partition at sector offset 239202.
Found EXT 2/3/4 partition at sector offset 279914.
Found EXT 2/3/4 partition at sector offset 418210.
Found EXT 2/3/4 partition at sector offset 643127.
Found EXT 2/3/4 partition at sector offset 667738.
Found EXT 2/3/4 partition at sector offset 741463.
Found EXT 2/3/4 partition at sector offset 873696.
Found EXT 2/3/4 partition at sector offset 890699.
Found EXT 2/3/4 partition at sector offset 918743.
Found EXT 2/3/4 partition at sector offset 984277.
Found EXT 2/3/4 partition at sector offset 988258.
Found EXT 2/3/4 partition at sector offset 1077737.
Так сложно что-то найти, нужно еще структуру учитывать…
FILE_SYSTEM_SIGNATURES = {
# b"\x53\xef": "EXT 2/3/4",
b"\x58\x46\x53\x42": "Btrfs",
b"\xfd\x37\x7a\x58\x5a\x00": "ZFS",
b"\xeb\x3c\x90\x28": "FAT",
b"\xeb\x52\x90\x4e": "NTFS",
b"LUKS": "LUKS",
}
С LUKS уже ложных срабатываний нет… Нужно хотя бы 4 байта сигнатура чтобы мусор отсеять
sudo ./find_partitions.py /dev/nvme0n1
Found LUKS partition at sector offset 2048.
Исправление rtxtxtrx, :
https://gist.github.com/bmaupin/a9d29f5fdc831d1d0164
Можно и башем, но питон универсальнее. После сигнатуры должно следовать что-то еще чтобы отделить всякий мусор которого будет очень много…
Это универсальнее:
#!/usr/bin/env python
import argparse
import itertools
import sys
# Sector size in bytes (usually 512 bytes)
SECTOR_SIZE = 512
# File system signatures
FILE_SYSTEM_SIGNATURES = {
b"\x53\xef": "EXT 2/3/4",
b"\x58\x46\x53\x42": "Btrfs",
b"\xfd\x37\x7a\x58\x5a\x00": "ZFS",
b"\xeb\x3c\x90\x28": "FAT",
b"\xeb\x52\x90\x4e": "NTFS",
}
def find_partitions(device_path):
try:
# Open the device for reading
with open(device_path, "rb") as device:
for sector_offset in itertools.count():
# Read one sector
sector_data = device.read(SECTOR_SIZE)
if not sector_data:
break
# Check if the sector starts with any file system signature
for signature, fs_name in FILE_SYSTEM_SIGNATURES.items():
if sector_data.startswith(signature):
print(
f"Found {fs_name} partition at sector offset {sector_offset}."
)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
# Create argument parser
parser = argparse.ArgumentParser(
description="Search for all occurrences of file system signatures on a device."
)
parser.add_argument(
"device", type=str, help="Path to the device (e.g., /dev/sda)"
)
args = parser.parse_args()
find_partitions(args.device)
Но все равно мусора много:
~/workspace/hacking
(.venv) ❯ sudo ./find_partitions.py /dev/nvme0n1
[sudo] password for sergey:
Found EXT 2/3/4 partition at sector offset 236473.
Found EXT 2/3/4 partition at sector offset 239202.
Found EXT 2/3/4 partition at sector offset 279914.
Found EXT 2/3/4 partition at sector offset 418210.
Found EXT 2/3/4 partition at sector offset 643127.
Found EXT 2/3/4 partition at sector offset 667738.
Found EXT 2/3/4 partition at sector offset 741463.
Found EXT 2/3/4 partition at sector offset 873696.
Found EXT 2/3/4 partition at sector offset 890699.
Found EXT 2/3/4 partition at sector offset 918743.
Found EXT 2/3/4 partition at sector offset 984277.
Found EXT 2/3/4 partition at sector offset 988258.
Found EXT 2/3/4 partition at sector offset 1077737.
Так сложно что-то найти, нужно еще структуру учитывать
Исходная версия rtxtxtrx, :
https://gist.github.com/bmaupin/a9d29f5fdc831d1d0164
Можно и башем, но питон универсальнее. После сигнатуры должно следовать что-то еще чтобы отделить всякий мусор которого будет очень много