test_aslr.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from pathlib import Path
  2. import sys
  3. from test_dropbear import *
  4. def test_reexec(request, dropbear):
  5. """
  6. Tests that two consecutive connections have different address layouts.
  7. This indicates that re-exec makes ASLR work
  8. """
  9. map_script = (Path(request.node.fspath).parent / "parent_dropbear_map.py").resolve()
  10. # run within the same venv, for python deps
  11. activate = own_venv_command()
  12. cmd = f"{activate}; {map_script}"
  13. print(cmd)
  14. r = dbclient(request, cmd, capture_output=True, text=True)
  15. map1 = r.stdout.rstrip()
  16. print(r.stderr, file=sys.stderr)
  17. r.check_returncode()
  18. r = dbclient(request, cmd, capture_output=True, text=True)
  19. map2 = r.stdout.rstrip()
  20. print(r.stderr, file=sys.stderr)
  21. r.check_returncode()
  22. print(map1)
  23. print(map2)
  24. # expect something like
  25. # "563174d59000-563174d5d000 r--p 00000000 00:29 4242372 /home/matt/src/dropbear/build/dropbear"
  26. assert map1.endswith('/dropbear') or map1.endswith('/dropbearmulti')
  27. a1 = map1.split()[0]
  28. a2 = map2.split()[0]
  29. print(a1)
  30. print(a2)
  31. # relocation addresses should differ
  32. assert a1 != a2