comparison 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
comparison
equal deleted inserted replaced
1860:5001e9c5641f 1861:2b3a8026a6ce
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5 import time
6 import psutil
7
8 from pathlib import Path
9
10
11 want_name = "dropbear"
12 # Walks up the parent process tree, prints the first line of /proc/pid/maps when
13 # it finds the wanted name
14
15 def main():
16
17 try:
18 for p in psutil.Process().parents():
19 print(p.pid, file=sys.stderr)
20 print(p.name(), file=sys.stderr)
21 print(p.cmdline(), file=sys.stderr)
22
23 if want_name in p.name():
24 with (Path('/proc') / str(p.pid) / "maps").open() as f:
25 map0 = f.readline().rstrip()
26 print(map0)
27 return
28
29 raise RuntimeError(f"Couldn't find parent {want_name} process")
30 except Exception as e:
31 print(psutil.Process().parents())
32 for p in psutil.Process().parents():
33 print(p.name())
34 print(e)
35 # time.sleep(100)
36 raise
37
38 if __name__ == "__main__":
39 main()