diff test/parent_dropbear_map.py @ 1861:2b3a8026a6ce

Add re-exec for server This allows ASLR to re-randomize the address space for every connection, preventing some vulnerabilities from being exploitable by repeated probing. Overhead (memory and time) is yet to be confirmed. At present this is only enabled on Linux. Other BSD platforms with fexecve() would probably also work though have not been tested.
author Matt Johnston <matt@ucc.asn.au>
date Sun, 30 Jan 2022 10:14:56 +0800
parents
children 1c9215154d4a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/parent_dropbear_map.py	Sun Jan 30 10:14:56 2022 +0800
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+import time
+import psutil
+
+from pathlib import Path
+
+
+want_name = "dropbear"
+# Walks up the parent process tree, prints the first line of /proc/pid/maps when
+# it finds the wanted name
+
+def main():
+
+	try:
+		for p in psutil.Process().parents():
+			print(p.pid, file=sys.stderr)
+			print(p.name(), file=sys.stderr)
+			print(p.cmdline(), file=sys.stderr)
+
+			if want_name in p.name():
+				with (Path('/proc') / str(p.pid) / "maps").open() as f:
+					map0 = f.readline().rstrip()
+				print(map0)
+				return
+
+		raise RuntimeError(f"Couldn't find parent {want_name} process")
+	except Exception as e:
+		print(psutil.Process().parents())
+		for p in psutil.Process().parents():
+			print(p.name())
+		print(e)
+		# time.sleep(100)
+		raise
+
+if __name__ == "__main__":
+	main()