Skip to content

Commit

Permalink
version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ErdemOzgen committed Mar 13, 2024
1 parent 4643e4f commit e8cf4a4
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 93 deletions.
193 changes: 153 additions & 40 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,158 @@
# syntax=docker/dockerfile:1.4
FROM --platform=$BUILDPLATFORM ubuntu:22.04
# Step 0: Choose the BlackArch Linux base image for the build stage
FROM blackarchlinux/blackarch:latest AS build

ARG TARGETARCH
ARG VERSION=1.0.1
ARG RELEASES_URL="https://github.com/ErdemOzgen/blackdagger/releases"
ARG TARGET_FILE="blackdagger_${VERSION}_linux_${TARGETARCH}.tar.gz"
# Step 1: Set the environment variables using values from .env file
ENV TELEGRAM_API_KEY=${TELEGRAM_API_KEY}
ENV TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID}

ARG USER="blackdagger"
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Step 0: Initialize keyring and populate Arch Linux keyring
RUN pacman-key --init && pacman-key --populate archlinux

# Step 1: Update the Arch Linux keyring and upgrade the system
RUN pacman -Sy --noconfirm archlinux-keyring && pacman -Syu --noconfirm



# Step 2: Upgrade the system and install required dependencies using Pacman
RUN pacman -Syu --noconfirm \
base-devel \
git \
python \
python-pip \
go \
wget \
net-tools \
jq \
aws-cli \
nano



# Step 3: Set the working directory
WORKDIR /go/src/app


# Step 4: Install the Go scripts
RUN go version \
&& go install -v github.com/projectdiscovery/notify/cmd/notify@latest

# Step 5: Add Go bin to PATH
RUN echo 'export PATH=$PATH:/root/go/bin' >> ~/.bashrc

# Step 6: Set the working directory
WORKDIR /work_dir

# Step 7: Copy the file and folders into the container
#COPY . .
COPY ./entrypoint.sh entrypoint.sh
COPY ./startservices.sh startservices.sh
COPY ./update_telegram_config.sh /usr/local/bin/update_telegram_config
COPY ./provider-config.yaml /root/.config/notify/provider-config.yaml


# RUN wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh && \
# chmod +x Anaconda3-2021.05-Linux-x86_64.sh && \
# ./Anaconda3-2021.05-Linux-x86_64.sh -b -p /opt/anaconda3 && \
# rm Anaconda3-2021.05-Linux-x86_64.sh

# Use a separate stage for runtime to keep the final image smaller
FROM blackarchlinux/blackarch:latest AS runtime

# Copy the Anaconda installation from the build stage
#COPY --from=build /opt/anaconda3 /opt/anaconda3
#Copy all binaries from the builder image to the runtime image
COPY --from=build /root/go/bin /root/go/bin
COPY --from=build /usr/local/bin /usr/local/bin
COPY --from=build /usr/local/sbin /usr/local/sbin
COPY --from=build /usr/bin /usr/bin
COPY --from=build /usr/sbin /usr/sbin
COPY --from=build /go/src/app /go/src/app
COPY --from=build /usr /usr
COPY --from=build /lib /lib
COPY --from=build /lib64 /lib64
COPY --from=build /opt /opt
#COPY --from=build / /

# Initialize keyring and populate Arch Linux keyring
RUN pacman-key --init && pacman-key --populate archlinux

# Update the Arch Linux keyring and upgrade the system
#RUN pacman -Sy --noconfirm archlinux-keyring && pacman -Syu --noconfirm
# Set the PATH for Miniconda
#RUN echo 'export PATH=$PATH:/opt/anaconda3/bin' >> ~/.bashrc

RUN pacman -Sy --noconfirm --overwrite '*' jre11-openjdk
RUN pacman -Sy --noconfirm --overwrite '*' jdk11-openjdk
WORKDIR /work_dir

# For WebAnalyzer pull this docker and run as API endpoint ==> docker pull erdemozgen/wap_api
# Set the entry point to /bin/bash
RUN echo 'export PATH="/root/go/bin:/sbin:/usr/bin:/root/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/usr/bin/core_perl:$PATH"' >> ~/.bashrc
RUN python -m venv blackdaggerenv
RUN echo 'source blackdaggerenv/bin/activate' >> ~/.bashrc
RUN echo "alias install='pacman -S --noconfirm --overwrite \"*\"'" >> ~/.bashrc
RUN echo "alias update='pacman -Syu --noconfirm --overwrite \"*\"'" >> ~/.bashrc
RUN echo "alias remove='pacman -R --noconfirm'" >> ~/.bashrc
RUN echo "alias search='pacman -Ss'" >> ~/.bashrc
RUN source ~/.bashrc
RUN pacman -Sy --noconfirm --overwrite '*' openssh
# Generate SSH host keys
RUN ssh-keygen -A

RUN wget https://github.com/yudai/gotty/releases/download/v1.0.1/gotty_linux_amd64.tar.gz -O gotty.tar.gz \
&& tar -xzf gotty.tar.gz \
&& mv gotty /usr/local/bin/ \
&& rm gotty.tar.gz


# Generate a self-signed SSL certificate
RUN openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost'
COPY ./provider-config.yaml /root/.config/notify/provider-config.yaml
RUN echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk' >> ~/.bashrc
RUN echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
RUN source ~/.bashrc
COPY ./update_telegram_config.sh /usr/local/bin/update_telegram_config
RUN chmod +x /usr/local/bin/update_telegram_config

# Move the certificate and key to a specific directory (optional)
RUN mkdir -p /etc/gotty && mv cert.pem key.pem /etc/gotty/
RUN mkdir -p /work_dir/scan_data
RUN source ~/.bashrc

# Set blackdagger user password
# ARG USER="blackdagger"
# ARG USER_UID=1000
# ARG USER_GID=$USER_UID
ENV BLACKDAGGER_HOST=0.0.0.0
ENV BLACKDAGGER_PORT=8080

# RUN /bin/bash -c ' \
# # Update the system and install sudo, handling file conflicts \
# pacman -Syu --noconfirm --overwrite "*" && \
# pacman -S --noconfirm --overwrite "*" sudo && \
# # Clean the package cache to reduce image size \
# pacman -Scc --noconfirm && \
# # User and permissions setup, checking if group/user already exists \
# if ! getent group ${USER_GID}; then \
# groupadd -g ${USER_GID} ${USER}; \
# fi; \
# if ! id -u ${USER} > /dev/null 2>&1; then \
# useradd -m -s /bin/bash -u ${USER_UID} -g ${USER_GID} ${USER}; \
# fi; \
# echo "${USER} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${USER} && \
# chmod 0440 /etc/sudoers.d/${USER} \
# '


RUN curl -L https://raw.githubusercontent.com/ErdemOzgen/blackdagger/main/scripts/downloader.sh | bash

EXPOSE 8080 8090

RUN <<EOF
# User and permissions setup
apt-get update
apt-get install -y sudo tzdata wget
groupadd -g ${USER_GID} ${USER} || true
useradd -m ${USER} -u ${USER_UID} -g ${USER_GID} -s /bin/bash
echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER}
chmod 0440 /etc/sudoers.d/${USER}

# Download and install gotty
wget https://github.com/some-location/gotty/releases/download/v1.0.0/gotty_linux_amd64 -O /usr/local/bin/gotty
chmod +x /usr/local/bin/gotty
EOF

USER blackdagger
WORKDIR /home/blackdagger
RUN <<EOF
export TARGET_FILE="blackdagger_${VERSION}_Linux_${TARGETARCH}.tar.gz"
wget ${RELEASES_URL}/download/v${VERSION}/${TARGET_FILE}
tar -xf ${TARGET_FILE} && rm *.tar.gz
sudo mv blackdagger /usr/local/bin/
mkdir .blackdagger
EOF

ENV blackdagger_HOST=0.0.0.0
ENV blackdagger_PORT=8080

# Start blackdagger in the background and gotty in the foregrounds
COPY startservices.sh /home/blackdagger/startservices.sh
#RUN chmod +x startservices.sh
#ENTRYPOINT [ "./startservices.sh" ]
COPY ./entrypoint.sh /entrypoint.sh
COPY ./startservices.sh /startservices.sh
COPY update_telegram_config.sh /usr/local/bin/update_telegram_config
RUN mv /work_dir/blackdagger /usr/local/bin/blackdagger
RUN sh -c 'cp /root/go/bin/* /usr/bin/'
RUN source ~/.bashrc
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DST_DIR=$(SRC_DIR)/internal
BUILD_VERSION=$(shell date +'%y%m%d%H%M%S')
LDFLAGS=-X 'main.version=$(BUILD_VERSION)'

VERSION=1.0.1
VERSION=1.0.2
DOCKER_CMD := docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --build-arg VERSION=$(VERSION) --push --no-cache

DEV_CERT_SUBJ_CA="/C=TR/ST=ASIA/L=TOKYO/O=DEV/OU=blackdagger/CN=*.blackdagger.dev/emailAddress[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var (
// rootCmd represents the base command when called without any subcommands
rootCmd = &cobra.Command{
Use: "blackdagger",
Short: "YAML-based DAG scheduling tool for red teaming.",
Long: `YAML-based DAG scheduling tool for red teaming.`,
Short: "YAML-based DAG scheduling tool for Red teaming,CART,DevOps,DevSecOps,MLOps,MLSecOps.",
Long: `YAML-based DAG scheduling tool for Red teaming,CART,DevOps,DevSecOps,MLOps,MLSecOps.`,
}
)

Expand Down
32 changes: 7 additions & 25 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
version: "3.9"
services:

# init container updates permission
init:
image: "erdemozgen/blackdagger:latest"
user: root
volumes:
- blackdagger:/home/blackdagger/.blackdagger
command: chown -R blackdagger /home/blackdagger/.blackdagger/

# ui web server process
# blackdagger server
server:
image: "erdemozgen/blackdagger:latest"
build: .
environment:
- blackdagger_PORT=8080
- blackdagger_DAGS=/home/blackdagger/.blackdagger/dags
- TERM=xterm
restart: unless-stopped
ports:
- "8080:8080"
- "8090:8090"
volumes:
- blackdagger:/home/blackdagger/.blackdagger
- ./dags/:/home/blackdagger/.blackdagger/dags
depends_on:
- init

# scheduler process
scheduler:
image: "erdemozgen/blackdagger:latest"
environment:
- blackdagger_DAGS=/home/blackdagger/.blackdagger/dags
restart: unless-stopped
volumes:
- blackdagger:/home/blackdagger/.blackdagger
- ./dags/:/home/blackdagger/.blackdagger/dags
command: blackdagger scheduler
depends_on:
- init
#command: ["bash", "/home/blackdagger/startservices.sh"] # Custom command to start the services
command: ["sh", "-c", "/startservices.sh"]

volumes:
blackdagger: {}

13 changes: 13 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Start the SSH server if needed
#/usr/sbin/sshd -D &

# If additional arguments were passed to the container, execute them
if [ $# -gt 0 ]; then
# Execute the provided command or script
exec "$@"
else
# Start an interactive shell if no arguments were provided
exec /bin/bash
fi
2 changes: 1 addition & 1 deletion internal/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package constants

var (
Version = "1.0.1"
Version = "1.0.2"
)

const (
Expand Down
44 changes: 22 additions & 22 deletions internal/pb/step.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e8cf4a4

Please sign in to comment.