Systém souborů 13.06.2018 vjj 1
13.06.2018 vjj 2 historie přístup k souborům pouze pomocí absolutních adres svazek disk cylindr / stopa sektor každý soubor smí obsadit pouze jedno souvislé místo na začátku souboru je uvedena jeho délka
13.06.2018 vjj 3 historie File System první byl Unix tree of Files and Directories file names využití prostoru na disku fragmentované soubory mapa souborů: fragmenty souborů (spojový seznam obsazených sektorů) volné sektory
NTFS 13.06.2018 vjj 4
13.06.2018 vjj 5 Soubory CopyFile MoveFile MoveFileEx
13.06.2018 vjj 6 CreateDirectory RemoveDirectory GetCurrentDirectory SetCurrentDirectory Directory / Folder
13.06.2018 vjj 7 Logické jednotky n = GetLogicalDriveStrings (0, NULL); HANDLE hprocheap = GetProcessHeap () ; LPSTR lpszbuffer = HeapAlloc (hprocheap, 0, n+1) ; GetLogicalDriveStrings (n, lpszbuffer) ; A:\ [0] B:\ [0] C:\ [0] D:\ [0] [0] DWORD bitmask = GetLogicalDrives (VOID) ;
13.06.2018 vjj 8 Typ jednotky UINT GetDriveType (LPSTR lpszrootpathname) ; 0 Nelze určit 1 Neexistuje DRIVE_REMOVEABLE DRIVE_FIXED DRIVE_CDROM DRIVE_RAMDISK Virtuální disk DRIVE_REMOTE Namapovaný disk
13.06.2018 vjj 9 GetVolumeInformation get info Label, Serial Number, MaxComponentLength, File System Flags, File System Name GetDiskFreeSpace bytes per sector sectors per cluster number of clusters (total) number of free clusters DeviceIoControl
13.06.2018 vjj 10 CreateFile HANDLE hfile = CreateFile ( lpszname, AccessRights, ShareMode, lpsecurityattributes, open or create, flags and attributes, htemplatefile ) ;
13.06.2018 vjj 11 open driver hdevice = CreateFile( "\\\\.\\DriverName", GENERIC_READ GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ) ;
13.06.2018 vjj 12 Read File BOOL ReadFile ( hfile, lpszbuffer, dwnumberofbytestoread, lpdwnumberofbytesread, lpoverlapped ) ;
13.06.2018 vjj 13 Write File BOOL WriteFile ( hfile, lpszbuffer, dwnumberofbytestowrite, lpdwnumberofbyteswritten, lpoverlapped ) ;
13.06.2018 vjj 14 MFT Master File Table standardní atributy jméno Security Descriptor Read only, Archive, System, Hidden čas vytvoření, posledního přístupu a posledních úprav hard links jméno souboru nebo adresáře Unicode soubor může mít více jmen (např. jméno ve formátu 8.3 nebo hard link ) datová struktura určující přístupová práva k souboru Data pojmenovaná data Index Root Index Allocation Bitmap Reparse vlastní obsah souboru nepojmenovaný proud dat tento atribut mohou mít pouze soubory dat, nikoliv adresáře další, pojmenované, proudy dat ADS - Alternative Data Streams pro implementaci velkých adresářů tyto atributy mohou mít pouze adresáře, nikoliv soubory dat systémový filtr, který je automaticky spuštěn při každém přístupu k souboru nebo adresáři
šifrování 13.06.2018 vjj 15
13.06.2018 vjj 16 šifrování / dešifrování > cipher /e adresář > cipher /d adresář
13.06.2018 vjj 17 šifrování / dešifrování EncryptFile ("FileName") ; DecryptFile ("FileName", 0) ;
komprese 13.06.2018 vjj 18
13.06.2018 vjj 19 Komprese Compression Unit = 16 clusters DWORD attrib ; GetVolumeInformation ("c:\", NULL, 0, NULL, NULL, &attrib, NULL, 0, NULL) ; if (attrib & FS_FILE_COMPRESSION)...
13.06.2018 vjj 20 komprese USHORT FileCompression = COMPRESSION_FORMAT_DEFAULT ; COMPRESSION_FORMAT_NONE ; COMPRESSION_FORMAT_LNZT1 ; DWORD BytesReturned ; DeviceIoControl (hfile, FSCTL_SET_COMPRESSION, &FileCompression, sizeof (USHORT), NULL, 0, &BytesReturned, NULL) ;
13.06.2018 vjj 21 GetFileSize (hfile) ; velikost souboru Vrací stále stejnou velikost bez ohledu na případnou komprimaci GetCompressedFileSize (hfile) ; Vrací skutečný počet bajtů, které komprimovaný soubor dat zabírá na disku
13.06.2018 vjj 22 řídké soubory 8 TB 0 B
13.06.2018 vjj 23 nastavení atributu souboru #define _WIN32_WINNT 0x0501 #include <Winioctl.h> DWORD BytesReturned ; DeviceIoControl (hfile, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &BytesReturned, NULL) ;
13.06.2018 vjj 24 8 TB 0 B #define _WIN32_WINNT 0x0500 #include <Winioctl.h> HANDLE hfile ; DWORD dw ; LONG giga64 ; hfile = CreateFile ("c:\\sparsefile.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL) ; DeviceIoControl (hfile, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &dw, NULL) ; giga64 = 2048 ; // 2048 * 4 GB = 8 TB SetFilePointer (hfile, 0, &giga64, FILE_BEGIN) ; SetEndOfFile (hfile) ; CloseHandle (hfile) ;
13.06.2018 vjj 25 GetFileSize (hfile) ; Velikost souboru Vrací stále stejnou velikost bez ohledu na případné vynechání nulových "clusterů" GetCompressedFileSize (hfile) ; Vrací skutečný počet bajtů, které soubor na disku zaujímá
13.06.2018 vjj 26 streams 0 kb 4 GB
13.06.2018 vjj 27 NTFS - Stream C:\> ECHO "text" > SOUBOR.txt:myStream C:\> MORE < SOUBOR.TXT C:\> MORE < SOUBOR.TXT:myStream "text" C:\> DIR SOUBOR.txt:myStream... size 0 B
13.06.2018 vjj 28 obsah co lze skrýt v pojmenovaném streamu? náhled (thumbnail) Zone.Identifier viry,......
13.06.2018 vjj 29 Zone.Identifier Very small ADS (called Zone.Identifier) are also added within Internet Explorer (and now also other browsers) to mark files that have been downloaded from external sites: they may be unsafe to run locally and the local shell will require confirmation from the user before opening them. When the user indicates that they no longer want this confirmation dialog, this ADS is simply dropped from the MFT entry for downloaded files
13.06.2018 vjj 30 Add-Content Clear-Content Get-Content Get-Item Out-String Remove-Item Set-Content PowerShell 3.0
13.06.2018 vjj 31 NAME Test-AlternateDataStream PowerShell PSCX 3.0 SYNOPSIS PSCX Cmdlet: Tests for the existence of the specified alternate data stream from an NTFS file. SYNTAX Test-AlternateDataStream [-Path] <String[]> [-Name] <String> [<CommonParameters>] Test-AlternateDataStream [-LiteralPath] <String[]> [-Name] <String> [<CommonParameters>] DESCRIPTION Tests for the existence of the specified alternate data stream from an NTFS file. REMARKS To see the examples, type: "get-help Test-AlternateDataStream -examples". For more information, type: "get-help Test-AlternateDataStream -detailed". For technical information, type: "get-help Test-AlternateDataStream -full".
13.06.2018 vjj 32 Test-AlternateDataStream > dir Test-AlternateDataStream -Name Zone.Identifier Verbose... VERBOSE: Processing C:\Users\vjj\Downloads\threat.exe True... > cat < "threat.exe:zone.identifier" [ZoneTransfer] ZoneId=3
13.06.2018 vjj 33 SysInternals streams [-s] [-d] <file or directory> -s -d Recurse subdirectories. Delete streams. Streams takes wildcards e.g. 'streams *.txt'
13.06.2018 vjj 34 streams > SysinternalsSuite\streams.exe *.* Streams v1.56 - Enumerate alternate NTFS data streams Copyright (C) 1999-2007 Mark Russinovich Sysinternals - www.sysinternals.com threat.exe: :Zone.Identifier:$DATA 26
13.06.2018 vjj 35 Zone.Identifier > more < "threat.exe:zone.identifier" [ZoneTransfer] ZoneId=3
13.06.2018 vjj 36 NTFS - Stream C:\> COPY 4GB.mp4 > SOUBOR.txt:myStream