File size: 18,291 Bytes
cd80032 |
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
diff --git a/.aixcc/.gitignore b/.aixcc/.gitignore
new file mode 100644
index 000000000..bb575c1f6
--- /dev/null
+++ b/.aixcc/.gitignore
@@ -0,0 +1 @@
+!*.bin
\ No newline at end of file
diff --git a/.aixcc/README.md b/.aixcc/README.md
new file mode 100644
index 000000000..eb90702ba
--- /dev/null
+++ b/.aixcc/README.md
@@ -0,0 +1,10 @@
+# Apache Tika - Guest Economics
+
+This challenge is a delta scan challenge.
+The challenge includes one synthetic vulnerability (vuln\_3).
+
+# Challenge Rounds
+
+This challenge has been included in the following set of rounds.
+
+* (none yet)
diff --git a/.aixcc/challenge.yaml b/.aixcc/challenge.yaml
new file mode 100644
index 000000000..75311f187
--- /dev/null
+++ b/.aixcc/challenge.yaml
@@ -0,0 +1,36 @@
+metadata_spec_version: v1
+
+name: 'Guest Economics'
+
+# fuzz_tooling project info that pairs to this challenge
+fuzz_tooling_project_name: 'tika'
+fuzz_tooling_url: https://github.com/aixcc-finals/oss-fuzz-aixcc.git
+fuzz_tooling_ref: challenge-state/tk-delta-02
+
+challenge_type: delta # full | delta
+
+base_ref: 87c62bccc3a6fd0343df073511fc520a235618b3
+delta_ref: challenges/tk-delta-02
+
+
+# A list of the vulnerabilities included in this challenge
+# This should always match the dir names in .aixcc/vulns/*
+vulnerabilities:
+ - vuln_3
+
+sarif:
+ broadcast: true
+ target: .aixcc/vulns/vuln_3/vuln.yaml
+ correct: true
+
+# harness fuzz targets available for this challenge
+harnesses:
+ - 'HtmlParserFuzzer'
+ - 'M3U8ParserFuzzer'
+ - 'RTFParserFuzzer'
+ - 'TextAndCSVParserFuzzer'
+ - 'ThreeDXMLParserFuzzer'
+ - 'TikaAppRUnpackerFuzzer'
+ - 'TikaAppUnpackerFuzzer'
+ - 'TikaAppUntarringFuzzer'
+ - 'XliffParserFuzzer'
diff --git a/.aixcc/test.sh b/.aixcc/test.sh
new file mode 100755
index 000000000..3e152876d
--- /dev/null
+++ b/.aixcc/test.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# turn off some of the longer running tests
+MAVEN_ARGS="-Djacoco.skip=true -Drat.skip=true -Dossindex.skip -Dcheckstyle.skip=true -Dsurefire.failIfNoSpecifiedTests=false \
+ -Dtest=!TestChmExtraction,!OOXMLParserTest.testMultiThreaded,!TikaIT"
+
+if [ -z "${MVN}" ]; then
+ MVN=mvn
+fi
+
+$MVN clean test $MAVEN_ARGS -am -pl :tika-app
diff --git a/.aixcc/vulns/vuln_3/README.md b/.aixcc/vulns/vuln_3/README.md
new file mode 100644
index 000000000..be4be9de2
--- /dev/null
+++ b/.aixcc/vulns/vuln_3/README.md
@@ -0,0 +1,7 @@
+# Vuln 3
+
+The M3U8Parser is vulnerable to SSRF on untrusted data.
+
+This CPV adds a M3U8 parser to process content from URLs. This is very
+loosely based on the more complex CVE-2016-1897 and CVE-2016-1898 that were
+discovered in FFMPEG.
diff --git a/.aixcc/vulns/vuln_3/blobs/data.bin b/.aixcc/vulns/vuln_3/blobs/data.bin
new file mode 100644
index 000000000..9a3fb8097
--- /dev/null
+++ b/.aixcc/vulns/vuln_3/blobs/data.bin
@@ -0,0 +1,7 @@
+#EXTM3U
+#EXT-X-VERSION:3
+#EXT-X-PLAYLIST-TYPE:VOD
+#EXT-X-TARGETDURATION:5220
+#EXTINF:5220,
+http://jazzer.com/some-video
+#EXT-X-ENDLIST
\ No newline at end of file
diff --git a/.aixcc/vulns/vuln_3/patches/good_patch.diff b/.aixcc/vulns/vuln_3/patches/good_patch.diff
new file mode 100644
index 000000000..f32f79995
--- /dev/null
+++ b/.aixcc/vulns/vuln_3/patches/good_patch.diff
@@ -0,0 +1,22 @@
+diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/java/org/apache/tika/parser/m3/M3U8Parser.java b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/java/org/apache/tika/parser/m3/M3U8Parser.java
+index aef1d333d..73436da63 100644
+--- a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/java/org/apache/tika/parser/m3/M3U8Parser.java
++++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/java/org/apache/tika/parser/m3/M3U8Parser.java
+@@ -161,17 +161,6 @@ public class M3U8Parser implements Parser {
+ // split on , then the first value is the length (can be -1),
+ // the last value is the title; intermediate values are key=value format
+ metadata.add(PLAY_LIST_LINK, nextLine);
+- if (! nextLine.startsWith("http")) {
+- return;
+- }
+- EmbeddedDocumentExtractor ex = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context);
+- Metadata m = new Metadata();
+- if (ex.shouldParseEmbedded(m)) {
+- try (TikaInputStream tis = TikaInputStream.get(new URL(nextLine))) {
+- ex.parseEmbedded(tis, new BodyContentHandler(new EmbeddedContentHandler(xhtml)), m,
+- true);
+- }
+- }
+ }
+
+ private String getNextContentLine(BufferedReader reader) throws IOException {
diff --git a/.aixcc/vulns/vuln_3/vuln.yaml b/.aixcc/vulns/vuln_3/vuln.yaml
new file mode 100644
index 000000000..97542f7f8
--- /dev/null
+++ b/.aixcc/vulns/vuln_3/vuln.yaml
@@ -0,0 +1,28 @@
+metadata_spec_version: v1
+
+name: M3U8 SSRF
+
+author: Tim Allison
+
+details:
+
+ cwes:
+ - CWE-918
+
+ description: >
+ The M3U8Parser can be triggered to fetch the contents of a URL that an attacker may not have authorization to fetch.
+
+ locations:
+ - path_from_root: 'tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/java/org/apache/tika/parser/m3/M3U8Parser.java'
+ startLine: 170
+ startColumn: 13
+ endLine: 173
+ endColumn: 14
+
+pov:
+ blob: 'data.bin'
+ harness: 'M3U8ParserFuzzer'
+
+patch:
+ good: 'good_patch.diff'
+ bad: 'bad_patch.diff'
\ No newline at end of file
diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/java/org/apache/tika/parser/m3/M3U8Parser.java b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/java/org/apache/tika/parser/m3/M3U8Parser.java
new file mode 100644
index 000000000..aef1d333d
--- /dev/null
+++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/java/org/apache/tika/parser/m3/M3U8Parser.java
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.m3;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+import java.util.Set;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.extractor.EmbeddedDocumentExtractor;
+import org.apache.tika.extractor.EmbeddedDocumentUtil;
+import org.apache.tika.io.TikaInputStream;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.Property;
+import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.metadata.XMPDM;
+import org.apache.tika.mime.MediaType;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.parser.Parser;
+import org.apache.tika.sax.BodyContentHandler;
+import org.apache.tika.sax.EmbeddedContentHandler;
+import org.apache.tika.sax.XHTMLContentHandler;
+import org.apache.tika.utils.StringUtils;
+
+/**
+ * Basic parser for m3u8 files
+ */
+public class M3U8Parser implements Parser {
+ public static final String M3U8_PREFIX = "m3u8:";
+ public static final Property PLAY_LIST_LINK = Property.internalTextBag(M3U8_PREFIX + "link");
+ public static final Property M3U8_VERSION = Property.internalInteger(M3U8_PREFIX + "version");
+ public static final Property PLAY_LIST_TYPE = Property.internalText(M3U8_PREFIX + "type");
+ private static final Set<MediaType> SUPPORTED = Set.of(
+ MediaType.application("vnd.apple.mpegurl"));
+
+ private static final String TARGET_DURATION = "#EXT-X-TARGETDURATION:";
+ private static final String EXTINF = "#EXTINF:";
+ private static final String ENDLIST = "#EXT-X-ENDLIST";
+ private static final String EXTVERSION = "#EXT-X-VERSION:";
+ private static final String EXTKEY = "#EXT-X-KEY:";
+ private static final String EXTPLAYLISTTYPE = "#EXT-X-PLAYLIST-TYPE:";
+
+ @Override
+ public Set<MediaType> getSupportedTypes(ParseContext context) {
+ return SUPPORTED;
+ }
+
+ @Override
+ public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
+ ParseContext context) throws IOException, SAXException, TikaException {
+ XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
+ xhtml.startDocument();
+ _parse(stream, xhtml, metadata, context);
+ xhtml.endDocument();
+ }
+
+ private void _parse(InputStream stream, XHTMLContentHandler xhtml, Metadata metadata,
+ ParseContext context) throws IOException, SAXException {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream,
+ StandardCharsets.UTF_8))) {
+ String line = reader.readLine();
+ while (line != null) {
+ if (line.startsWith("##")) {
+ //comment -- do nothing
+ } else if (line.startsWith(TARGET_DURATION)) {
+ parseDuration(TARGET_DURATION, line, metadata);
+ } else if (line.startsWith(EXTINF)) {
+ handleLink(line, reader, xhtml, metadata, context);
+ } else if (line.startsWith(ENDLIST)) {
+ break;
+ } else if (line.startsWith(EXTVERSION)) {
+ Integer val = getInt(EXTVERSION, line);
+ if (val != null) {
+ metadata.set(M3U8_VERSION, val);
+ }
+ } else if (line.startsWith(EXTKEY)) {
+ metadata.set(TikaCoreProperties.IS_ENCRYPTED, true);
+ } else if (line.startsWith(EXTPLAYLISTTYPE)) {
+ String t = line.substring(EXTPLAYLISTTYPE.length());
+ if (!StringUtils.isBlank(t)) {
+ metadata.set(PLAY_LIST_TYPE, t);
+ }
+ }
+ line = reader.readLine();
+ }
+ }
+ }
+
+ private Integer getInt(String key, String line) {
+ int i = line.indexOf(key);
+ if (i < 0) {
+ return null;
+ }
+ if (i >= line.length() - 1) {
+ return null;
+ }
+ if (key.length() >= line.length()) {
+ return null;
+ }
+ String substring = line.substring(key.length()).trim();
+ try {
+ return Integer.parseInt(substring);
+ } catch (NumberFormatException e) {
+ //log? swallow for now
+ }
+ return null;
+ }
+
+ private Double getDouble(String key, String line) {
+ int i = line.indexOf(key);
+ if (i < 0) {
+ return null;
+ }
+ if (i >= line.length() - 1) {
+ return null;
+ }
+ if (key.length() >= line.length()) {
+ return null;
+ }
+ String substring = line.substring(key.length()).trim();
+ try {
+ return Double.parseDouble(substring);
+ } catch (NumberFormatException e) {
+ //log? swallow for now
+ }
+ return null;
+ }
+
+ private void handleLink(String line, BufferedReader reader,
+ XHTMLContentHandler xhtml, Metadata metadata,
+ ParseContext context) throws IOException, SAXException {
+ String nextLine = getNextContentLine(reader);
+ if (nextLine == null) {
+ return;
+ }
+ //TODO -- parse contents in EXTINF line
+ // split on , then the first value is the length (can be -1),
+ // the last value is the title; intermediate values are key=value format
+ metadata.add(PLAY_LIST_LINK, nextLine);
+ if (! nextLine.startsWith("http")) {
+ return;
+ }
+ EmbeddedDocumentExtractor ex = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context);
+ Metadata m = new Metadata();
+ if (ex.shouldParseEmbedded(m)) {
+ try (TikaInputStream tis = TikaInputStream.get(new URL(nextLine))) {
+ ex.parseEmbedded(tis, new BodyContentHandler(new EmbeddedContentHandler(xhtml)), m,
+ true);
+ }
+ }
+ }
+
+ private String getNextContentLine(BufferedReader reader) throws IOException {
+ String line = reader.readLine();
+ while (true) {
+ if (line == null) {
+ return null;
+ } else if (line.trim().isBlank() || line.startsWith("##")) {
+ //empty or comment
+ } else {
+ return line;
+ }
+ line = reader.readLine();
+ }
+ }
+
+ private void parseDuration(String key, String line, Metadata metadata) {
+ Double durationInSeconds = getDouble(key, line);
+ if (durationInSeconds == null) {
+ return;
+ }
+ DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ROOT);
+ df.applyPattern("0.0#");
+ metadata.set(XMPDM.DURATION, df.format(durationInSeconds));
+ }
+}
diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/resources/META-INF/services/org.apache.tika.parser.Parser b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/resources/META-INF/services/org.apache.tika.parser.Parser
index 53bc7ab9f..c2361df8c 100644
--- a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/resources/META-INF/services/org.apache.tika.parser.Parser
+++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/main/resources/META-INF/services/org.apache.tika.parser.Parser
@@ -15,6 +15,7 @@
org.apache.tika.parser.audio.AudioParser
org.apache.tika.parser.audio.MidiParser
+org.apache.tika.parser.m3.M3U8Parser
org.apache.tika.parser.mp3.Mp3Parser
org.apache.tika.parser.mp4.MP4Parser
org.apache.tika.parser.video.FLVParser
diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/test/java/org/apache/tika/parser/m3/M3U8ParserTest.java b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/test/java/org/apache/tika/parser/m3/M3U8ParserTest.java
new file mode 100644
index 000000000..dbf38be9e
--- /dev/null
+++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/test/java/org/apache/tika/parser/m3/M3U8ParserTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.m3;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.tika.TikaTest;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.XMPDM;
+
+public class M3U8ParserTest extends TikaTest {
+
+ @Test
+ public void testBasic() throws Exception {
+ //test file is based on MIT licensed:
+ // https://github.com/globocom/m3u8/blob/master/tests/playlists/relative-playlist.m3u8
+ List<Metadata> metadataList = getRecursiveMetadata("testM3U8.m3u8");
+ Metadata m = metadataList.get(0);
+ assertEquals("5220.0", m.get(XMPDM.DURATION));
+ assertEquals("entire1.ts", m.get(M3U8Parser.PLAY_LIST_LINK));
+ assertEquals(3, m.getInt(M3U8Parser.M3U8_VERSION));
+ assertEquals("VOD", m.get(M3U8Parser.PLAY_LIST_TYPE));
+ }
+}
diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/test/resources/test-documents/testM3U8.m3u8 b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/test/resources/test-documents/testM3U8.m3u8
new file mode 100644
index 000000000..3feca7b00
--- /dev/null
+++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-audiovideo-module/src/test/resources/test-documents/testM3U8.m3u8
@@ -0,0 +1,7 @@
+#EXTM3U
+#EXT-X-VERSION:3
+#EXT-X-PLAYLIST-TYPE:VOD
+#EXT-X-TARGETDURATION:5220
+#EXTINF:5220,
+entire1.ts
+#EXT-X-ENDLIST
\ No newline at end of file
|