Skip to content

Commit 2aa82b8

Browse files
authored
Create a new db user instead of overwriting the root user (BC-SECURITY#562)
* Create a new db user instead of overwriting the root user * fix a couple other issues * use root password for github action mysql * attempt mysql root password twice
1 parent ce7407b commit 2aa82b8

File tree

10 files changed

+39
-14
lines changed

10 files changed

+39
-14
lines changed

.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Git
2-
.git
2+
**.git
33
.gitignore
44

55
# CI

.github/docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ services:
2020
image: mysql:8.0
2121
restart: always
2222
environment:
23-
MYSQL_ROOT_PASSWORD: 'root'
23+
MYSQL_USER: 'empire_user'
24+
MYSQL_PASSWORD: 'empire_password'
2425
MYSQL_DATABASE: test_empire
2526
volumes:
2627
- db:/var/lib/mysql

.github/workflows/dockerimage.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ jobs:
1616
with:
1717
submodules: 'recursive'
1818
- name: Publish Docker
19-
uses: elgohr/Publish-Docker-Github-Action@2.9
19+
uses: elgohr/Publish-Docker-Github-Action@v5
2020
with:
2121
name: bcsecurity/empire
2222
username: ${{ secrets.DOCKER_USERNAME }}
2323
password: ${{ secrets.DOCKER_PASSWORD }}
2424
dockerfile: Dockerfile
25-
tag_names: true
25+
default_branch: main
26+
tag_names: true

.github/workflows/lint-and-test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
- name: Set up MySQL
5454
run: |
5555
sudo systemctl start mysql
56+
mysql -u root -proot -e "CREATE USER IF NOT EXISTS 'empire_user'@'localhost' IDENTIFIED BY 'empire_password';" || true
57+
mysql -u root -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'empire_user'@'localhost' WITH GRANT OPTION;" || true
58+
mysql -u root -proot -e "FLUSH PRIVILEGES;" || true
5659
- name: Install dependencies
5760
run: |
5861
poetry env use ${{ matrix.python-version }}

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99
- Fix module error in PSRansom (@Cx01N)
10+
- Update the install script to set up a new db user instead of overwriting the root user (@Vinnybod)
11+
- Update the Starkiller syncer to skip updating if not in a git repo (@Vinnybod)
12+
- Update the Docker CI action to publish latest on 'main' branch (@Vinnybod)
1013
- Fix install of Poetry for Debian based systems (@Vinnybod)
1114

1215
## [5.0.3] - 2023-02-20

empire/server/api/app.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from datetime import datetime
55
from json import JSONEncoder
6+
from pathlib import Path
67

78
import socketio
89
import uvicorn
@@ -47,7 +48,9 @@ def load_starkiller(v2App):
4748
starkiller_submodule_dir = "empire/server/api/v2/starkiller"
4849
starkiller_temp_dir = "empire/server/api/v2/starkiller-temp"
4950

50-
if empire_config.starkiller.auto_update:
51+
if (
52+
Path(starkiller_submodule_dir) / ".git"
53+
).exists() and empire_config.starkiller.auto_update:
5154
sync_starkiller(empire_config.dict())
5255

5356
v2App.mount(

empire/server/config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ database:
33
use: mysql
44
mysql:
55
url: localhost:3306
6-
username: root
7-
password: root
6+
username: empire_user
7+
password: empire_password
88
database_name: empire
99
sqlite:
1010
location: empire/server/data/empire.db

empire/server/core/db/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def try_create_engine(engine_url: str, *args, **kwargs) -> Engine:
3434
try:
3535
with engine.connect():
3636
pass
37-
except OperationalError:
37+
except OperationalError as e:
38+
log.error(e, exc_info=True)
3839
log.error(f"Failed connecting to database using {engine_url}")
3940
log.error("Perhaps the MySQL service is not running.")
4041
log.error("Try executing: sudo systemctl start mysql")

empire/test/test_server_config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ database:
33
use: sqlite
44
mysql:
55
url: localhost:3306
6-
username: root
7-
password: root
6+
username: empire_user
7+
password: empire_password
88
database_name: test_empire
99
sqlite:
1010
location: empire/test/test_empire.db

setup/install.sh

+17-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ function install_mysql() {
5555
# https://imsavva.com/silent-installation-mysql-5-7-on-ubuntu/
5656
# http://www.microhowto.info/howto/perform_an_unattended_installation_of_a_debian_package.html
5757
echo mysql-apt-config mysql-apt-config/enable-repo select mysql-8.0 | sudo debconf-set-selections
58-
echo mysql-community-server mysql-community-server/root-pass password "root" | sudo debconf-set-selections
59-
echo mysql-community-server mysql-community-server/re-root-pass password "root" | sudo debconf-set-selections
6058
echo mysql-community-server mysql-server/default-auth-override select "Use Strong Password Encryption (RECOMMENDED)" | sudo debconf-set-selections
6159
6260
if [ "$OS_NAME" == "DEBIAN" ]; then
@@ -77,6 +75,21 @@ function install_mysql() {
7775
echo -e "\x1b[1;34m[*] Starting MySQL\x1b[0m"
7876
}
7977
78+
function start_mysql() {
79+
sudo systemctl start mysql.service || true # will fail in a docker image
80+
81+
# Add the default empire user to the mysql database
82+
mysql -u root -e "CREATE USER IF NOT EXISTS 'empire_user'@'localhost' IDENTIFIED BY 'empire_password';" || true
83+
mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'empire_user'@'localhost' WITH GRANT OPTION;" || true
84+
mysql -u root -e "FLUSH PRIVILEGES;" || true
85+
86+
# Some OS have a root password set by default. We could probably
87+
# be more smart about this, but we just try both.
88+
mysql -u root -proot -e "CREATE USER IF NOT EXISTS 'empire_user'@'localhost' IDENTIFIED BY 'empire_password';" || true
89+
mysql -u root -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'empire_user'@'localhost' WITH GRANT OPTION;" || true
90+
mysql -u root -proot -e "FLUSH PRIVILEGES;" || true
91+
}
92+
8093
function install_xar() {
8194
# xar-1.6.1 has an incompatibility with libssl 1.1.x that is patched here
8295
wget https://github.com/BC-SECURITY/xar/archive/xar-1.6.1-patch.tar.gz
@@ -148,8 +161,8 @@ install_powershell
148161
if ! command_exists mysql; then
149162
install_mysql
150163
fi
151-
sudo systemctl start mysql.service || true # will fail in a docker image
152-
mysql -u root -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');" || true # Set root password to root if its blank
164+
165+
start_mysql
153166
154167
if [ "$ASSUME_YES" == "1" ] ;then
155168
answer="Y"

0 commit comments

Comments
 (0)