modified options in make_elf to disable newer GNU linker warnings
linker options
the stable/dev repositories of asm/make_elf throw when building ELFs due to an error with a newly implemented GNU linker warning that warns about LOAD segment with RWX permissions. Adding the --no-warn-rwx-segments and --no-warn-execstack linker options remediates this issue
See kernel.org mailing list for explanation of these new gnu linker warnings
error replication
from pwn import * p = run_assembly('push 0xbad') [ERROR] There was an error running ['/usr/bin/x86_64-linux-gnu-ld', '--oformat=elf32-i386', '-EL', '-m', 'elf_i386', '-z', 'execstack', '-o', '/tmp/pwn-asm-phbp53vv/step3', '/tmp/pwn-asm-phbp53vv/step2', '--section-start=.shellcode=0x10000000', '--entry=0x10000000', '-z', 'max-page-size=4096', '-z', 'common-page-size=4096']: It had this on stdout: /usr/bin/x86_64-linux-gnu-ld: warning: /tmp/pwn-asm-phbp53vv/step3 has a LOAD segment with RWX permissions
[ERROR] An error occurred while assembling: 1: .section .shellcode,"awx" 2: .global _start 3: .global __start 4: .p2align 2 5: _start: 6: __start: 7: .intel_syntax noprefix 8: push 0xbad Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/pwnlib/asm.py", line 710, in asm _run(linker + ldflags) File "/usr/local/lib/python3.10/dist-packages/pwnlib/asm.py", line 404, in _run log.error(msg, *args) File "/usr/local/lib/python3.10/dist-packages/pwnlib/log.py", line 424, in error raise PwnlibException(message % args) pwnlib.exception.PwnlibException: There was an error running ['/usr/bin/x86_64-linux-gnu-ld', '--oformat=elf32-i386', '-EL', '-m', 'elf_i386', '-z', 'execstack', '-o', '/tmp/pwn-asm-phbp53vv/step3', '/tmp/pwn-asm-phbp53vv/step2', '--section-start=.shellcode=0x10000000', '--entry=0x10000000', '-z', 'max-page-size=4096', '-z', 'common-page-size=4096']: It had this on stdout: /usr/bin/x86_64-linux-gnu-ld: warning: /tmp/pwn-asm-phbp53vv/step3 has a LOAD segment with RWX permissions
Traceback (most recent call last):
File "
This needs some guard around the linker version, since unkown arguments don't appear to be ignored on older versions.
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
$ ld --no-warn-rwx-segments
ld: unrecognized option '--no-warn-rwx-segments'
ld: use the --help option for usage information
$ ld --no-warn-execstack
ld: unrecognized option '--no-warn-execstack'
ld: use the --help option for usage information
Thank you. Updated to include a guard. Additionally, updated another location where it was necessary to add the new linker options.
Sadly, it seems that your method of checking ld versioning does not account for all types of output.
re.search(r' (\d+\.\d+.\d+)', result) doesn't pick up 2.39.
The regex does not pickup Kali Linux's and Garuda's output of ld --version:
Here is the example of such output
GNU ld (GNU Binutils for Debian) 2.39
Copyright (C) 2022 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
I'd suggest changing the regex to (\d+(?:\.\d+)+).
Another option would be to execute ld --no-warn-rwx-segments --help and check the return status.