Good morning everyone. Thank you for being here so early. I'm so glad to have this opportunity to talk with you at the DEF CON Blue Team Village. My name is Yan and my colleague's name is Siyu but he can't be here because of his visa so I will share it by myself this time. And I'm not good at English so if you have any questions about this talk, it's better that we can chat face-to-face after I finish this talk. Thank you. The topic is Embedded Microsoft ATA but you are completely exposed by the event log. So I will talk about how our team attacked AD attacks and what we have done. We are the zero key team from 360. Our team focus on web application security and testing and enterprise security. And this is our team's blog website but there are all Chinese blogs now. I think we will write some English blogs later. Okay, this talk has six parts. The first part introduce why we do it. And the second part is the architecture we have designed to analyze the event log in real time. In the third part, we will show you some detections in detail. In the fourth part, we will show you the examples in the current program we use to detect the AD attacks. Finally, we will show you the summary and the synopsis. Okay, let's go. Most enterprises are managed using active directory now. AD attack always occurs in the APT. Through it, the attacks can access to the important assets. So the enterprises has paid more attention to the AD security now. We need to detect advanced attacks and insider threats before they cause damage to our organization. But from the internal recon to assess the AD attack covers multiple attack kill chance stages. There are many methods and tools to do the AD attack. So it's hard to distinguish the normal and abnormal behaviors. There are a few tools we can use to protect our AD. Even many defenders don't know they have suffered the AD attack. First to the AD attack, the blue team is always in a passive situation. They said I can detect AD attacks but you can't. I have to say the Microsoft ATA. Microsoft ATA may be the most famous and the best tools to detect AD attacks. The main detection method of ATA is to analyze the traffic through an ATA gateway or the deployed lightweight gateway directly on the DC. Addition, it can import and analyze Windows event tool. Microsoft ATA can detect multiple suspicious activities and cover most of the attack kill chance. To be honest, it's the first company to achieve such a great effect. But is that all? First, the ATA is not cheap. It's price is $80 per user. I saw it on their documents that to our company, there are more than 6,000 employees in the company. It may cost about $500,000. Moreover, ATA has some limitations. They analyze traffic mainly so we have some problems with encrypted traffic, the unmonitored protocols and the update to detect new attacks and some bypassing and so on. So if you want to know more about ATA bypass, you can refer to this Black Hat talk. So we decided to do it by ourself, although the Microsoft ATA is really great. We do not use the traffic to detect attacks. The only thing we focus on is the event log of the DC. The event log records all the user activities and the object changes in active directory. Before we analyze the event log, we need to turn on all the audit items in the local audit policy. So let's look at the format of the event log. There are 2 different parts in the event log. The first part is general information such as the system information. The second part is detailed information of changes according to different event IDs. We focus on those common IDs. You can see that different event ID uh represents different interesting action. Okay, this picture is an architecture we designed. We collect the event logs on all of the DCs by one log bit and send them to the log stash. Next, log stash will save the logs to RabbitMQ. After that, the logs will be consumed to trials. One is saved to the elastic search. Another one is analyzed by our detection algorithm. We learn the behavior of users through logs and then generate alarms. Finally, we can see the detail alarm data on the web console. Our architecture is very lightweight so just install the one log bit on all DCs. There is no other impact on the domain environment. So let's punch the intruders. Then this is an important part. According to the way of detections, we will explain this content through 5 kinds. The contents covers most common attacks and more detection methods are not listed because of time. The first kind, incompleted Kerberos protocol. Let's review the Kerberos process which is roughly divided to 3 steps. The first step is authentication service, aka AS. The user generates the password hash and sends it to the KDC. After the KDC verifies the user has verified it successfully, the TGT is encrypted by the password hash of the content named the KRB TGT. And the final TGT is returned to the user. The second step is the TK grant service. The user sends the TGT to the KDC, then the KDC does not verify whether the user has permissions to the service. It only checks whether the TGT can be decrypted with the password of the content named the KRB TGT. And the user then uses the machine password of the target service to get the ST. Finally, the user uses ST to access the target service. The last step is the TGS. In the previous 2 steps, the AS request will trigger the 4768 log and the TGS request will trigger the 4769 log. So the complete Kerberos will have both 4768 and 4769 logs. We can track each Kerberos TKT request by the event logs. So let's see the Kerberos TKT request. This is a golden TKT. The TGT is encrypted using password hash of the account named the KRB TGT. Once we got this hash, we can forge any user's TGT which is a golden TKT. Because the TGT is forged, the user does not send a corresponding AS request from the machine and there is no 4768 log on the DC. And moreover, the default maximum lifetime for TGT and ST is 10 hours. So the detection idea is very obvious. When we found the 4769 event log, we can search for the corresponding TGT request record according to the time of the TGT maximum lifetime. For example, we- we received a 4769 log whose source IP is xxx.12 and the target username is hacker. Next, we need to find a 4768 log from the stored logs. So we need to find the 4769 log whose source IP is also xxx.12 and target username is hacker and the time is within 10 hours. Just like the picture. If you can't find one, maybe you have been attacked by the golden TKT. Golden TKT is forged TGT but the silver TKT is forged ST. The ST is encrypted by the password hash of the machine. If we have the machine password hash, we can forge the ST. So the attacker will not send the boss AS request and there are neither 4768 nor 4769 logs left on the DC. So how can we detect it? The detection idea is similar to the golden TKT. When the 4624 event is triggered on the DC, find the corresponding 4768 and 4769 event logs. For example, we received a 4624 log whose source IP is xxx.12, target username is hacker. Next, we will need to find a 4769 log from the stored logs. We need to find a 4769 log from the stored logs. We need to find a 4769 log whose source IP is xxx.12, target username is hacker. If you can't find one, maybe you have been attacked by a silver TKT. You can see that it seems that we can only detect the silver TKT when attacking the DC use silver TKT. I will talk about another way to detect the silver TKT in another part later. So only rely on the event log, we can't exactly link the TGT and the ST according to a unique ID. I can't find such a value in the log. Currently we only rely on source IP and target username and target username to track the source of the TKT request. The source IP may change, causing some false positives. In theory, there are- there is no false negative and you can reduce false positives by add some filters. Okay, the second kind, login records. Login records are very important. In addition to the Kerberos protocol introduced earlier, there is another authentication protocol in the domain, NTLM. Here is how we detect positive hash. Attackers can remotely access a target workstation with NTLM hash by using tools such as Mimikaz, WMIC, SMB client and so on. If a domain account is used for authentication, the 4776 event log will be triggered on the DC. The target account and the source workstation name are displayed in the log. Although we can't analyze the abnormal protocol like ATA to track the PTH, but we can establish a mapping of user names and the workstations by recording login event log. Each domain account should log into its own machine and the cross machine login behavior is not allowed. So when we found that the target user name and the computer name shown in the 4776 log are not the same as the known mapping, we need to pay attention to it. But unfortunately, we found some false positives because many people use their own domain account to log in a public computer. The third kind, sensitive action, includes some high risk operations and activities that do not match the target's identity. Case 1, modify ACL. ACL is a list of access control entries. The ACL determines who can access the objects in the AD and each object have a property called security descriptor which store the information about it. ACL is divided into DACL and SACL. The DACL lists the security information about who have access rights to the object and his level of access. Here we mainly focus on DACL. The SACL modification is recorded in detail in the 5136 log. The SS-SDDL syntax is used to describe the permission information in the log. It defines the SID of the AD object, the group ID, and the flags of the DACL. It contains a list of ACE and each ACE defines the group ID and the flags of the permissions of an object. Next, let me explain how to detect ACL-related attacks. CVE 2018 8581, the popular exchange vulnerability at the beginning of the year. Attacker modifies the ACL by NTLM relate to DC and then execute DC sync. The requirement to execute DC sync is to have the replicating directory changes and the replicating directory changes all permissions. So the attack use the exchange account to modify the ADCL and the ACL and add the permission to modify the ACL we are 5136 event log. Then we can check the permissions after passing the attribute value. Monitor all 5136 events and find out that someone add abnormal account access to the ACL. Pay attention to the user who performs the modification- modify operation if it's a default account like the exchange then the domain is likely to have been attacked because this account rarely has active operations. Case 2, detect DC shadow. It can remotely modify the object information in the domain without logging to the domain controllers. The actor stimulates the machine as a DC sending a sync request to the real domain controller. The technique is considered difficult to detect, however, the attack can be easily detected by analyzing the event log. We select 2 of the event logs to introduce detection. First the DC shadow. As the SPN to the current computer, the value is prefixed with the DIS interface GUID like E3514235 dot dot here. So we detect 4742 event log and check the SPN value modification of the computer account. If a special value in it and the computer is not a DC, this is a DC shadow attack. Second, we check the replication monitoring event, the false none to none log. If the source address is not a DC, this is also a DC shadow attack. Another one, admin privilege granted. Attacks at compromised account to some client. The attacker can use this group to keep persistence. These groups are not just domain admins and administrators, but also include backup operators, DNS admins, server operators, account operators, and so on. So we need to pay attention to the following event log like this one. The member name is hacker and the target user name is domain admins. It seems that the hacker will be added to the domain admins and have the administrator's privileges. Constraint delegation. Adding to account to the administrator group is too obvious and easy to find. So the attacker can access the DC by setting the constraint delegation on the target DC for the compromised account. For example, setting the value of a log to delegate to is LDAP slash DC dot DefCon dot org and you can execute DC sync to DC. The detection of the constraint delegation is easy. Modify a user account where triggered by the attacker. 4, 7, 3, 8 event log. We can check a lot to delegate to field and find a sensitive value such as LDAP, CIFS, and host to find the attacks. The fourth kind, honeypot account. We can create accounts with administrator privileges that contain settings which are of interest to the attackers. Those accounts don't look any different from the normal accounts, they just have the attractive permissions. The first honeypot account have attractive SPN value. Cobra hosting's first step is to find a service account which with a specific prefix value for SPN or admin account equal to 1. The attackers attempts to request the ST using RC4 encryption and the local offline crack password. If the account has privileges such as permissions, have administrator privileges, the attacker can quickly access. Pay close attention to all activities related to the honeypot account such as SAM, Cobras, and account login and so on. If the honeypot account with SPN value of the MS SQL server, service prefix does not attract the attacker, set a constraint delegation with a value of LDAP slash DC DEF CON organization for this account. Once the attacker crack this honeypot account, he can got all the passwords from the account via DC sync. While it's so great, the attacker can only need to request the ST and then have a cup of coffee waiting for the password to be crashed successfully. But we are waiting for them to. The third honeypot account not required pre-auth. If setting the do not require Cobras authentication, the attacker can request the TGT for offline uh cracking. We can turn this option on to induce uh attackers to request it so that we can detect malicious behaviors. Final pay attention please. In your situation, the honeypot account will not be used so any related locks will be triggered by the attacker. In order to prevent successful cracking the honeypot account, must set a complex password and the password length is greater than 12 uh no no no no, 25. Also in order to prevent and catch the TKs of being takeover by other messers, do not log in and use the account. The fifth part, detect unknown threats. Case 1, fake account info. Each user has a unique and unchanging SID in the domain. You can query the information of account by username or SID. When an attacker use Mimikatz to create a silver ticket, he can fill in any user and any ID parameters. This ticket is valid but the lock will record all the information. So when the attackers use silver ticket to log in to the DC, the following 4, 6, 2, 4 locks will be left on the DC. When the attacker randomly filled in the username or SID, we can see that the username and SID can't match or can't be queried. So we can use another way to detect the silver ticket when the hacker is not careful. Case 2, privilege escalation. I think it's very worth to show. The 4, 6, 7, 2 event log is triggered on the DC when the administrator logs in to the DC. In other words, only the administrator's login can trigger the 4, 6, 7, 2 event log. The 3, 4, 6, 7, 2 event log can trigger the subject username and the subject user SID fields show the current administrator's name and SID. So what can we do? We found something interesting. After you successfully escalate privilege with MS-1406A and you log in to the DC, it will trigger the 4, 6, 7, 2 event log. But at this point, you are not an administrator. You just forged a PAC and got temporary administrator privileges. So when we found the name in the 4, 6, 7, 2 log but he is not an administrator, it must have been attacked. More than MS-14068, there may be other ways to escalate privileges in the future. As long as it is a temporary privilege escalation, it must not escape this detection. At the last, more detections. We can detect the co-hosting AS request by monitoring the value of ticket encryption type in 4, 6, 7, 2 event log. And 4, 7, 6, 8 and 4, 7, 6, 9 event log. We can recognize the attacker's tools by monitoring the value of ticket options in 4, 7, 6, 8 and 4, 7, 6, 9 event log. There are many tricks here but it needs a long time to describe them. So I won't talk about these tricks and many other detections in detail this time. If you are interested in them, I can show you after I finished the talk. Achievements here. There are some videos. It's so sorry that it only has the Chinese version. So the first one is easy. It's an example that we detect the target admin group enumeration. We executed the net group domain admin slash domain account comment. Open our web console. We detect it. It shows that someone enumerated the domain groups by using the account name test user 1. Okay, this is an example that we detect the golden ticket attack. We use the minicast to create a golden ticket and then use it. Oh, just wait. Okay, then we detect it. It shows that the computer 1 is requesting the ST and never requested a TGT. So we regard it as a golden ticket attack. We can also get detailed information on the web console. Okay, this is an example of a DC shadow. We also use the minicast to do the DC shadow attack. Okay, we detect that the computer 0 to simulate the domain controller 01 with the privileges of the account exchange 01 because it has modified the value of computer 02's SPN value to the abnormal value. Okay, the last and complex one, CVE 2018 and 8581. We use the tools to relay the exchange's NTIM hash to the DC and modify the ACL. Oh, wait a moment. It needs some time. No, no, no, no, no, no. Okay, succeed. Here we will find the NTIM of the computer 02 which is exchange server has been relayed to the DC01. It can show the detailed information of the machine and the user. Then the exchange server modified the ACL. You can see the new alarm in the abnormal ACL modification. We detect it successfully. At the last conclusion, this is the end of the presentation. Thank you. There are some limitations with event log. First, there are some false positives in the detection of lateral movement. But if you can collect local event logs, you can detect lateral movement attacks more exactly. Second, if the attack methods do not trigger the event logs on DC, we cannot detect them such as elevation to DA from DNS admin memberships, attacking circuit server, pass the hash with local account, searching info by LDAP and so on. Although there are some limitations, I think it's worth to do it. We only do the DC event log analysis. It's lightweight and easy to deploy. And we have finished about 36 kinds of alarms belong to different stages. We can detect most persistent attacks by analyzing event logs such as admin SD holder, DSRM, group policy, DC shadow, SID history, modify ACL and so on. So in a word, the process of attack generates traffic and the result of the attack is event log. Our analysis is based on the results of the attack which is less likely to be bypassed or confused than the process analysis. So I think if you have known the attack methods, you can build your own ATA by analyzing event logs. It's not very hard. And the last one is the Q&A. Okay, that's all. It's hard to do the Q&A directly for me. So if you have any questions, we can chat face to face. You can also directly message us via Twitter or email. Okay, thank you. Thank you all.