Skip to content

Instantly share code, notes, and snippets.

@eschulte
Last active April 16, 2019 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eschulte/d69231d47f9175cc367ccc46d477fd2a to your computer and use it in GitHub Desktop.
Save eschulte/d69231d47f9175cc367ccc46d477fd2a to your computer and use it in GitHub Desktop.
# Build souffle
FROM ubuntu:18.04 as souffle
RUN apt-get -y update && apt-get -y install automake bison build-essential clang doxygen flex git libtool make mcpp openjdk-8-jdk pkg-config python sqlite3 libsqlite3-dev subversion swi-prolog zlib1g-dev
RUN git clone -b 1.4.0 https://github.com/souffle-lang/souffle
RUN cd souffle && sh ./bootstrap
RUN cd souffle && ./configure --prefix=/usr --enable-64bit-domain --disable-provenance
RUN cd souffle && make -j4 install
RUN cd souffle && cp include/souffle/RamTypes.h /usr/include/souffle/
# Build the faulty version of UnrealIRCd
# This is the oldest version of Ubuntu that seems to work w/Docker.
FROM ubuntu:14.04 as unrealircd
RUN apt-get -y update && apt-get -y install automake build-essential git libssl-dev wget
RUN wget http://stalkr.net/files/unrealircd/Unreal3.2.8.1_backdoor.tar.gz
RUN tar xzf Unreal3.2.8.1_backdoor.tar.gz
WORKDIR /Unreal3.2
# This change was required to get the build to go through.
RUN sed -i 's/inline void parse_addlag/void parse_addlag/' src/parse.c
RUN ./configure
# As was this extra call to gcc.
RUN make; cd src/;gcc -I../include -I/Unreal3.2/extras/regexp/include -I/Unreal3.2/extras/c-ares/include -L../extras/c-ares/lib -pipe -g -O2 -funsigned-char -fno-strict-aliasing -Wno-pointer-sign -o ircd timesynch.o res.o s_bsd.o auth.o aln.o channel.o cloak.o crule.o dbuf.o events.o fdlist.o hash.o help.o ircd.o ircsprintf.o list.o lusers.o match.o modules.o packet.o parse.o s_auth.o s_conf.o s_debug.o s_err.o s_extra.o s_kline.o s_misc.o s_numeric.o s_serv.o s_svs.o socket.o ssl.o s_user.o charsys.o scache.o send.o support.o umodes.o version.o whowas.o zip.o cidr.o random.o extcmodes.o extbans.o md5.o api-isupport.o api-command.o -lcrypt -lnsl -L../extras/regexp/lib -ltre -lcares -lrt -ldl
# Build GTIRB, GTIRB-pprinter, and DDisasm
FROM ubuntu:18.04
RUN apt-get -y update && \
apt-get -y install clang git build-essential \
wget curl autoconf libtool cmake mcpp
# Build capstone
RUN cd /usr/local/src \
&& wget https://github.com/aquynh/capstone/archive/4.0.1.tar.gz \
&& tar xf 4.0.1.tar.gz \
&& cd capstone-4.0.1 \
&& CAPSTONE_ARCHS=x86 ./make.sh \
&& CAPSTONE_ARCHS=x86 ./make.sh install
# Build protobuf
RUN cd /usr/local/src \
&& wget https://github.com/google/protobuf/releases/download/v3.6.0/protobuf-cpp-3.6.0.tar.gz \
&& tar xf protobuf-cpp-3.6.0.tar.gz \
&& cd protobuf-3.6.0 \
&& ./configure \
&& make \
&& make install
RUN ldconfig
# Build Boost
ARG BOOST_VERSION=1.67.0
ARG BOOST_VERSION_=1_67_0
ENV BOOST_VERSION=${BOOST_VERSION}
ENV BOOST_VERSION_=${BOOST_VERSION_}
ENV BOOST_ROOT=/usr/include/boost
RUN cd /home && wget https://dl.bintray.com/boostorg/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_}.tar.gz \
&& tar xfz boost_${BOOST_VERSION_}.tar.gz \
&& rm boost_${BOOST_VERSION_}.tar.gz \
&& cd boost_${BOOST_VERSION_} \
&& ./bootstrap.sh --prefix=/usr --with-libraries=program_options,filesystem,system,serialization \
&& ./b2 install \
&& cd /home \
&& rm -rf boost_${BOOST_VERSION_}
# Build GTIRB
RUN git clone https://github.com/GrammaTech/gtirb
RUN cmake /gtirb -B/gtirb/build -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_COMPILER=g++-7 -DGTIRB_USE_SYSTEM_BOOST=ON
RUN make -C/gtirb/build install
# Build gtirb-pprinter
RUN git clone https://github.com/GrammaTech/gtirb-pprinter
RUN cmake /gtirb-pprinter -B/gtirb-pprinter/build -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_COMPILER=g++-7 -DGTIRB_PPRINTER_USE_SYSTEM_BOOST=ON
RUN make -C/gtirb-pprinter/build install
# Build ddisasm
COPY --from=souffle /usr/bin/souffle-compile /usr/bin/souffle-compile
COPY --from=souffle /usr/bin/souffle-config /usr/bin/souffle-config
COPY --from=souffle /usr/bin/souffle /usr/bin/souffle
COPY --from=souffle /usr/bin/souffle-profile /usr/bin/souffle-profile
COPY --from=souffle /usr/share/man/man1/souffle.1 /usr/share/man/man1/souffle.1
COPY --from=souffle /usr/share/man/man1/souffle-config.1 /usr/share/man/man1/souffle-config.1
COPY --from=souffle /usr/share/man/man1/souffle-profile.1 /usr/share/man/man1/souffle-profile.1
COPY --from=souffle /usr/share/man/man1/souffle-compile.1 /usr/share/man/man1/souffle-compile.1
COPY --from=souffle /usr/include/souffle/ /usr/include/souffle
ENV TERM xterm
# RUN git clone https://github.com/grammatech/ddisasm.git
RUN git clone https://git.grammatech.com/rewriting/ddisasm.git --branch other-symbols-without-address
RUN rm -rf /ddisasm/build /ddisasm/CMakeCache.txt /ddisasm/CMakeFiles /ddisasm/CMakeScripts
RUN cmake /ddisasm -B/ddisasm/build -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_COMPILER=g++-7 -DDDISASM_USE_SYSTEM_BOOST=ON
RUN make -C/ddisasm/build install
ENV PATH=/ddisasm/build/bin:$PATH
# Copy in the UnrealIRCd binary.
COPY --from=unrealircd /Unreal3.2/ /Unreal3.2/
COPY --from=unrealircd /Unreal3.2/src/ircd /ircd
# Analyze the resulting ircd binary
WORKDIR /
RUN ddisasm /ircd --ir /ircd.gtirb
RUN gtirb-pprinter /ircd.gtirb -o /ircd.s
# Inspect with GTIRB.
COPY blog.cpp blog.cpp
RUN g++ --std=c++17 blog.cpp -lgtirb
RUN ./a.out /ircd.gtirb 1
# Repair.
RUN sed 's/system@PLT/puts@PLT/' -i ircd.s
RUN gcc ircd.s -o ircd-fixed -lcrypt -lrt -ldl -lc -lpthread -no-pie
@eschulte
Copy link
Author

eschulte commented Apr 15, 2019

Alternately, the Dockerfile based on Arch Linux is somewhat simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment