annotate test/test_aslr.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 b550845e500b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1861
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 from pathlib import Path
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 import sys
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 from test_dropbear import *
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 def test_reexec(request, dropbear):
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 """
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 Tests that two consecutive connections have different address layouts.
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 This indicates that re-exec makes ASLR work
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 """
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 cmd = (Path(request.node.fspath).parent / "parent_dropbear_map.py").resolve()
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 r = dbclient(request, cmd, capture_output=True, text=True)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 map1 = r.stdout.rstrip()
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 print(r.stderr, file=sys.stderr)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 r.check_returncode()
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 r = dbclient(request, cmd, capture_output=True, text=True)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 map2 = r.stdout.rstrip()
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 print(r.stderr, file=sys.stderr)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 r.check_returncode()
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 print(map1)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 print(map2)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 # expect something like
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 # "563174d59000-563174d5d000 r--p 00000000 00:29 4242372 /home/matt/src/dropbear/build/dropbear"
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 assert map1.endswith('/dropbear')
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 assert ' r--p ' in map1
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 a1 = map1.split()[0]
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 a2 = map2.split()[0]
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 print(a1)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 print(a2)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 # relocation addresses should differ
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 assert a1 != a2
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34