1 00:00:02,840 --> 00:00:07,440 Hello, everyone. Welcome to my talk named Normalizing Empire's Traffic to 2 00:00:07,440 --> 00:00:13,660 Avoid Animal-Based Ideas. Can everyone hear my voice? Is it okay in the back side? Okay, 3 00:00:13,700 --> 00:00:21,240 great. So let me introduce myself first. I'm Utkuşen. I'm usually doing researches and 4 00:00:21,240 --> 00:00:26,600 writing tools which are about offensive side of security. I'm currently working in tier 5 00:00:26,600 --> 00:00:33,200 security, which is not live yet, but it will be live soon. You can find detailed information on 6 00:00:33,200 --> 00:00:40,780 my website and you can follow me on Twitter if you are interested in. So in this presentation, I 7 00:00:40,780 --> 00:00:46,600 will talk, start to talk about current state of defense and how we prefer assumed scenarios. 8 00:00:47,600 --> 00:00:52,980 After that, we will check advantages and disadvantages of network intervention detection 9 00:00:52,980 --> 00:00:56,580 systems and their evasion techniques. After that, we will take a look at the 10 00:00:56,600 --> 00:01:02,660 entire project and its situation against animal-based systems. Then we will check proposed 11 00:01:02,660 --> 00:01:11,520 solutions and the first order tool which can be candidate solution for these problems. So you 12 00:01:11,520 --> 00:01:16,340 are seeing a very basic architecture of a network in there. There are client computers located 13 00:01:16,340 --> 00:01:21,400 alongside with the other assets like server, databases, et cetera. On top of them, there is 14 00:01:21,400 --> 00:01:26,460 also an intervention detection system which controls the whole traffic and tries to identify 15 00:01:26,460 --> 00:01:33,040 malicious traffic. So also we have a concept named perimeter defense in there. This concept 16 00:01:33,040 --> 00:01:41,240 isolates your internal network and acts like a door which connects you to the outside. But as we can 17 00:01:41,240 --> 00:01:46,960 observe from recent breaches, perimeter defenses are not holding attackers from an organization 18 00:01:46,960 --> 00:01:56,060 network. A good crafted email is usually enough to gain a foothold on the network. So more and more 19 00:01:56,060 --> 00:02:01,660 attackers are using these techniques in order to bypass the perimeter defenses. Uh so gaining a 20 00:02:01,660 --> 00:02:09,180 foothold on the internal network is not not a big deal anymore. So as attacker profile has 21 00:02:09,180 --> 00:02:14,020 been changed by time uh defense methods are also changing. Uh besides that penetration 22 00:02:14,020 --> 00:02:19,900 testing concepts are changing too. Uh today organization and testers are mostly focused 23 00:02:19,900 --> 00:02:26,480 on uh assume bridge approaches. So assume bridge is simply accepting that attackers are 24 00:02:26,480 --> 00:02:33,160 bypassed your uh perimeter defenses and got a foothold on your network. So the red teams and 25 00:02:33,160 --> 00:02:38,920 testers will be focused on post exploitation instead of passing the perimeter defenses. So 26 00:02:38,920 --> 00:02:44,060 rather than traditional vulnerability scanning, testing activities uh becomes a cat and mouse 27 00:02:44,060 --> 00:02:49,880 game between attackers and defenders. Uh we can show NITS the next step. Uh we can show 28 00:02:49,900 --> 00:02:54,140 network intrusion detection systems as an initial step for detecting attackers on the 29 00:02:54,140 --> 00:03:00,560 network. Uh we can talk about two main type of NITS in there. Uh they are signature based and 30 00:03:00,560 --> 00:03:12,740 anomaly based. So you know the signature based systems. Uh it is a signature stack of 31 00:03:12,740 --> 00:03:18,100 previously known attacks. It compares each network package with those predefined patterns. Uh 32 00:03:18,100 --> 00:03:19,880 if they match uh well then uh you can use it. Uh if they match uh well then uh you can use it. 33 00:03:26,540 --> 00:03:33,740 Uh if they match uh well then uh you can use it. But uh you can indeed trust that they match 34 00:03:33,740 --> 00:03:39,800 your attack. So uh if you uh use it. Uh if you uh you find your one fan by, uh you can use it 35 00:03:39,800 --> 00:03:45,140 entirely. Uh also for uh攻 controllers uh though them uh tochok calendar will do it. Uh uh record 36 00:03:45,140 --> 00:03:50,560 changing the traffic elements such as package size, headers and some known strings. Also 37 00:03:50,560 --> 00:03:58,400 maybe you can apply some encoding methods too. Anomaly based systems are a bit sophisticated 38 00:03:58,400 --> 00:04:04,260 than signature based systems. Anomaly based needs refers to building a statistical model 39 00:04:04,260 --> 00:04:11,480 describing the normal traffic and flagging the abnormal traffic. To do that it analyzes the 40 00:04:11,480 --> 00:04:17,620 normal network traffic and applies various data science techniques to build a pattern. This 41 00:04:17,620 --> 00:04:23,360 kind of systems exist but they are usually commercial products and not open source tools. 42 00:04:24,100 --> 00:04:30,540 There are some theoretical concepts described in various researches but they are not so 43 00:04:30,540 --> 00:04:37,620 practical yet. So anomaly based systems have a chance to catch a new type of attacks. We can 44 00:04:37,620 --> 00:04:41,460 show the overall process in a basic chart. Anomaly based systems are based on the 45 00:04:41,460 --> 00:04:46,920 algorithm should record the daily traffic first in order to build a baseline. So what do we 46 00:04:46,920 --> 00:04:53,200 mean by daily traffic? It's the regular activities of the regular users on the network. For 47 00:04:53,200 --> 00:05:01,480 example, visiting a news website, sending an email via SMTP or accessing a server via SSH etc. 48 00:05:01,640 --> 00:05:06,720 That kind of things. After done that capture data will be given to the learning algorithm. It 49 00:05:06,720 --> 00:05:11,440 will be trained by this data to create a pattern which means the data will be used to 50 00:05:11,460 --> 00:05:17,320 build normal traffic profile. After done this program listens to the network and compares each 51 00:05:17,320 --> 00:05:22,100 network package with the normal traffic profile. If it's not fit to the normal traffic 52 00:05:22,100 --> 00:05:30,220 profile it's flexed as a normal traffic. The evasion part is a bit tricky than the signature 53 00:05:30,220 --> 00:05:35,520 based systems. We can list the evasion methods into two different categories, pre-training 54 00:05:35,520 --> 00:05:41,440 evasion and post-training evasion. The training refers that analyzing the normal traffic to build a 55 00:05:41,460 --> 00:05:50,380 pattern. So as we know that anomal based system needs to capture and analyze regular network 56 00:05:50,380 --> 00:05:55,660 traffic in order to build a pattern. So we are assuming that during traffic capture only legit 57 00:05:55,660 --> 00:06:01,940 users are generating legit network traffic. So that we are expecting that anomal based system 58 00:06:01,940 --> 00:06:08,280 will be able to differentiate malicious traffic from the normal traffic. But what if an 59 00:06:08,280 --> 00:06:13,360 attacker is located on the network before the training process is done. He can generate 60 00:06:13,360 --> 00:06:19,080 malicious traffic. So it will be included in the normal traffic pattern. For example in this 61 00:06:19,080 --> 00:06:27,020 chart a user visits Amazon.com another one connects some server via SSH. But the other one 62 00:06:27,020 --> 00:06:34,000 the attacker is users matter purters reverse TCP traffic. It generates that traffic. So anomal 63 00:06:34,000 --> 00:06:38,260 based system will include this on the normal profile. So in future when an attacker is 64 00:06:38,260 --> 00:06:48,500 running matter purter on the network anomal based system won't catch it. But we can say this 65 00:06:48,500 --> 00:06:53,800 scenario is not realistic right? How can an attacker know when the traffic is going to be 66 00:06:53,800 --> 00:07:03,000 trained? It's hard. We can't counter malicious insider threats. In a realistic scenario we 67 00:07:03,000 --> 00:07:08,140 expect that attacker can't know when the traffic training is done. Therefore we need to focus on 68 00:07:08,140 --> 00:07:14,660 post training evasion. In this scenario we will assume that a trained anomal based system 69 00:07:14,660 --> 00:07:20,600 watches the whole network. So we as an attacker should gain a foothold on the network and 70 00:07:20,600 --> 00:07:28,660 exfiltrate the data without causing any anomal alerts. To achieve that we need a post 71 00:07:28,660 --> 00:07:36,040 exploitation framework. So I could choose Metasploit for this job but instead I choose Empire. 72 00:07:36,040 --> 00:07:43,520 Because I love this project. It's very flexible for me. Easy to add and remove things. Also 73 00:07:43,520 --> 00:07:52,480 written in Python which I prefer over Ruby for myself. So how many people used Empire project 74 00:07:52,480 --> 00:07:59,460 before? Okay. There are quite a lot of people. But there are some also people who doesn't know 75 00:07:59,460 --> 00:08:06,020 it. Okay. So we can describe. So Empire is basically a post exploitation framework. It's a 76 00:08:06,040 --> 00:08:12,340 post exploitation framework like Metasploit. We can describe Empire's workflow in two parts. 77 00:08:12,480 --> 00:08:17,640 Agent and listener. So agent states the infected machine on the network which takes and 78 00:08:17,640 --> 00:08:25,160 executes tasks on there. So listener is described as communication server, the C2 server in which 79 00:08:25,160 --> 00:08:33,400 agent connects there, gets designated task and sends related output to the C2 server. Empire 80 00:08:33,400 --> 00:08:36,020 supports different type of listeners such as agent and listener. So agent and listener is the 81 00:08:36,020 --> 00:08:42,600 HTTP, HTTPS drop box and there were some others too. But even though HTTPS connection encrypts 82 00:08:42,600 --> 00:08:47,600 all communication, we will assume there is a solution on the network which intercepts and 83 00:08:47,600 --> 00:08:55,080 decrypts TLS communication. Because of that, HTTP listener will be our main focus. There are 84 00:08:55,080 --> 00:09:00,360 different traits of this HTTP listener as you can see on the slide. We will see how these traits 85 00:09:00,360 --> 00:09:06,000 affect our visibility on the network in upcoming slides. Okay. So we can see that there are a lot of 86 00:09:06,020 --> 00:09:09,600 different types of encryption. HTTP listener provides an encrypted communication even without 87 00:09:09,600 --> 00:09:16,280 TLS connection. This encryption is done in two parts. The client data which includes data like 88 00:09:16,280 --> 00:09:22,820 command to be executed and its output, it's encrypted symmetrically with AES algorithm. On the 89 00:09:22,820 --> 00:09:29,180 other hand, there is metadata routing data package which is responsible for routing packages to 90 00:09:29,180 --> 00:09:35,840 the right destination. It's also encrypted with our C4 algorithm. So we will consider these encrypted 91 00:09:36,020 --> 00:09:42,700 payloads are not decryptable by a solution on the fly since there is no publicly known product, has 92 00:09:42,700 --> 00:09:49,660 man in the middle capacity for an empire's communication. So assuming that an agent is 93 00:09:49,660 --> 00:09:56,320 deployed on the network, we will check the communication between agent and C2 server. After the 94 00:09:56,320 --> 00:10:02,880 initial negotiation, agent will connect to the C2 server in every N seconds. You can see generic 95 00:10:02,880 --> 00:10:06,000 request and response of a heartbeat connection in there. So we can see that we are not decrypting the 96 00:10:06,020 --> 00:10:13,460 data. So we can list following traits which can be inside of an anomaly based system. First, the 97 00:10:13,460 --> 00:10:20,080 request URI. As shown in the request, agents make its connection to a with a get request to a 98 00:10:20,080 --> 00:10:28,560 specific URI. It's read.PHP in this example. So if only HTML or ASPX pages are in use on the 99 00:10:28,560 --> 00:10:34,260 local network, this PHP extension may be flagged by the anomaly detection system because it's 100 00:10:34,260 --> 00:10:35,800 something different than the. 101 00:10:38,160 --> 00:10:44,880 And if we have a user agent value, if all users on the network uses Microsoft Windows with 102 00:10:44,880 --> 00:10:51,780 Chrome browser, setting the user agent value to Mac OS with Safari browser probably will be flagged 103 00:10:51,780 --> 00:10:56,020 by the anomaly detection system because it's something else, something different. It's not 104 00:10:56,020 --> 00:11:04,100 familiar traffic. It's also the same with the server headers, if you are using Microsoft IS 105 00:11:04,100 --> 00:11:12,100 servers in the network, setting the server header as Apache, won't be a good choice for you. 106 00:11:14,720 --> 00:11:21,820 Okay. The last one is post request body actually. As seen in the example request, post 107 00:11:21,820 --> 00:11:27,580 request body is encrypted and contains gibberish characters. If all users are browsing regular 108 00:11:27,580 --> 00:11:34,680 websites, this will be likely to be flagged by animal detection system. So we listed the 109 00:11:34,680 --> 00:11:40,580 traits which should be considered by an animal based system. Now let's check how can we adjust 110 00:11:40,580 --> 00:11:48,920 them. We can get the traits into two different groups. Traits that can be changed in listeners 111 00:11:48,920 --> 00:11:55,260 option menu and the traits that can be changed by changing empire source code. Our first group 112 00:11:55,260 --> 00:11:57,480 consists, request your user ID and password. The first group consists, request your user 113 00:11:57,480 --> 00:12:02,730 agent value, server header, port and connection interval. Second group consists, default 114 00:12:03,440 --> 00:12:13,940 HTML content and post request body. So let's look at the proposed solution. With which 115 00:12:13,940 --> 00:12:20,180 method we can normalize the mentioned traits. The proposed solution is called polymorphic 116 00:12:20,180 --> 00:12:27,300 blending attack. It's a useful technique for awaiting animal based systems. From a high level of 117 00:12:27,480 --> 00:12:33,080 perspective, the idea is creating attack packages which are matches to the normal traffic 118 00:12:33,080 --> 00:12:38,780 profile. Of course, to use this technique, attacker should know what is considered as normal, 119 00:12:38,880 --> 00:12:44,540 right? The attacker should know the features which are used to train a normal traffic profile. 120 00:12:45,480 --> 00:12:51,120 So to do that, our model requires a traffic capture data of the network after the normal 121 00:12:51,120 --> 00:12:57,460 training process is done. By analyzing the traffic capture, we can do some deductions about the 122 00:12:57,460 --> 00:13:03,060 behavior and its relation to the normal traffic profile. For normalizing the first group of 123 00:13:03,060 --> 00:13:08,240 traits, which are request your user agent, server header and port, we need to analyze the traffic 124 00:13:08,240 --> 00:13:15,240 capture and identify most common values. For example, which user agent values preferred most, 125 00:13:15,360 --> 00:13:20,620 which ports are used, what kind of server headers in there, et cetera. After identifying these 126 00:13:20,620 --> 00:13:25,860 most common values, we can configure empire's listeners option. After that we can start the agent 127 00:13:25,860 --> 00:13:27,440 and C to communication. After that, we can start the agent and C to communication. To use a basic 128 00:13:31,780 --> 00:13:34,900 We also have a connection interval in the first group of 129 00:13:34,900 --> 00:13:39,180 traits. However, finding normal connection interval, it's not an 130 00:13:39,180 --> 00:13:43,040 easy task. One way to do it, figuring the connection interval 131 00:13:43,040 --> 00:13:47,740 and frequency of users to the specific websites. However, this 132 00:13:47,740 --> 00:13:50,360 solution will not be practical since there can be delays, 133 00:13:51,000 --> 00:13:53,880 interruptions during the traffic capture and this will analyze 134 00:13:54,940 --> 00:14:01,180 our results. The second solution actually relies on false positive 135 00:14:01,180 --> 00:14:05,220 rates of an anomaly detection systems. Some research mentioned 136 00:14:05,220 --> 00:14:09,300 that the false positive rate of an anomaly based system has a 137 00:14:09,300 --> 00:14:12,860 positive correlation with the size of the network. Which means 138 00:14:12,860 --> 00:14:15,840 that in a large network, even if we keep connection interval 139 00:14:15,840 --> 00:14:20,200 values small and get flagged by anomaly detection system, this 140 00:14:20,200 --> 00:14:22,940 will be likely to be seen as false positive by analysts 141 00:14:22,940 --> 00:14:23,860 because of the network size. So, if we keep the connection 142 00:14:23,880 --> 00:14:28,280 interval, it usually happens a lot. However, if we are located 143 00:14:28,280 --> 00:14:31,960 in a small network, we need to set the connection interval 144 00:14:31,960 --> 00:14:36,960 higher than a defined threshold. The disadvantages of this method 145 00:14:36,960 --> 00:14:41,160 is C2 agent communication will be delayed, but it's a tradeoff 146 00:14:41,160 --> 00:14:44,600 to keep our communication out of sight from anomaly detection 147 00:14:44,980 --> 00:14:50,420 system. For the second group of traits, which are explained on 148 00:14:50,420 --> 00:14:53,860 the previous section, default HTML content. The first group of 149 00:14:53,860 --> 00:14:54,360 traits are normalizing the sequence of text messages and 150 00:14:54,360 --> 00:14:57,940 Python. It's a can be chosen by identifying most visited website 151 00:14:57,940 --> 00:15:01,780 in traffic capture data. However, normalizing post request 152 00:15:01,780 --> 00:15:05,660 body of the communication is not achievable by using traffic 153 00:15:05,660 --> 00:15:09,340 capture data, of course. As it explained in previous sections, 154 00:15:09,560 --> 00:15:13,140 post request is encrypted and contains gibberish characters. 155 00:15:15,580 --> 00:15:19,560 So, here's the deal. If we encrypt the post request body, it 156 00:15:19,560 --> 00:15:22,580 gives us power over signature based solutions because it won't 157 00:15:22,580 --> 00:15:27,520 match with any malicious signature. However, a normal based system will flag this since it's 158 00:15:27,520 --> 00:15:33,260 not like a normal HTTP data. On the other hand if we don't use encryption in there our problem 159 00:15:33,260 --> 00:15:39,740 is bigger. Now signature based IDS will catch us since it may contain some malicious 160 00:15:39,740 --> 00:15:46,840 integrator like who am I, cat etc. Also a normal based IDS will catch this. Same reason with 161 00:15:46,840 --> 00:15:54,780 the previous one it's not like a normal HTTP data. Instead of directly encrypting the data we 162 00:15:54,780 --> 00:16:01,000 can use Markov obfuscation tool which is created by silence appear team. So let's check the 163 00:16:01,000 --> 00:16:08,440 overall process in the slide. First we need a training data which consists of lots of texts. 164 00:16:08,920 --> 00:16:14,980 Silence team used an English book for their demonstration. After that Markov encode 165 00:16:14,980 --> 00:16:16,740 algorithm is trained by this book. 166 00:16:16,840 --> 00:16:25,040 To build a model. Then the model is built. It's ready to encode any string to a fairly meaningful 167 00:16:25,040 --> 00:16:33,300 English text. For example this is the data of an ETC pass VD file. Normally every IDS solution will 168 00:16:33,300 --> 00:16:41,020 flag this. However when we use English book to generate a model and encode that string with Markov 169 00:16:41,020 --> 00:16:46,740 obfuscation tool we got this result. It seems like a meaningful English text like a 170 00:16:46,740 --> 00:16:52,520 blog post. However when it's decoded by using a same model we will have the initial content of 171 00:16:52,520 --> 00:16:59,800 the ETC pass VD file. Uh you can check the silence appear team's ήταν page in order to 172 00:16:59,800 --> 00:17:06,880 get more information about this tool. So the operation steps will be like this. First we need 173 00:17:06,880 --> 00:17:14,360 to encode encrypted content with BAS64 to get rid of gibberish characters. As we talked we also 174 00:17:14,360 --> 00:17:16,720 need lots of texts which will be used to try to pass the IDS code in SAY clone right here. The 175 00:17:16,740 --> 00:17:23,300 used as training data for Markov obfuscation. One way to do it, including training data 176 00:17:23,300 --> 00:17:28,820 inside the agent, however, it won't be practical since it will increase the agent size a lot. 177 00:17:30,380 --> 00:17:36,620 Instead of that, we can download the data set from an external source. It doesn't have to be 178 00:17:36,620 --> 00:17:43,480 our own website. We can program it for crawling and parsing text from, like, news websites, 179 00:17:43,480 --> 00:17:49,900 blogs, et cetera. After that, we are ready to encode our data. And we will send the encoded 180 00:17:49,900 --> 00:18:01,560 data along with the training data to the C2 server. Since the system will see only English 181 00:18:01,560 --> 00:18:08,300 text, it will think that it's kind of blog post or a forum comment, and probably it won't 182 00:18:08,300 --> 00:18:13,460 raise any alerts. But there are some drawbacks, of course. First of all, the system is 183 00:18:13,480 --> 00:18:18,500 structured in the following ways. The first one is, our training phase will consume time and 184 00:18:18,500 --> 00:18:24,560 resource of the deployed computer. Time may not be a very big problem, but if there is a 185 00:18:24,560 --> 00:18:29,720 centralized resource monitoring solution on the network, may identify this 186 00:18:29,720 --> 00:18:36,620 resource uses spikes. The other drawback is you need to implement Markov obfuscation code 187 00:18:36,620 --> 00:18:43,460 inside the agent. Because it should do this by . We can send some comments and expect a 188 00:18:43,480 --> 00:18:48,240 outputs at that moment. This issue will increase agent file 189 00:18:48,240 --> 00:18:55,120 size also. So we created a tool called first order which is 190 00:18:55,120 --> 00:18:59,100 written in python. With given pick up file first order can 191 00:19:00,240 --> 00:19:03,760 extract key features of the network such as most used ports, 192 00:19:04,080 --> 00:19:07,740 most used user agents, server headers, how many different 193 00:19:07,740 --> 00:19:12,240 machines are located on the network, etc. It can extract all 194 00:19:12,240 --> 00:19:14,640 the traits which we discussed in the previous sections. 195 00:19:15,160 --> 00:19:19,100 According to these identified data, it automatically configures 196 00:19:19,100 --> 00:19:24,100 empires listener. So let's see a small demo video to see its own 197 00:19:24,100 --> 00:19:38,800 action. Sorry, I can't pause the video so I need to explain in 198 00:19:38,800 --> 00:19:42,120 real time. So first order takes three 199 00:19:42,120 --> 00:19:42,220 hours. First order takes three hours. First order takes three 200 00:19:42,240 --> 00:19:44,640 hours. And it takes five minutes to once after five minutes 201 00:19:44,640 --> 00:19:46,480 to transfer data to the next entry, and then it again 202 00:19:46,480 --> 00:19:47,800 automatically will generate the image of empires listener. And 203 00:19:47,800 --> 00:19:53,440 after then, it analyzes the package data and provides us a 204 00:19:53,440 --> 00:19:58,220 summary of the capture file, most used elements, and it 205 00:19:58,220 --> 00:20:02,700 automatically generates an empire listener. So since this 206 00:20:02,700 --> 00:20:07,740 Empire listener is feted by the most common elements of the 207 00:20:07,740 --> 00:20:12,220 network, uh probably it will bypass the anomalies by seeing 208 00:20:12,240 --> 00:20:16,620 detection system located on the network. Because we are using 209 00:20:16,620 --> 00:20:21,400 the normal traffic profile of the network to build an agent 210 00:20:21,400 --> 00:20:25,400 and C2 communication. But if you use default configuration of the 211 00:20:25,400 --> 00:20:32,100 empire, probably anomaly based system will catch it. So this 212 00:20:32,100 --> 00:20:36,520 tool is available on this address. So feel free to use it. 213 00:20:36,900 --> 00:20:41,780 Submit issues if you find any bugs. And of course send some 214 00:20:41,780 --> 00:20:52,780 stars. So as a result, we can say that defense mechanisms are 215 00:20:52,780 --> 00:20:57,180 evolving to something smarter, something better. Maybe in 216 00:20:57,180 --> 00:20:59,900 future signature based approaches will be totally 217 00:20:59,900 --> 00:21:10,500 abandoned. And there is a high probability that machine 218 00:21:10,500 --> 00:21:11,760 learning based defense mechanisms will be completely 219 00:21:23,520 --> 00:21:29,140 cheaper and wider than today. So attackers should also evolve in 220 00:21:29,140 --> 00:21:32,960 this way. We need to find smarter ways to mislead artificial 221 00:21:32,960 --> 00:21:37,820 intelligence. Thank you for listening. That's all I got.