Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed docker issues #707

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
FROM ubuntu:24.04

ARG BINWALK_INSTALL_DIR="/tmp/binwalk"
ARG DEFAULT_WORKING_DIR="/analysis"

WORKDIR /tmp

# Update apt and install git
RUN apt-get update && apt-get upgrade -y && apt-get install -y git
# Update apt
RUN apt-get update && apt-get upgrade -y

# Pull down latest Binwalk code
RUN git clone https://github.com/ReFirmLabs/binwalk.git
# Copy over the Binwalk build directory
RUN mkdir -p ${BINWALK_INSTALL_DIR}
COPY . ${BINWALK_INSTALL_DIR}

# Allow pip to install packages system-wide
RUN mkdir -p $HOME/.config/pip && echo "[global]" > $HOME/.config/pip/pip.conf && echo "break-system-packages = true" >> $HOME/.config/pip/pip.conf

# Install all system dependencies
RUN /tmp/binwalk/dependencies/ubuntu.sh
RUN ${BINWALK_INSTALL_DIR}/dependencies/ubuntu.sh

# Install Rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

# Build and install Binwalk
RUN cd /tmp/binwalk && /root/.cargo/bin/cargo build --release && cp ./target/release/binwalk /usr/local/bin/binwalk
RUN cd ${BINWALK_INSTALL_DIR} && /root/.cargo/bin/cargo build --release && cp ./target/release/binwalk /usr/local/bin/binwalk

# Clean up binwalk build directory
RUN rm -rf /tmp/binwalk
RUN rm -rf ${BINWALK_INSTALL_DIR}

RUN useradd -m -u 1337 -s /sbin/nologin appuser
# Create the working directory
RUN mkdir -p ${DEFAULT_WORKING_DIR} && chmod 777 ${DEFAULT_WORKING_DIR}
WORKDIR ${DEFAULT_WORKING_DIR}

WORKDIR /home/appuser
# Run as the default ubuntu user
USER ubuntu

USER appuser
# Enable this environment variable to remove extractor top-level symlink,
# as the symlink target path in the docker environment will not match that of the host.
ENV BINWALK_RM_EXTRACTION_SYMLINK=1

ENTRYPOINT [ "binwalk" ]
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ fn main() {
// Number of seconds to wait before printing debug progress info
const PROGRESS_INTERVAL: u64 = 30;

// If this env var is set during extraction, the Binwalk.base_target_file symlink will
// be deleted at the end of extraction.
const BINWALK_RM_SYMLINK: &str = "BINWALK_RM_EXTRACTION_SYMLINK";

// Output directory for extracted files
let mut output_directory: Option<String> = None;

Expand Down Expand Up @@ -213,6 +217,16 @@ fn main() {
}
}

// If BINWALK_RM_SYMLINK env var was set, delete the base_target_file symlink
if cliargs.extract && std::env::var(BINWALK_RM_SYMLINK).is_ok() {
if let Err(e) = std::fs::remove_file(&binwalker.base_target_file) {
error!(
"Request to remove extraction symlink file {} failed: {}",
binwalker.base_target_file, e
);
}
}

// All done, show some basic statistics
display::print_stats(
cliargs.quiet,
Expand Down