Hack The Box - Windows Fundamentals - course notes

From PedrosBrainDump

Windows Versions

Operating System Names Version Number
Windows NT 4 4.0
Windows 2000 5.0
Windows XP 5.1
Windows Server 2003, 2003 R2 5.2
Windows Vista, Server 2008 6.0
Windows 7, Server 2008 R2 6.1
Windows 8, Server 2012 6.2
Windows 8.1, Server 2012 R2 6.3
Windows 10, Server 2016, Server 2019 10.0

Command Get-WmiObject

We can use the Get-WmiObject to find information about the operating system. Get-WmiObject can be used to start and stop services on local and remote computers, and more

Get-WmiObject -Class <some class>
  • Get-WmiObject - the command
  • -Class <some class> - you can use:
    • Win32_Process to get a process listing
    • Win32_Service to get a listing of services
    • Win32_Bios to get Basic Input/Output System (BIOS) information
  • ComputerName parameter to get information about remote computers

FS Structure

Directory Function
Perflogs Can hold Windows performance logs but is empty by default.
Program Files On 32-bit systems, all 16-bit and 32-bit programs are installed here. On 64-bit systems, only 64-bit programs are installed here.
Program Files (x86) 32-bit and 16-bit programs are installed here on 64-bit editions of Windows.
ProgramData This is a hidden folder that contains data that is essential for certain installed programs to run. This data is accessible by the program no matter what user is running it.
Users This folder contains user profiles for each user that logs onto the system and contains the two folders Public and Default.
Default This is the default user profile template for all created users. Whenever a new user is added to the system, their profile is based on the Default profile.
Public This folder is intended for computer users to share files and is accessible to all users by default. This folder is shared over the network by default but requires a valid network account to access.
AppData Per user application data and settings are stored in a hidden user subfolder (i.e., cliff.moore\AppData). Each of these folders contains three subfolders. The Roaming folder contains machine-independent data that should follow the user's profile, such as custom dictionaries. The Local folder is specific to the computer itself and is never synchronized across the network. LocalLow is similar to the Local folder, but it has a lower data integrity level. Therefore it can be used, for example, by a web browser set to protected or safe mode.
Windows The majority of the files required for the Windows operating system are contained here.
System, System32, SysWOW64 Contains all DLLs required for the core features of Windows and the Windows API. The operating system searches these folders any time a program asks to load a DLL without specifying an absolute path.
WinSxS The Windows Component Store contains a copy of all Windows components, updates, and service packs.

File System

There are 5 types of Windows file systems: FAT12, FAT16, FAT32, NTFS, and exFAT. FAT12 and FAT16 are no longer used on modern Windows operating system.

Pros of FAT32:

  • Device compatibility - it can be used on computers, digital cameras, gaming consoles, smartphones, tablets, and more.
  • Operating system cross-compatibility - It works on all Windows operating systems starting from Windows 95 and is also supported by MacOS and Linux.

Cons of FAT32:

  • Can only be used with files that are less than 4GB.
  • No built-in data protection or file compression features.
  • Must use third-party tools for file encryption.

Pros of NTFS:

  • NTFS is reliable and can restore the consistency of the file system in the event of a system failure or power loss.
  • Provides security by allowing us to set granular permissions on both files and folders.
  • Supports very large-sized partitions.
  • Has journaling built-in, meaning that file modifications (addition, modification, deletion) are logged.

Cons of NTFS:

  • Most mobile devices do not support NTFS natively.
  • Older media devices such as TVs and digital cameras do not offer support for NTFS storage devices.

Permissions

The NTFS file system has many basic and advanced permissions. Some of the key permission types are:

Permission Type Description
Full Control Allows reading, writing, changing, deleting of files/folders.
Modify Allows reading, writing, and deleting of files/folders.
List Folder Contents Allows for viewing and listing folders and subfolders as well as executing files. Folders only inherit this permission.
Read and Execute Allows for viewing and listing files and subfolders as well as executing files. Files and folders inherit this permission.
Write Allows for adding files to folders and subfolders and writing to a file.
Read Allows for viewing and listing of folders and subfolders and viewing a file's contents.
Traverse Folder This allows or denies the ability to move through folders to reach other files or folders. For example, a user may not have permission to list the directory contents or view files in the documents or web apps directory in this example c:\users\bsmith\documents\webapps\backups\backup_02042020.zip but with Traverse Folder permissions applied, they can access the backup archive.

Files and folders inherit the NTFS permissions of their parent folder for ease of administration, so administrators do not need to explicitly set permissions for each file and folder.

Integrity Control Access Control List (icacls)

We can list out the NTFS permissions on a specific directory by running either icacls from within the working directory or icacls <directory> against a directory not currently in.

The resource access level is listed after each user in the output. The possible inheritance settings are:

  • (CI): container inherit
  • (OI): object inherit
  • (IO): inherit only
  • (NP): do not propagate inherit
  • (I): permission inherited from parent container

In the above example, the NT AUTHORITY\SYSTEM account has object inherit, container inherit, inherit only, and full access permissions. This means that this account has full control over all file system objects in this directory and subdirectories.

Basic access permissions are as follows:

  • F : full access
  • D :  delete access
  • N :  no access
  • M :  modify access
  • RX :  read and execute access
  • R :  read-only access
  • W :  write-only access
C:\htb> icacls c:\Users
c:\Users NT AUTHORITY\SYSTEM:(OI)(CI)(F)
         BUILTIN\Administrators:(OI)(CI)(F)
         BUILTIN\Users:(RX)
         BUILTIN\Users:(OI)(CI)(IO)(GR,GE)
         Everyone:(RX)
         Everyone:(OI)(CI)(IO)(GR,GE)

Successfully processed 1 files; Failed processing 0 files

We can add and remove permissions via the command line using icacls. Here we are executing icacls in the context of a local administrator account showing the C:\users directory where the joe user does not have any write permissions.


Using the command

icacls c:\users /grant joe:f

(e.g.)

C:\htb> icacls c:\users /grant joe:f
processed file: c:\users
Successfully processed 1 files; Failed processing 0 files

we can grant the joe user full control over the directory, but given that (oi) and (ci) were not included in the command, the joe user will only have rights over the c:\users folder but not over the user subdirectories and files contained within them.

C:\htb> >icacls c:\users
c:\users WS01\joe:(F)
         NT AUTHORITY\SYSTEM:(OI)(CI)(F)
         BUILTIN\Administrators:(OI)(CI)(F)
         BUILTIN\Users:(RX)
         BUILTIN\Users:(OI)(CI)(IO)(GR,GE)
         Everyone:(RX)
         Everyone:(OI)(CI)(IO)(GR,GE)

Successfully processed 1 files; Failed processing 0 files

These permissions can be revoked using the command

icacls c:\users /remove joe