# Normal domain user access

## Configuring

### Prerequisite&#x20;

{% content-ref url="../../../initial-access-attacks/username-enumeration" %}
[username-enumeration](https://ad-lab.gitbook.io/building-a-windows-ad-lab/vulnerabilities-and-misconfigurations-and-attacks/initial-access-attacks/username-enumeration)
{% endcontent-ref %}

### Configuring

1. Login to `WEB01` as the `Administrator` user with password `Welcome01!`.
2. Open "Microsoft SQL Server Management Studio"

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fzd1yAMluQFrPc7My55l3%2Fimage.png?alt=media&#x26;token=3d64e8ac-d1b8-4972-93e2-686b13393a46" alt=""></div>

3\. Login with the `Administrator` user using Windows Authentication.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fn4D48s963sPAYBlZZO8Z%2Fimage.png?alt=media&#x26;token=578358dd-6f27-4f48-ac07-a03d29d64af3" alt=""></div>

4\. Expand the "Security" and "Logins" folders. Right click on "Logins" and click "New Login".

5\. Click on "Search", click "Locations" and expand the directories and click on "Amsterdam.bank.local".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FA3C5qhn08Qkur3mnYmzY%2Fimage.png?alt=media&#x26;token=f18d9937-ade3-4e93-abd2-3a6ed97a0160" alt=""></div>

6\. Fill in "Richard" and click "Check Names".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FoDMtDsPo6kx7THL8DL7O%2Fimage.png?alt=media&#x26;token=478d3c3e-48cc-42ce-a7f0-a164e6e481b4" alt=""></div>

7\. At "Default Database" select "Production".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FDCgZgi49jmxmAdYpIhoy%2Fimage.png?alt=media&#x26;token=4a5920c1-6ff1-401c-aa19-e921dc656e0f" alt=""></div>

8\. Click on "User Mapping" and select "Production".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fu6JQ3iC53p9RVY4suqyb%2Fimage.png?alt=media&#x26;token=2968178c-8e5f-45ad-b48b-740fba6b6b85" alt=""></div>

9\. Click "OK".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Flphx7zGIIHkXbtOHgqQo%2Fimage.png?alt=media&#x26;token=67e744b3-eb80-46c0-b040-e5e8d608ba6e" alt=""></div>

## Attacking

### How it works

Check for MSSQL servers inside the domain and try to login using the credentials from the current user or from another user. Sometimes all Domain Users have access to the database and its even possible that everyone is sysadmin on the database.

### Tools

* [PowerUpSQL](https://github.com/NetSPI/PowerUpSQL)
* [HeidiSQL](https://www.heidisql.com/)

### Executing the attack

#### PowerUpSQL

1. Download PowerUpSQL on the kali machine and host it on a webserver:

```
wget https://raw.githubusercontent.com/NetSPI/PowerUpSQL/master/PowerUpSQL.ps1
python3 -m http.server 8090
```

2\. Login to `WS01` as `Richard` with the password `Sample123`.

3\. Start PowerShell and download and execute an amsi and PowerUpSQL in memory:

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FVahjXeZoFDRRHIjSV0k1%2Fimage.png?alt=media&#x26;token=f47b2611-a3ca-4b2c-b749-b4f75582de6e" alt=""></div>

4\. Get the SQL instances from the domain:

```
Get-SQLInstanceDomain
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F0DDic8V406kiU1diXpZ7%2Fimage.png?alt=media&#x26;token=5c82529e-b466-4e12-8bfb-9a029e236e1f" alt=""></div>

The output shows one SQL Instance.

5\. Get the SQL instances from the domain and check access:

```
Get-SQLInstanceDomain | Get-SQLConnectionTestThreaded
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FDYiFTomSuBsHA9tLCJJr%2Fimage.png?alt=media&#x26;token=0235cd02-d575-4894-9bcc-448385c5c397" alt=""></div>

The output shows that we can access the MSSQL instance `WEB01.amsterdam.bank.local`.

If ran from a user that doesn't have access (for example John), it says `not accessible`.

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FhHdLdHEB9h5WBLzs7V8R%2Fimage.png?alt=media\&token=a946f2e9-3949-4b82-acc4-ba0b947fffd2)

6\. To get more info about the session on the SQL server run:

```
Get-SQLServerInfo -Instance WEB01.amsterdam.bank.local
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FsZKdnR0bfgLIEAx7QdCR%2Fimage.png?alt=media&#x26;token=ba065904-52a1-4521-82f9-cdaa08f4c93f" alt=""></div>

It shows that we aren't sysadmin. Which means we can't execute commands on the database, but our user has access to the database. So we can look into the database for sensitive information or we might be able to escalate our privileges to sysadmin.

#### Connecting with HeidiSQL

1. Download [HeidiSQL](https://www.heidisql.com/download.php?download=portable-64) on `WS01`.
2. To execute SQL queries and look into the database start heidiSQL.
3. Click on "New" on the left bottom and configure the following settings:

* Network Type: `Microsoft SQL Server (TCP/IP)`
* Library: `SQLOLEDB`
* Hostname / IP: `WEB01.amsterdam.bank.local`
* Select: "Use Windows Authentication"
* Port: `1433`

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fg7It7g7p7dAxdo2DueH2%2Fimage.png?alt=media\&token=e9ae385f-1417-46d4-83ca-8d1af28b6401)

4\. Click "OK" on the security Issue warning.

5\. Click on the databases on the left and see if we got access to any:

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fpo37MfnBXiK1RKDCuR1b%2Fimage.png?alt=media&#x26;token=c1cd80c2-d215-46ab-a714-12f94522f98b" alt=""></div>

We are able to access the Production database, but not the Development one.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FzHHyMlY02m9F8KAZExxi%2Fimage.png?alt=media&#x26;token=ea2ab435-9021-4f81-a75d-adbd671b71c2" alt=""></div>

## Defending

### Recommendations

* Periodically audit who has access to which SQL servers / databases etc.

### Detection

## References

{% embed url="<https://github.com/NetSPI/PowerUpSQL>" %}

{% embed url="<https://www.heidisql.com>" %}
