If you have network access to an Active Directory (AD) environment but do not have a domain session, you can still perform enumeration to gather information about the AD infrastructure. This can be useful for reconnaissance purposes or when conducting a penetration test.
#### Enumerating SQL Server instances
One way to gather information is by enumerating SQL Server instances within the AD environment. SQL Server instances often contain valuable information, such as user credentials or sensitive data.
To enumerate SQL Server instances, you can use tools like `sqlcmd` or `osql` to connect to the SQL Server service and query for available instances. The following command can be used:
```plaintext
sqlcmd -S <server_name> -U <username> -P <password> -Q "SELECT name FROM sys.sysdatabases"
```
Replace `<server_name>`, `<username>`, and `<password>` with the appropriate values. This command will retrieve the names of the databases hosted on the SQL Server instance.
#### Enumerating SQL Server linked servers
Another technique is to enumerate SQL Server linked servers. Linked servers allow SQL Server to access data from other data sources, which can include other SQL Server instances or even non-SQL Server databases.
To enumerate linked servers, you can query the `sys.servers` table in the `master` database. The following command can be used:
Replace `<server_name>`, `<username>`, and `<password>` with the appropriate values. This command will retrieve the names and data sources of the linked servers configured on the SQL Server instance.
#### Enumerating SQL Server databases
If you have access to a SQL Server instance, you can also enumerate the databases hosted on that instance. This can be done by querying the `sys.databases` table in the `master` database. The following command can be used:
```plaintext
sqlcmd -S <server_name> -U <username> -P <password> -d master -Q "SELECT name FROM sys.databases"
Replace `<server_name>`, `<username>`, and `<password>` with the appropriate values. This command will retrieve the names of the databases hosted on the SQL Server instance.
By enumerating SQL Server instances, linked servers, and databases, you can gather valuable information about the AD environment and potentially identify vulnerabilities or misconfigurations that can be exploited during a penetration test.
When conducting a penetration test or security assessment, it is important to gather as much information as possible about the target Active Directory (AD) environment. Enumerating from inside the domain allows for a deeper understanding of the network and potential vulnerabilities.
- **SQL Server Browser Service**: The SQL Server Browser service listens on UDP port 1434 and provides information about SQL Server instances running on the network. By querying this service, it is possible to obtain a list of SQL Server instances and their corresponding ports.
- **SQL Server Configuration Manager**: The SQL Server Configuration Manager is a Microsoft Management Console (MMC) snap-in that provides a graphical interface for managing SQL Server services and network protocols. It can be used to view and modify the configuration settings of SQL Server instances.
- **SQL Server Discovery**: By sending UDP packets to port 1434, it is possible to discover SQL Server instances running on the network. This can be done using tools like `sqlcmd` or `osql`.
Once the SQL Server instances have been enumerated, further analysis can be performed to identify potential vulnerabilities or misconfigurations that could be exploited.
After identifying the SQL Server instances, the next step is to enumerate the databases hosted on each instance. This can be done using various methods, such as:
- **SQL Server Management Studio (SSMS)**: SSMS is a graphical tool provided by Microsoft for managing SQL Server. It can be used to connect to a SQL Server instance and view the list of databases.
- **SQL Server Management Studio(SSMS)**:SSMS是由Microsoft提供的用于管理SQL Server的图形工具。可以使用它连接到SQL Server实例并查看数据库列表。
- **SQL Server Command Line Tools**: Tools like `sqlcmd` or `osql` can be used to execute SQL queries against a SQL Server instance and retrieve information about the databases.
- **SQL Server Information Schema**: The SQL Server Information Schema is a set of views that provide information about the tables, columns, and other database objects within a SQL Server database. Queries can be executed against these views to retrieve metadata about the databases.
By enumerating the SQL Server databases, it is possible to gather valuable information about the data stored within the AD environment, such as sensitive information or potential targets for further exploitation.
To access a MSSQL database, you can use various methods:
- **SQL Server Management Studio (SSMS):** This is the official graphical tool provided by Microsoft to manage MSSQL databases. It allows you to connect to a remote MSSQL server and access the databases.
- **Command Line Tools:** MSSQL provides command line tools such as `sqlcmd` and `osql` that allow you to execute SQL queries and commands directly from the command prompt.
- **Programming Languages:** You can use programming languages like Python, Java, or C# to connect to a MSSQL database and perform operations on it.
- **Third-Party Tools:** There are also third-party tools available that provide additional features and functionalities for working with MSSQL databases.
To access a MSSQL database, you will need the following information:
- **Server Name:** The name or IP address of the MSSQL server you want to connect to.
- **Authentication Method:** MSSQL supports two authentication methods: Windows Authentication and SQL Server Authentication. Windows Authentication uses the credentials of the currently logged-in Windows user, while SQL Server Authentication requires a username and password.
Get-SQLQuery -Instance "sql.domain.io,1433" -Query 'SELECT * FROM OPENQUERY("sql2.domain.io", ''SELECT * FROM sys.configurations WHERE name = ''''xp_cmdshell'''''');'