Skip to content

Commit b4a8f37

Browse files
authored
Merge pull request #10 from slashbinslashcat/bashcve/bashcve
sunglasses
2 parents 62a2d29 + 3c26594 commit b4a8f37

7 files changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dockerfile
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
What truly is a bug? Is it just an unintended side effect of badly written code, or is it a deeper metaphor, highlighting that no matter how hard we try we can never achieve perfection?
2+
3+
I don't know but here is a bash CVE challenge, go crash it.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Dockerfile: build unpatched bash-4.3 in a historically-compatible environment
2+
FROM ubuntu:24.04
3+
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
RUN mkdir -p /challenge/bin
7+
COPY run_bashfile.c crash_to_flag.c /challenge/
8+
9+
WORKDIR /opt
10+
11+
# Install build deps (including bison so parse.y is generated)
12+
RUN apt-get update && apt-get install -y --no-install-recommends \
13+
cmake python3-pwntools git build-essential wget bison flex gettext gawk perl file ca-certificates \
14+
&& rm -rf /var/lib/apt/lists/*
15+
# Fetch bash 4.3 source
16+
RUN wget -q https://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz && \
17+
tar -xzf /opt/bash-4.3.tar.gz -C /opt && rm /opt/bash-4.3.tar.gz
18+
RUN wget https://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-027 -O /challenge/patch.diff
19+
ADD --chown=0:0 --chmod=6755 http://github.com/pwncollege/exec-suid/releases/latest/download/exec-suid /usr/bin/exec-suid
20+
WORKDIR /opt/bash-4.3
21+
22+
# Configure and build (debug symbols, no optimization), install to /opt/bash43
23+
RUN CFLAGS="-g -O0 -D_GNU_SOURCE" ./configure --prefix=/opt/bash43 && \
24+
make -j"$(nproc)" && \
25+
make install
26+
27+
# Build helper binary
28+
RUN gcc -fPIC -shared -o /challenge/crash_to_flag.so /challenge/crash_to_flag.c
29+
RUN gcc -I/challenge/include -o /challenge/bin/run_bashfile /challenge/*.c -L/challenge/lib
30+
RUN chmod 0755 /challenge/bin/run_bashfile
31+
RUN chmod 755 /opt/bash43/bin/bash
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "base_templates/crash_to_flag.c" %}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <unistd.h>
5+
6+
int main(int argc, char *argv[]) {
7+
if (argc != 2) {
8+
fprintf(stderr, "Usage: %s <shell_script.sh>\n", argv[0]);
9+
return 1;
10+
}
11+
12+
const char *filename = argv[1];
13+
size_t len = strlen(filename);
14+
15+
if (len > 3 && strcmp(filename + len - 3, ".sh") != 0) {
16+
printf("The file '%s' is NOT a .sh file.\n", filename);
17+
return 1;
18+
}
19+
20+
printf("Running your script: %s\n", filename);
21+
printf("=====================================\n\n");
22+
23+
const char *custom_bash = "/opt/bash43/bin/bash";
24+
setenv("LD_PRELOAD", "/challenge/crash_to_flag.so", 1);
25+
char *newargv[] = { (char *)custom_bash, (char *)filename, NULL };
26+
int ret = execv(custom_bash, newargv);
27+
if (ret == -1) {
28+
perror("execl failed");
29+
return 1;
30+
}
31+
32+
printf("=====================================\n\n");
33+
printf("Script ran sucessfully\n");
34+
return 0;
35+
}
231 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
echo "/opt/bash43/bin/bash --version | grep -m 1 'version'" > /tmp/get_version.sh
4+
chmod +x /tmp/get_version.sh
5+
/challenge/bin/run_bashfile /tmp/get_version.sh

0 commit comments

Comments
 (0)