Ejemplo n.º 1
0
    def test_gcc(self):
        sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
        output = os.path.join(self.tmp_dir, "gcc.section")

        gcc = lief.parse(sample_path)
        for i in range(10):
            section = Section(".test.{:d}".format(i),
                              lief.ELF.SECTION_TYPES.PROGBITS)
            section.type = lief.ELF.SECTION_TYPES.PROGBITS
            section += lief.ELF.SECTION_FLAGS.EXECINSTR
            section += lief.ELF.SECTION_FLAGS.WRITE
            section.content = STUB.segments[
                0].content  # First LOAD segment which holds payload

            if i % 2 == 0:
                section = gcc.add(section, loaded=True)
                gcc.header.entrypoint = section.virtual_address + STUB.header.entrypoint
            else:
                section = gcc.add(section, loaded=False)

        gcc.write(output)

        st = os.stat(output)
        os.chmod(output, st.st_mode | stat.S_IEXEC)

        p = Popen(output, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        stdout, _ = p.communicate()
        self.logger.debug(stdout.decode("utf8"))
        self.assertIsNotNone(
            re.search(r'LIEF is Working', stdout.decode("utf8")))
Ejemplo n.º 2
0
    def test_gcc(self):
        sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
        output = os.path.join(self.tmp_dir, "gcc.section")

        gcc = lief.parse(sample_path)
        section = Section()
        section.name = "test"
        section.type = lief.ELF.SECTION_TYPES.PROGBITS
        section.content = STUB.segments[
            0].content  # First LOAD segment which holds payload
        section.alignment = 8
        section = gcc.add_section(section, True)

        gcc.header.entrypoint = section.virtual_address + STUB.header.entrypoint

        gcc.write(output)

        st = os.stat(output)
        os.chmod(output, st.st_mode | stat.S_IEXEC)

        p = Popen(output, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        stdout, _ = p.communicate()
        self.logger.debug(stdout.decode("utf8"))
        self.assertIsNotNone(
            re.search(r'LIEF is Working', stdout.decode("utf8")))
Ejemplo n.º 3
0
import lief
from lief.ELF import Section

ls = lief.parse("/bin/clang")
stub = lief.parse("hello_lief.bin")

section = Section()
section.name = "test"
section.type = lief.ELF.SECTION_TYPES.PROGBITS
section.content = stub.segments[
    0].data  # First LOAD segment which holds payload
section.entry_size = 0
section.alignment = 8
section = ls.add_section(section, True)

ls.header.entrypoint = section.virtual_address + stub.header.entrypoint

ls.write("lst.section")
# Have fun !