|
| 1 | +#!/usr/bin/env python |
| 2 | +import sys |
| 3 | +import os |
| 4 | + |
| 5 | +import socket |
| 6 | +import pickle |
| 7 | +import base64 |
| 8 | +import marshal |
| 9 | +import types |
| 10 | +import inspect |
| 11 | +import encodings.string_escape |
| 12 | + |
| 13 | +class Flag(object): |
| 14 | + def __init__(self): |
| 15 | + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 16 | + s.connect(("172.17.0.1", 1234)) |
| 17 | + self.flag = s.recv(1024).strip() |
| 18 | + s.close() |
| 19 | +flag = Flag() |
| 20 | + |
| 21 | +from seccomp import * |
| 22 | + |
| 23 | +f = SyscallFilter(KILL) |
| 24 | +f.add_rule_exactly(ALLOW, "read") |
| 25 | +f.add_rule_exactly(ALLOW, "write", Arg(0, EQ, sys.stdout.fileno())) |
| 26 | +f.add_rule_exactly(ALLOW, "write", Arg(0, EQ, sys.stderr.fileno())) |
| 27 | +f.add_rule_exactly(ALLOW, "close") |
| 28 | +f.add_rule_exactly(ALLOW, "exit_group") |
| 29 | + |
| 30 | +f.add_rule_exactly(ALLOW, "open", Arg(1, EQ, 0)) |
| 31 | +f.add_rule_exactly(ALLOW, "stat") |
| 32 | +f.add_rule_exactly(ALLOW, "lstat") |
| 33 | +f.add_rule_exactly(ALLOW, "lseek") |
| 34 | +f.add_rule_exactly(ALLOW, "fstat") |
| 35 | +f.add_rule_exactly(ALLOW, "getcwd") |
| 36 | +f.add_rule_exactly(ALLOW, "readlink") |
| 37 | +f.add_rule_exactly(ALLOW, "mmap", Arg(3, MASKED_EQ, 2, 2)) |
| 38 | +f.add_rule_exactly(ALLOW, "munmap") |
| 39 | +f.load() |
| 40 | + |
| 41 | +data = os.read(0, 4096) |
| 42 | +try: |
| 43 | + res = pickle.loads(data) |
| 44 | + print 'res: %r\n' % res |
| 45 | +except Exception as e: |
| 46 | + print >>sys.stderr, "exception", repr(e) |
| 47 | + |
| 48 | +os._exit(0) |
0 commit comments