# SQL Server

### Create a SQL User

1. Login to `DC03` as the `Administrator` user with password `Welcome01!`.
2. Open the "Server Manager" and open the "Active Directory Users and Computers" tool in the tool section.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F69ksSg3HpSkrQ43mJFWX%2Fimage.png?alt=media&#x26;token=3d1cd938-85eb-4aaa-b65b-6c0cfdab125d" alt=""></div>

3\. Expand the "secure.local" directory, right click on "User" and select "New" and "User".

4\. Create a user with the name `sa_sql`.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fri7SlxsWFiTcQLvJzhCC%2Fimage.png?alt=media&#x26;token=f2ce1a3d-58ed-4816-bddf-5981dd6c4044" alt=""></div>

5\. Set the password "`Iloveyou2`" and create the user.&#x20;

6\. Open the tab "Account" and select "Password never expires" under "Account options".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Ffci490UDhtEDXrP7lkt7%2Fimage.png?alt=media&#x26;token=03b0fd28-133d-454d-8c3d-edc33de523cc" alt=""></div>

### Installing SQL Server

1. Login to `DATA01` as the `Administrator` user with password `Welcome01!`.
2. Download SQL Server 2019 from [Microsoft Evaluation Center](https://www.microsoft.com/en-us/evalcenter/evaluate-sql-server-2019).

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FtiUt1G4c8oDeErXA0X29%2Fimage.png?alt=media\&token=f006aeed-a044-4fc3-a96b-6649248d338f)

3\. When smartscreen comes up select "Run".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FtbHmRcKannK1CCmQ0e8c%2Fimage.png?alt=media&#x26;token=da5d9bf9-19f0-4359-91d4-efeed5dc7453" alt=""></div>

{% hint style="info" %}
The SQL Server Installation may require internet access, temporally add a second adapter in the machine settings and select the NAT network. The machine should have internet access. (ps our first adapter is different since our lab runs on a ESXI host).

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F8OA7HNRvbPzvkOOBySWT%2Fimage.png?alt=media\&token=a90b7409-c674-4ca8-a4a3-c17a9cc4dfd8)
{% endhint %}

4\. On "Select an installation type" select "Basic":

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FG3Iuix7UeExolESakWSj%2Fimage.png?alt=media&#x26;token=c9e7ea51-ef8c-4a98-a1e9-ab32894136a9" alt=""></div>

5\. Accept the License Terms and click "Install".

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F0zEZBrGMu6i8Htio1Ulv%2Fimage.png?alt=media\&token=793c3564-c62c-4dc5-a2ca-43b586ea6e27)

6\. Once the installation is finished, click on "Customize".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F5zRvhnYzSiDIQUjRSQNJ%2Fimage.png?alt=media&#x26;token=ba30ffc8-8c76-46e5-bb77-b9c4fad3b59c" alt=""></div>

8\. Click next till the "License Terms" step.

7\. Check "Use Microsoft Update to check for updates" and click next till the step "License Terms" and accept them:

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F6BwrN2zQQd0fjKijO7Uo%2Fimage.png?alt=media\&token=31d37867-8b78-4c73-82ca-d4250edb7e2c)

8\. At the step "Feature Selection" choose the following options:

* Database ENgine Services
* SQL Server Replication
* Client Tools Connectivity
* Client Tools SDK

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FwugtYqUPphOSiNAAYo48%2Fimage.png?alt=media&#x26;token=133b4b12-89d9-4b44-9742-01a5ec9ef436" alt=""></div>

9\. Click Next and fill in the Instance name `data`.

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FcuajSsO7cYXksRLEfCtr%2Fimage.png?alt=media\&token=b26ccf02-8491-40fe-aad5-a396fba2448f)

10\. Change the "Startup Type" for the "SQL Server Agent" to "Automatic" and make sure all three are set to "Automatic". Then change the account name for "SQL Server agent" and "SQL Server Database Engine" to `sa_sql` and fill in the password `Iloveyou2`.

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fl252iDyaJgQnEFBnqaLr%2Fimage.png?alt=media\&token=3acbf072-6ab9-4812-b322-55eb7e260200)

11\. At the next step select "Windows authentication mode". Then select "Add" at the "Specify SQL Server administrators" and add `secure\administrator` then click "Next".&#x20;

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FfNLVOAcuHvUAMRpm618t%2Fimage.png?alt=media&#x26;token=782ff201-cbfd-48cd-a0b7-f8fc4bacfc16" alt=""></div>

12\. Click "Install" and wait for the installation to finish.

13\. Open the "SQL Configuration Manager".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FOSijVvFiMdU855k5Ib4U%2Fimage.png?alt=media&#x26;token=7f48cc57-bdf1-448d-aa57-6f7a4999e238" alt=""></div>

14\. Expand "SQL Server Network Configuration" and select "Protocols for DATA". Double click on "TCP/IP" and select the "IP Addresses" tab. Fill in `1433` for "TCP Port".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F6QSaCtWSY4TKoekI7mTK%2Fimage.png?alt=media&#x26;token=118d768e-82f8-4760-9867-b867007e63d3" alt=""></div>

15\. Scroll to the bottom and also configure IPAll:

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FyI8QKNuFynf39oVHfNj2%2Fimage.png?alt=media&#x26;token=e229f388-1f1e-4d67-b638-c0c2fb27488e" alt=""></div>

15\. Then click "Apply".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FT2RplHyPoLgY917eAyT4%2Fimage.png?alt=media&#x26;token=ff3679d7-58e9-488b-a1f4-bcc0bd5e1b77" alt=""></div>

16\. Open "SQL Server services" and right click on "SQL Server (DATA)" and click "Restart".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FU0rRzlclPYel1RQSSLXH%2Fimage.png?alt=media&#x26;token=3cab22d9-5597-48db-9557-a44b78197224" alt=""></div>

17\. Do the same for "SQL Server Agent".

18\. Download and Install [SQL Server Mangement Studio](https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?redirectedfrom=MSDN\&view=sql-server-ver15). Just Click "Install" and reboot the system.

### Configuring Windows Firewall for SQL Server

1. Search for "Windows Defender Firewall with Advanced Security" and select "Windows Defender Firewall with Advanced Security".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F0jYKacwWIfmF2N7Hpb6m%2Fimage.png?alt=media&#x26;token=b6c08527-1b40-4380-b3b7-fc3081d2c422" alt=""></div>

2\. Right click on "Inbound Rules" and select "New rule".

3\. Select "Port" and click "Next".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FTSua2MRXTvUXIlQSSWya%2Fimage.png?alt=media&#x26;token=8b6ffe4f-7506-4377-bac5-cd575425cc4a" alt=""></div>

4\. Make sure "TCP" is selected and fill in port `1433` and click "Next":

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FJ9tHABc9FLHAGrDK6u4r%2Fimage.png?alt=media&#x26;token=3809abbc-a42d-4ad5-aebe-e4b12ea7b9de" alt=""></div>

5\. Click next at the step "Profile". Fill in the name "Allow TCP 1433 MSSQL Server for all" and click "Finish".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Fcdr1iSwWcPE1I9N8ZfZz%2Fimage.png?alt=media&#x26;token=4385d724-761d-47a0-9ddc-88dbc41b9118" alt=""></div>

### Testing connectivity

1\. Open the Kali machine and run a quick Nmap to check if the port is open:

```
sudo nmap -p 1433 10.0.0.101 -Pn -n
Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-14 18:14 CET
Nmap scan report for 10.0.0.101
Host is up (0.0100s latency).

PORT     STATE SERVICE
1433/tcp open  ms-sql-s

Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds
                                                             
```
