Database System Security Workbook
Database System Security Workbook
STUDENT NAME
REG. NO
YEAR
SEMESTER
SECTION
FACULTY
LABORATORY WORKBOOK
4
21CS3260R DATABASE & SYSTEMS SECURITY
Table of Contents
6. Hashing in Oracle...........................................................54
4
21CS3260R DATABASE & SYSTEMS SECURITY
The laboratory framework includes a creative element but shifts the time-intensive
aspects outside of the Two-Hourclosed laboratory period. Within this structure, each
laboratory includes three parts: Prelab, In-lab, and Post-lab.
a. Pre-Lab
The Prelab exercise is a homework assignment that links the lecture with the
laboratory period - typically takes 2 hours to complete. The goal is to synthesize the
information they learn in lecture with material from their textbook to produce a
working piece of software. Prelab Students attending a two-hour closed laboratory
are expected to make a good-faith effort to complete the Prelab exercise before
coming to the lab. Their work need not be perfect, but their effort must be real
(roughly 80 percent correct).
b. In-Lab
The In-lab section takes place during the actual laboratory period. The First hour of
the laboratory period can be used to resolve any problems the students might have
experienced in completing the Prelab exercises. The intent is to give constructive
feedback so that students leave the lab with working Prelab software - a significant
accomplishment on their part. During the second hour, students complete the In-lab
exercise to reinforce the concepts learned in the Prelab. Students leave the lab
having received feedback on their Prelab and In-lab work.
c. Post-Lab
The last phase of each laboratory is a homework assignment that is done following
the laboratory period. In the Post-lab, students analyse the efficiency or utility of a
given system call. Each Post-lab exercise should take roughly 120 minutes to
complete.
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sl (50M Signatur
Date Experiment Name (5M) (5M)
No LOGIC EXECUTION RESULT ANALYSIS ) e
(10M) (10M) (10M) (5M)
10
11
12
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of roles and privileges in a database.
To understand and implement the concept of data manipulation and authorization
in a database.
PRE-REQUISITE:
In lab, you do not have the admin access to the server and hence cannot perform the
required essential operations.
So, configure using the ‘Net Configuration Assistant’ and create an alias to connect to the
oracle instance. The steps to do so are mentioned below-
Go to the ‘Oracle’ folder in the start menu Click on ‘Net Configuration Assistant’ Click
on ‘Other Choices’ when asked to login and click on the ‘Samyak’ user and login using the
password ‘klu@123’ Choose ‘Local Net Service Name Configuration’ Choose ‘Add’
Service Name: orcl Choose ‘TCP’ Host Name: desktop-t11csnm (or) 10.30.11.121(may
be subject to change. Ask the server admin for details if the aforementioned Host Names
don’t work) Choose ‘Yes, perform a test’ Net Service Name: dbs Click ‘No’.
4
21CS3260R DATABASE & SYSTEMS SECURITY
Pre-Lab:
Sol)
Sol)
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
them.
Sol)
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. Create a user with a default tablespace, temporary tablespace and with a 2M quota.
Q2. Alter the earlier created user and change his password as well as lock his account.
NOTE – The account is now locked. Unlock it using the alter command again.
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q4. PayrollSpecialist - this group of employee needs to create a session and is responsible
for working with all of the Employee data. Create this role using SQL.
Q5. Provide system and object privileges to the role created earlier.
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q6. Grant the earlier created role (with the added privileges) to the earlier created user.
Q7. Now you will test if the earlier created user can SELECT from the hr.EMPLOYEES table.
Display all the employees with the last name ‘Smith’.
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Q1. Connect to any database as SYS user and grant him SYSDBA privilege.
Sol)
Q2. Write a query to retrieve all the columns of data from V$PWFILE_USERS view.
Sol)
Q3. Create a role named appaccess and grant the ability to read the application tables to
that role.
Sol)
Q4.Create a role create_session_role that will have only one privilege CREATE SESSION in
order to connect to an ORACLE database.
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q6.Create the user secadm and grant him password protected create_session_role
Sol)
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of backups using Oracle.
To understand and implement the concept of database recovery and restoring in
Oracle.
Pre-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. Enable ARCHIVELOG mode and change flash recovery area size using SQL.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q3. Write a query to list details about all the database users
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of triggersfor database security.
To understand and implement the concept of restricting access using triggers.
Pre-Lab:
Q1. What is a trigger in sql? What all events are triggers written to be executed in
response to?
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. Create a table ‘emp_data_labtrig’ with the columns ‘eno’, ‘ename’, ‘job’, ‘hire_day’
and ‘salary’ and insert the following data:
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q3. Fire the trigger ‘labtrig’ and test whether it works by deleting the row where the
employee name is ‘Kay’ and check the ‘emp_backup_labtrig’ table and write the output.
(That means you have to delete the required row and display emp_backup_labtrig to see if
the deleted row has been copied into the table successfully.)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
--------------------------------------------------------------------------------------------------------------------------
Q4. Create a table ‘rest_table’ and create a trigger ‘restrictions’ that does not let a user
change the content of the table during working hours (8 am to 6 pm) and during a
Thursday or a Friday.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q5. Test the trigger by trying to delete the row where employee name is ‘Jay’ and write
the output.
Sol)
--------------------------------------------------------------------------------------------------------------------------
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Sol)
Q2. Create a trigger ‘restrict_dummy’ on update/delete that will turn the attempted
operation around and reject it.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q3. Test the trigger ‘restrict_dummy’ by updating the record where LOC is York to New
and write the output.
Sol)
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of triggersfor database security.
To understand and implement the concept of auditing using triggers.
Pre-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. Create a table ‘emp_data_labtrig2’ with the column ‘eno’, ‘ename’, ‘job’, ‘hire_day’
and ‘salary’ and insert the following data:
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q3. Fire the trigger ‘labtrig2’ and test whether it works by updating the row where the
employee name is ‘Kay’ and check the ‘emp_backup_labtrig2’ table and write the output.
(That means you have to update the required row and display emp_backup_labtrig2 to see
if the updated row has been copied into the table successfully.)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
--------------------------------------------------------------------------------------------------------------------------
Flow of the program – (from Q4 to Q6)
Create trigger ‘auditDEPTAR’ that audits according to given requirements and stores the
output in ‘deptaudit’ table.
Test the trigger by inserting data and display the ‘deptaudit’ table.
Dept table -
4
21CS3260R DATABASE & SYSTEMS SECURITY
CHANGED_TIME DATE
Sol)
Q5. Create a trigger ‘auditDEPTAR’ that audits the operations performed on the ‘dept’
table.
The trigger should work after any insert, update or delete operation.
It must log those operations in a table called ‘deptaudit’. It should display ‘I’ for insert, ‘U’
for update and ‘D’ for delete.
It must also log the data (i.e. ‘deptno’, ‘dname’, ‘loc’) as well as who changed the data and
when it was changed.
Sample Output-
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q6. Display the audit table after insertion of data and write the output.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Q1. Create a table ‘bank_transactions’ with the column ‘TID’, ‘TNO’, ‘NAME’, ‘CREATOR’
and insert the following data:
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q3. Fire the trigger ‘labtrig22’ and test whether it works by updating the row where the
name is ‘James’ and check the ‘bank_transactions_audit’ table and write the output.
(That means you have to update the required row and display bank_transactions_audit to
see if the updated row has been copied into the table successfully.)
Sol)
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of Java Cryptography.
To understand and implement the concept of Digital Signature generation.
Pre-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q4.Why is the KeyPairGenerator class used in java cryptography and what are the steps to
create KeyPairGenerator Class?
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. Generate the Digital Signature of the file sample.txt and store the output in
sample1.txt using java.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Sol)
Q2. Grant create procedure, create table, create view system priviliges to appsec_role.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Q4. To run an application, we will create an application user, appusr. numerous people
will use an application, and the application will connect all of them to Oracle as our one
big application user. Write a query that they do not need individual person accounts and
passwords for this access
Sol)
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
6. Hashing in Oracle
Learning Outcomes:
To understand and implement the concept of use of hashing for database security.
To understand and implement the concept of hashing in Oracle.
Pre-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Q4. What are the different cryptographic hash algorithms present in DBMS_CRYPTO?
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Create function ‘get_hash’ to hash given username and password using specified
algorithm.
Create procedure ‘add_user’ which executes ‘get_hash’ function and stores the
given username and hashed password in the table ‘app_users’.
Display table ‘app_users’ which has username and hashed password from
‘add_user’ procedure.
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q1. Create a table ‘app_users’ with the following columns: id, username, password. ‘id’ is
the primary key and ‘username’ is unique.
Sol)
Sol)
Q3. Grant execute on dbms_crypto package to the user to be able to use that to hash.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q4. Create a function ‘get_hash’ (which uses dbms_crypto) in PL/SQL to hash the given
username and password using SH1 algorithm.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q5. Create a procedure ‘add_user’ which executes the ‘get_hash’ function and stores the
given username and hashed password in the table ‘app_users’.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q6. Execute the function ‘add_user’ with inputs as ‘labtest’ (for username) and ‘labtest1’
(for password) and display the table ‘app_users’ from Q5.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Q1. Create a function ‘get_hash’ (which uses dbms_crypto) in PL/SQL to hash the given
username and password using MD4 algorithm.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q2. Execute the function ‘add_user’ with inputs as ‘labtest2’ (for username) and
‘labtest12’ (for password) and display the table ‘app_users’.
Sol)
Q3. Create a function ‘get_hash’ (which uses dbms_crypto) in PL/SQL to hash the given
username and password using MD5 algorithm.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q4. Execute the function ‘add_user’ with inputs as ‘labtest3’ (for username) and
‘labtest123’ (for password) and display the table ‘app_users’.
Sol)
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of hashing in Oracle.
To understand and implement the concept of validation using hashing in Oracle.
Pre-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Create function ‘get_hash’ to hash given username and password using specified
algorithm.
Create procedure ‘add_user’ which executes ‘get_hash’ function and stores the
given username and hashed password in the table ‘app_users’.
Display table ‘app_users’ which has username and hashed password from
‘add_user’ procedure.
Create a procedure ‘valid_user’ that validates the given credentials using the
‘get_hash’ function and ‘app_users’ table.
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q1. Drop the table ‘app_users’ created in the previous lab and create a table ‘app_users’
with the following columns: id, username, password. ‘id’ is the primary key and
‘username’ is unique.
Sol)
Q2. Drop the sequence created in the previous lab and create a sequence ‘app_users_seq’.
Sol)
Q3. Similar to the previous lab, grant execute on dbms_crypto package to the user to be
able to use that to hash.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q4. Similar to the previous lab, create a function ‘get_hash’ in PL/SQL to hash the given
username and password usingSH1 algorithm.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q5. Similar to the previous lab, create a procedure ‘add_user’ which executes the
‘get_hash’ function and stores the given username and hashed password in the table
‘app_users’.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q6. Execute the function ‘add_user’ with inputs as ‘labtest’ (for username) and ‘labtest1’
(for password) and display the table ‘app_users’ from Q5.
Sol)
Q7. Create a procedure ‘valid_user’ that will check if the username and password given as
input by user is valid or not by checking with the previously stored values in the
‘app_users’ table and validating.
Username 1 – labtest
Password 1 – labtest1
------------------------------
Username 2 – labtest1
Password 2 – labtest2
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q3. Create a role named hrview_role. Through that role we will grant access to the data
needed by a variety of applications that we plan to build. At the outset, we only want
folks who are on our internal network to access this data, and only during our normal
office hours of 7 AM to 7 PM
Sol)
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of hashing using Oracle.
To understand and implement the concept of hashing data in transit in Oracle.
Pre-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Sol)
Q5. How many bits does the hash value of MD5 have?
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. You are a database security consultant for a company. The company has given you the
task of creating a registration page which takes username and password as inputs and
stores the hashed value of the password in a database table. You plan to store the hash
value of the password in the database. The hashing is done using MD5. You are to
implement this using Javascript.
First, create a html page with the username and password fields. Once the credentials are
given as input and submit button is pressed, the javascript program in the background will
hash the password and store it in the database along with the username.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Q1. You are a database security consultant for a company. The company has given you the
task of creating apage which takes username, password and gender as inputs and stores
the hashed value of the password, gender in a database table. You plan to store the hash
values of the password, gender in the database. The hashing is done using MD5. You are
to implement this using Javascript.
First, create a html page with the username, password and gender fields. Once the details
are given as input and submit button is pressed, the javascript program in the background
will hash the password, gender and store it in the database along with the username and
original value of gender.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of hashing using Oracle.
To understand and implement the concept of hashing data in transit in Oracle.
To understand and implement the concept of validating data in transit in Oracle.
Pre-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Q4. What method of java can you use to check if two strings are equal?
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. You are a database security consultant for a company. The company has given you the
task of creating a login page which takes username and password as inputs and hashes
the password and compares it with the previously stored hash value (from previous lab)in
the database table and validates it. The hashing is done using MD5. You are to implement
this using Javascript.
First, create a html page with the username and password fields. Once the credentials are
given as input and submit button is pressed, the javascript program in the background will
hash the password and compare it with the previously stored value in the database.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Q1.Toggle Between Roles
You can see the effects of running SET ROLE by observing your current session roles as you
toggle back and forth between create_session_role and secadm_role. As secadm user, do
this and observe the list of roles when you do each SELECT query:
i) SELECT * FROM sys.session_roles;
ii) SET ROLE create_session_role;
iii) SELECT * FROM sys.session_roles;
iv) EXECUTE sys.p_check_secadm_access;
v) SELECT * FROM sys.session_roles;
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of encryption using Oracle.
To understand and implement the concept of encrypting data in transit in Oracle.
Pre-Lab:
Sol)
Q2. What are the different packages available in Java Cryptography API?
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. You are a database security consultant. You want to store some confidential
information in your database. Do this using AES encryption.
First, create a html page with the username and secret message fields. Once the inputs are
given and submit button is pressed, the javascript program in the background will encrypt
the message using AES and store it in the database along with the username.
------------------------------------------------------------------------
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
/**
* Encrypts the given plain text
*
4
21CS3260R DATABASE & SYSTEMS SECURITY
return cipher.doFinal(plainText);
}
/**
* Decrypts the given byte array
*
* @paramcipherTextThe data to decrypt
*/
public byte[] decrypt(byte[] cipherText) throws Exception
{
SecretKeySpecsecretKey = new SecretKeySpec(key, ALGORITHM);
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
return cipher.doFinal(cipherText);
}
}
------------------------------------------------------------------------
Usage example:
4
21CS3260R DATABASE & SYSTEMS SECURITY
AdvancedEncryptionStandardadvancedEncryptionStandard =
newAdvancedEncryptionStandard(encryptionKey);
byte[] cipherText = advancedEncryptionStandard.encrypt(plainText);
byte[] decryptedCipherText = advancedEncryptionStandard.decrypt(cipherText);
------------------------------------------------------------------------
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Sol)
Q2.Our application security user needs to create procedures, functions, Java stored
procedures, tables, and views. When creating those items, appsec requires the CREATE
PROCEDURE, CREATE TABLE, and CREATE VIEW system privileges. We will grant those
privileges to a role named appsec_role, and grant that role to the appsec user.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q3. Write a query to specify how much space appsec may use, a quota. We’ll start out
permitting two megabytes of space
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q4.Write a query to Create a table in the appsec schema for logging errors and create a
trigger associated with that table.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of encrypting using Oracle.
To understand and implement the concept of encrypting data in transit in Oracle.
To understand and implement the concept of validating data after encryption in
Oracle.
Pre-Lab:
Sol)
Sol)
Q3. How many bits of data do the data and keys have in AES?
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Q5. Write a short note on Cipher Block Chaining and draw its diagram.
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Hint - https://www.enterprisedb.com/edb-docs/d/edb-postgres-advanced-server/user-
guides/database-compatibility-for-oracle-developers-guide/9.4/
Database_Compatibility_for_Oracle_Developers_Guide.1.178.html
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. You are a database security consultant. You stored some confidential information
previously in your database using AES encryption.
First, create a html page with the username and secret message fields. Once the inputs are
given and submit button is pressed, the javascript program in the background will encrypt
the message using AES.Thencheck it with the data (stored in the previous lab) of the
secret message in the database table using a function. If both of them match then print
“Secret Verified Successfully”, else print “Invalid Secret”.
Create a function to check if both the values in the table are matching.
NOTE – There can only be two values in the table. One, the values entered in the previous
lab and two, the values entered in this lab.
------------------------------------------------------------------------
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
4
21CS3260R DATABASE & SYSTEMS SECURITY
/**
* Encrypts the given plain text
*
* @paramplainTextThe plain text to encrypt
*/
public byte[] encrypt(byte[] plainText) throws Exception
{
SecretKeySpecsecretKey = new SecretKeySpec(key, ALGORITHM);
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return cipher.doFinal(plainText);
}
/**
* Decrypts the given byte array
*
* @paramcipherTextThe data to decrypt
*/
public byte[] decrypt(byte[] cipherText) throws Exception
{
SecretKeySpecsecretKey = new SecretKeySpec(key, ALGORITHM);
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
return cipher.doFinal(cipherText);
}
}
Usage example:
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Q1.We want HR to execute the appsec security structures. We’d like to create a role to
which we might grant execute on a package, and then grant that role to whomever needs
it.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q2.Write a query to grant access to HR Security Package, hr_sec_pkg, to a role that appusr
has, the hrview_role
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q3.Connect to Oracle database as appsec user, and set your role to the non-default role,
appsec_role:
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Q5.Create Index for the Application Security Error Log Table, t_appsec_errors
Sol)
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Learning Outcomes:
To understand and implement the concept of hashing using Oracle.
To understand and implement the concept of hashing data in transit in Oracle.
Pre-Lab:
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
Sol)
Q4. Can we store pictures in the database and if so, how it can be done?
Sol)
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
In-Lab:
Q1. You are a database security consultant for a company. The company has given you the
task of creating a page which takes username, message, gender and place as inputs and
stores the hashed value of the message, gender, place in a database table. You plan to
store the hash values of the message, gender, place in the database. The hashing is done
using MD5. You are to implement this using Javascript.
First, create a html page with the username, message, genderand place fields. Once the
details are given as input and submit button is pressed, the javascript program in the
background will hash the message, gender, place and store it in the database along with
the username and original value of message, gender, place.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Post-Lab:
Q1. You are a database security consultant for a company. The company has given you the
task of creating a registration page which takes username, password, gender and place as
inputs and stores the hashed value of the password, gender, placein a database table. You
plan to store the hash values of the password, gender, place in the database. The hashing
is done using MD5. You are to implement this using Javascript.
First, create a html page with the username, password, genderand place fields. Once the
details are given as input and submit button is pressed, the javascript program in the
background will hash the password, gender, place and store it in the database along with
the username and original value of gender, place.
Sol)
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
Evaluator’s Observation
4
21CS3260R DATABASE & SYSTEMS SECURITY
4
21CS3260R DATABASE & SYSTEMS SECURITY
ROUGH
4
21CS3260R DATABASE & SYSTEMS SECURITY
ROUGH