1 00:00:00,000 --> 00:00:03,100 [Music] 2 00:00:05,000 --> 00:00:07,680 Apache Tika is an open source project 3 00:00:07,680 --> 00:00:09,519 hosted by the patri software Foundation 4 00:00:09,519 --> 00:00:11,400 it's in around for a while it is 5 00:00:11,400 --> 00:00:13,000 designed as the bavel fish for file 6 00:00:13,000 --> 00:00:15,639 format processing it allows just an API 7 00:00:15,639 --> 00:00:17,240 for putting in lots of different file 8 00:00:17,240 --> 00:00:20,920 types this is often a parser Suite that 9 00:00:20,920 --> 00:00:22,680 is used behind the scenes and often 10 00:00:22,680 --> 00:00:24,000 people don't even know they're using it 11 00:00:24,000 --> 00:00:25,960 so it's embedded in major projects such 12 00:00:25,960 --> 00:00:28,679 as elastic search open search pachy 13 00:00:28,679 --> 00:00:31,199 solar major search systems that need to 14 00:00:31,199 --> 00:00:33,440 take files make the text searchable uh 15 00:00:33,440 --> 00:00:35,079 just to give a a sense of what what Tika 16 00:00:35,079 --> 00:00:37,280 can do I will show you our app it's not 17 00:00:37,280 --> 00:00:38,800 how most people would use T in an 18 00:00:38,800 --> 00:00:40,640 application but it does allow you to 19 00:00:40,640 --> 00:00:42,360 explore some of the content within a 20 00:00:42,360 --> 00:00:44,760 single file it's a docx file but it has 21 00:00:44,760 --> 00:00:47,120 an embedded zip file in it and inside 22 00:00:47,120 --> 00:00:48,760 that embedded zip file are further zip 23 00:00:48,760 --> 00:00:51,280 files so it's a effectively a nested set 24 00:00:51,280 --> 00:00:52,920 of zip files inside of zip files inside 25 00:00:52,920 --> 00:00:54,640 of zip files lots of people know that 26 00:00:54,640 --> 00:00:56,559 you can have embedded files zip files 27 00:00:56,559 --> 00:00:58,920 have embedded files and so on but one of 28 00:00:58,920 --> 00:01:00,760 the really fun things is you can often 29 00:01:00,760 --> 00:01:02,120 put embedded files in lots of other 30 00:01:02,120 --> 00:01:03,440 formats and that's part of the richest 31 00:01:03,440 --> 00:01:05,920 of Tika is that it parses through those 32 00:01:05,920 --> 00:01:07,479 embedded files and will'll give you that 33 00:01:07,479 --> 00:01:09,840 extracted content let's look at what I 34 00:01:09,840 --> 00:01:12,520 view as the most important view of this 35 00:01:12,520 --> 00:01:15,759 and that's this Json file format view of 36 00:01:15,759 --> 00:01:19,560 the data where you have a a map of all 37 00:01:19,560 --> 00:01:21,640 the metadata objects but it's a list of 38 00:01:21,640 --> 00:01:23,159 those where the first object is the 39 00:01:23,159 --> 00:01:25,520 container file that docx file and then 40 00:01:25,520 --> 00:01:27,799 you can see down here we have an ineed 41 00:01:27,799 --> 00:01:30,159 file inside of that which is an EMF 42 00:01:30,159 --> 00:01:31,759 which effectively is just the image for 43 00:01:31,759 --> 00:01:34,600 that zip file inside that dox file and 44 00:01:34,600 --> 00:01:36,920 then we see that we have some content in 45 00:01:36,920 --> 00:01:38,880 here and remember we we saw those text 46 00:01:38,880 --> 00:01:41,600 files with embed 1 embed one two in 47 00:01:41,600 --> 00:01:43,960 embed 3 we actually have some real text 48 00:01:43,960 --> 00:01:46,280 in that text file and we can see that 49 00:01:46,280 --> 00:01:48,880 the embedded resource path for that file 50 00:01:48,880 --> 00:01:51,079 is embed 3 text inside of a zip file 51 00:01:51,079 --> 00:01:52,680 inside of a zip file inside of a zip 52 00:01:52,680 --> 00:01:55,360 file and then that's all at the root 53 00:01:55,360 --> 00:01:58,159 level effectively of that docx file so 54 00:01:58,159 --> 00:01:59,920 all of the embedded files with the Met 55 00:01:59,920 --> 00:02:02,880 data content is extracted here and then 56 00:02:02,880 --> 00:02:05,240 from this applications could make that 57 00:02:05,240 --> 00:02:07,280 searchable they could look for uh 58 00:02:07,280 --> 00:02:09,080 specific keywords they could run natural 59 00:02:09,080 --> 00:02:10,399 language processing on it to pill out 60 00:02:10,399 --> 00:02:13,000 human names or phone numbers or social 61 00:02:13,000 --> 00:02:14,280 security numbers any of the other things 62 00:02:14,280 --> 00:02:15,680 that people care about lots of different 63 00:02:15,680 --> 00:02:17,560 uses for why people would want text out 64 00:02:17,560 --> 00:02:20,599 of this so for Tikka the main 65 00:02:20,599 --> 00:02:22,239 vulnerabilities that I focus on were 66 00:02:22,239 --> 00:02:24,599 path traversal and then the other one's 67 00:02:24,599 --> 00:02:26,120 uh command injection the file that 68 00:02:26,120 --> 00:02:29,319 triggers this is a ZIP file and inside 69 00:02:29,319 --> 00:02:31,519 that zip file file there's a file called 70 00:02:31,519 --> 00:02:35,040 dot dot the URL encoding for the Slash 71 00:02:35,040 --> 00:02:36,360 and then dot dot and then the URL 72 00:02:36,360 --> 00:02:38,959 encoding for that slash so all of the 73 00:02:38,959 --> 00:02:42,080 work in file name utils to warn against 74 00:02:42,080 --> 00:02:45,360 that do dot slash are totally nullified 75 00:02:45,360 --> 00:02:47,239 because that has passed through here and 76 00:02:47,239 --> 00:02:49,680 then it becomes active here and that 77 00:02:49,680 --> 00:02:51,400 gives us the ability to Traverse out of 78 00:02:51,400 --> 00:02:52,959 that Target directory part of the 79 00:02:52,959 --> 00:02:55,360 challenge for this is that the CRS has 80 00:02:55,360 --> 00:02:57,200 to figure out what's going on with this 81 00:02:57,200 --> 00:02:59,560 third party library and then it has to 82 00:02:59,560 --> 00:03:01,920 re realized that this line should have 83 00:03:01,920 --> 00:03:03,440 happened up here so that all of the 84 00:03:03,440 --> 00:03:05,840 protections would have been in place 85 00:03:05,840 --> 00:03:08,280 when that decoding had already happened 86 00:03:08,280 --> 00:03:10,480 so simply moving this further up here 87 00:03:10,480 --> 00:03:11,959 would have solved the problem the next 88 00:03:11,959 --> 00:03:14,560 one is the favorite of what I've done 89 00:03:14,560 --> 00:03:17,560 it's going to be a doozy to fix so the 90 00:03:17,560 --> 00:03:20,040 way this works is this is a command 91 00:03:20,040 --> 00:03:22,239 injection uh vulnerability which means 92 00:03:22,239 --> 00:03:25,040 that the user controls what text goes 93 00:03:25,040 --> 00:03:27,560 into the command with the right input 94 00:03:27,560 --> 00:03:30,640 file this will run user generated 95 00:03:30,640 --> 00:03:31,959 command on the command line for the 96 00:03:31,959 --> 00:03:33,599 system that it's running on which is 97 00:03:33,599 --> 00:03:37,319 that this cpv hijacks the existing 98 00:03:37,319 --> 00:03:40,080 external parure that taica already has 99 00:03:40,080 --> 00:03:41,959 and then just modifies the command based 100 00:03:41,959 --> 00:03:44,400 on user data so the target file is an 101 00:03:44,400 --> 00:03:49,280 HTML file with an embedded JPEG file and 102 00:03:49,280 --> 00:03:52,599 if the HTML file has a metadata field 103 00:03:52,599 --> 00:03:55,400 called ETF tool path then this will 104 00:03:55,400 --> 00:03:57,040 configure the exf tool which sounds 105 00:03:57,040 --> 00:03:58,879 super awesome now we can run exf on the 106 00:03:58,879 --> 00:04:00,720 in better JP file right what this is 107 00:04:00,720 --> 00:04:02,920 doing is going through and saying along 108 00:04:02,920 --> 00:04:04,840 the list of parsers find a comp 109 00:04:04,840 --> 00:04:07,000 composite external parser which is the 110 00:04:07,000 --> 00:04:10,439 thing that we use to call external C 111 00:04:10,439 --> 00:04:12,120 it's finding that except tool parser 112 00:04:12,120 --> 00:04:13,400 that already exists that will call out 113 00:04:13,400 --> 00:04:16,000 to that external process it's taking it 114 00:04:16,000 --> 00:04:17,880 changing what command is going to be 115 00:04:17,880 --> 00:04:19,639 called based on the metadata inside that 116 00:04:19,639 --> 00:04:24,320 HTML file and then if there is a JPEG or 117 00:04:24,320 --> 00:04:25,919 some other image file format that the 118 00:04:25,919 --> 00:04:28,479 exit tool would process then it runs 119 00:04:28,479 --> 00:04:29,919 that command and then the other another 120 00:04:29,919 --> 00:04:31,720 thing this does is that it then resets 121 00:04:31,720 --> 00:04:34,160 the exf tool so it tries to conceal the 122 00:04:34,160 --> 00:04:35,800 fact that it changed the underlying 123 00:04:35,800 --> 00:04:38,199 parser at parse time make it a little 124 00:04:38,199 --> 00:04:39,560 bit harder to figure out what happened 125 00:04:39,560 --> 00:04:43,080 and what went wrong