Penetration Basics - Active Directory Information Gathering 2: Bypass AV

Onedaysec
4 min read
2 views
Penetration Basics - Active Directory Information Gathering 2: Bypass AV — One Day Sec default thumbnail

0x00 Preface

---

In the previous article 'Penetration Basics - Active Directory Information Gathering', common information gathering methods were introduced using examples of obtaining all users, all computers, and all groups in Active Directory.

However, in practical use, some tools may be blocked by antivirus software.

Therefore, this article will supplement the gathering methods while bypassing antivirus software interception.

0x01 Introduction

---

This article will cover the following:

  • Using csvde to obtain Active Directory information
  • Using ldifde to obtain Active Directory information
  • Using AdFind to obtain Active Directory information
  • Using a lightweight gathering tool developed in C#

0x02 Using csvde to obtain Active Directory information

---

Documentation:

https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/cc732101(v=ws.11)

Files exported using csvde are in CSV format and can be viewed with Microsoft Excel

By default, it can only be used on the following systems, for example:

  • Windows Server 2003
  • Windows Server 2008
  • Windows Server 2003 R2
  • Windows Server 2008 R2
  • Windows Server 2012,
  • Windows Server 2003 with SP1
  • Windows 8
  • ...

1. Example of exporting Active Directory information from the current domain

Export all information from the current domain:

csvde -f all.csv

Export all user information in the current domain:

csvde -f user.csv -r "(&(objectCategory=person))"

Export all machine information in the current domain:

csvde -f machine.csv -r "(&(objectCategory=computer))"

Export all group information in the current domain:

csvde -f group.csv -r "(&(objectCategory=group))"

Export all user information in the Domain Admins group in the current domain:

csvde -f admin.csv -r "(&(objectCategory=group)(name=Domain Admins))"

Export all OU information in the current domain:

csvde -f ou.csv -r "(&(objectCategory=organizationalUnit))"

Export all domain usernames in the current domain:

csvde -f username.csv -r "(&(objectCategory=person))" -l SamAccountName

Export all computer names in the current domain:

csvde -f machinename.csv -r "(&(objectCategory=computer))" -l name

2. Example of remotely exporting Active Directory information from outside the domain

Export all information from the remote domain:

csvde -s 192.168.1.1 -a test\admin Password -f all.csv

0x03 Using ldifde to obtain Active Directory information

---

Documentation:

https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/cc731033(v=ws.11)

The file format exported using ldifde is LDIF, which can be viewed with notepad.exe

1. Example of exporting Active Directory information from the current domain

Export all information from the current domain:

ldifde -f all.txt

Export all user information from the current domain:

ldifde -r "(&(objectCategory=person))" -f user.txt

Export all machine information from the current domain:

ldifde -r "(&(objectCategory=computer))" -f machine.txt

Export all group information from the current domain:

ldifde -r "(&(objectCategory=group))" -f group.txt

Export user information for all administrator groups in the current domain:

ldifde -r "(&(objectCategory=group)(name=Domain Admins))" -f admin.txt

Export all OU information in the current domain:

ldifde -r "(&(objectCategory=organizationalUnit))" -f ou.txt

Export all domain usernames in the current domain:

ldifde -r "(&(objectCategory=person))" -l SamAccountName -f username.txt

Export all computer names in the current domain:

ldifde -r "(&(objectCategory=computer))" -l name -f machinename.txt

2. Example of remotely exporting Active Directory information from outside the domain

Export all information from the remote domain:

ldifde -s 192.168.1.1 -a test\admin Password -f all.txt

0x04 Using AdFind to obtain Active Directory information

---

Download address:

https://www.joeware.net/freetools/tools/adfind/

1. Example of Exporting Active Directory Information from Current Domain

Export all information from current domain:

adfind.exe -h 127.0.0.1>all.txt

Export all user information from current domain:

adfind.exe -h 127.0.0.1 -f objectcategory=person>user.txt

Export all machine information from current domain:

adfind.exe -h 127.0.0.1 -f objectcategory=computer>machine.txt

Export all group information from current domain:

adfind.exe -h 127.0.0.1 -f objectcategory=group>group.txt

Export all user information from Domain Admins group in current domain:

adfind.exe -h 127.0.0.1 -f "(&(objectCategory=group)(name=Domain Admins))">admin.txt

Export all OU information from current domain:

adfind.exe -h 127.0.0.1 -f objectcategory=organizationalUnit>ou.txt

Export all domain usernames from current domain:

adfind.exe -h 127.0.0.1 -f objectcategory=person SamAccountName>username.txt

Export all computer names in the current domain:

adfind.exe -h 127.0.0.1 -f objectcategory=computer name>machinename.txt

2. Example of remotely exporting Active Directory information from outside the domain

Export all information from the remote domain:

adfind.exe -h 192.168.1.1 -u test\admin -up Password>all.txt

0x05 Lightweight acquisition tool developed in C#

---

SharpView implements the functionality of PowerView for obtaining Active Directory information through .Net, with comprehensive features, but it may be intercepted by antivirus software.

By calling the System.DirectoryServices namespace, we can easily implement simple functions to meet basic needs, and typically, it will not be intercepted by antivirus software.

Here, the previous code ListUserMailbyLDAP.cs can be used as a template, and only the query statement needs to be modified.

I have implemented a lightweight tool based on the basic functionality of AdFind as a reference. The complete code has been uploaded to GitHub, and the address is as follows:

An open-source project

SharpADFindDemo can be directly compiled on Windows systems with .Net 3.5 or .Net 4

The compilation method is as follows:

C:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe SharpADFindDemo.cs /r:System.DirectoryServices.dll
or
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe SharpADFindDemo.cs /r:System.DirectoryServices.dll

Supports exporting the following AD information:

  • user, all domain user information
  • machine, all domain computer information
  • group, all domain group information
  • ou, all domain OU information
  • username, export only domain usernames
  • machinename, export only domain computer names
  • groupname, export only domain group names
  • ouname, export only domain OU names

Note that the default maximum number of exports is 1000

0x06 Summary

---

This article supplements the methods for obtaining Active Directory information, introduces three commonly used tools, develops a lightweight acquisition tool SharpADFindDemo using C#, and suggests that it can serve as a template to integrate additional features with SharpView in the future.

Related Questions & Answers

How does the lightweight C# tool SharpADFindDemo help avoid antivirus detection?

SharpADFindDemo is a custom C# tool that leverages the `System.DirectoryServices` namespace to query Active Directory, making it less likely to be flagged by antivirus compared to popular tools like PowerView or SharpView. It can be compiled directly on a target system using `csc.exe` and supports exporting users, computers, groups, and OUs. The tool is designed based on AdFind functionality and serves as a template for integrating more advanced features. For a deeper understanding of similar gathering techniques, see the original article [Penetration Basics - Active Directory Information Gathering 2: Bypass AV](/news/penetration-basics-active-directory-information-gathering-2-bypass-av).

What are the key differences between `csvde` and `ldifde` for AD information gathering?

Both `csvde` and `ldifde` are built-in Windows tools that export Active Directory data. The main difference is the output format: `csvde` produces CSV files that can be opened in Excel, while `ldifde` produces LDIF files viewable in notepad. Their syntax and filtering capabilities are very similar—for instance, `ldifde -r "(&(objectCategory=computer))" -f machine.txt` exports all computers. Both are trusted by most antivirus because they are native Windows utilities.

How can `csvde` be used to extract Active Directory information without being blocked by antivirus?

`csvde` is a built-in Windows command-line tool that exports AD data in CSV format, and it is typically not flagged by antivirus. For example, to export all users in the current domain, you can run `csvde -f user.csv -r "(&(objectCategory=person))"`. It can also be used remotely with the `-s` and `-a` parameters. More details on running `csvde` on older systems can be found in [Penetration Basics - Running csvde on Windows 7](/news/penetration-basics-running-csvde-on-windows-7).

What is the main goal of the article 'Penetration Basics - Active Directory Information Gathering 2: Bypass AV'?

The article focuses on gathering Active Directory information while bypassing antivirus software. It builds on the methods introduced in [Penetration Basics - Obtaining Active Directory Information](/news/penetration-basics-obtaining-active-directory-information) but addresses the problem that some tools may be blocked by AV. It covers using `csvde`, `ldifde`, `AdFind`, and a custom lightweight C# tool as alternatives that are less likely to trigger AV.

Continue Reading