Code Monkey home page Code Monkey logo

adrecon's Introduction

ADRecon: Active Directory Recon Follow ADRecon on Twitter

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;
  • 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 and memberships;
  • 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;
  • 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)

Optional

Installing

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

git clone https://github.com/sense-of-security/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 -Protocol 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 -Protocol 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

-Protocol <String>
    Which protocol to use; ADWS (default) or 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 Kerberoast)
    Valid values include: Forest, Domain, Trusts, Sites, Subnets, PasswordPolicy, FineGrainedPasswordPolicy, DomainControllers, Users, UserSPNs, PasswordAttributes, Groups, GroupMembers, OUs, ACLs, GPOs, gPLinks, GPOReport, DNSZones, 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)

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

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, the Sense of Security 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.

Copyright (C) Sense of Security

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 merati avatar prashant3535 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  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

adrecon's Issues

Improper parser of ManagedBy when Accounts are Entered Last, First

My domain uses Last, First format for the accounts. When the script parses the ManagedByValue it returns only the Last Name. The DN is a follow:

CN=Ramos, Carlos,OU=Technology_HQ,OU=Users,DC=Domain,DC=local

Script result is Ramos\

I thought I could fix with the follow code replacement but not sure why it is not wording.
Your Code: ManagedBy = (ManagedByValue.Split(',')[0]).Split('=')[1];
Replacement: ManagedBy = (ManagedByValue.Split(',OU=')[0]).Replace(',',',').Replace('CN=','');

I see your code uses a Class. Never used them so wondering it the syntax of it is not acceptable in a class.

I would think it would be advantages for your script to be able to handle such a situation. I have worked with several large companies and they all used Last, First for accounts. Only ran into one merge where the other company use first last.

Any help is appreciated.

Thanks,

Carlos

PS Beautiful work on the script. Thanks for sharing it.

Total user accounts

First, great software. It has been a lifesaver for me and my company. The 3 times I have run it, when I go to the User Stats, the code says =CountA(Users!A301:A301)-1. and I always end up with a total of 0 in Red, and the percentages are always throwing a divide by zero error. is that correct?

thanks

[Feature Request] Add PDF Output Type

Hi,

I'd like to see an option for PDF in the -OutputType parameter. I think it could be really helpful for those that just want a quick read only file (point in time) to throw into their documentation and for audits.

ADRecon -Protocol LDAP issue

I am receiving an issue where when I run the command:

.\ADRecon.ps1 -Protocol LDAP -DomainController -Credential -Collect Forest,Domain,PasswordPolicy,FineGrainedPasswordPolicy,DomainControllers,Users,UserSPNs,Groups,GroupMembers,OUs,GPOs,GPOReport,DNSZones,Printers,Computers,ComputerSPNs,LAPS,Bitlocker -OutputType Excel

A parameter cannot be found that matches parameter name 'Protocol'.
At line:1 char:15

  • .\ADRecon.ps1 -Protocol LDAP -DomainController IP -Credential ...
  •           ~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [ADRecon.ps1], ParameterBindingException
    • FullyQualifiedErrorId : NamedParameterNotFound,ADRecon.ps1

The older version worked fine. This only started after I upgraded to the newer version of the powershell script.
Please advise. Thank you.

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

Export to JSON gives XML output.

Choosing options to export to JSON gives XML output.

The JSON object is a string which does not have a .Save() method, it looks like this line was copied from the XML option where the XML object does have a .Save() method, so I just copied this from the HTML function and it works correctly.

Replace line 4159 in Function Export-ADRJSON, originally:

(ConvertTo-JSON -InputObject $ADRObj).Save($ADFileName)

with:

ConvertTo-JSON -InputObject $ADRObj | Out-File -FilePath $ADFileName

This looks like it was just an oversight while copying and pasting the XML function, but the Export-ADRJSON function was actually never called from anywhere in the script.

Replace line 4316 in Function Export-ADR, originally:

Export-ADRXML -ADRObj $ADRObj -ADFileName $ADFileName

with:

Export-ADRJSON -ADRObj $ADRObj -ADFileName $ADFileName

Password Quality Check

Would love to be able to run this and get a password quality report on each user as well.

Thanks!

Feature Request: HTML Report with homepage and hyperlinks

Hi,
great job and thank you for sharing.
It would be nice to have HTML reports with home page and hyperlinks to all detailed reports (like Excel) and graphs, to be able to publish the results on internal webserver.
Regards.

Red.

Phantom "Server" Parameter Exception/Error

I randomly keep getting this error when running the program.

Command
C:\Users\<nope>\Desktop\AD-Recon-Logs\ADRecon.ps1 -DomainController <FQDN> -Credential domain\user -OutputDir C:\Users\<Nope>\Desktop\AD-Recon-Logs\Test\

Error
[*] ADRecon v180429 by Prashant Mahajan (@prashant3535) from Sense of Security. [*] Running on <Domain>\Computer - Member Workstation [EXCEPTION] A parameter cannot be found that matches parameter name 'Server'.

Recognized as a virus

Whenever I try to run the script I get a message that it was detected as a virus by Microsoft defender and many other anti-viruses.
Is there a fix/explanation for this?

Help- Error in execution

PS C: \ ADRecon-master>. \ ADRecon.ps1-LDAP protocol -DomainController server01.sidkron.local -Credential sidkron \ administ
ractor
C: \ ADRecon-master \ ADRecon.ps1: It is not possible to process the transformation of the argument into a parameter 'Credential'. It is not
It is possible to convert the value "sidkron \ administrator" of type "System.String" into type "System.Management.Automation.PSCred
ential ".
In line: 1 character: 82
+. \ ADRecon.ps1-LDAP protocol -DomainController server01.sidkron.local -Credential <<<< sidkron \ administrator
+ CategoryInfo: InvalidData: (:) [ADRecon.ps1], ParameterBindin ... mationException
+ FullyQualifiedErrorId: ParameterArgumentTransformationError, ADRecon.ps1

rate limiting

Is there any way to limit the numbers of requests/querys made to AD? e.g. no more than 500 object requests per minute?

thanks!

Exporting to Excel

Getting this error from a different system with Excel 2016 installed. Excel is activated Version 16.0.4549.1000

Export-ADRExcel : [EXCEPTION] Unable to get the SaveAs property of the Workbook class
At C:\users<username>\Downloads\ADRecon.ps1:12646 char:13

  •         Export-ADRExcel $ADROutputDir
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Export-ADRExcel

Multiple ambiguous overloads found for "Split"

While running ADRecon on windows 7 + powershell 2.0 I saw this error

Multiple ambiguous overloads found for "Split" and the argument count: "2".
At C:\123\ADRecon-master\ADRecon.ps1:4879 char:117
+                 $Obj | Add-Member -MemberType NoteProperty -Name Name -Value
([System.String]::Join(" ", $name.Split <<<< ([System.String[]]$null, [System.S
tringSplitOptions]::RemoveEmptyEntries)))
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Multiple ambiguous overloads found for "Split" and the argument count: "2".
At C:\123\ADRecon-master\ADRecon.ps1:4879 char:117
+                 $Obj | Add-Member -MemberType NoteProperty -Name Name -Value
([System.String]::Join(" ", $name.Split <<<< ([System.String[]]$null, [System.S
tringSplitOptions]::RemoveEmptyEntries)))
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Additional Attributes

Hi, first, thanks so much for making this code available!

Secondly, I’ve been struggling to add other attributes like user accounts’ “info”, the pivot tables don’t seem to like that... would it be possible to understand which lines would have to be modified to include other attributes for computer, group, and user objects without affecting any other part of the script?

Thanks again!

[ISSUE] Script generate following errors

Hi,

Would you have any idea why the following errors occurs ?
I am not proficient in Powershell unfortunately.

"
At D:\powershell\activedirectory\ADRecon.ps1:121 char:86

  • ... "Header header-logged-out position-relative f4 py-3" role="banner" >
  •                                                                      ~
    

Missing file specification after redirection operator.
At D:\powershell\activedirectory\ADRecon.ps1:136 char:21

  •                 ~
    

The '<' operator is reserved for future use.
At D:\powershell\activedirectory\ADRecon.ps1:140 char:21

  •                 ~
    

The '<' operator is reserved for future use.
At D:\powershell\activedirectory\ADRecon.ps1:145 char:21

  •                 ~
    

The '<' operator is reserved for future use.
At D:\powershell\activedirectory\ADRecon.ps1:150 char:21

  •                 ~
    

The '<' operator is reserved for future use.
At D:\powershell\activedirectory\ADRecon.ps1:154 char:21

  •                 ~
    

The '<' operator is reserved for future use.
At D:\powershell\activedirectory\ADRecon.ps1:388 char:185

  • ... TF-8" method="post"><input name="utf8" type="hidden" value="✓" ...
  •                                                             ~
    

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At D:\powershell\activedirectory\ADRecon.ps1:392 char:18

  • Join GitHub today

  •              ~
    

The '<' operator is reserved for future use.
At D:\powershell\activedirectory\ADRecon.ps1:501 char:53

  •                                                 ~
    

Missing file specification after redirection operator.
At D:\powershell\activedirectory\ADRecon.ps1:518 char:17

  •             ~
    

The '<' operator is reserved for future use.
Not all parse errors were reported. Correct the reported errors and try again.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingFileSpecification
"
I have tried with many set of parameters without any change in errors

Thanks

Zoltan

Recycle Bin 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.

Invalid Path

Hi all,

Very silly question here, but I keep getting an invalid path error everytime I try to use the -GenExcel flag.
Is this wrong:
-GenExcel C:/ADRecon-Report/

LDAP bind Unsuccessful

Hi, While running the script just by typing /AdRecon.ps1 gives me following warnings & error.
I am not sure how to even begin to debug. Can you help?

WARNING: Error initializing default drive: 'The server has rejected the client credentials.'.
WARNING: [Invoke-ADRecon] Error importing ActiveDirectory Module from RSAT (Remote Server Administration Tools) ... Co
ntinuing with LDAP
[*] Running on heiway.net\HSTSHEA19097 - Member Server
[Invoke-ADRecon] LDAP bind Unsuccessful
*

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.