VirtualBox

Ticket #18737: poc_18737.py

File poc_18737.py, 1.8 KB (added by justinsteven, 5 years ago)
Line 
1#!/usr/bin/env python3
2import sys
3import os
4import tempfile
5
6# [+] Config
7verbose_output = False
8colorful_output = False
9
10if verbose_output and colorful_output:
11 import colorama
12
13def main():
14 my_dir = os.path.dirname(os.path.realpath(__file__))
15 tempdir = tempfile.mkdtemp(dir = my_dir)
16
17 success_modes = []
18 failure_modes = []
19
20 for mode in range(0o000, 0o1000):
21 try:
22 res = os.open(os.path.join(tempdir, str(mode)),
23 os.O_CREAT | os.O_EXCL | os.O_RDWR,
24 mode)
25 success_modes.append(mode)
26 except PermissionError:
27 failure_modes.append(mode)
28
29 print("Successes:")
30 print(list(map(oct, success_modes)))
31
32 print("Failures:")
33 print(list(map(oct, failure_modes)))
34
35 if verbose_output:
36 for mode in range(0o000, 0o1000):
37 buf = []
38
39 if colorful_output:
40 if mode in success_modes:
41 buf.append(colorama.Fore.GREEN)
42 elif mode in failure_modes:
43 buf.append(colorama.Fore.RED)
44 else:
45 buf.append(colorama.Fore.BLUE)
46
47 buf.append(str(oct(mode)))
48 buf.append("\t\t{}".format(perm_to_text(mode)))
49
50 if mode in success_modes:
51 buf.append("\t PASS")
52 elif mode in failure_modes:
53 buf.append("\t\t FAIL")
54 else:
55 buf.append("\t\t\tWTF")
56
57 if colorful_output:
58 buf.append(colorama.Style.RESET_ALL)
59
60 print("".join(buf))
61
62def perm_to_text(perm):
63 res = []
64 if perm < 0 or perm > 0o777:
65 raise ValueError
66 # For each nibble
67 for i in range(2,-1,-1):
68 # Extract the nibble
69 nibble = (perm & (0o7 << (i*3))) >> (i*3)
70 # Test the nibble for rwx
71 res.append("r" if nibble & 0o4 else "-")
72 res.append("w" if nibble & 0o2 else "-")
73 res.append("x" if nibble & 0o1 else "-")
74 return "".join(res)
75
76if (__name__ == "__main__"):
77 sys.exit(main())

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy