Skip to content

Instantly share code, notes, and snippets.

@k4lizen
Created March 15, 2024 17:27
Show Gist options
  • Save k4lizen/03aff92e597cc5bffdbdc053f98c72b8 to your computer and use it in GitHub Desktop.
Save k4lizen/03aff92e597cc5bffdbdc053f98c72b8 to your computer and use it in GitHub Desktop.
Get LIBC and intrepreter from Dockerfile
#!/bin/sh
# dependencies: docker and https://github.com/BurntSushi/ripgrep
libc_renamed=libc.so.6
ldlinux_renamed=ld-linux.so
if distro=$(rg -or '$1$2' -- '(?:--from=|FROM )(debian|ubuntu)(\S+)?' Dockerfile); then
if container=$(docker container create "$distro"); then
if libs=$(docker run "$distro" ldd /bin/true); then
libs=$(printf %s "$libs" | awk 'NF == 4 {print $3}; NF == 2 {print $1}')
for lib in $libs; do
case $lib in
*libc*.so* ) docker cp -L "$container":"$lib" "$libc_renamed" ;;
*ld-linux*.so* ) docker cp -L "$container":"$lib" "$ldlinux_renamed" ;;
esac
done
else
# fallback if ldd is not available
docker cp -L "$container":/lib64/ld-linux-x86-64.so.2 "$ldlinux_renamed"
docker cp -L "$container":/lib/x86_64-linux-gnu/libc.so.6 "$libc_renamed"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment