eeriedusk / nysm

nysm is a stealth post-exploitation container.
Apache License 2.0
237 stars 39 forks source link

Compilation error on Ubuntu: libelf or zstd not correct? #3

Open yzegfell opened 2 months ago

yzegfell commented 2 months ago

Hi!

I am trying to compile this in a VM running Ubuntu

6.8.0-41-generic #41-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug  2 20:41:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS"

When running make, I get the following error message:

  MKDIR    .output
  MKDIR    .output/libbpf
  LIB      libbpf.a
  MKDIR    /home/user/Desktop/nysm/src/.output//libbpf/staticobjs
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/bpf.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/btf.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/libbpf.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/libbpf_errno.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/netlink.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/nlattr.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/str_error.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/libbpf_probes.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/bpf_prog_linfo.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/btf_dump.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/hashmap.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/ringbuf.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/strset.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/linker.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/gen_loader.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/relo_core.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/usdt.o
  CC       /home/user/Desktop/nysm/src/.output//libbpf/staticobjs/zip.o
  AR       /home/user/Desktop/nysm/src/.output//libbpf/libbpf.a
  INSTALL  bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h bpf_helpers.h bpf_helper_defs.h bpf_tracing.h bpf_endian.h bpf_core_read.h skel_internal.h libbpf_version.h usdt.bpf.h
  INSTALL  /home/user/Desktop/nysm/src/.output//libbpf/libbpf.pc
  INSTALL  /home/user/Desktop/nysm/src/.output//libbpf/libbpf.a 
  BPF      .output/nysm.bpf.o
  GEN-SKEL .output/nysm.skel.h
  CC       .output/nysm.o
  BINARY   nysm
/usr/bin/ld: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0x113): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: (.text+0x2a9): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x2b4): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x2db): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x5a0): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x5ab): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x6b9): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x835): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x86f): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x91b): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0xa12): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xbfc): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xc04): undefined reference to `ZSTD_isError'
/usr/bin/ld: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xd4d): undefined reference to `ZSTD_isError'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:79: nysm] Error 1

I have tried to search for error sources with libelf/libz but have not managed to fix this error. Is it reproducible or has the libraries changed so it is not compatible with the code any longer?

eeriedusk commented 2 months ago

Hello!

Thanks for raising this issue! I was able to reproduce it on Ubuntu 24.04. You can fix this by adding:

-l:libzstd.a

in the Makefile where it builds the application binary (l.79). I still have to check if it affects other distros.