Code Monkey home page Code Monkey logo

adrecon's Introduction

ADRecon: Active Directory Recon Follow ADRecon on Twitter

This repo contains updates to the original concept and code by Prashant Mahajan (@prashant3535) while working at Sense of Security.

ADRecon is a tool which extracts and combines various artefacts (as highlighted below) out of an AD environment. The information can be presented in a specially formatted Microsoft Excel report that includes summary views with metrics to facilitate analysis and provide a holistic picture of the current state of the target AD environment.

The tool is useful to various classes of security professionals like auditors, DFIR, students, administrators, etc. It can also be an invaluable post-exploitation tool for a penetration tester.

It can be run from any workstation that is connected to the environment, even hosts that are not domain members. Furthermore, the tool can be executed in the context of a non-privileged (i.e. standard domain user) account. Fine Grained Password Policy, LAPS and BitLocker may require Privileged user accounts. The tool will use Microsoft Remote Server Administration Tools (RSAT) if available, otherwise it will communicate with the Domain Controller using LDAP.

The following information is gathered by the tool:

  • Forest;
  • Domain;
  • Trusts;
  • Sites;
  • Subnets;
  • Schema History;
  • Default and Fine Grained Password Policy (if implemented);
  • Domain Controllers, SMB versions, whether SMB Signing is supported and FSMO roles;
  • Users and their attributes;
  • Service Principal Names (SPNs);
  • Groups, memberships and changes;
  • Organizational Units (OUs);
  • GroupPolicy objects and gPLink details;
  • DNS Zones and Records;
  • Printers;
  • Computers and their attributes;
  • PasswordAttributes (Experimental);
  • LAPS passwords (if implemented);
  • BitLocker Recovery Keys (if implemented);
  • ACLs (DACLs and SACLs) for the Domain, OUs, Root Containers, GPO, Users, Computers and Groups objects (not included in the default collection method);
  • GPOReport (requires RSAT);
  • Kerberoast (not included in the default collection method); and
  • Domain accounts used for service accounts (requires privileged account and not included in the default collection method).

ADRecon was presented at: Black Hat Arsenal Asia 2018 - Slidedeck

Black Hat Arsenal USA 2018 | DEFCON 26 Demolabs - Slidedeck

Bay Area OWASP - Slidedeck

CHCON - Slidedeck

Getting Started

These instructions will get you a copy of the tool up and running on your local machine.

Prerequisites

  • .NET Framework 3.0 or later (Windows 7 includes 3.0)
  • PowerShell 2.0 or later (Windows 7 includes 2.0)
    • Powershell Core on Windows is supported (Tested on PowerShell v7.2.2 running on Windows 10)
  • A Windows host (Powershell for Linux/macOS is not supported)

Optional

Installing

If you have git installed, you can start by cloning the repository:

git clone https://github.com/adrecon/ADRecon.git

Otherwise, you can download a zip archive of the latest release. The intent is to always keep the master branch in a working state.

Usage

Examples

To run ADRecon on a domain member host.

PS C:\> .\ADRecon.ps1

To run ADRecon on a domain member host as a different user.

PS C:\>.\ADRecon.ps1 -DomainController <IP or FQDN> -Credential <domain\username>

To run ADRecon on a non-member host using LDAP.

PS C:\>.\ADRecon.ps1 -Method LDAP -DomainController <IP or FQDN> -Credential <domain\username>

To run ADRecon with specific modules on a non-member host with RSAT. (Default OutputType is STDOUT with -Collect parameter)

PS C:\>.\ADRecon.ps1 -Method ADWS -DomainController <IP or FQDN> -Credential <domain\username> -Collect Domain, DomainControllers

To generate the ADRecon-Report.xlsx based on ADRecon output (CSV Files).

PS C:\>.\ADRecon.ps1 -GenExcel C:\ADRecon-Report-<timestamp>

When you run ADRecon, a ADRecon-Report-<timestamp> folder will be created which will contain ADRecon-Report.xlsx and CSV-Folder with the raw files.

Parameters

-Method <String>
    Which method to use; ADWS (default), LDAP

-DomainController <String>
    Domain Controller IP Address or Domain FQDN.

-Credential <PSCredential>
    Domain Credentials.

-GenExcel <String>
    Path for ADRecon output folder containing the CSV files to generate the ADRecon-Report.xlsx. Use it to generate the ADRecon-Report.xlsx when Microsoft Excel is not installed on the host used to run ADRecon.

-OutputDir <String>
    Path for ADRecon output folder to save the CSV/XML/JSON/HTML files and the ADRecon-Report.xlsx. (The folder specified will be created if it doesn't exist) (Default pwd)

-Collect <String>
    Which modules to run (Comma separated; e.g Forest,Domain. Default all except ACLs, Kerberoast and DomainAccountsusedforServiceLogon)
    Valid values include: Forest, Domain, Trusts, Sites, Subnets, SchemaHistory, PasswordPolicy, FineGrainedPasswordPolicy, DomainControllers, Users, UserSPNs, PasswordAttributes, Groups, GroupChanges, GroupMembers, OUs, ACLs, GPOs, gPLinks, GPOReport, DNSZones, DNSRecords, Printers, Computers, ComputerSPNs, LAPS, BitLocker, Kerberoast DomainAccountsusedforServiceLogon.

-OutputType <String>
    Output Type; Comma seperated; e.g CSV,STDOUT,Excel (Default STDOUT with -Collect parameter, else CSV and Excel).
    Valid values include: STDOUT, CSV, XML, JSON, HTML, Excel, All (excludes STDOUT).

-DormantTimeSpan <Int>
    Timespan for Dormant accounts. (Default 90 days)

-PassMaxAge <Int>
    Maximum machine account password age. (Default 30 days)

-PageSize <Int>
    The PageSize to set for the LDAP searcher object. (Default 200)

-Threads <Int>
    The number of threads to use during processing objects (Default 10)

-OnlyEnabled <Bool>
    Only collect details for enabled objects.

-Log <Switch>
    Create ADRecon Log using Start-Transcript

-Logo <String>
    Which Logo to use in the excel file? (Default ADRecon)
    Values include: ADRecon, CyberCX, Payatu.

Future Plans

  • Replace System.DirectoryServices.DirectorySearch with System.DirectoryServices.Protocols and add support for LDAP STARTTLS and LDAPS (TCP port 636).
  • Add Domain Trust Enumeration.
  • Add option to filter default ACLs.
  • Gather ACLs for other objects such as Users, Group, etc.
  • Additional export and storage option: export to STDOUT, SQLite, xml, json, html, pdf.
  • Use the EPPlus library for Excel Report generation and remove the dependency on MS Excel.
  • List issues identified and provide recommended remediation advice based on analysis of the data.
  • Add PowerShell Core support.

Bugs, Issues and Feature Requests

Please report all bugs, issues and feature requests in the issue tracker. Or let me (@prashant3535) know directly.

Contributing

Pull request are always welcome.

Mad props

Thanks for the awesome work by @_wald0, @CptJesus, @harmj0y, @mattifestation, @PyroTek3, @darkoperator, @ITsecurityAU Team, @CTXIS Team, @CxCyber Team, @payatulabs Team and others.

License

ADRecon is a tool which gathers information about the Active Directory and generates a report which can provide a holistic picture of the current state of the target AD environment.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

This program borrows and uses code from many sources. All attempts are made to credit the original author. If you find that your code is used without proper credit, please shoot an insult to @prashant3535, Thanks.

adrecon's People

Contributors

arcayr avatar noraj avatar prashant3535 avatar smcgu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adrecon's Issues

Recycle Bin Status Enumeration Issue

In some environments where the Active Directory Recycle Bin is enabled, it is reported as disabled in the CSV and Excel reports when using the LDAP method from a Stand Alone workstation. There are two primary possible reasons why this occurs:

  1. AD Recycle Bin is available via Server 2008 R2 and later forest levels (https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/get-started/adac/introduction-to-active-directory-administrative-center-enhancements--level-100-). According to the scripts own FLAD variable, the forest functional level integer value for 2008R2 is 4, but in both the ADWS and LDAP Recycle Bin Feature Status Enumeration code, there is a check to see if Forest Mode is 6 or greater (Windows 2012R2 or later) before it will even enumerate the feature. This should be 4 to include Windows Server 2008R2 and later - correct?

  2. For the LDAP method from a standalone workstation, some AD environments have been observed returning the "msDS-EnabledFeatureBL" property in all lower case. While powershell is mostly case indifferent, it appears that this Active Directory property is case sensitive.

For environments where the property is returned in all lower case "msds-enabledfeaturebl" (see example below on a manual step through of the ADRecon script)

Capture

the check "$ADRecycleBin.Properties.'msDS-EnabledFeatureBL'.Count -gt 0" fails (even when Recycle Bin is enabled) and the report shows the Recycle Bin Feature as disabled. This is all despite the script enumerating the $ADRecycleBin variable correctly on a manual step through; the output of the variable shows the Recycle Bin Feature option is enabled and the proper applied scope when the affected property is called using all lower case, I am not certain that this property is always returned in lower case - but have found two different AD environments where it is.

Broken Excel Document

Hey Prashant,

Just wanted to let you know the latest update has broken excel document generation.
The scripts saves the ISM control column name as 'ISM Controls 10Mar2022' on line 5519, but line 7691 expects it to be 'ISM Controls 16Jun2022'.

This causes excel to repair the document on startup, with no way to save the repaired file:
image

Should be a simple fix, change the name parameter on line 5519 to 'ISM Controls 16Jun2022'.

Thanks & love the tool!

Excel reporting problem

This issue is for situations that you run adrecon collect, create a folder with csv files, then try to merge

Command:
Invoke-ADRecon -GenExcel .\ADRecon-Report-20200326214743\

Output:

cmdlet Invoke-ADRecon at command pipeline position 1
Supply values for the following parameters:
Collect[0]:

Unable to generate report with overridden default parameters

For Example:
I'm trying to generate a report by overriding the DormantTimeSpan parameter in the adrecon.ps1 script. I'm using the following command:
./adrecon.ps1 -DormantTimeSpan 180 -GenExcel "..path\to\report"

The script executes without any errors, but the generated report still contains the default results. I have tried various combinations, but I have been unsuccessful in getting the desired output.

Operating System: Windows 10 Ver 22H2
PowerShell Version: 5.1.19041.3

Cannot Find TEMP file as Write access to C: is denied.

Hi,

Is it possible to create the temp files in the working directory opposed to TEMP. During testing i dont always have access to the "C:\windows\temp" directory.

[*] ADRecon v1.27 by Prashant Mahajan (@prashant3535)
WARNING: [Invoke-ADRecon] ActiveDirectory Module from RSAT (Remote Server Administration Tools) is not installed ...
Continuing with LDAP
Add-Type : (0) : Source file 'C:\windows\temp\kf2y4vmy.0.cs' could not be found

Anyway around this?

ADRecon from Linux

  • ADRecon v1.24
  • .NET 5.0.204
  • PowerShell 7.1.3
  • ArchLinux

it seems that despite the fact I'm running the tool from linux, the prerequisites are satisfied.

PS /tmp/ADRecon> .\ADRecon.ps1 -DomainController 10.x.x.x -Credential domain.xxx\user
...
[*] ADRecon v1.24 by Prashant Mahajan (@prashant3535)
[Invoke-ADRecon] The term 'Get-CimInstance' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Computer Role could not be identified.
Remove-Variable: /tmp/ADRecon/ADRecon.ps1:11814
 Line |
11814 |      Remove-Variable computer
      |      ~~~~~~~~~~~~~~~~~~~~~~~~
      | Cannot find a variable with the name 'computer'.

Remove-Variable: /tmp/ADRecon/ADRecon.ps1:11815
 Line |
11815 |      Remove-Variable computerdomainrole
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      | Cannot find a variable with the name 'computerdomainrole'.

Remove-Variable: /tmp/ADRecon/ADRecon.ps1:11816
 Line |
11816 |      Remove-Variable computerrole
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      | Cannot find a variable with the name 'computerrole'.

WARNING: [Invoke-ADRecon] ActiveDirectory Module from RSAT (Remote Server Administration Tools) is not installed ... Continuing with LDAP
...

Does ADRecon absolutely requires to run on a Windows host?

Running script in offline mode

Is there a way to run the script in "offline" mode without admin creds? I'm thinking of the situation where I have a disk image for analysis during an IR. I can get a copy of the NTDS folder from the image and run the script against it without the server being running. @prashant3535

generate excel error

While processing excel file, the errors accur.
image
Another question, Messy Chinese character
image

LastPasswordSet date has not the right time in certain case

I noticed on certain operating systems, when the output format date is '%m/%d/%Y %H:%M:%S %p', there is a time difference about 2 hours between the lastPasswordSet and the whenCreated field.

However, this information is wrong because the user has never changed his password. Both values should be the same.

Capture d’écran 2022-11-15 à 11 47 04

We check on our Active Directory and the LastPasswordSet value is 6/14/2016 1:25:44 PM.

It could be problematic when we want to detect users have not changed their initial password by comparing lastPasswordSet and whenCreated.

Thanks in advance

AMSI raise error

Hello,
thanks for your effort in this project.
On recent windows systems ADRecon.ps1 raise the error “This script contains malicious content and has been blocked by your antivirus software”, this should be related to the AMSI component.
Do you know which section of the code is detected as malicious and how to fix/bypass it?

Lots of PowerShell errors when generating a report

Hello,

when generating a report, I get tons of PowerShell errors. The Excel file is generated and usable, but I don't know what these errors mean, and if they are preventing something from being generated in the report. I also think they should be eliminated for the sake of not having erros when running the tool 😊

Here are a few of these errors. My system is in French, so I did my best to translate them.

Value doesn't belong in the expected range.
At D:\tools\adrecon\ADRecon.ps1:5509 : 17
+ ...             $worksheet.Range($ObjValues[$i]).FormatConditions.Add([Mi ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException
Invalid index. (HRESULT exception: 0x8002000B (DISP_E_BADINDEX))
At D:\tools\adrecon\ADRecon.ps1:5514 : 17
+ ...             $worksheet.Range($_).FormatConditions.Item(1).StopIfTrue  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Cannot find an overload for « Style » and the number of arguments: « 1 »
At D:\tools\adrecon\ADRecon.ps1:4960 : 5
+     $worksheet.Cells.Item($row,$column).Style = "Heading 2"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : RuntimeException
HRESULT exception: 0x800A03EC
At D:\tools\adrecon\ADRecon.ps1:5914 : 17
+ ...             Get-ADRExcelChart -ChartType "xlPie" -ChartLayout 3 -Char ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

You can get here a ZIP file containing the full error log, the CSV files, and the generated Excel file: ADRecon.zip

This was run on a testing environment, but the same errors happen on real environments.

Could you look into it and tell me why these errors occur, or what can I do to help you fix them?

Feature Request

It would be great if I could have the script run daily/weekly and do a diff from my original run and compare it to the current settings and email it to me.

This way I can do see what changes and when to detect compromise

Virus and Trojan detected by my side too

Hello

I am not capable anymore to download and install the tool : Trojan has been detected and the tools remove by the antivirus.

Can you please update the tool ?

Regards

Invalid characters

There looks to be some invalid characters in the script body, smart quotes and longer hyphens. Script errors out unless you replace these.

Smart quotes on these lines:
10297
10311
10322
10325
10326

Long hyphens on these lines:
11285
11293

Destination array was not long enough. Check destIndex and length, and the array's lower bounds.

BTW - This script is awesome

Im getting the following error (we have > 10,000 groups)

[-] Group Memberships - May take some time
Exception caught: System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.Dictionary2.Resize(Int32 newSize, Boolean forceNewHashCodes) at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)
at ADRecon.ADWSClass.GroupRecordDictionaryProcessor.processRecord(Object record)

Enumerating ACLs stalls OS

Enumerating ACLs in large environments can cause system resource exhaustion in large environments.

I have been able to update the Function Get-ADRACL to include -SearchBase $DnBase and $objSearcherPath.SearchRoot = "LDAP://$DnBase" using an additional property, but that isn't ideal.

The property could be brought into the helper Function Invoke-ADRecon or could be used to iterate through the subtrees as smaller chunks.

Let me know if you want me to merge the -SearchBase and SearchRoot as an example to test with.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.