$OpenBSD: patch-pwnlib_elf_elf_py,v 1.5 2021/01/18 20:11:41 jasper Exp $

- Add support for checking for retguard

Index: pwnlib/elf/elf.py
--- pwnlib/elf/elf.py.orig
+++ pwnlib/elf/elf.py
@@ -1761,6 +1761,15 @@ class ELF(ELFFile):
     aslr=pie
 
     @property
+    def retguard(self):
+        """:class:`bool`: Whether the current binary was compiled with retguard."""
+        s_randomdata = self.get_section_by_name('.openbsd.randomdata')
+        if s_randomdata and len(s_randomdata.data()) >= 48:
+            return True
+
+        return False
+
+    @property
     def rpath(self):
         """:class:`bool`: Whether the current binary has an ``RPATH``."""
         dt_rpath = self.dynamic_by_tag('DT_RPATH')
@@ -1819,6 +1828,10 @@ class ELF(ELFFile):
                 True: green("PIE enabled"),
                 False: red("No PIE (%#x)" % self.address)
             }[self.pie],
+            "Retguard:".ljust(10) + {
+                True: green("Retguard found"),
+                False: red("No retguard found"),
+            }[self.retguard],
         ])
 
         # Execstack may be a thing, even with NX enabled, because of glibc
