Kitxuuu commited on
Commit
b874896
·
verified ·
1 Parent(s): 507b7fc

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder-jvm/Dockerfile +68 -0
  2. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/jcc/jcc_test.go +186 -0
  3. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/path/to/header.h +15 -0
  4. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/LICENSE +13 -0
  5. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/README.md +3 -0
  6. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/__init__.py +20 -0
  7. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/command_injection.py +106 -0
  8. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/redos.py +84 -0
  9. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/sanlib.py +227 -0
  10. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/yaml_deserialization.py +42 -0
  11. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/eval_command_injection.py +52 -0
  12. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/os_command_injection.py +52 -0
  13. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/ansible-runner-cve-2021-4041/fuzz_ansible_runner.py +64 -0
  14. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/build.sh +22 -0
  15. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/fuzz_pytorch_lightning.dict +1 -0
  16. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/fuzz_pytorch_lightning.py +67 -0
  17. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/subprocess_popen_injection.py +51 -0
  18. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/yaml_deserialization_simple.py +54 -0
  19. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/experimental/SystemSan/PoEs/pytorch-lightning-1.5.10/Makefile +12 -0
  20. local-test-tika-full-01-vuln_7/fuzz-tooling/infra/experimental/chronos/README.md +49 -0
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder-jvm/Dockerfile ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ ################################################################################
16
+
17
+ ARG IMG_TAG=latest
18
+ FROM ghcr.io/aixcc-finals/base-builder:${IMG_TAG} AS base
19
+
20
+ ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64
21
+ ENV JAVA_15_HOME /usr/lib/jvm/java-15-openjdk-amd64
22
+ ENV JVM_LD_LIBRARY_PATH $JAVA_HOME/lib/server
23
+ ENV PATH $PATH:$JAVA_HOME/bin
24
+ ENV JAZZER_API_PATH "/usr/local/lib/jazzer_api_deploy.jar"
25
+ ENV JAZZER_JUNIT_PATH "/usr/local/bin/jazzer_junit.jar"
26
+
27
+ RUN install_java.sh
28
+
29
+ RUN chmod 777 /usr/local/bin && chmod 777 /usr/local/lib
30
+
31
+ FROM base AS builder
32
+ RUN useradd -m jazzer_user
33
+
34
+ USER jazzer_user
35
+
36
+ WORKDIR $SRC
37
+
38
+ RUN git clone https://github.com/aixcc-finals/jazzer-aixcc jazzer && \
39
+ cd jazzer && \
40
+ git checkout 43791565a765b854b537d878c9cab757ff1f2140
41
+
42
+ WORKDIR $SRC/jazzer
43
+
44
+ RUN echo "build --java_runtime_version=local_jdk_17" >> .bazelrc \
45
+ && echo "build --cxxopt=-stdlib=libc++" >> .bazelrc \
46
+ && echo "build --linkopt=-lc++" >> .bazelrc
47
+
48
+ RUN bazel build \
49
+ //src/main/java/com/code_intelligence/jazzer:jazzer_standalone_deploy.jar \
50
+ //deploy:jazzer-api \
51
+ //deploy:jazzer-junit \
52
+ //launcher:jazzer
53
+
54
+ RUN cp $(bazel cquery --output=files //src/main/java/com/code_intelligence/jazzer:jazzer_standalone_deploy.jar) /usr/local/bin/jazzer_agent_deploy.jar && \
55
+ cp $(bazel cquery --output=files //launcher:jazzer) /usr/local/bin/jazzer_driver && \
56
+ cp $(bazel cquery --output=files //deploy:jazzer-api) $JAZZER_API_PATH && \
57
+ cp $(bazel cquery --output=files //deploy:jazzer-junit) $JAZZER_JUNIT_PATH
58
+
59
+ FROM base AS final
60
+
61
+ COPY --from=builder /usr/local/bin/jazzer_agent_deploy.jar /usr/local/bin/jazzer_agent_deploy.jar
62
+ COPY --from=builder /usr/local/bin/jazzer_driver /usr/local/bin/jazzer_driver
63
+ COPY --from=builder $JAZZER_API_PATH $JAZZER_API_PATH
64
+ COPY --from=builder $JAZZER_JUNIT_PATH $JAZZER_JUNIT_PATH
65
+
66
+ RUN chmod 755 /usr/local/bin && chmod 755 /usr/local/lib
67
+
68
+ WORKDIR $SRC
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/jcc/jcc_test.go ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+ "strings"
7
+ "testing"
8
+ )
9
+
10
+ func TestExtractMissingHeader(t *testing.T) {
11
+ missingHeaderMessage := `path/to/file.cpp:8:10: fatal error: 'missingheader.h' file not found
12
+
13
+ #include "missingheader.h"
14
+
15
+ ^~~~~~~~~~~~
16
+
17
+ 1 error generated.
18
+ `
19
+
20
+ res, _ := ExtractMissingHeader(missingHeaderMessage)
21
+ expected := "missingheader.h"
22
+ if strings.Compare(res, expected) != 0 {
23
+ t.Errorf("Got: %s. Expected: %s.", res, expected)
24
+ }
25
+ }
26
+
27
+ func TestGetHeaderCorrectedFilename(t *testing.T) {
28
+ missingHeaderMessage := `path/to/file.cpp:8:10: fatal error: 'missingheader.h' file not found
29
+
30
+ #include "missingheader.h"
31
+
32
+ ^~~~~~~~~~~~
33
+
34
+ 1 error generated.
35
+ `
36
+ _, correctedFilename, _ := GetHeaderCorrectedFilename(missingHeaderMessage)
37
+ expected := "path/to/jcc-corrected-file.cpp"
38
+ if strings.Compare(correctedFilename, expected) != 0 {
39
+ t.Errorf("Got: %s. Expected: %s.", correctedFilename, expected)
40
+ }
41
+ }
42
+
43
+ func TestFindMissingHeader(t *testing.T) {
44
+ pwd, _ := os.Getwd()
45
+ t.Setenv("JCC_MISSING_HEADER_SEARCH_PATH", pwd)
46
+
47
+ location, _ := FindMissingHeader("header.h")
48
+ expected := pwd + "/testdata/path/to/header.h"
49
+ if strings.Compare(location, expected) != 0 {
50
+ t.Errorf("Got: %s. Expected: %s.", location, expected)
51
+ }
52
+ }
53
+
54
+ func TestCorrectMissingHeaders(t *testing.T) {
55
+ pwd, _ := os.Getwd()
56
+ t.Setenv("JCC_MISSING_HEADER_SEARCH_PATH", pwd)
57
+ cfile := pwd + "/testdata/cfile.c"
58
+ cmd := [4]string{"-fsanitize=address", cfile, "-o", "/tmp/blah"}
59
+ res, err := CorrectMissingHeaders("clang", cmd[:])
60
+ if !res {
61
+ fmt.Println(err)
62
+ t.Errorf("Expected successful compilation")
63
+ }
64
+ }
65
+
66
+ func TestGetHeaderCorrectedCmd(t *testing.T) {
67
+ compilerErr := `testdata/cpp.cc:8:10: fatal error: 'missingheader.h' file not found
68
+
69
+ #include "missingheader.h"
70
+
71
+ ^~~~~~~~~~~~
72
+
73
+ 1 error generated.
74
+ `
75
+
76
+ cmd := [3]string{"-fsanitize=address", "file.cpp", "path/to/cpp.cc"}
77
+ expectedFixedCmd := [3]string{"-fanitize=address", "file.cpp", "path/to/jcc-corrected-cpp.cc"}
78
+ fixedCmd, _, _ := GetHeaderCorrectedCmd(cmd[:], compilerErr)
79
+ if strings.Compare(fixedCmd[1], expectedFixedCmd[1]) != 0 {
80
+ t.Errorf("Expected %s, got: %s", expectedFixedCmd, fixedCmd)
81
+ }
82
+ }
83
+
84
+ func TestCppifyHeaderIncludes(t *testing.T) {
85
+ t.Setenv("JCC_CPPIFY_PROJECT_HEADERS", "1")
86
+ src := `// Copyright blah
87
+ #include <stddef.h>
88
+
89
+ #include "fuzz.h"
90
+ #include "x/y.h"
91
+ extern "C" LLVMFuzzerTestOneInput(uint8_t* data, size_t sz) {
92
+ return 0;
93
+ }`
94
+ newFile, _ := CppifyHeaderIncludes(src)
95
+ expected := `// Copyright blah
96
+ #include <stddef.h>
97
+
98
+ extern "C" {
99
+ #include "fuzz.h"
100
+ }
101
+ extern "C" {
102
+ #include "x/y.h"
103
+ }
104
+ extern "C" LLVMFuzzerTestOneInput(uint8_t* data, size_t sz) {
105
+ return 0;
106
+ }
107
+ /* JCCCppifyHeadersMagicString */
108
+ `
109
+ if strings.Compare(newFile, expected) != 0 {
110
+ t.Errorf("Expected: %s, got: %s", expected, newFile)
111
+ }
112
+ }
113
+
114
+ func TestCppifyHeaderIncludesShouldnt(t *testing.T) {
115
+ src := `// Copyright blah
116
+ #include <stddef.h>
117
+
118
+ #include "fuzz.h"
119
+ #include "x/y.h"
120
+ extern "C" LLVMFuzzerTestOneInput(uint8_t* data, size_t sz) {
121
+ return 0;
122
+ }`
123
+ newFile, _ := CppifyHeaderIncludes(src)
124
+ if strings.Compare(newFile, src) != 0 {
125
+ t.Errorf("Expected: %s. Got: %s", src, newFile)
126
+ }
127
+ }
128
+
129
+ func TestCppifyHeaderIncludesAlready(t *testing.T) {
130
+ src := `// Copyright blah
131
+ #include <stddef.h>
132
+
133
+ #include "fuzz.h"
134
+ #include "x/y.h"
135
+ extern "C" LLVMFuzzerTestOneInput(uint8_t* data, size_t sz) {
136
+ return 0;
137
+ }
138
+ /* JCCCppifyHeadersMagicString */
139
+ `
140
+ newFile, _ := CppifyHeaderIncludes(src)
141
+ if strings.Compare(newFile, src) != 0 {
142
+ t.Errorf("Expected %s, got: %s", src, newFile)
143
+ }
144
+ }
145
+
146
+ func TestExtractMissingHeaderNonHeaderFailure(t *testing.T) {
147
+ missingHeaderMessage := `clang: error: no such file or directory: 'x'
148
+ clang: error: no input files`
149
+
150
+ header, res := ExtractMissingHeader(missingHeaderMessage)
151
+ if res {
152
+ t.Errorf("Expected no match, got: %s", header)
153
+ }
154
+ }
155
+
156
+ func TestReplaceMissingHeader(t *testing.T) {
157
+ cfile := `// Copyright 2035 Robots
158
+ #include <stddef.h>
159
+
160
+ #include <cstdint>
161
+
162
+ // Some libraries like OpenSSL will use brackets for their own headers.
163
+ #include <missingheader.h>
164
+
165
+ int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) {
166
+ return 0;
167
+ }
168
+ `
169
+
170
+ res := ReplaceMissingHeader(cfile, "missingheader.h", "path/to/includes/missingheader.h")
171
+ expected := `// Copyright 2035 Robots
172
+ #include <stddef.h>
173
+
174
+ #include <cstdint>
175
+
176
+ // Some libraries like OpenSSL will use brackets for their own headers.
177
+ #include "path/to/includes/missingheader.h"
178
+
179
+ int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) {
180
+ return 0;
181
+ }
182
+ `
183
+ if strings.Compare(res, expected) != 0 {
184
+ t.Errorf("Got: %s. Expected: %s.", res, expected)
185
+ }
186
+ }
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/path/to/header.h ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 Google LLC
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ int xhg(void);
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/LICENSE ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/README.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # pysecsan
2
+
3
+ Security sanitizers for vulnerability detection during runtime.
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/__init__.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Glue for pysecsan library."""
15
+
16
+ # Import sanlib and expose only needs functionality by way of __all__
17
+ from .sanlib import *
18
+
19
+ # pylint: disable=undefined-all-variable
20
+ __all__ = ['add_hooks']
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/command_injection.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ ################################################################################
16
+ """Sanitizers for capturing code injections."""
17
+
18
+ from typing import Optional
19
+ from pysecsan import sanlib
20
+
21
+
22
+ def get_all_substr_prefixes(main_str, sub_str):
23
+ """Yields all strings prefixed with sub_str in main_str."""
24
+ idx = 0
25
+ while True:
26
+ idx = main_str.find(sub_str, idx)
27
+ if idx == -1:
28
+ return
29
+ yield main_str[0:idx]
30
+ # Increase idx the length of the substring from the current position
31
+ # where an occurence of the substring was found.
32
+ idx += len(sub_str)
33
+
34
+
35
+ # pylint: disable=unsubscriptable-object
36
+ def check_code_injection_match(elem, check_unquoted=False) -> Optional[str]:
37
+ """identify if elem is an injection match."""
38
+ # Check exact match
39
+ if elem == 'exec-sanitizer':
40
+ return 'Explicit command injection found.'
41
+
42
+ # Check potential for injecting into a string
43
+ if 'FROMFUZZ' in elem:
44
+ if check_unquoted:
45
+ # return true if any index is unquoted
46
+ for sub_str in get_all_substr_prefixes(elem, 'FROMFUZZ'):
47
+ if sub_str.count('\"') % 2 == 0:
48
+ return 'Fuzzer controlled content in data. Code injection potential.'
49
+
50
+ # Return None if all fuzzer taints were quoted
51
+ return None
52
+ return 'Fuzzer-controlled data in command string. Injection potential.'
53
+ return None
54
+
55
+
56
+ # pylint: disable=invalid-name
57
+ def hook_pre_exec_subprocess_Popen(cmd, **kwargs):
58
+ """Hook for subprocess.Popen."""
59
+
60
+ arg_shell = 'shell' in kwargs and kwargs['shell']
61
+
62
+ # Command injections depend on whether the first argument is a list of
63
+ # strings or a string. Handle this now.
64
+ # Example: tests/poe/ansible-runner-cve-2021-4041
65
+ if isinstance(cmd, str):
66
+ res = check_code_injection_match(cmd, check_unquoted=True)
67
+ if res is not None:
68
+ # if shell arg is true and string is tainted and unquoted that's a
69
+ # definite code injection.
70
+ if arg_shell is True:
71
+ sanlib.abort_with_issue('Code injection in Popen', 'Command injection')
72
+
73
+ # It's a maybe: will not report this to avoid false positives.
74
+ # TODO: add more precise detection here.
75
+
76
+ # Check for hg command injection
77
+ # Example: tests/poe/libvcs-cve-2022-21187
78
+ if cmd[0] == 'hg':
79
+ # Check if the arguments are controlled by the fuzzer, and this given
80
+ # arg is not preceded by --
81
+ found_dashes = False
82
+ for idx in range(1, len(cmd)):
83
+ if cmd[0] == '--':
84
+ found_dashes = True
85
+ if not found_dashes and check_code_injection_match(cmd[idx]):
86
+ sanlib.abort_with_issue(
87
+ 'command injection likely by way of mercurial. The following'
88
+ f'command {str(cmd)} is executed, and if you substitute {cmd[idx]} '
89
+ 'with \"--config=alias.init=!touch HELLO_PY\" then you will '
90
+ 'create HELLO_PY', 'Command injection')
91
+
92
+
93
+ def hook_pre_exec_os_system(cmd):
94
+ """Hook for os.system."""
95
+ res = check_code_injection_match(cmd)
96
+ if res is not None:
97
+ sanlib.abort_with_issue(f'code injection by way of os.system\n{res}',
98
+ 'Command injection')
99
+
100
+
101
+ def hook_pre_exec_eval(cmd, *args, **kwargs):
102
+ """Hook for eval. Experimental atm."""
103
+ res = check_code_injection_match(cmd, check_unquoted=True)
104
+ if res is not None:
105
+ sanlib.abort_with_issue(f'Potential code injection by way of eval\n{res}',
106
+ 'Command injection')
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/redos.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ ################################################################################
16
+ """Sanitizer for regular expression dos."""
17
+
18
+ # pylint: disable=protected-access
19
+
20
+ import time
21
+ import os
22
+ from pysecsan import sanlib
23
+
24
+ START_RE_TIME = None
25
+
26
+
27
+ # Hooks for regular expressions.
28
+ # Main problem is to identify ReDOS attemps. This is a non-trivial task
29
+ # - https://arxiv.org/pdf/1701.04045.pdf
30
+ # - https://dl.acm.org/doi/pdf/10.1145/3236024.3236027
31
+ # and the current approach we use is simply check for extensive computing time.
32
+ # In essence, this is more of a refinement of traditional timeout checker from
33
+ # the fuzzer, which, effectively will detect these types of attacks by way of
34
+ # timeouts.
35
+ #
36
+ # Perhaps the smartest would be to use something like e.g.
37
+ # https://github.com/doyensec/regexploit to scan the regex patterns.
38
+ # Other heuristics without going too technical on identifying super-linear
39
+ # regexes:
40
+ # - check
41
+ # - if 'taint' exists in re.compile(xx)
42
+ # - check
43
+ # - for backtracking possbility in PATTERN within re.comile(PATTERN)
44
+ # - and
45
+ # - 'taint' in findall(XX) calls.
46
+ # pylint: disable=global-statement
47
+ def hook_post_exec_re_pattern_findall(self, re_str):
48
+ """Hook post exeution re.compile().findall()."""
49
+ _ = self # Satisfy lint
50
+ global START_RE_TIME
51
+ try:
52
+ endtime = time.time() - START_RE_TIME
53
+ if endtime > 4:
54
+ sanlib.abort_with_issue(f'Potential ReDOS attack.\n {re_str}', 'ReDOS')
55
+ except NameError:
56
+ sanlib.sanitizer_log(
57
+ 'starttime is not set, which it should have. Error in PySecSan',
58
+ sanlib.LOG_INFO)
59
+ os._exit(1)
60
+
61
+
62
+ def hook_pre_exec_re_pattern_findall(self, string):
63
+ """Hook pre execution of re.pattern().findall()."""
64
+ _ = (self, string) # Satisfy lint
65
+ global START_RE_TIME
66
+ START_RE_TIME = time.time()
67
+
68
+
69
+ def hook_post_exec_re_compile(retval, pattern, flags=None):
70
+ """Hook for re.compile post execution to hook returned objects functions."""
71
+ _ = (pattern, flags) # Satisfy lint
72
+ sanlib.sanitizer_log('Inside of post compile hook', sanlib.LOG_DEBUG)
73
+ wrapper_object = sanlib.create_object_wrapper(
74
+ findall=(hook_pre_exec_re_pattern_findall,
75
+ hook_post_exec_re_pattern_findall))
76
+ hooked_object = wrapper_object(retval)
77
+ return hooked_object
78
+
79
+
80
+ def hook_pre_exec_re_compile(pattern, flags=None):
81
+ """Check if tainted input exists in pattern. If so, likely chance of making
82
+ ReDOS possible."""
83
+ _ = (pattern, flags) # Satisfy lint
84
+ sanlib.sanitizer_log('Inside re compile hook', sanlib.LOG_DEBUG)
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/sanlib.py ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ ################################################################################
16
+ """Core routines for pysecsan library."""
17
+
18
+ # pylint: disable=protected-access
19
+
20
+ import re
21
+ import os
22
+ import functools
23
+ import subprocess
24
+ import traceback
25
+ import importlib.util
26
+
27
+ from typing import Any, Callable, Optional
28
+ from pysecsan import command_injection, redos, yaml_deserialization
29
+
30
+ LOG_DEBUG = 0
31
+ LOG_INFO = 1
32
+ PYSECSAN_LOG_LVL = LOG_INFO
33
+
34
+ # Message that will be printed to stdout when an issue is found.
35
+ PYSECSAN_BUG_LABEL = r'===BUG DETECTED: PySecSan:'
36
+
37
+
38
+ # pylint: disable=global-statement
39
+ def sanitizer_log(msg, log_level, force=False, log_prefix=True):
40
+ """Helper printing function."""
41
+ global PYSECSAN_LOG_LVL
42
+ if log_level >= PYSECSAN_LOG_LVL or force:
43
+ if log_prefix:
44
+ print(f'[PYSECSAN] {msg}')
45
+ else:
46
+ print(f'{msg}')
47
+
48
+
49
+ def sanitizer_log_always(msg, log_prefix=True):
50
+ """Wrapper for sanitizer logging. Will always log"""
51
+ sanitizer_log(msg, 0, force=True, log_prefix=log_prefix)
52
+
53
+
54
+ def is_module_present(mod_name):
55
+ """Identify if module is importable."""
56
+ # pylint: disable=deprecated-method
57
+ return importlib.util.find_spec(mod_name) is not None
58
+
59
+
60
+ def _log_bug(bug_title):
61
+ sanitizer_log_always('%s %s ===' % (PYSECSAN_BUG_LABEL, bug_title),
62
+ log_prefix=False)
63
+
64
+
65
+ def abort_with_issue(msg, bug_title):
66
+ """Print message, display stacktrace and force process exit.
67
+
68
+ Use this function for signalling an issue is found and use the messages
69
+ logged from this function to determine if a fuzzer found a bug.
70
+ """
71
+ # Show breaker string using an ASAN approach (uses 65 =)
72
+ sanitizer_log_always("=" * 65, log_prefix=False)
73
+
74
+ # Log issue message
75
+ _log_bug(bug_title)
76
+ sanitizer_log_always(msg)
77
+
78
+ # Log stacktrace
79
+ sanitizer_log_always("Stacktrace:")
80
+ traceback.print_stack()
81
+
82
+ # Force exit
83
+ # Use os._exit here to force exit. sys.exit will exit
84
+ # by throwing a SystemExit exception which the interpreter
85
+ # handles by exiting. However, code may catch this exception,
86
+ # and thus to avoid this we exit the process without exceptions.
87
+ # pylint: disable=protected-access
88
+ sanitizer_log_always("Exiting")
89
+ os._exit(1)
90
+
91
+
92
+ def is_exact_taint(stream) -> bool:
93
+ """Checks if stream is an exact match for taint from fuzzer."""
94
+ # The fuzzer has to get 8 characters right. This may be a bit much,
95
+ # however, when found it shows a high level of control over the data.
96
+ if stream == 'FROMFUZZ':
97
+ return True
98
+
99
+ return False
100
+
101
+
102
+ def create_object_wrapper(**methods):
103
+ """Hooks functions in an object.
104
+
105
+ This is needed for hooking built-in types and object attributes.
106
+
107
+ Example use case is if we want to find ReDOS vulnerabilities, that
108
+ have a pattern of
109
+
110
+ ```
111
+ import re
112
+ r = re.compile(REGEX)
113
+ for _ in r.findall(...)
114
+ ```
115
+
116
+ In the above case r.findall is a reference to
117
+ re.Pattern.findall, which is a built-in type that is non-writeable.
118
+
119
+ In order to hook such calls we need to wrap the object, and also hook the
120
+ re.compile function to return the wrapped/hooked object.
121
+ """
122
+
123
+ class Wrapper():
124
+ """Wrap an object by hiding attributes."""
125
+
126
+ def __init__(self, instance):
127
+ object.__setattr__(self, 'instance', instance)
128
+
129
+ def __setattr__(self, name, value):
130
+ object.__setattr__(object.__getattribute__(self, 'instance'), name, value)
131
+
132
+ def __getattribute__(self, name):
133
+ instance = object.__getattribute__(self, 'instance')
134
+
135
+ def _hook_func(self, pre_hook, post_hook, orig, *args, **kargs):
136
+ if pre_hook is not None:
137
+ pre_hook(self, *args, **kargs)
138
+ # No need to pass instance here because when we extracted
139
+ # the function we used instance.__getattribute__(name) which
140
+ # seems to include it. I think.
141
+ orig_retval = orig(*args, **kargs)
142
+
143
+ if post_hook is not None:
144
+ post_hook(self, *args, **kargs)
145
+ return orig_retval
146
+
147
+ # If this is a wrapped method, return a bound method
148
+ if name in methods:
149
+ pre_hook = methods[name][0]
150
+ post_hook = methods[name][1]
151
+ orig = instance.__getattribute__(name)
152
+ return (lambda *args, **kargs: _hook_func(self, pre_hook, post_hook,
153
+ orig, *args, **kargs))
154
+
155
+ # Otherwise, just return attribute of instance
156
+ return instance.__getattribute__(name)
157
+
158
+ return Wrapper
159
+
160
+
161
+ # pylint: disable=unsubscriptable-object
162
+ def add_hook(function: Callable[[Any], Any],
163
+ pre_exec_hook: Optional[Callable[[Any], Any]] = None,
164
+ post_exec_hook: Optional[Callable[[Any], Any]] = None):
165
+ """Hook a function.
166
+
167
+ Hooks can be placed pre and post function call. At least one hook is
168
+ needed.
169
+
170
+ This hooking is intended on non-object hooks. In order to hook functions
171
+ in objects the `create_object_wrapper` function is used in combination
172
+ with function hooking initialisation functions post execution.
173
+ """
174
+ if pre_exec_hook is None and post_exec_hook is None:
175
+ raise Exception('Some hooks must be included')
176
+
177
+ @functools.wraps(function)
178
+ def run(*args, **kwargs):
179
+ sanitizer_log(f'Hook start {str(function)}', LOG_DEBUG)
180
+
181
+ # Call hook
182
+ if pre_exec_hook is not None:
183
+ pre_exec_hook(*args, **kwargs)
184
+
185
+ # Call the original function in the even the hook did not indicate
186
+ # failure.
187
+ ret = function(*args, **kwargs)
188
+
189
+ # Post execution hook. Overwrite return value if anything is returned
190
+ # by post hook.
191
+ if post_exec_hook is not None:
192
+ tmp_ret = post_exec_hook(ret, *args, **kwargs)
193
+ if tmp_ret is not None:
194
+ sanitizer_log('Overwriting return value', LOG_DEBUG)
195
+ ret = tmp_ret
196
+ sanitizer_log(f'Hook end {str(function)}', LOG_DEBUG)
197
+ return ret
198
+
199
+ return run
200
+
201
+
202
+ def add_hooks():
203
+ """Sets up hooks."""
204
+ sanitizer_log('Starting', LOG_INFO)
205
+ os.system = add_hook(os.system,
206
+ pre_exec_hook=command_injection.hook_pre_exec_os_system)
207
+ subprocess.Popen = add_hook(
208
+ subprocess.Popen,
209
+ pre_exec_hook=command_injection.hook_pre_exec_subprocess_Popen)
210
+
211
+ __builtins__['eval'] = add_hook(
212
+ __builtins__['eval'], pre_exec_hook=command_injection.hook_pre_exec_eval)
213
+
214
+ re.compile = add_hook(re.compile,
215
+ pre_exec_hook=redos.hook_pre_exec_re_compile,
216
+ post_exec_hook=redos.hook_post_exec_re_compile)
217
+
218
+ # Hack to determine if yaml is elligible, because pkg_resources does
219
+ # not seem to work from pyinstaller.
220
+ # pylint: disable=import-outside-toplevel
221
+ if is_module_present('yaml'):
222
+ import yaml
223
+ sanitizer_log('Hooking pyyaml.load', LOG_DEBUG)
224
+ yaml.load = add_hook(
225
+ yaml.load,
226
+ pre_exec_hook=yaml_deserialization.hook_pre_exec_pyyaml_load,
227
+ )
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/yaml_deserialization.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ ################################################################################
16
+ """Catches vulnerable yaml desrializations that can potentially lead to
17
+ arbitrary code execution."""
18
+ from pysecsan import sanlib
19
+
20
+ try:
21
+ import yaml
22
+ # pylint: disable=broad-except
23
+ except Exception:
24
+ pass
25
+
26
+
27
+ def hook_pre_exec_pyyaml_load(stream, loader):
28
+ """Hook for pyyaml.load_yaml.
29
+
30
+ Exits if the loader is unsafe or vanilla loader and the stream passed
31
+ to the loader is controlled by the fuzz data
32
+ """
33
+ # Ensure loader is the unsafe loader or vanilla loader
34
+ if loader not in (yaml.loader.Loader, yaml.loader.UnsafeLoader):
35
+ return
36
+
37
+ # Check for exact taint in stream
38
+ if sanlib.is_exact_taint(stream):
39
+ msg = (
40
+ 'Yaml deserialization issue.\n'
41
+ 'Unsafe deserialization can be used to execute arbitrary commands.\n')
42
+ sanlib.abort_with_issue(msg, 'Yaml deserialisation')
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/eval_command_injection.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Fuzzer targetting command injection of eval."""
16
+ # pylint: disable=eval-used
17
+
18
+ import sys
19
+ import atheris
20
+ import pysecsan
21
+
22
+ pysecsan.add_hooks()
23
+
24
+
25
+ def list_files_perhaps(param, magicval):
26
+ """Pass fuzzer data into eval."""
27
+ if len(param) < 3:
28
+ return
29
+ if magicval == 1337:
30
+ try:
31
+ eval("FROMFUZZ")
32
+ except ValueError:
33
+ pass
34
+
35
+
36
+ def test_one_input(data):
37
+ """Fuzzer entrypoint."""
38
+ fdp = atheris.FuzzedDataProvider(data)
39
+ list_files_perhaps(fdp.ConsumeUnicodeNoSurrogates(24),
40
+ fdp.ConsumeIntInRange(500, 1500))
41
+
42
+
43
+ def main():
44
+ """Set up and start fuzzing."""
45
+
46
+ atheris.instrument_all()
47
+ atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
48
+ atheris.Fuzz()
49
+
50
+
51
+ if __name__ == '__main__':
52
+ main()
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/os_command_injection.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Fuzzer targetting command injection of os.system."""
16
+
17
+ import os
18
+ import sys
19
+ import atheris
20
+ import pysecsan
21
+
22
+
23
+ def list_files_perhaps(param, magicval):
24
+ """Pass fuzzer data into os.system."""
25
+ if 'B' not in param:
26
+ return
27
+ if magicval == 1338:
28
+ os.system('exec-san')
29
+ elif magicval == 1339:
30
+ os.system('ls -la FROMFUZZ')
31
+ else:
32
+ os.system('ls -la ./')
33
+
34
+
35
+ def test_one_input(data):
36
+ """Fuzzer entrypoint."""
37
+ fdp = atheris.FuzzedDataProvider(data)
38
+ list_files_perhaps(fdp.ConsumeUnicodeNoSurrogates(24),
39
+ fdp.ConsumeIntInRange(500, 1500))
40
+
41
+
42
+ def main():
43
+ """Set up and start fuzzing."""
44
+ pysecsan.add_hooks()
45
+
46
+ atheris.instrument_all()
47
+ atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
48
+ atheris.Fuzz()
49
+
50
+
51
+ if __name__ == '__main__':
52
+ main()
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/ansible-runner-cve-2021-4041/fuzz_ansible_runner.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Targets: https://github.com/advisories/GHSA-6j58-grhv-2769."""
16
+
17
+ import sys
18
+ import atheris
19
+ import pexpect
20
+ import pysecsan
21
+ import ansible_runner
22
+ from ansible_runner.config.runner import RunnerConfig
23
+
24
+ pysecsan.add_hooks()
25
+
26
+
27
+ def test_one_input(data):
28
+ """Fuzzer entrypoint."""
29
+ fdp = atheris.FuzzedDataProvider(data)
30
+
31
+ conf = RunnerConfig('/tmp/')
32
+ conf.suppress_ansible_output = True
33
+ conf.expect_passwords = {pexpect.TIMEOUT: None, pexpect.EOF: None}
34
+ conf.cwd = str('/tmp/')
35
+ conf.env = {}
36
+ conf.job_timeout = 10
37
+ conf.idle_timeout = 0
38
+ conf.pexpect_timeout = 2.
39
+ conf.pexpect_use_poll = True
40
+ conf.command = 'from_fuzzer'
41
+
42
+ runner = ansible_runner.Runner(conf)
43
+ runner.resource_profiling = True
44
+ # rc.resource_profiling_base_cgroup = "; exec-san"
45
+ assistance = True
46
+ if assistance and fdp.ConsumeIntInRange(1, 100) > 80:
47
+ conf.resource_profiling_base_cgroup = 'FROMFUZZ'
48
+ else:
49
+ conf.resource_profiling_base_cgroup = fdp.ConsumeUnicodeNoSurrogates(24)
50
+ try:
51
+ runner.run()
52
+ except (RuntimeError, ValueError, TypeError) as _:
53
+ pass
54
+
55
+
56
+ def main():
57
+ """Set up and start fuzzing."""
58
+ atheris.instrument_all()
59
+ atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
60
+ atheris.Fuzz()
61
+
62
+
63
+ if __name__ == '__main__':
64
+ main()
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/build.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -eu
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ ################################################################################
17
+
18
+ git clone --depth 1 --branch 1.5.10 https://github.com/PyTorchLightning/pytorch-lightning.git
19
+ cd pytorch-lightning
20
+ python3 -m pip install .
21
+ cd ../
22
+ python3 ./fuzz_pytorch_lightning.py
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/fuzz_pytorch_lightning.dict ADDED
@@ -0,0 +1 @@
 
 
1
+ "os.system('exec-sanitizer')"
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/fuzz_pytorch_lightning.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/local/bin/python3
2
+ #
3
+ # Copyright 2022 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ ################################################################################
18
+ """Exploit pytorch lightning with fuzzer's input as a random env variable.
19
+ This PoC is extended from a report in GitHub Advisory Database:
20
+ https://github.com/advisories/GHSA-r5qj-cvf9-p85h
21
+ The original report documents an exploit using a specific environment variable,
22
+ we show a way to achieve the same exploit with an arbitrary env variable.
23
+ """
24
+
25
+ import os
26
+ import sys
27
+ import atheris
28
+ import pysecsan
29
+
30
+ pysecsan.add_hooks()
31
+
32
+ with atheris.instrument_imports():
33
+ from pytorch_lightning import Trainer
34
+ from pytorch_lightning.utilities.argparse import parse_env_variables
35
+
36
+
37
+ def prepare_fuzzing_input(data):
38
+ """Prepare the data needed by the exploit with input data from fuzzers."""
39
+ data = data.replace(b'\0', b'')
40
+ env_name = 'AN_ARBITRARY_ENV_NAME'
41
+ return data, env_name
42
+
43
+
44
+ def exploit_target(env_value, env_name):
45
+ """This target is based on a snippet from the official documentation of
46
+ `parse_env_variables`:
47
+ https://pytorch-lightning.readthedocs.io/en/stable/api/pytorch_lightning.utilities.argparse.html # pylint: disable=line-too-long
48
+ It might not be the most realistic example,
49
+ but serves as a PoC to show that SystemSan works for Python."""
50
+ os.environb[env_name.encode()] = env_value
51
+ parse_env_variables(Trainer, template=env_name)
52
+
53
+
54
+ def TestOneInput(data): # pylint: disable=invalid-name
55
+ """Exploit the target only with input data from fuzzers."""
56
+ env_value, env_name = prepare_fuzzing_input(data)
57
+ exploit_target(env_value, env_name)
58
+
59
+
60
+ def main():
61
+ """Fuzz target with atheris."""
62
+ atheris.Setup(sys.argv, TestOneInput)
63
+ atheris.Fuzz()
64
+
65
+
66
+ if __name__ == '__main__':
67
+ main()
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/subprocess_popen_injection.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Fuzzer displaying insecure use of subprocess.Popen."""
16
+
17
+ import sys
18
+ import subprocess
19
+ import atheris
20
+ import pysecsan
21
+
22
+
23
+ def list_files_perhaps(param):
24
+ """Insecure call to Popen."""
25
+ try:
26
+ subprocess.Popen(' '.join(['ls', '-la', param]), shell=True)
27
+ except ValueError:
28
+ pass
29
+
30
+
31
+ def test_one_input(data):
32
+ """Fuzzer entrypoint."""
33
+ fdp = atheris.FuzzedDataProvider(data)
34
+
35
+ if fdp.ConsumeIntInRange(1, 10) == 5:
36
+ list_files_perhaps('FROMFUZZ')
37
+ else:
38
+ list_files_perhaps('.')
39
+
40
+
41
+ def main():
42
+ """Set up and start fuzzing."""
43
+ pysecsan.add_hooks()
44
+
45
+ atheris.instrument_all()
46
+ atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
47
+ atheris.Fuzz()
48
+
49
+
50
+ if __name__ == '__main__':
51
+ main()
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/yaml_deserialization_simple.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/python3
2
+ # Copyright 2022 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Fuzzer triggering insecure yaml serialization."""
16
+
17
+ import sys
18
+ import yaml
19
+ import atheris
20
+ import pysecsan
21
+
22
+
23
+ def serialize_with_tainted_data(param, magicval):
24
+ """Pass data to insecure yaml functions."""
25
+ if magicval == 1337:
26
+ try:
27
+ yaml.load(param, yaml.Loader)
28
+ except yaml.YAMLError:
29
+ pass
30
+ elif magicval == 1338:
31
+ try:
32
+ yaml.load('FROMFUZZ', yaml.Loader)
33
+ except yaml.YAMLError:
34
+ pass
35
+
36
+
37
+ def test_one_input(data):
38
+ """Fuzzer entrypoint."""
39
+ fdp = atheris.FuzzedDataProvider(data)
40
+ serialize_with_tainted_data(fdp.ConsumeUnicodeNoSurrogates(32),
41
+ fdp.ConsumeIntInRange(500, 1500))
42
+
43
+
44
+ def main():
45
+ """Set up and start fuzzing."""
46
+ pysecsan.add_hooks()
47
+
48
+ atheris.instrument_all()
49
+ atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
50
+ atheris.Fuzz()
51
+
52
+
53
+ if __name__ == '__main__':
54
+ main()
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/experimental/SystemSan/PoEs/pytorch-lightning-1.5.10/Makefile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .POSIX:
2
+ CXX = clang++
3
+ CFLAGS = -std=c++17 -Wall -Wextra -O3 -g3
4
+
5
+ SystemSan: SystemSan.cpp
6
+ $(CXX) $(CFLAGS) -lpthread -o $@ $^
7
+
8
+ run: clean SystemSan fuzz_pytorch_lightning.py
9
+ ./SystemSan ./fuzz_pytorch_lightning.py -dict=vuln.dict
10
+
11
+ clean:
12
+ rm -f SystemSan /tmp/tripwire
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/experimental/chronos/README.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Chronos: rebuilding OSS-Fuzz harnesses using cached builds
2
+
3
+ ## Pre-built images.
4
+
5
+ Daily pre-built images are available at:
6
+
7
+ - `us-central1-docker.pkg.dev/oss-fuzz/oss-fuzz-gen/<PROJECT>-ofg-cached-address`
8
+ - `us-central1-docker.pkg.dev/oss-fuzz/oss-fuzz-gen/<PROJECT>-ofg-cached-coverage`
9
+
10
+ They can be used as drop-in replacements for the usual `gcr.io/oss-fuzz/<PROJECT>` images.
11
+
12
+ These images are generated in 2 ways:
13
+ - (Preferred) [Generate](https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/bash_parser.py)
14
+ a replay build script that can be re-run alongside existing build artifacts,
15
+ leveraging existing build system mechanisms to avoid rebuilding (e.g. running
16
+ `make` twice should not actually rebuild everything). This is error-prone, so
17
+ we validate the script works by running it.
18
+ - (Fallback, if the replay build script didn't work). We leverage
19
+ [ccache](https://ccache.dev/), to provide a compiler cache. This is often not
20
+ as fast as the replay build script, because some project builds spend
21
+ significant time doing non-compiler tasks (e.g. checking out submodules,
22
+ running configure scripts).
23
+
24
+ Note: this mechanism does not work for every single OSS-Fuzz project today. The
25
+ resulting image may either:
26
+ - Not provide much performance improvement compared with a normal image, or
27
+ - Not exist at all (if neither approach worked).
28
+
29
+ Stats from a recent run: <https://gist.github.com/oliverchang/abaf3a1106a2b923c0ac3a577410aaaa>
30
+ (Feb 3 2025).
31
+
32
+ ## Usage locally
33
+
34
+ **Example 1: htslib**
35
+
36
+ From the OSS-Fuzz root
37
+
38
+ ```sh
39
+ $ RUN_ALL=1 ./infra/experimental/chronos/build_cache_local.sh htslib c address
40
+ ...
41
+ ...
42
+ Vanilla compile time:
43
+ 17
44
+ Replay worked
45
+ Replay compile time:
46
+ 2
47
+ Ccache compile time:
48
+ 9
49
+ ```