CSSP Database Security
CSSP Database Security
CSSP Database Security
LAB
LAB Assignments
1. Practical on installation of MySql database server.
2. Practical on routine DBA job.
3. Practical on creation of user in MySql database.
4. Practical on Assigning Database roles to user.
5. Practical on password guidelines.
6. Practical on certificate guidelines.
7. Practical on Database backup and restore procedure.
8. Practical on Database Auditing (MySql to be used).
9. Practical on ODBC connectivity to MySql database.
10. Practical on JDBC connectivity to MySql database.
Introduction to MySql:-
MySQL is an open source Relational Database Management System. MySQL is very fast
reliable and flexible Database Management System. It provides a very high performance and it is
multi threaded and multi user Relational Database management system.
MySQL Features
1. MySQL are very fast and much reliable for any type of application.
2. MySQL is very Lightweight application.
3. MySQL command line tool is very powerful and can be used to run SQL queries against
database.
4. MySQL supports indexing and binary objects.
5. It is allow changes to structure of table while server is running.
6. MySQL has a wide user base.
7. It is a very fast thread-based memory allocation system.
8. MySQL Written in C and C++ language.
9. MySQL code is tested with different compilers.
10. MySQL is available as a separate program for use in a client/server network environment.
11. The MySQL available for the most Unix operating platform.
12. MySQL are the available for window operating system window NT, window 95 ,and
window 98.
13. MySQL available for OS/2.
14. Programming libraries for C, Python, PHP, Java , Delphi etc. are available to connect to
MySQL database.
MySQL Advantages:
Availability of Source
MySQL source code is available that's why now you can recompile the source code.
Cross-Platform support
MySQL supports more then twenty different platform including the major Linux distribution
.Mac OS X, UNIX and Microsoft windows.
Yum:-
The Yellow dog Updater Modified (YUM) is a package management application for
computers running Linux operating systems. A package is usually a software
application, but the term can also encompass other items such as documentation,
source code, and extra levels for games. Package management is a term used to
describe the processes of adding, removing, and updating software on a computer.
Note: The above configuration is required when your Linux machine is working
behind a proxy server.
Installation of MySql:-
1- Logon by using username root and password lab@123 then press Enter key and type yum
install yum and press Enter key.
Create Database, Create MySQL User and Enable Remote Connections to MySQL
Database
4- DB_NAME = webdb
5- USER_NAME = webdb_user
6- REMOTE_IP = 10.0.0.13
7- PASSWORD = password123
8- PERMISSIONS = ALL
12- Now test the remote database connectivity for this type the following command
mysql –h 10.0.0.13 –u webdb_user –p webdb then press Enter key.
13- Now login in the mysql server for this type mysql –u root –p –h localhost and press
Enterkey
14- Now the root user connected to localuser
Enable Remote Connection to MySQL Server –> Open MySQL Port (3306) on Iptables
Firewall (as root user again)
Practical on routine DBA job
Maintenance Activities
• DB Management Documentation
• Creating KB Articles
• Auditing SLA & OLA
• DB Report Generation
• DB History Reports
• Network Share Management
• AD Syncup Issues
• Windows Cluster Management
• DCOM & COM+ Issues
• WMI Errors
• SAN Issues
• Storage & RAID Issues
• MOM Monitoring
• REDGATE Tools
• Design Tools
o UML
o TOAD
o ERWIN
Practical on password guidelines.
1- Don’t share root user password and mysql.user table acess with anyone till you have full trust
on it. Because that encrypted password is real password in MySQL so if anyone knows that than
he/she can easily login with any user if he has access to his host
2- Check with “mysql -uroot ” command, If you can easily login without asking password than
you are in trouble. Anyone can login with root user in that server. In this case, you can use
“mysql_secure_installation” utility. By running it, you can set root password, remove
anonymous users and also restrict users which are connecting from outside of the server.
3- There should not be any user without password. Even try to avoid “%” in hosts. Frequently
change root password.
4- Check users permissions with “SHOW GRANTS” command and remove unnecessary
permissions by “REVOKE” command if needed. Even don’t give permissions to users for
multiple hosts/dbs until needed.
5- Don’t use any words from dictionary in password. It can be break easily by some hack
program.
6- If data is that much sensitive than use SSL connections between MySQL client and server.
7-As MySQL is using 3306 by default, it should be blocked from outside of network. It should
not be accessible by un-trusted users/hosts.
8-Don’t run the mysqld daemon as the linux root user. It should be always run by MySQL user
itself. If you run mysqld with another linux user than root, you dont need to change the root user
name in mysql.user table because there is no any connection between MySQL users and Linux
users.
9-Don’t give the process privileges to all users. Because “show processlist” command can show
all the running queries on the servers. It might be possible that someone is chagning the
password and another can see it by “show processlist” i.e update user set password =
old_password(“abc”)
10-If you don’t trust your DNS, you should use IP numbers instead of hostnames in the
mysql.user table. In any case, you should be very careful about creating grant table entries using
hostname values that contain wild cards! If you want to restrict the number of connections for a
single user, you can do this by setting the max_user_connections variable in mysqld.
Database Backup:-
1- Type mysql –u root –p and press Enter key after that enter password password123
3- Now type show databases and press Enter key. This would check that already
database present or not
4- Now create a database people for this type create database people; and press
Enter key.
5- Now we want to grant ( GRANT ) all user rights ( ALL ) from ( ON ) the entire (
* ) people database to ( TO ) your account ( yourusername@localhost ) with
your user password being stuffedpoodle ( IDENTIFIED BY "stuffedpoodle" ).
6- Now type mysql –u ted –p and press Enter key then Enter password stuffedpoodle
and press Enter key.
How to create a table relating to the people database:-
firstName varchar(30),
lastName varchar(30),
age int,
gender varchar(13)
);
2- Now type the following commands
3- Now insert into our table (specifying the rows) and inputting the values(actual data) that
we want. (NOTE: We are not filling in the primary key.)
7-Type select * from peopleInfo; and press Enter key this would display the tables .
Practical on Database backup and restore procedure.
There is a function called mysqldump. To backup your database (in this case backup the people
database):
We first have to create the .txt file that we will be backing it up to. Open a blank .txt file and
save it as backupfile.sql .
According to EvansData, MySQL is the most popular database with over 53% market share
among other open source RDBMS. The following section talks about accessing MySQL with
WinSQL.
MySQL can be downloaded from http://www.mysql.com. This database comes in two flavors:
Community Server Edition and Enterprise Edition. Community server is available for free and
does not include support. On the other hand, Enterprise edition is geared toward mission critical
applications backed up with full support from MySQL. The discussion below assumes that you
are using the community server.
At the time of this document, MySQL ODBC connector 5.0 was available as a beta release.
Initial tests with WinSQL using this driver did not show any problems. However, if you are
interested in a more stable but older release, visit
http://dev.mysql.com/downloads/connector/odbc/3.51.html
We recommend using the download package that comes with an installer. The document
assumes you are installing the server on Windows. For installation on other platforms refer to the
documentation that comes with MySQL. Run the installer on your machine, which will copy
necessary files on to your hard disk. Towards the end of installation process it will prompt you to
configure the MySQL server.
It is important to remember the value on this screen, which refers to the TCP/IP port. You will
have to specify this number when creating an ODBC DSN for MySQL. The default value for
this parameter is 3306 and can be changed to any number below 65000.
Another important value to remember is the password for the ?root? account. More discussion
about the root account will follow in the authentication section.
By default ?root? access is only available for the local machine. This is done for security
reasons. However, if you are planning to access this database from another machine using the
root access, check the ?Enable root access from remote machines?.
Once all information is collected, the Configuration wizard will run a set of scripts to save the
values specified by the user. One important point to remember is to turn Windows Firewall off
during the configuration process. This is because it may prevent MySQL service from listening
on the TCP/IP port In that case you might get the following error.
Once the database is correctly setup and installed, you can check its status from Windows
Services module in Control Panel.
The ODBC driver for MySQL is not bundled with the server. Therefore, you need to install that
separately. The link to download this driver is shown above. All screens in the installer are self-
explanatory and there are no setup options as all the installer does is to copy files and change
some registry settings.
Before connecting to the database, you need to create an ODBC DSN. The steps below show
how to create a DSN referring to a MySQL database running either on Windows, Linux or any
other supported operating system.
1. Start the ODBC manager. This can be done from within WinSQL by clicking File/Open
ODBC manager, or by double clicking the Data Sources (ODBC) link in Windows
Control Panel.
2. Ensure that the MySQL ODBC driver is installed on the machine by clicking the Drivers
tab.
3. Next click the either User DSN or System DSN tab to create a DSN
4. To add a new data source, click the Add button and select MySQL/Connector ODBC
from the list.
5. Following screen is displayed, which is used to specify connection settings.
After creating ODBC DSN, start WinSQL. In the connection window, you will see your newly
created DSN for MySQL.
IMPORTANT: Ensure that you select MySQL as the Database type, which enables MySQL
specific features in WinSQL.
Important Concepts
Default Values
Following table lists values for some important parameters in MySQL database.
TCP/IP Port: 3306
Password: <blank>
Security
As mentioned earlier, MySQL creates a user called ?root?. By default, the password is blank and
client access is restricted to local machine. This default setting is modified by the Configuration
Wizard that is run automatically after installation. It can also be modified later on by submitting
SQL queries.
Every user in MySQL can be restricted not only by a pair of user id and password strings, but
also by the host machine's IP address. Therefore, when creating a new user you have to specify
the host name where this user is authorized to connect from. Wild card characters such as ?%? or
?_? can be used to specify a host as well as subnet mask. For more information about security,
refer to section 5.8 in MySQL 5.0 reference manual.
Example 1:
Example 2:
Both examples above create a user name 'scott', sets his password to 'tiger' and grants connection
access from any machine. In addition to granting connection access, Example 2 also grants other
privileges such as creating tables and modifying data. Refer to MySQL manual for more details.
Creating new database
Every instance of MySQL may have one or more database. When MySQL is first installed, it
creates two databases during installation:
It is recommended that you create another database for your needs rather than creating tables in
the existing database.
The name of the database is specified in the ODBC DSN and therefore, you always connect to
that database. In the above example we specified ?mysql? as the database name. WinSQL
displays the name of the current database in the catalog window.
You can switch to a different database either by selecting the desired value from this pick list or
issuing a ?USE? statement. For example:
USE NewDbName
Practical on JDBC connectivity to MySQL database.
Data types of MySQL and Java programming language are not same, its need some
mechanism for transferring data between an database using MySQL data types and a
application using Java data types. To connect to MySQL from Java you have to use the
JDBC driver from MySQL. The MySQL JDBC driver is called "MySQL Connector/J".
Class.forName("com.mysql.jdbc.Driver");
Connection connection = null;
connection = DriverManager.getConnection(
"jdbc:mysql://hostname:port/dbname","username", "password");
connection.close();
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
try {
connection = DriverManager
.getConnection("jdbc:mysql://localhost:3306/mkyongcom",
"root", "password");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
}
}
3. Run it
Assume JDBCExample.java is store in c:\test folder, together with MySQL JDBC driver
2- Now verify the server is actually running or not by typing the MySQL user by viewing the
current process list:
5- Now restrict the ports that can be accessed to the bare minimum, SSH and MySQL for this
type nmap –sS –p 1- 65535 10.0.0.13
6- To test record all connections and queries on the MySQL server to create an audit trail. Check
the startup options to see if --log was enabled:
ps auxwww | grep –i mysql