1. 程式人生 > >Mysql資料庫安全連結和密碼加密方式及破解

Mysql資料庫安全連結和密碼加密方式及破解

使用SSL安全連結Mysql資料庫


一、使用SSL安全連線

To use SSL connections between the MySQL server and client programs, your system must

support either OpenSSL or yaSSL and your version of MySQL must be built with SSL support.

To make it easier to use secure connections, MySQL is bundled with yaSSL as of MySQL

5.0.10. (MySQL and yaSSL employ the same licensing model, whereas OpenSSL uses an

Apache-style license.) yaSSL support initially was available only for a few platforms, but now

it is available on all platforms supported by MySQL AB.

To get secure connections to work with MySQL and SSL, you must do the following:

If you are not using a binary (precompiled) version of MySQL that has been built with SSL

support, and you are going to use OpenSSL rather than the bundled yaSSL library, install

OpenSSL if it has not already been installed. We have tested MySQL with OpenSSL 0.9.6. To

If you are not using a binary (precompiled) version of MySQL that has been built with SSL

support, configure a MySQL source distribution to use SSL. When you configure MySQL,

invoke the configure script with the appropriate option to select the SSL library that you

want to use.

For yaSSL:
shell> ./configure --with-yassl

For OpenSSL:
shell> ./configure --with-openssl

Before MySQL 5.0, it was also neccessary to use --with-vio, but that option is no longer

required.

Note that yaSSL support on Unix platforms requires that either /dev/urandom or

/dev/random be available to retrieve true random numbers. For additional information

(especially regarding yaSSL on Solaris versions prior to 2.8 and HP-UX)

Make sure that you have upgraded your grant tables to include the SSL-related columns in

the mysql.user table. This is necessary if your grant tables date from a version of MySQL

older than 4.0.

To check whether a server binary is compiled with SSL support, invoke it with the --ssl

option. An error will occur if the server does not support SSL:

shell> mysqld --ssl --help

060525 14:18:52 [ERROR] mysqld: unknown option '--ssl'To check whether a running

mysqld server supports SSL, examine the value of the have_openssl system variable:

mysql> SHOW VARIABLES LIKE 'have_openssl';
+---------------+-------+|
Variable_name | Value |
+---------------+-------+|
have_openssl  | YES   |
+---------------+-------+

If the value is YES, the server supports SSL connections. If the value is DISABLED, the

server supports SSL connections but was not started with the appropriate --ssl-xxx options

(described later in this section). If the value is YES, the server supports SSL connections.

To start the MySQL server so that it allows clients to connect via SSL, use the options that

identify the key and certificate files the server needs when establishing a secure connection:

shell> mysqld --ssl-ca=cacert.pem /      
         --ssl-cert=server-cert.pem /      
         --ssl-key=server-key.pem

一般情況下mysql伺服器會隨開機自啟動,如果需要支援ssl,則修要修改配置文

件/etc/mysql/my.cnf,設定ssl-ca,ssl-cert,ssl-key. 然後/etc/init.d/mysql restart--ssl-ca

identifies the Certificate Authority (CA) certificate.

--ssl-cert identifies the server public key. This can be sent to the client and authenticated

against the CA certificate that it has.

--ssl-key identifies the server private key.

To establish a secure connection to a MySQL server with SSL support, the options that a

client must specify depend on the SSL requirements of the user account that the client uses.

If the account has no special SSL requirements or was created using a GRANT statement

that includes the REQUIRE SSL option, a client can connect securely by using just the --ssl-

ca option:

shell> mysql --ssl-ca=cacert.pem

To require that a client certificate also be specified, create the account using the REQUIRE

X509 option. Then the client must also specify the proper client key and certificate files or

the server will reject the connection:

shell> mysql --ssl-ca=cacert.pem /      
         --ssl-cert=client-cert.pem /      
         --ssl-key=client-key.pem

In other words, the options are similar to those used for the server. Note that the

Certificate Authority certificate has to be the same.

A client can determine whether the current connection with the server uses SSL by checking

the value of the Ssl_cipher status variable. The value of Ssl_cipher is non-empty if SSL is

used, and empty otherwise. For example:

mysql> SHOW STATUS LIKE 'Ssl_cipher';
+---------------+--------------------+
| Variable_name | Value             
|+---------------+--------------------+
| Ssl_cipher    | DHE-RSA-AES256-SHA
|+---------------+--------------------+

For the mysql client, you can use the STATUS or /s command and check the SSL line:

mysql> /s...SSL:                   

Not in use...Or:

mysql> /s...SSL:                   

Cipher in use is DHE-RSA-AES256-SHA...To establish a secure connection from within an

application program, use the mysql_ssl_set() C API function to set the appropriate certificate

options before calling mysql_real_connect().

二、對資料庫帳號設定不同的安全連線型別

There are a number of different possibilities for limiting connection types for a given

account:
REQUIRE NONE indicates that the account has no SSL or X509 requirements. This is the

default if no SSL-related REQUIRE options are specified. Unencrypted connections are

allowed if the username and password are valid. However, encrypted connections can also

be used, at the client's option, if the client has the proper certificate and key files. That is,

the client need not specify any SSL commmand options, in which case the connection will be

unencrypted. To use an encrypted connection, the client must specify either the --ssl-ca

option, or all three of the --ssl-ca, --ssl-key, and --ssl-cert options.

The REQUIRE SSL option tells the server to allow only SSL-encrypted connections for the

account.

GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' 
IDENTIFIED BY 'goodsecret' REQUIRE SSL;

To connect, the client must specify the --ssl-ca option, and may additionally specify the --ssl

-key and --ssl-cert options.

REQUIRE X509 means that the client must have a valid certificate but that the exact

certificate, issuer, and subject do not matter. The only requirement is that it should be

possible to verify its signature with one of the CA certificates.

GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' 
IDENTIFIED BY 'goodsecret' REQUIRE X509;

To connect, the client must specify the --ssl-ca, --ssl-key, and --ssl-cert options. This is also

true for ISSUER and SUBJECT because those REQUIRE options imply X509.

REQUIRE ISSUER 'issuer' places the restriction on connection attempts that the client must

present a valid X509 certificate issued by CA 'issuer'. If the client presents a certificate that

is valid but has a different issuer, the server rejects the connection. Use of X509 certificates

always implies encryption, so the SSL option is unnecessary in this case.

GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' 
IDENTIFIED BY 'goodsecret' 
REQUIRE ISSUER '/C=FI/ST=Some-State/L=Helsinki/   
O=MySQL Finland AB/CN=Tonu Samuel/[email protected]';

Note that the 'issuer' value should be entered as a single string.
REQUIRE SUBJECT 'subject' places the restriction on connection attempts that the client

must present a valid X509 certificate containing the subject subject. If the client presents a

certificate that is valid but has a different subject, the server rejects the connection.

GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' 
IDENTIFIED BY 'goodsecret' 
REQUIRE SUBJECT '/C=EE/ST=Some-State/L=Tallinn/   
O=MySQL demo client certificate/   
CN=Tonu Samuel/[email protected]';

Note that the 'subject' value should be entered as a single string.
REQUIRE CIPHER 'cipher' is needed to ensure that ciphers and key lengths of sufficient

strength are used. SSL itself can be weak if old algorithms using short encryption keys are

used. Using this option, you can ask that a specific cipher method is used to allow a

connection.

GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' 
IDENTIFIED BY 'goodsecret' 
REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA';

The SUBJECT, ISSUER, and CIPHER options can be combined in the REQUIRE clause like

this:

GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' 
IDENTIFIED BY 'goodsecret' 
REQUIRE SUBJECT '/C=EE/ST=Some-State/L=Tallinn/   
O=MySQL demo client certificate/   
CN=Tonu Samuel/[email protected]' 
AND ISSUER '/C=FI/ST=Some-State/L=Helsinki/   
O=MySQL Finland AB/CN=Tonu Samuel/[email protected]' 
AND CIPHER 'EDH-RSA-DES-CBC3-SHA';

The AND keyword is optional between REQUIRE options.

三、為Mysql製作ssl證書
This section demonstrates how to set up SSL certificate and key files for use by MySQL

servers and clients. The first example shows a simplified procedure such as you might use

from the command line. The second shows a script that contains more detail. Both examples

use the openssl command that is part of OpenSSL.

The following example shows a set of commands to create MySQL server and client

certificate and key files. You will need to respond to several prompts by the openssl

commands. For testing, you can press Enter to all prompts. For production use, you should

provide non-empty responses.

# Create clean environment
shell> rm -rf newcertsshell> mkdir newcerts && cd newcerts

# Create CA certificate
shell> openssl genrsa 2048 > ca-key.pem
shell> openssl req -new -x509 -nodes -days 1000 /        
         -key ca-key.pem > ca-cert.pem

# Create server certificate
shell> openssl req -newkey rsa:2048 -days 1000 /        
         -nodes -keyout server-key.pem > server-req.pem
shell> openssl x509 -req -in server-req.pem -days 1000 /        
         -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem

# Create client certificate
shell> openssl req -newkey rsa:2048 -days 1000 /        
         -nodes -keyout client-key.pem > client-req.pem
shell> openssl x509 -req -in client-req.pem -days 1000 /        
         -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > client-cert.pem 

mysql通過ssl的方式生成祕鑰

-- mysql ssl 生成祕鑰


1 check ssl是否已經開啟
mysql> show variables like '%ssl%';
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| have_openssl  | DISABLED |
| have_ssl      | DISABLED |
| ssl_ca        |          |
| ssl_capath    |          |
| ssl_cert      |          |
| ssl_cipher    |          |
| ssl_crl       |          |
| ssl_crlpath   |          |
| ssl_key       |          |
+---------------+----------+
9 rows in set (0.00 sec)

2 沒有開啟,所以開啟
在my.cnf末尾端設定ssl 引數, 然後重新啟動mysql服務即可
mysql> show variables like '%ssl%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_openssl  | YES   |
| have_ssl      | YES   |
| ssl_ca        |       |
| ssl_capath    |       |
| ssl_cert      |       |
| ssl_cipher    |       |
| ssl_crl       |       |
| ssl_crlpath   |       |
| ssl_key       |       |
+---------------+-------+
9 rows in set (0.00 sec)

3 通過openssl生成證書的配置, 在mysql db server上生成祕鑰
mkdir -p /etc/mysql/newcerts/
cd /etc/mysql/newcerts/


3.1 openssl genrsa 2048 > ca-key.pem
3.2 openssl req -new -x509 -nodes -days 1000 -key ca-key.pem > ca-cert.pem

[[email protected] newcerts]# openssl req -new -x509 -nodes -days 1000 -key ca-key.pem > ca-cert.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:ch
State or Province Name (full name) []:shh
Locality Name (eg, city) [Default City]:shh
Organization Name (eg, company) [Default Company Ltd]:xx
Organizational Unit Name (eg, section) []:db
Common Name (eg, your name or your server''s hostname) []:mysql.yest.nos
Email Address []:[email protected]


3.3 openssl req -newkey  rsa:2048  -days 1000 -nodes -keyout server-key.pem > server-req.pem
[[email protected] newcerts]# openssl req -newkey  rsa:2048  -days 1000 -nodes -keyout server-key.pem > server-req.pem
Generating a 2048 bit RSA private key
.......................................................................................................+++
..........................................................+++
writing new private key to 'server-key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:ch
State or Province Name (full name) []:shh
Locality Name (eg, city) [Default City]:ssh
Organization Name (eg, company) [Default Company Ltd]:xx
Organizational Unit Name (eg, section) []:db
Common Name (eg, your name or your server''s hostname) []:mysql.yest.nos
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:820923
An optional company name []:xx


4 在mysql db server客戶端生成ssl檔案
4.1 openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem

 [[email protected] newcerts]# openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem
Signature ok
subject=/C=ch/ST=shh/L=ssh/O=ea/OU=db/CN=mysql.yest.nos/[email protected]
Getting CA Private Key

4.2 openssl  req -newkey  rsa:2048  -days 1000 -nodes -keyout client-key.pem > client-req.pem

[[email protected] newcerts]# openssl  req -newkey  rsa:2048  -days 1000 -nodes -keyout client-key.pem > client-req.pem
Generating a 2048 bit RSA private key
.......+++
........................................................+++
writing new private key to 'client-key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:ch
State or Province Name (full name) []:shh
Locality Name (eg, city) [Default City]:shh
Organization Name (eg, company) [Default Company Ltd]:xx
Organizational Unit Name (eg, section) []:db
Common Name (eg, your name or your server''s hostname) []:mysql.yest.nos
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:820923
An optional company name []:xx


4.3
openssl x509 -req -in client-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > client-cert.pem

[[email protected] newcerts]# openssl x509 -req -in client-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > client-cert.pem
Signature ok
subject=/C=ch/ST=shh/L=shh/O=ea/OU=db/CN=mysql.yest.nos/[email protected]
Getting CA Private Key

5
copy clent.* 3個檔案到客戶端機器上面/opt/mysql/ssl/去。

6 登陸驗證
mysql -uxxx -pxxxx --ssl-ca=/opt/mysql/ssl/ca-cert.pem --ssl-cert=/opt/mysql/ssl/server-cert.pem --ssl-key=/opt/mysql/ssl/server-key.pem


詳解MYSQL資料庫密碼的加密方式及破解方法轉載連線

相關推薦

Mysql資料庫安全連結密碼加密方式破解

使用SSL安全連結Mysql資料庫 一、使用SSL安全連線 To use SSL connections between the MySQL server and client programs, your system must support either Ope

詳解MYSQL資料庫密碼加密方式破解方法(2)

2.將MySQL使用者密碼字串加入到Cain破解列表     本文使用Cain & Abel 來破解MYSQL資料庫使用者密碼,Cain & Abel是一個可以破解屏保、PWL密碼、共享密碼、快取口令、遠端共享口令、SMB口令、支援VNC口令解碼、C

詳解MYSQL資料庫密碼加密方式破解方法

MYSQL資料庫使用者密碼跟其它資料庫使用者密碼一樣,在應用系統程式碼中都是以明文出現的,在獲取檔案讀取許可權後即可直接從資料庫連線檔案中讀取,例如asp程式碼中的conn.asp資料庫連線檔案,在該檔案中一般都包含有資料庫型別,物理位置,使用者名稱和密碼等資訊;而在M

資料庫連線使用者名稱密碼加密

1. 需求背景我們在開發應用時,需要連線資料庫,一般把資料庫資訊放在一個屬性配置檔案中,比如jdbc.properties,具體的內容#mysql的配置檔案 jdbc.url=jdbc:mysql://127.0.0.1:3306/test jdbc.username=roo

常見的使用者密碼加密方式以及破解方法

PBKDF2演算法,該演算法原理大致相當於在HASH演算法基礎上增加隨機鹽,並進行多次HASH運算,隨機鹽使得彩虹表的建表難度大幅增加,而多次HASH也使得建表和破解的難度都大幅增加。使用PBKDF2演算法時,HASH演算法一般選用sha1或者sha256,隨機鹽的長度一般不能少於8位元組,HASH次數至少也

Mysql 修改密碼加密方式

Mysql 安裝完客戶端連線報錯:“Authentication plugin 'caching_sha2_password' cannot be loaded: ”意思是客戶端不支援caching_sha2_password的加密方式。執行命令use mysql; sel

MySQL密碼加密方式

我們先來看一下mysql的加密方式: mysql> select password('abc'); +-------------------------------------------+ | password('abc') |

MYSQL資料庫裡面的所有密碼批量MD5加密

如果你的欄位夠長度的話: UPDATE users SET password = MD5(password); 如果長度不夠,可以先增加長度後再做,或者多建一列,完成後刪除原來的列!(如passwd) UPDATE users SET passwd = MD5(passwo

js的常見的三種密碼加密方式-MD5加密、Base64加密解密sha1加密詳解總結

寫在前面寫前端的時候,很多的時候是避免不了註冊這一關的,但是一般的註冊是沒有任何的難度的,無非就是一些簡單的獲取使用者輸入的資料,然後進行簡單的校驗以後呼叫介面,將資料傳送到後端,完成一個簡單的註冊的流程,那麼一般來說,密碼是不做加密的。但是也有一些資料庫裡面存放的是加密後的

Spring+mysql+druid對資料庫連線的使用者名稱密碼加密

1.首先進入到druid-1.0.26.jar這個jar包所在的位置,然後開啟cmd,執行命令:java -cp druid-1.0.26.jar com.alibaba.druid.filter.config.ConfigTools 123456 2.分別得到:pri

查看、修改mysql的用戶名密碼

查看、修改mysql的用戶名和密碼一、查看密碼 這時你需要進入/etc/mysql目錄下,執行sudo vi debian.cnf或者sudo vimdebian.cnf查看裏面的用戶名和密碼, 然後使用這個文件中的用戶名和密碼進入mysql, 如果debian.cnf中的用戶名為deb

一、MySQL資料庫之簡介安裝

一、基礎部分 1.資料庫是簡介     之前所學,資料要永久儲存,比如使用者註冊的使用者資訊,都是保存於檔案中,而檔案只能存在於某一臺機器上。 如果我們不考慮從檔案中讀取資料的效率問題,並且假設我們的程式所有的元件都執行在一臺機器上,那麼用檔案存

mysql資料庫中 IN EXISTS 的誤區

       前言:最近在看 《高效能mysql第三版》 這本書,讀到子查詢優化那章,書中說mysql會將in子查詢改寫成exists查詢(書中基於的mysql版本是5.1.50和5.5),於是乎我又上網找了下資料,發現網上說法幾乎都是: &

linux rsync 指定使用者名稱密碼方式同步

  rsync 客戶端 172.17.0.29 rsync 服務端 --daemon  方式執行 172.17.0.31 備份端 以下首先說明服務端的安裝情況: 1  檢查是否安裝rsync     rpm -qa

mysql資料庫建立索引使用

1. 2               需要注意: ,後續新增修改索引。。需要注意索引需要的不同資料庫引擎 alter table user add fulltext(欄

Mysql資料庫-----表記錄欄位管理

表記錄管理 1.插入記錄(insert)        1)insert into 表名 values(值1),(值2)...;        2)insert into 表名(欄位,欄位2) values(

MySql(五):MySQL資料庫安全管理

一、前言 對於任何一個企業來說,其資料庫系統中所儲存資料的安全性無疑是非常重要的,尤其是公司的有些商業資料,可能資料就是公司的根本。 失去了資料,可能就失去了一切 本章將針對mysql的安全相關內容進行較為詳細的介紹。 二、資料庫系統安全相關因素 1、外圍網路 讓我們的mysql處在

Oracle資料庫忘記使用者名稱密碼怎麼辦

方法一:   首先進入sqlplus:進入的方式有兩種,一種是通過cmd命令臺輸入sqlplus,另外一種是直接在開始-》程式-》Oracle-》應用程式開發-》sqlplus。 搜尋 “Oracle 11g預設使用者名稱,密碼”,可以找到很多相關的預設使用者

MySQL資料庫三大正規化反正規化

第一正規化(1NF): 資料表中的每一列(欄位),必須是不可拆分的最小單元,也就是確保每一列的原子性。 Table: t_user_info — — — — — —

MySQL資料庫安全基線(加固方法)

MySQL資料庫安全加固方法 基本安全原則 選擇穩定版本並及時更新、打補丁 嚴禁使用弱口令,定期更新口令 嚴格的許可權分配和訪問控制 具體安全配置 系統層面配置 系統安裝時,需要確認沒有其他⽤戶登入在伺服器上。 選擇穩定的版本