Code Monkey home page Code Monkey logo

finduncommonshares's Introduction

The script FindUncommonShares.py is a Python equivalent of PowerView's Invoke-ShareFinder.ps1 allowing to quickly find uncommon shares in vast Windows Active Directory Domains.
GitHub release (latest by date) YouTube Channel Subscribers

Features

  • Only requires a low privileges domain user account.
  • Automatically gets the list of all computers from the domain controller's LDAP.
  • Ignore the hidden shares (ending with $) with --ignore-hidden-shares.
  • Multithreaded connections to discover SMB shares.
  • Export results in JSON with IP, name, comment, flags and UNC path with --export-json <file.json>.
  • Export results in XLSX with IP, name, comment, flags and UNC path with --export-xlsx <file.xlsx>.
  • Export results in SQLITE3 with IP, name, comment, flags and UNC path with --export-sqlite <file.db>.
  • Iterate on LDAP result pages to get every computer of the domain, no matter the size.

Demonstration

Quick win commands

  • List all shares where your current user has WRITE access:

    ./FindUncommonShares.py -u user -p 'Podalirius123!' -d DOMAIN --dc-ip 192.168.1.71 --writable
    
  • Export list of shares in the domain to an Excel file for the client:

    ./FindUncommonShares.py -u user -p 'Podalirius123!' -d DOMAIN --dc-ip 192.168.1.71 --export-xlsx ./examples/results.xlsx
    
  • List all shares with access rights for your current user:

    ./FindUncommonShares.py -u user -p 'Podalirius123!' -d DOMAIN --dc-ip 192.168.1.71 --check-user-access
    

Usage

$ ./FindUncommonShares.py -h
FindUncommonShares v3.0 - by @podalirius_

usage: FindUncommonShares.py [-h] [-v] [--use-ldaps] [-q] [--debug] [-no-colors] [-t THREADS] [-l LDAP_QUERY] [-ns NAMESERVER]
                             [--check-user-access] [--readable] [--writable] [-I] [-i IGNORED_SHARES] [-s ACCEPTED_SHARES]
                             [--export-xlsx EXPORT_XLSX] [--export-json EXPORT_JSON] [--export-sqlite EXPORT_SQLITE] --dc-ip ip
                             address [-d DOMAIN] [-u USER] [--no-pass | -p PASSWORD | -H [LMHASH:]NTHASH | --aes-key hex key] [-k]

Find uncommon SMB shares on remote machines.

options:
  -h, --help            show this help message and exit
  -v, --verbose         Verbose mode. (default: False).
  --use-ldaps           Use LDAPS instead of LDAP.
  -q, --quiet           Show no information at all.
  --debug               Debug mode. (default: False).
  -no-colors            Disables colored output mode.
  -t THREADS, --threads THREADS
                        Number of threads (default: 20).
  -l LDAP_QUERY, --ldap-query LDAP_QUERY
                        LDAP query to use to extract computers from the domain.
  -ns NAMESERVER, --nameserver NAMESERVER
                        IP of the DNS server to use, instead of the --dc-ip.
  --check-user-access   Check if current user can access the share.
  --readable            Only list shares that current user has READ access to.
  --writable            Only list shares that current user has WRITE access to.
  -I, --ignore-hidden-shares
                        Ignores hidden shares (shares ending with $)
  -i IGNORED_SHARES, --ignore-share IGNORED_SHARES
                        Specify shares to ignore explicitly. (e.g., --ignore-share 'C$' --ignore-share 'Backup')
  -s ACCEPTED_SHARES, --show-share ACCEPTED_SHARES
                        Specify shares to show explicitly. (e.g., --show-share 'C$' --show-share 'Backup')

Output files:
  --export-xlsx EXPORT_XLSX
                        Output XLSX file to store the results in.
  --export-json EXPORT_JSON
                        Output JSON file to store the results in.
  --export-sqlite EXPORT_SQLITE
                        Output SQLITE3 file to store the results in.

Authentication & connection:
  --dc-ip ip address    IP Address of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted it will use the
                        domain part (FQDN) specified in the identity parameter
  -d DOMAIN, --domain DOMAIN
                        (FQDN) domain to authenticate to
  -u USER, --user USER  user to authenticate with

Credentials:
  --no-pass             Don't ask for password (useful for -k)
  -p PASSWORD, --password PASSWORD
                        Password to authenticate with
  -H [LMHASH:]NTHASH, --hashes [LMHASH:]NTHASH
                        NT/LM hashes, format is LMhash:NThash
  --aes-key hex key     AES key to use for Kerberos Authentication (128 or 256 bits)
  -k, --kerberos        Use Kerberos authentication. Grabs credentials from .ccache file (KRB5CCNAME) based on target parameters. If
                        valid credentials cannot be found, it will use the ones specified in the command line

Exported results

Each JSON entry looks like this:

{
    "computer": {
        "fqdn": "TDC01.DOMAIN.local",
        "ip": "192.168.1.71"
    },
    "share": {
        "name": "IPC$",
        "comment": "Remote IPC",
        "hidden": true,
        "uncpath": "\\\\192.168.1.71\\IPC$\\",
        "type": {
            "stype_value": 2147483651,
            "stype_flags": [
                "STYPE_IPC",
                "STYPE_TEMPORARY"
            ]
        },
        "access_rights": {
            "readable": true,
            "writable": false
        }
    }
}

Credits

finduncommonshares's People

Contributors

lefayjey avatar p0dalirius avatar pedroflor avatar sqglsec avatar xybytes 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

finduncommonshares's Issues

[bug] Unable to authenticate using a NT hash

Hi,

Thank you for this tool!

I am trying to authenticate using a NT hash but for unknown reasons I am unable to format my command in a way this tool accepts. I have tried different syntax but so far none works. Including the one that is outputted in the the error message (which does not make sence). What is the correct syntax? If this is a bug, perhaps Kerberos authentication should be verified as well.

shares1

[bug] Output File Doesn't Respect Flags

When using certain flags, such as --ignore-hidden-shares or --readable, the exported output file does not seem to adhere to the specified filters. For instance, as demonstrated in the attached image, despite activating the --ignore-hidden-shares and --readable flags, the output includes all shares. This includes shares to which I lack read access, and hidden shares like C$. Is this the intended behavior?

share01

share02

Add additional logging to know which DNS Names are failing to resolve.

Ran into this issue today where nothing was resolving. While troubleshooting I added the target_name to the --debug output to help. Figured someone else may find it useful as well. Pull request incoming. Trash it if you don't think it's useful. :)

python3 FindUncommonShares.py -u administrator -p 'REDACTED' --dc-ip 192.168.1.20 --debug
FindUncommonShares v3.0 - by @podalirius_

[>] Extracting all computers ...
[+] Found 7 computers in the domain. 

[>] Enumerating shares ...
[!] Could not resolve user.lab.local

[>] Skipping common share 'ADMIN$' on 'ws01.lab.local' (comment: 'Remote Admin') 
[>] Skipping common share 'C$' on 'ws01.lab.local' (comment: 'Default share') 
[>] Skipping common share 'IPC$' on 'ws01.lab.local' (comment: 'Remote IPC') 
[>] Found 'Temp' on 'ws01.lab.local' 
[>] Skipping common share 'ADMIN$' on 'dc01.lab.local' (comment: 'Remote Admin') 
[>] Skipping common share 'C$' on 'dc01.lab.local' (comment: 'Default share') 
[>] Skipping common share 'IPC$' on 'dc01.lab.local' (comment: 'Remote IPC') 
[>] Skipping common share 'NETLOGON' on 'dc01.lab.local' (comment: 'Logon server share ') 
[>] Skipping common share 'SYSVOL' on 'dc01.lab.local' (comment: 'Logon server share ') 
[+] Bye Bye!

[bug] Issue when attempting to run with password authentication

Running FindUncommonShares.py with password-based authentication results in an authentication invalid error due to the logic in the sectools/windows/ldap.py library. Currently, the condition check on line 169 of the ldap.py library gets triggered when no hashes are supplied to FindUncommonShares.py because the nthash and lmhash variables are passed as empty strings instead of 'None' type.

error

Removing the condition checks for nthash is not None and lmhash is not None in line 169 of the ldap.py library resolves the issue but I'm not sure if these conditions should be kept.

Running FindUncommonShares.py after removing the two conditional checks mentioned above results in the tool running as expected.

success

[bug] ValueError: max_workers must be greater than 0, when no computer object is found

[>] Extracting all computers ...
[+] Found 0 computers in the domain.

[>] Enumerating shares ...
Traceback (most recent call last):
  File "./FindUncommonShares.py", line 648, in <module>
    with ThreadPoolExecutor(max_workers=min(options.threads, len(computers.keys()))) as tp:
  File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 104, in __init__
    raise ValueError("max_workers must be greater than 0")
ValueError: max_workers must be greater than 0

[enhancement] Change colors of output

Hi!
I'll like to suggest changing slightly the color schema for the access types:

access: $\color[rgb]{1,0,0} WRITE$
access: $\color[rgb]{0,1,0} READ$
access: $\color[rgb]{1,1,0} DENIED$

I you like, I can make the changes and submit a pull request.

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.