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
+52
@@ -0,0 +1,52 @@
|
||||
// Isolation probe: TCP, UDP, listening, name resolution, and raw, packet,
|
||||
// and netlink sockets must all fail.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var reached []string
|
||||
for _, target := range []struct{ network, address string }{
|
||||
{"tcp", "1.1.1.1:53"}, {"tcp", "127.0.0.1:8443"}, {"tcp6", "[::1]:8443"}, {"udp", "8.8.8.8:53"},
|
||||
} {
|
||||
connection, err := net.DialTimeout(target.network, target.address, time.Second)
|
||||
if err == nil {
|
||||
// UDP "connects" without traffic; a write proves the route.
|
||||
if _, writeErr := connection.Write([]byte("x")); writeErr == nil {
|
||||
reached = append(reached, target.address)
|
||||
}
|
||||
_ = connection.Close()
|
||||
}
|
||||
}
|
||||
if listener, err := net.Listen("tcp", "127.0.0.1:0"); err == nil {
|
||||
reached = append(reached, "listen")
|
||||
_ = listener.Close()
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if _, err := net.DefaultResolver.LookupHost(ctx, "example.com"); err == nil {
|
||||
reached = append(reached, "dns")
|
||||
}
|
||||
for _, socket := range []struct{ domain, kind, protocol int }{
|
||||
{syscall.AF_INET, syscall.SOCK_RAW, syscall.IPPROTO_ICMP},
|
||||
{syscall.AF_PACKET, syscall.SOCK_RAW, 0},
|
||||
{syscall.AF_NETLINK, syscall.SOCK_RAW, 0},
|
||||
} {
|
||||
if fd, err := syscall.Socket(socket.domain, socket.kind, socket.protocol); err == nil {
|
||||
reached = append(reached, fmt.Sprintf("socket %d", socket.domain))
|
||||
_ = syscall.Close(fd)
|
||||
}
|
||||
}
|
||||
if len(reached) == 0 {
|
||||
fmt.Println("blocked")
|
||||
return
|
||||
}
|
||||
fmt.Println("reached " + strings.Join(reached, ", "))
|
||||
}
|
||||
Reference in new issue
Block a user