1 00:00:04,850 --> 00:00:09,710 Apache TCA is an open source project hosted by the Apache Software Foundation. 2 00:00:09,710 --> 00:00:10,770 It's been around for a while. 3 00:00:10,770 --> 00:00:14,310 It is designed as the Babelfish for file format processing. 4 00:00:14,310 --> 00:00:17,830 It allows just an API for putting in lots of different file types. 5 00:00:17,830 --> 00:00:24,050 This is often a parser suite that is used behind the scenes and often people don't even know they're using it. 6 00:00:24,050 --> 00:00:33,390 So it's embedded in major projects such as Elasticsearch, OpenSearch, Apache Solr, major search systems that need to take files and make text searchable. 7 00:00:33,390 --> 00:00:37,010 Just to give a sense of what TCA can do, I will show you our app. 8 00:00:37,010 --> 00:00:43,430 It's not how most people would use TCA in an application, but it does allow you to explore some of the content within a single file. 9 00:00:43,430 --> 00:00:46,530 It's a docx file, but it has an embedded zip file in it. 10 00:00:46,550 --> 00:00:49,130 And inside that embedded zip file are further zip files. 11 00:00:49,130 --> 00:00:53,810 So it's effectively a nested set of zip files inside of zip files inside of zip files. 12 00:00:53,810 --> 00:00:58,190 Lots of people know that you can have embedded files, zip files have embedded files, and so on. 13 00:00:58,530 --> 00:01:02,670 But one of the really fun things is you can often put embedded files in lots of other formats. 14 00:01:02,670 --> 00:01:08,610 And that's part of the richness of TCA is that it parses through those embedded files and will give you that extracted content. 15 00:01:08,610 --> 00:01:12,590 Let's look at what I view as the most important view of this. 16 00:01:12,590 --> 00:01:25,030 And that's this JSON file format view of the data where you have a map of all the metadata objects, but it's a list of those where the first object is the container file, that docx file. 17 00:01:25,030 --> 00:01:34,350 And then you can see down here we have an embedded file inside of that, which is an emf, which effectively is just the image for that zip file inside that docx file. 18 00:01:34,490 --> 00:01:37,610 And then we see that we have some content in here. 19 00:01:37,670 --> 00:01:41,010 And remember, we saw those text files with embed1 and embed2. 20 00:01:41,210 --> 00:01:45,390 In embed3, we actually have some real text in that text file. 21 00:01:45,690 --> 00:01:53,450 And we can see that the embedded resource path for that file is embed3 text inside of a zip file, inside of a zip file, inside of a zip file. 22 00:01:53,490 --> 00:01:57,850 And then that's all at the root level, effectively, of that docx file. 23 00:01:57,850 --> 00:02:02,610 So all of the embedded files with their metadata content is extracted here. 24 00:02:02,610 --> 00:02:06,070 And then from this, applications could make that searchable. 25 00:02:06,070 --> 00:02:08,470 They could look for specific keywords. 26 00:02:08,470 --> 00:02:15,270 They could run natural language processing on it to pull out human names or phone numbers or social security numbers, any of the other things that people care about. 27 00:02:15,270 --> 00:02:18,470 Lots of different uses for why people would want text out of this. 28 00:02:18,570 --> 00:02:25,730 So for Tika, the main vulnerabilities that I focus on were path traversal and then the other one's command injection. 29 00:02:25,730 --> 00:02:27,630 The file that triggers this is a zip file. 30 00:02:27,810 --> 00:02:37,490 And inside that zip file, there's a file called dot dot, the URL encoding for the slash, and then dot dot, and then the URL encoding for that slash. 31 00:02:37,490 --> 00:02:46,970 So all of the work in file name utils to warn against that dot dot slash are totally nullified because that has passed through here. 32 00:02:46,970 --> 00:02:49,470 And then it becomes active here. 33 00:02:49,470 --> 00:02:52,650 And that gives us the ability to traverse out of that target directory. 34 00:02:52,650 --> 00:02:58,530 Part of the challenge for this is that the CRS has to figure out what's going on with this third-party library. 35 00:02:58,530 --> 00:03:08,330 And then it has to realize that this line should have happened up here, so that all of the protections would have been in place when that decoding had already happened. 36 00:03:08,330 --> 00:03:11,610 So simply moving this further up here would have solved the problem. 37 00:03:11,610 --> 00:03:14,470 The next one is the favorite of what I've done. 38 00:03:14,470 --> 00:03:17,030 It's going to be a doozy to fix. 39 00:03:17,030 --> 00:03:26,350 So the way this works is, this is a command injection vulnerability, which means that the user controls what text goes into the command. 40 00:03:26,350 --> 00:03:34,250 With the right input file, this will run a user-generated command on the command line for the system it's running on, which is really bad. 41 00:03:34,410 --> 00:03:43,010 This CPV hijacks the existing external parser that Tika already has, and then just modifies the command based on user data. 42 00:03:43,010 --> 00:03:48,510 So the target file is an HTML file with an embedded JPEG file. 43 00:03:48,790 --> 00:03:57,810 And if the HTML file has a metadata field called ExifToolPath, then this will configure the ExifTool, which sounds super awesome. 44 00:03:57,810 --> 00:04:00,170 Now we can run Exif on the embedded JPEG file, right? 45 00:04:00,170 --> 00:04:10,450 What this is doing is going through and saying, along the list of parsers, find a composite external parser, which is the thing that we use to call external code. 46 00:04:10,450 --> 00:04:14,890 It's finding that ExifTool parser that already exists that will call out to that external process. 47 00:04:14,890 --> 00:04:29,290 It's taking it, changing what command is going to be called based on the metadata inside that HTML file, and then if there is a JPEG or some other image file format that the ExifTool would process, then it runs that command. 48 00:04:29,290 --> 00:04:37,750 And then the other thing this does is that it then resets the ExifTool so it tries to conceal the fact that it changed the underlying parser at parse time. 49 00:04:37,750 --> 00:04:40,470 It makes it a do-it-half-do-what-went-wrong.