[00:00.000 --> 00:05.500] Good morning everyone. Thank you for being here so early. I'm so glad to have this [00:05.500 --> 00:12.080] opportunity to talk with you at the DEF CON Blue Team Village. My name is Yan and my [00:12.080 --> 00:19.940] colleague's name is Siyu but he can't be here because of his visa so I will share it by [00:19.940 --> 00:29.040] myself this time. And I'm not good at English so if you have any questions about this talk, [00:29.620 --> 00:37.520] it's better that we can chat face-to-face after I finish this talk. Thank you. The topic is [00:37.520 --> 00:46.120] Embedded Microsoft ATA but you are completely exposed by the event log. So I will talk [00:46.720 --> 00:57.000] about how our team attacked AD attacks and what we have done. We are the zero key team [00:57.000 --> 01:07.180] from 360. Our team focus on web application security and testing and enterprise security. And [01:07.180 --> 01:14.820] this is our team's blog website but there are all Chinese blogs now. I think we will write some [01:14.820 --> 01:25.640] English blogs later. Okay, this talk has six parts. The first part introduce why we do it. [01:25.640 --> 01:33.300] And the second part is the architecture we have designed to analyze the event log in real [01:33.300 --> 01:42.000] time. In the third part, we will show you some detections in detail. In the fourth part, we [01:42.000 --> 01:50.060] will show you the examples in the current program we use to detect the AD attacks. Finally, [01:50.060 --> 01:57.280] we will show you the summary and the synopsis. Okay, let's go. Most enterprises are managed [01:57.280 --> 02:05.940] using active directory now. AD attack always occurs in the APT. Through it, the attacks can [02:05.940 --> 02:12.860] access to the important assets. So the enterprises has paid more attention to the AD security [02:12.860 --> 02:20.040] now. We need to detect advanced attacks and insider threats before they cause damage to [02:20.060 --> 02:30.220] our organization. But from the internal recon to assess the AD attack covers multiple attack [02:30.220 --> 02:41.460] kill chance stages. There are many methods and tools to do the AD attack. So it's hard to [02:41.460 --> 02:48.580] distinguish the normal and abnormal behaviors. There are a few tools we can use to protect our [02:48.580 --> 02:58.280] AD. Even many defenders don't know they have suffered the AD attack. First to the AD attack, [02:58.280 --> 03:06.560] the blue team is always in a passive situation. They said I can detect AD attacks but you can't. [03:08.920 --> 03:17.540] I have to say the Microsoft ATA. Microsoft ATA may be the most famous and the best tools to [03:17.540 --> 03:26.360] detect AD attacks. The main detection method of ATA is to analyze the traffic through an ATA [03:26.360 --> 03:36.180] gateway or the deployed lightweight gateway directly on the DC. Addition, it can import and [03:36.180 --> 03:44.860] analyze Windows event tool. Microsoft ATA can detect multiple suspicious activities and cover [03:44.860 --> 03:51.920] most of the attack kill chance. To be honest, it's the first company to achieve such a great [03:51.920 --> 04:05.380] effect. But is that all? First, the ATA is not cheap. It's price is $80 per user. I saw it on [04:05.380 --> 04:14.840] their documents that to our company, there are more than 6,000 employees in the company. [04:15.310 --> 04:29.660] It may cost about $500,000. Moreover, ATA has some limitations. They analyze traffic mainly [04:29.660 --> 04:38.520] so we have some problems with encrypted traffic, the unmonitored protocols and the update to [04:38.520 --> 04:46.600] detect new attacks and some bypassing and so on. So if you want to know more about ATA [04:46.600 --> 04:54.300] bypass, you can refer to this Black Hat talk. So we decided to do it by ourself, although the [04:54.300 --> 05:06.360] Microsoft ATA is really great. We do not use the traffic to detect attacks. The only thing we [05:06.360 --> 05:13.640] focus on is the event log of the DC. The event log records all the user activities and the [05:13.640 --> 05:22.640] object changes in active directory. Before we analyze the event log, we need to turn on all the [05:22.640 --> 05:34.120] audit items in the local audit policy. So let's look at the format of the event log. There are 2 [05:34.120 --> 05:40.140] different parts in the event log. The first part is general information such as the system [05:40.140 --> 05:46.740] information. The second part is detailed information of changes according to different event [05:46.740 --> 05:57.880] IDs. We focus on those common IDs. You can see that different event ID uh represents different [05:57.880 --> 06:07.480] interesting action. Okay, this picture is an architecture we designed. We collect the event [06:07.480 --> 06:17.440] logs on all of the DCs by one log bit and send them to the log stash. Next, log stash will save [06:17.440 --> 06:27.860] the logs to RabbitMQ. After that, the logs will be consumed to trials. One is saved to the [06:27.880 --> 06:39.120] elastic search. Another one is analyzed by our detection algorithm. We learn the behavior of [06:39.120 --> 06:47.480] users through logs and then generate alarms. Finally, we can see the detail alarm data on the [06:47.480 --> 06:57.300] web console. Our architecture is very lightweight so just install the one log bit on all DCs. [06:57.300 --> 07:09.660] There is no other impact on the domain environment. So let's punch the intruders. Then this is [07:09.660 --> 07:17.880] an important part. According to the way of detections, we will explain this content through [07:18.800 --> 07:25.840] 5 kinds. The contents covers most common attacks and more detection methods are not listed [07:25.840 --> 07:37.240] because of time. The first kind, incompleted Kerberos protocol. Let's review the Kerberos [07:37.240 --> 07:48.400] process which is roughly divided to 3 steps. The first step is authentication service, aka AS. [07:49.400 --> 07:55.820] The user generates the password hash and sends it to the KDC. After the KDC verifies the [07:55.840 --> 08:03.340] user has verified it successfully, the TGT is encrypted by the password hash of the content [08:03.340 --> 08:13.640] named the KRB TGT. And the final TGT is returned to the user. The second step is the TK [08:13.640 --> 08:22.560] grant service. The user sends the TGT to the KDC, then the KDC does not verify whether the [08:22.560 --> 08:31.540] user has permissions to the service. It only checks whether the TGT can be decrypted with the [08:31.540 --> 08:41.680] password of the content named the KRB TGT. And the user then uses the machine password of the [08:41.680 --> 08:52.540] target service to get the ST. Finally, the user uses ST to access the target service. The [08:52.560 --> 09:02.360] last step is the TGS. In the previous 2 steps, the AS request will trigger the 4768 log and the TGS [09:02.360 --> 09:16.360] request will trigger the 4769 log. So the complete Kerberos will have both 4768 and 4769 logs. We [09:16.360 --> 09:22.540] can track each Kerberos TKT request by the event logs. So let's see the Kerberos TKT request. [09:22.560 --> 09:31.060] This is a golden TKT. The TGT is encrypted using password hash of the account named the KRB TGT. [09:31.060 --> 09:41.680] Once we got this hash, we can forge any user's TGT which is a golden TKT. Because the TGT is [09:41.680 --> 09:51.200] forged, the user does not send a corresponding AS request from the machine and there is no 4768 [09:51.200 --> 10:05.540] log on the DC. And moreover, the default maximum lifetime for TGT and ST is 10 hours. So the [10:05.540 --> 10:17.880] detection idea is very obvious. When we found the 4769 event log, we can search for the [10:17.880 --> 10:26.360] corresponding TGT request record according to the time of the TGT maximum lifetime. For [10:26.360 --> 10:39.940] example, we- we received a 4769 log whose source IP is xxx.12 and the target username is [10:39.940 --> 10:47.860] hacker. Next, we need to find a 4768 log from the stored logs. So we need to find the [10:47.880 --> 10:57.300] 4769 log whose source IP is also xxx.12 and target username is hacker and the time is within 10 [10:57.300 --> 11:04.300] hours. Just like the picture. If you can't find one, maybe you have been attacked by the golden [11:04.300 --> 11:15.920] TKT. Golden TKT is forged TGT but the silver TKT is forged ST. The ST is encrypted by the [11:15.920 --> 11:22.480] password hash of the machine. If we have the machine password hash, we can forge the ST. So [11:22.480 --> 11:35.760] the attacker will not send the boss AS request and there are neither 4768 nor 4769 logs left [11:35.760 --> 11:45.280] on the DC. So how can we detect it? The detection idea is similar to the golden TKT. When the [11:46.300 --> 11:56.980] 4624 event is triggered on the DC, find the corresponding 4768 and 4769 event logs. For [11:56.980 --> 12:08.100] example, we received a 4624 log whose source IP is xxx.12, target username is hacker. Next, [12:08.100 --> 12:15.260] we will need to find a 4769 log from the stored logs. We need to find a 4769 log from the [12:15.280 --> 12:22.460] stored logs. We need to find a 4769 log whose source IP is xxx.12, target username is hacker. If [12:22.460 --> 12:30.020] you can't find one, maybe you have been attacked by a silver TKT. You can see that it seems [12:30.020 --> 12:39.440] that we can only detect the silver TKT when attacking the DC use silver TKT. I will talk [12:39.440 --> 12:49.340] about another way to detect the silver TKT in another part later. So only rely on the event [12:49.340 --> 13:01.240] log, we can't exactly link the TGT and the ST according to a unique ID. I can't find such a [13:01.240 --> 13:09.420] value in the log. Currently we only rely on source IP and target username and target [13:10.420 --> 13:18.500] username to track the source of the TKT request. The source IP may change, causing some [13:18.500 --> 13:28.280] false positives. In theory, there are- there is no false negative and you can reduce false [13:28.800 --> 13:39.420] positives by add some filters. Okay, the second kind, login records. Login records are [13:39.440 --> 13:47.160] very important. In addition to the Kerberos protocol introduced earlier, there is another [13:47.160 --> 13:57.760] authentication protocol in the domain, NTLM. Here is how we detect positive hash. Attackers [13:57.760 --> 14:08.520] can remotely access a target workstation with NTLM hash by using tools such as Mimikaz, WMIC, [14:08.520 --> 14:19.700] SMB client and so on. If a domain account is used for authentication, the 4776 event log will [14:19.700 --> 14:27.120] be triggered on the DC. The target account and the source workstation name are displayed in [14:27.120 --> 14:36.860] the log. Although we can't analyze the abnormal protocol like ATA to track the PTH, but we [14:36.860 --> 14:47.120] can establish a mapping of user names and the workstations by recording login event log. [14:47.640 --> 14:54.320] Each domain account should log into its own machine and the cross machine login behavior is [14:54.320 --> 15:03.040] not allowed. So when we found that the target user name and the computer name shown in the 4776 [15:03.040 --> 15:09.240] log are not the same as the known mapping, we need to pay attention to it. But [15:09.240 --> 15:17.920] unfortunately, we found some false positives because many people use their own domain account [15:17.920 --> 15:27.720] to log in a public computer. The third kind, sensitive action, includes some high risk [15:27.720 --> 15:43.340] operations and activities that do not match the target's identity. Case 1, modify ACL. ACL is a [15:43.340 --> 15:51.840] list of access control entries. The ACL determines who can access the objects in the AD and [15:51.840 --> 16:01.120] each object have a property called security descriptor which store the information about it. ACL [16:01.120 --> 16:12.200] is divided into DACL and SACL. The DACL lists the security information about who have access [16:12.200 --> 16:23.280] rights to the object and his level of access. Here we mainly focus on DACL. The SACL [16:25.720 --> 16:37.160] modification is recorded in detail in the 5136 log. The SS-SDDL syntax is used to describe the [16:37.160 --> 16:45.560] permission information in the log. It defines the SID of the AD object, the group ID, and the [16:45.560 --> 16:53.280] flags of the DACL. It contains a list of ACE and each ACE defines the group ID and the flags of the [16:53.300 --> 17:08.900] permissions of an object. Next, let me explain how to detect ACL-related attacks. CVE 2018 8581, [17:08.900 --> 17:18.600] the popular exchange vulnerability at the beginning of the year. Attacker modifies the ACL by [17:18.600 --> 17:32.280] NTLM relate to DC and then execute DC sync. The requirement to execute DC sync is to have the [17:32.280 --> 17:40.020] replicating directory changes and the replicating directory changes all permissions. So the [17:40.020 --> 17:48.580] attack use the exchange account to modify the ADCL and the ACL and add the permission to [17:51.340 --> 18:01.280] modify the ACL we are 5136 event log. Then we can check the permissions after passing the [18:01.280 --> 18:12.320] attribute value. Monitor all 5136 events and find out that someone add abnormal account access [18:12.320 --> 18:26.080] to the ACL. Pay attention to the user who performs the modification- modify operation if it's a [18:26.080 --> 18:35.620] default account like the exchange then the domain is likely to have been attacked because this [18:35.620 --> 18:48.860] account rarely has active operations. Case 2, detect DC shadow. It can remotely modify the [18:48.860 --> 18:57.660] object information in the domain without logging to the domain controllers. The actor [18:57.660 --> 19:05.600] stimulates the machine as a DC sending a sync request to the real domain controller. The [19:06.620 --> 19:15.760] technique is considered difficult to detect, however, the attack can be easily detected by [19:15.760 --> 19:26.280] analyzing the event log. We select 2 of the event logs to introduce detection. First the DC [19:26.280 --> 19:35.600] shadow. As the SPN to the current computer, the value is prefixed with the DIS interface [19:35.620 --> 19:53.380] GUID like E3514235 dot dot here. So we detect 4742 event log and check the SPN value [19:53.380 --> 20:01.260] modification of the computer account. If a special value in it and the computer is not a DC, [20:01.260 --> 20:12.560] this is a DC shadow attack. Second, we check the replication monitoring event, the false [20:12.560 --> 20:24.910] none to none log. If the source address is not a DC, this is also a DC shadow attack. Another [20:24.910 --> 20:33.570] one, admin privilege granted. Attacks at compromised account to some client. The [20:33.590 --> 20:39.010] attacker can use this group to keep persistence. These groups are not just domain [20:39.010 --> 20:49.290] admins and administrators, but also include backup operators, DNS admins, server operators, [20:49.290 --> 20:55.110] account operators, and so on. So we need to pay attention to the following event log like [20:55.110 --> 21:03.110] this one. The member name is hacker and the target user name is domain admins. It seems that [21:03.110 --> 21:10.210] the hacker will be added to the domain admins and have the administrator's privileges. [21:14.090 --> 21:23.070] Constraint delegation. Adding to account to the administrator group is too obvious and easy to [21:23.070 --> 21:33.090] find. So the attacker can access the DC by setting the constraint delegation on the target [21:33.630 --> 21:42.230] DC for the compromised account. For example, setting the value of a log to delegate to is [21:42.910 --> 21:55.710] LDAP slash DC dot DefCon dot org and you can execute DC sync to DC. The detection of the [21:55.710 --> 22:03.090] constraint delegation is easy. Modify a user account where triggered by the attacker. [22:03.110 --> 22:13.190] 4, 7, 3, 8 event log. We can check a lot to delegate to field and find a sensitive value such [22:13.190 --> 22:29.030] as LDAP, CIFS, and host to find the attacks. The fourth kind, honeypot account. We can [22:29.030 --> 22:37.170] create accounts with administrator privileges that contain settings which are of interest to [22:37.170 --> 22:46.910] the attackers. Those accounts don't look any different from the normal accounts, they just [22:46.910 --> 22:57.490] have the attractive permissions. The first honeypot account have attractive SPN value. [22:57.970 --> 23:07.110] Cobra hosting's first step is to find a service account which with a specific prefix value for [23:07.110 --> 23:20.830] SPN or admin account equal to 1. The attackers attempts to request the ST using RC4 [23:20.830 --> 23:27.470] encryption and the local offline crack password. If the account has privileges such as [23:27.490 --> 23:37.590] permissions, have administrator privileges, the attacker can quickly access. Pay close [23:37.590 --> 23:44.350] attention to all activities related to the honeypot account such as SAM, Cobras, and [23:46.090 --> 23:57.470] account login and so on. If the honeypot account with SPN value of the MS SQL server, [23:57.490 --> 24:06.070] service prefix does not attract the attacker, set a constraint delegation with a value of LDAP [24:06.070 --> 24:21.010] slash DC DEF CON organization for this account. Once the attacker crack this honeypot [24:21.010 --> 24:27.470] account, he can got all the passwords from the account via DC sync. While it's so [24:27.470 --> 24:35.190] great, the attacker can only need to request the ST and then have a cup of coffee waiting for [24:35.190 --> 24:43.210] the password to be crashed successfully. But we are waiting for them to. The third honeypot [24:43.210 --> 24:54.870] account not required pre-auth. If setting the do not require Cobras authentication, the [24:54.870 --> 25:04.110] attacker can request the TGT for offline uh cracking. We can turn this option on to [25:04.110 --> 25:14.910] induce uh attackers to request it so that we can detect malicious behaviors. Final pay [25:14.910 --> 25:21.890] attention please. In your situation, the honeypot account will not be used so any related [25:22.370 --> 25:31.490] locks will be triggered by the attacker. In order to prevent successful cracking the [25:31.490 --> 25:39.670] honeypot account, must set a complex password and the password length is greater than 12 uh no [25:39.670 --> 25:48.030] no no no, 25. Also in order to prevent and catch the TKs of being takeover by other [25:48.030 --> 26:01.030] messers, do not log in and use the account. The fifth part, detect unknown threats. Case 1, [26:01.030 --> 26:12.390] fake account info. Each user has a unique and unchanging SID in the domain. You can query the [26:12.390 --> 26:24.660] information of account by username or SID. When an attacker use Mimikatz to create a silver [26:24.660 --> 26:34.980] ticket, he can fill in any user and any ID parameters. This ticket is valid but the lock will [26:34.980 --> 26:44.120] record all the information. So when the attackers use silver ticket to log in to the DC, [26:45.000 --> 26:56.940] the following 4, 6, 2, 4 locks will be left on the DC. When the attacker randomly filled in the [26:56.940 --> 27:05.760] username or SID, we can see that the username and SID can't match or can't be queried. So we [27:05.760 --> 27:16.160] can use another way to detect the silver ticket when the hacker is not careful. Case 2, [27:16.180 --> 27:29.140] privilege escalation. I think it's very worth to show. The 4, 6, 7, 2 event log is triggered on [27:29.140 --> 27:39.860] the DC when the administrator logs in to the DC. In other words, only the administrator's [27:39.860 --> 27:46.160] login can trigger the 4, 6, 7, 2 event log. The 3, 4, 6, 7, 2 event log can trigger the [27:46.180 --> 27:55.160] subject username and the subject user SID fields show the current administrator's name and SID. [27:55.160 --> 28:05.640] So what can we do? We found something interesting. After you successfully escalate [28:05.640 --> 28:16.160] privilege with MS-1406A and you log in to the DC, it will trigger the 4, 6, 7, 2 event log. [28:17.480 --> 28:25.000] But at this point, you are not an administrator. You just forged a PAC and got temporary [28:27.760 --> 28:36.320] administrator privileges. So when we found the name in the 4, 6, 7, 2 log but he is not an [28:36.320 --> 28:46.160] administrator, it must have been attacked. More than MS-14068, there may be other ways to [28:47.200 --> 28:57.480] escalate privileges in the future. As long as it is a temporary privilege escalation, it must [28:57.480 --> 29:09.140] not escape this detection. At the last, more detections. We can detect the co-hosting AS [29:09.140 --> 29:16.160] request by monitoring the value of ticket encryption type in 4, 6, 7, 2 event log. [29:16.180 --> 29:25.560] And 4, 7, 6, 8 and 4, 7, 6, 9 event log. We can recognize the attacker's tools by monitoring [29:25.560 --> 29:36.460] the value of ticket options in 4, 7, 6, 8 and 4, 7, 6, 9 event log. There are many tricks [29:36.460 --> 29:46.160] here but it needs a long time to describe them. So I won't talk about these tricks and many [29:46.180 --> 29:53.360] other detections in detail this time. If you are interested in them, I can show you after I [29:53.360 --> 30:06.660] finished the talk. Achievements here. There are some videos. It's so sorry that it only has [30:06.660 --> 30:16.160] the Chinese version. So the first one is easy. It's an example that we detect the target [30:16.780 --> 30:27.460] admin group enumeration. We executed the net group domain admin slash domain account [30:27.460 --> 30:41.240] comment. Open our web console. We detect it. It shows that someone enumerated the domain [30:41.240 --> 30:57.240] groups by using the account name test user 1. Okay, this is an example that we detect the [30:57.240 --> 31:18.030] golden ticket attack. We use the minicast to create a golden ticket and then use it. Oh, [31:18.030 --> 31:28.060] just wait. Okay, then we detect it. It shows that the computer 1 is requesting the ST and [31:28.060 --> 31:37.620] never requested a TGT. So we regard it as a golden ticket attack. We can also get detailed [31:37.620 --> 31:51.340] information on the web console. Okay, this is an example of a DC shadow. We also use the [31:51.340 --> 32:12.740] minicast to do the DC shadow attack. Okay, we detect that the computer 0 to simulate the [32:12.740 --> 32:24.520] domain controller 01 with the privileges of the account exchange 01 because it has modified the [32:24.520 --> 32:42.600] value of computer 02's SPN value to the abnormal value. Okay, the last and complex one, CVE 2018 [32:43.820 --> 32:54.340] and 8581. We use the tools to relay the exchange's NTIM hash to the DC and modify the ACL. [32:55.240 --> 33:22.380] Oh, wait a moment. It needs some time. No, no, no, no, no, no. Okay, succeed. Here we will [33:22.380 --> 33:35.300] find the NTIM of the computer 02 which is exchange server has been relayed to the DC01. [33:43.050 --> 33:55.310] It can show the detailed information of the machine and the user. Then the exchange server [33:55.310 --> 34:05.290] modified the ACL. You can see the new alarm in the abnormal ACL modification. We detect it [34:05.290 --> 34:13.030] successfully. At the last conclusion, this is the end of the presentation. Thank you. [34:13.050 --> 34:20.690] There are some limitations with event log. First, there are some false positives in the detection [34:20.690 --> 34:30.170] of lateral movement. But if you can collect local event logs, you can detect lateral movement [34:30.170 --> 34:41.530] attacks more exactly. Second, if the attack methods do not trigger the event logs on DC, we [34:41.530 --> 34:50.650] cannot detect them such as elevation to DA from DNS admin memberships, attacking circuit [34:50.650 --> 35:00.930] server, pass the hash with local account, searching info by LDAP and so on. Although there are [35:00.930 --> 35:08.650] some limitations, I think it's worth to do it. We only do the DC event log analysis. It's [35:08.650 --> 35:18.290] lightweight and easy to deploy. And we have finished about 36 kinds of alarms belong to [35:18.290 --> 35:33.790] different stages. We can detect most persistent attacks by analyzing event logs such as [35:33.790 --> 35:49.570] admin SD holder, DSRM, group policy, DC shadow, SID history, modify ACL and so on. So in a [35:49.570 --> 35:59.590] word, the process of attack generates traffic and the result of the attack is event log. Our [35:59.590 --> 36:08.650] analysis is based on the results of the attack which is less likely to be bypassed or [36:09.430 --> 36:20.530] confused than the process analysis. So I think if you have known the attack methods, you can [36:20.530 --> 36:29.570] build your own ATA by analyzing event logs. It's not very hard. And the last one is the [36:29.590 --> 36:38.230] Q&A. Okay, that's all. It's hard to do the Q&A directly for me. So if you have any questions, we [36:38.230 --> 36:46.270] can chat face to face. You can also directly message us via Twitter or email. Okay, thank [36:46.270 --> 36:47.690] you. Thank you all.