BC-SECURITY / Empire

Empire is a post-exploitation and adversary emulation framework that is used to aid Red Teams and Penetration Testers.
https://bc-security.gitbook.io/empire-wiki/
BSD 3-Clause "New" or "Revised" License
4.28k stars 580 forks source link

[BUG] Can't create database 'empire' #740

Open cmitcho opened 3 months ago

cmitcho commented 3 months ago

Is there an existing issue for this?

Empire Version

5.4.2

Python Version

3.11.9

Operating System

Kali

Database

MySQL

Current Behavior

After updating Kali today (August 12th, 2024), I received an exception when attempting to start Empire:

┌──(kali㉿kali)-[~]
└─$ sudo powershell-empire server
Create mysql database empire
ERROR 1007 (HY000) at line 1: Can't create database 'empire'; database exists

Expected Behavior

Empire should check for the empire databases, and if created, skip database creation and move on to starting Empire.

Steps To Reproduce

  1. sudo powershell-empire server
  2. See exception

Anything else?

After reviewing source code for the initial powershell-empire command, there is a referenced sql command that is required to be installed. After installing, everything works as expected:

┌──(kali㉿kali)-[~]
└─$ vi /usr/bin/powershell-empire
..
..
#!/bin/sh

set -e

# Check if running as root
if [ `id -u` -ne 0 ]; then
   echo "Error: $0 must be run as root" 1>&2
   exit 1
fi

systemctl start mysql

# Check if the MySQL database empire exists.
# If the DB does not exist, it will create the DB, the DB user and the
# user password.
if ! mysqlshow "empire" > /dev/null 2>&1; then                                         <--- This guy right here

From here, I installed mysqlshow, and was able to move forward:

┌──(kali㉿kali)-[~]
└─$ mysqlshow
Command 'mysqlshow' not found, but can be installed with:
sudo apt install mariadb-client-compat
Do you want to install it? (N/y)y
sudo apt install mariadb-client-compat
Installing:
  mariadb-client-compat

Summary:
  Upgrading: 0, Installing: 1, Removing: 0, Not Upgrading: 0
  Download size: 27.0 kB
  Space needed: 103 kB / 13.3 GB available

Get:1 http://kali.download/kali kali-rolling/main amd64 mariadb-client-compat all 1:11.4.2-4 [27.0 kB]
Fetched 27.0 kB in 0s (344 kB/s)
Selecting previously unselected package mariadb-client-compat.
(Reading database ... 154113 files and directories currently installed.)
Preparing to unpack .../mariadb-client-compat_1%3a11.4.2-4_all.deb ...
Unpacking mariadb-client-compat (1:11.4.2-4) ...
Setting up mariadb-client-compat (1:11.4.2-4) ...

┌──(kali㉿kali)-[~]
└─$ sudo mysqlshow "empire"
Database: empire
+---------------------------+
|          Tables           |
+---------------------------+
..
..
REDACTED

┌──(kali㉿kali)-[~]
└─$ sudo powershell-empire server
[INFO]: Checking submodules...
[INFO]: No .git directory found. Skipping submodule check.
[INFO]: v2: Loading listener templates from: /usr/share/powershell-empire/empire/server/listeners/
Cx01N commented 3 months ago

Looks like there is an issue with Kali’s repo. Can you try the GitHub install method?

cmitcho commented 3 months ago

I should have mentioned, this happened today during an apt update -y && apt upgrade -y. Not a new install, this instance of Empire on Kali has been running since April. I am not sure if a new install would do this.

cmitcho commented 3 months ago

I tested this on a new install of Empire on Ubuntu 22.04. Anyone else coming across this should know the fix is to install the mariadb-client-compat package to resolve this problem.

Cx01N commented 2 months ago

I tested this on a new install of Empire on Ubuntu 22.04. Anyone else coming across this should know the fix is to install the mariadb-client-compat package to resolve this problem.

Thanks for the recommendation. Ill double check the install script is doing this correctly.