test(runner): verify sandbox isolation with a hostile program suite
This commit is contained in:
1 parent
afee564bf4
commit
e858280d91
38 files changed
+1359
-168
No files matched your search
+18
-8
@@ -1,13 +1,11 @@
|
||||
# Isolation probe: every attempt to reach a network must fail.
|
||||
# Isolation probe: every attempt to reach or sniff a network must fail,
|
||||
# including raw, packet, and netlink sockets and name resolution.
|
||||
import socket
|
||||
|
||||
attempts = [
|
||||
(socket.AF_INET, ("1.1.1.1", 53)),
|
||||
(socket.AF_INET, ("127.0.0.1", 8080)),
|
||||
(socket.AF_INET6, ("::1", 8080)),
|
||||
]
|
||||
attempts = 0
|
||||
reached = []
|
||||
for family, address in attempts:
|
||||
for family, address in ((socket.AF_INET, ("1.1.1.1", 53)), (socket.AF_INET, ("127.0.0.1", 8443)), (socket.AF_INET6, ("::1", 8443))):
|
||||
attempts += 1
|
||||
try:
|
||||
with socket.socket(family, socket.SOCK_STREAM) as connection:
|
||||
connection.settimeout(1)
|
||||
@@ -15,4 +13,16 @@ for family, address in attempts:
|
||||
reached.append(address[0])
|
||||
except OSError:
|
||||
pass
|
||||
print("blocked" if not reached else "reached " + " ".join(reached))
|
||||
for family, kind, protocol in ((socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP), (getattr(socket, "AF_PACKET", 17), socket.SOCK_RAW, 0), (getattr(socket, "AF_NETLINK", 16), socket.SOCK_RAW, 0)):
|
||||
attempts += 1
|
||||
try:
|
||||
socket.socket(family, kind, protocol).close()
|
||||
reached.append(f"socket {family}/{kind}")
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
socket.getaddrinfo("example.com", 443)
|
||||
reached.append("dns")
|
||||
except OSError:
|
||||
pass
|
||||
print("blocked" if not reached else "reached " + ", ".join(reached))
|
||||
Reference in new issue
Block a user