This article mainly introduces python3's knowledge of reading MySQL passwords from MYSQL-Front, which has good reference value. Next, let's take a look at it. This article mainly introduces python3's knowledge about reading MySQL-Front MYSQL passwords, which has good reference value. Let's take a look at it with the small editor.
Preface
The same routine is coming again. continue to try again.Read sensitive information from the configuration fileThis is the turnMySQL-Front.
MySQL-Front is an open-source mysql management tool. its official website is www.mysqlfront.de /.
Path of the configuration file:
The MySQL-Front configuration file is stored in the user directory and the environment variable is % appdata %.
In Windows 7, the storage path is:
C:\Users\%user%\AppData\Roaming\MySQL-Front\Accounts.xml
The xml file Accounts. XML stores all important information and the password is not encrypted by default. The last time I forgot the password of the mysql root user, I opened this file and immediately recovered the password,
This is not the benefit of encryption. → _ → However, there are always people who want to harm the hacker. They still need to protect these important information so as not to be read by the bad guys.
Format XML
The content in Accounts. xml is compressed into a row. You need to format it into a nice-looking format. You can search for these online tools.
The formatted content of Accounts. xml is as follows:
127.0.0.1
42847.9391816088
127.0.0.1
libMySQL.dll
root
3306
root
0
127.0.0.1
libMySQL.dll
daqin
3306
daqin
PyQuery, a tool for python to process XML and HTML
For the purpose of practice, I want to use the XML standard library of python to process XML, but the built-in python provides several methods: xml. sax xml. dom xml. minidom
There is also xml. parsers. expat, too many options, or decide to usePyQueryPyQuery is a jquery-style xml parsing and processing library based on lxml.
Lxml is a very important library of python. it is known that pandas, BeautifulSoup, and so on are partially functional dependent on lxml.
Run the following command to install the SDK:
pip install pyquery
After reading the tutorial, I can write out the code.
Python3 reads the MySQL-Front password:
# -*- coding: utf-8 -*-"""Created on 2017-04-22 22:53:35@author: codegay"""import osfrom pyquery import PyQuery as pyqxmlpath = os.environ['appdata']+r'\MySQL-Front\Accounts.xml'root = pyq(filename=xmlpath)for r in root('connection').items(): print("----------------------------------------------") print('host:',r('host').text()) print('username:',r('user').text()) print('password:',r('password').text())
Output after running the code:
----------------------------------------------host: 127.0.0.1username: rootpassword: root----------------------------------------------host: 127.0.0.1username: daqinpassword: daqin
The preceding figure shows how to read the user password details from MySQL-Front. For more information, see other related articles in the first PHP community!