-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest_extra_dataset.py
More file actions
154 lines (124 loc) · 4.85 KB
/
Copy pathtest_extra_dataset.py
File metadata and controls
154 lines (124 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/python3
import argparse
import os
import sys
from pathlib import Path
from pwn import context
from saeg import BANNER, FLAG, FLAG_FILE_NAMES, local_aeg
from testset import FAIL_MAX
EXTRA_TESTS = {
'ZONG_HENG_CUP_TEST_SET': {
'path': 'assets/extra_dataset/zonghengcup/',
'task': {
'pwn1': FAIL_MAX,
},
'libc': 'libc-2.31-x86.so',
'ld': 'ld-2.31-x86.so',
'sig': ['libc6_2.23-0ubuntu10_i386.sig'],
'concurrent': {
'pwn1': -1,
},
},
'WANG_DING_CUP_TEST_SET': {
'path': 'assets/extra_dataset/wangdingcup2023/',
'task': {
'bin-1': FAIL_MAX,
'bin-2': FAIL_MAX,
'bin-4': FAIL_MAX,
'bin-5': FAIL_MAX,
'bin-6': FAIL_MAX,
'bin-10': FAIL_MAX,
},
'static': ['bin-1', 'bin-2', 'bin-5', 'bin-6'],
'sig': ['libc6_2.23-0ubuntu7_i386.sig', 'extra_dataset/extra.sig']
},
'ZERATOOL_TEST_SET': {
'path': 'assets/extra_dataset/zeratool_challenges/',
'task': {
'bof1': FAIL_MAX,
'bof2': FAIL_MAX,
'bof3': FAIL_MAX,
'heap0': FAIL_MAX,
'ret': FAIL_MAX,
}
},
}
def chmod_x(path):
os.chmod(path, os.stat(path).st_mode | 0o111)
def chmod_x_children(path):
for child in path.glob('*'):
if child.is_file():
chmod_x(child)
def write_flags():
for flag_name in FLAG_FILE_NAMES:
Path(flag_name).write_text(FLAG)
def clean_flags():
for flag_name in FLAG_FILE_NAMES:
Path(flag_name).unlink(missing_ok=True)
def asset_path(root, asset_name):
return str(root / 'assets' / asset_name)
def task_concurrent(test_set, task_name, concurrent):
if concurrent is not None:
return concurrent
concurrent_setting = test_set.get('concurrent', 1)
if isinstance(concurrent_setting, dict):
return concurrent_setting.get(task_name, 1)
return concurrent_setting
def run_extra_tests(timeout, debug, concurrent):
context.log_level = 'error'
root = Path.cwd().resolve()
result = BANNER
chmod_x_children(root / 'assets')
for test_set_name, test_set in EXTRA_TESTS.items():
result += f"Testing {test_set_name} in {test_set['path']}\n"
failed = 0
failed_str = ''
test_timeout = int(test_set.get('timeout', timeout))
test_path = root / test_set['path']
chmod_x_children(test_path)
for task_name, baseline_time in test_set['task'].items():
to_test = str(test_path / task_name)
print(f"Testing {to_test}")
flirt = [asset_path(root, i) for i in test_set.get('sig')] if 'sig' in test_set else None
libc = asset_path(root, test_set.get('libc')) if 'libc' in test_set else None
ld = asset_path(root, test_set.get('ld')) if 'ld' in test_set else None
if 'static' in test_set and task_name in test_set['static']:
ld = None
active_size = task_concurrent(test_set, task_name, concurrent)
res, cost = local_aeg(to_test, flirt, libc, ld, test_timeout, debug, concurrent=active_size)
for _ in range(5):
if (not res and cost < 100) or cost > baseline_time:
res, cost = local_aeg(to_test, flirt, libc, ld, test_timeout, debug, concurrent=active_size)
if res:
if baseline_time != FAIL_MAX:
result += f"Passed, cost {str(cost)[:4]}s,\tbaseline " \
f"{str(baseline_time).rjust(5, ' ')}s" \
f",\t{'Diff'} {str(baseline_time - cost)[:5]}s" \
f",\t Ratio {str(baseline_time / cost)[:5]}x\tat {task_name}\n"
else:
result += f"Passed, cost {str(cost)[:4]}s,\tat {task_name}\n"
else:
failed_str += f"Test {task_name} failed\n"
failed += 1
result += failed_str
result += f"Total {len(test_set['task'])} tests, {f'{failed} failed' if failed else 'all passed'}\n"
result += BANNER
return result
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-T', '--timeout', help='timeout', default=300, type=int)
parser.add_argument('-D', '--debug', help='debug', default=False, action='store_true')
parser.add_argument('-c', '--concurrent', help='maximum concurrent active sim', default=None, type=int)
args = parser.parse_args()
try:
sys.set_int_max_str_digits(0x9999)
except AttributeError:
pass
write_flags()
try:
output = run_extra_tests(args.timeout, args.debug, args.concurrent)
print(output)
if Path('/test_res').is_dir():
Path('/test_res/extra_test_result.txt').write_text(output)
finally:
clean_flags()