HaKieuOanh LAB8
HaKieuOanh LAB8
1. On the desktop, press the key combination Win + R then enter WF.msc and select
OK.
- In the Windows Firewall with Advanced Security section, select the Inbound Rules
tab on the left, then click New Rule.
Create user1 to log in to SQL, right-click Security, select new -> login
Select SQL Server authentication, Enter Login name, Password and click OK
In Lab5 database, right-click Security, select new -> user
Select the Permissions tab, click Search, enter the user name and click Check Names Click
OK to continue
Tick the permissions we want to grant to user1 (select, insert) and press OK
Turn off SQL Server Management Studio, restart and reconnect using the user1 account
Execute query to check the access rights assigned to user1 Select permission, run the select
statement and observe the results select employeeName, email, phone from tblEmployee
So user1 has the right to select, continue with the right to insert, run the sql statement and
observe the results
insert into tblEmployee(employeeName,email,phone)
values('khanh','khanh@gmail.com','0284916472')
So user1 also has the insert right. Let's try the delete right, a right that user1 is not assigned.
Run the delete command and observe the results. delete from tblEmployee where
employeeName='khanh'
Revocation of rights
Disconnect and connect the database using the admin account to revoke user1's rights.
Revoke user1's insert rights by following the same steps as assigning rights and unchecking
insert rights.
Turn off SQL Server Management Studio, restart and reconnect using user1 account, execute
the insert statement and observe the results: insert into
tblEmployee(employeeName,email,phone) values('tri','tri@gmail.com','0284916472')
We see that user1 no longer has insert rights on the tblEmployee table
Check permissions
To check the rights of users on the tblEmployee table, we can repeat the steps in
the rights assignment section to observe the assigned rights of each user. Or run the
databasename nchar(50),
nchar(50), grantor
nchar(10), username
nchar(10), privilege
nchar(10)
)
insert into @tblTemp EXEC
sp_table_privileges @table_name =
Result:
Run each of the following commands in turn to create a filter for the tblEmployee table
Step 1:
GO
RETURNS TABLE
WITH SCHEMABINDING
AS
Step 2:
ON dbo.tblEmployee
WITH (STATE = ON);
Step 3:
password char(20) )
product_description char(50),
category char(20) )
Add data to the table:
SQLi in SELECT statement:
SQLi with UNION:
select * from products where category='gift'; drop table users--
Note: Use any database, in this section use a database named University
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD =‘VeryStrongPassword’;
GO
2. Create a certificate
Now that we have the DMK in the main database, we can generate keys and certificates
then encrypt them with the DMK. Command to create certificate:
USE master;
3. BackupCertificate
This is extremely important because if you lose your certificate, you lose all your data,
period. That's why, the safest way is to backup immediately after you create a certificate.
The command to backup:
GO
4. Create Database Encryption Key
It's time to create our master key, the Database Encryption Key. A certificate in the main
database will protect DEK, and DEK will encrypt data on every page. Command to create
DEK:
Use University
GO
Open the log file, view the logs on the computer and test for error cases.
Step 1: click view on the task bar, select object Explorer F8:
Step 2: After SQL Explorer appears, find the SQL Server Logs folder as shown in the
image, right-click on the folder, select view SQL server Log
Step 3: All logs appear, including time, source, and information for each log:
Step 4: Perform log testing in SQL server. Here, we will create a user with the username
'teacher2' and password: 123.
Step 5: Login this user into sql server. We use the sqlcmd command in windows cmd with the
user teacher2 but the password will be entered incorrectly:
Step 6: Reopen sql server logs to see the changes:
Step 7: We can also view other logs about Windows NT and database mail.