start	end	text
0	5500	Good morning everyone. Thank you for being here so early. I'm so glad to have this
5500	12080	opportunity to talk with you at the DEF CON Blue Team Village. My name is Yan and my
12080	19940	colleague's name is Siyu but he can't be here because of his visa so I will share it by
19940	29040	myself this time. And I'm not good at English so if you have any questions about this talk,
29620	37520	it's better that we can chat face-to-face after I finish this talk. Thank you. The topic is
37520	46120	Embedded Microsoft ATA but you are completely exposed by the event log. So I will talk
46720	57000	about how our team attacked AD attacks and what we have done. We are the zero key team
57000	67180	from 360. Our team focus on web application security and testing and enterprise security. And
67180	74820	this is our team's blog website but there are all Chinese blogs now. I think we will write some
74820	85640	English blogs later. Okay, this talk has six parts. The first part introduce why we do it.
85640	93300	And the second part is the architecture we have designed to analyze the event log in real
93300	102000	time. In the third part, we will show you some detections in detail. In the fourth part, we
102000	110060	will show you the examples in the current program we use to detect the AD attacks. Finally,
110060	117280	we will show you the summary and the synopsis. Okay, let's go. Most enterprises are managed
117280	125940	using active directory now. AD attack always occurs in the APT. Through it, the attacks can
125940	132860	access to the important assets. So the enterprises has paid more attention to the AD security
132860	140040	now. We need to detect advanced attacks and insider threats before they cause damage to
140060	150220	our organization. But from the internal recon to assess the AD attack covers multiple attack
150220	161460	kill chance stages. There are many methods and tools to do the AD attack. So it's hard to
161460	168580	distinguish the normal and abnormal behaviors. There are a few tools we can use to protect our
168580	178280	AD. Even many defenders don't know they have suffered the AD attack. First to the AD attack,
178280	186560	the blue team is always in a passive situation. They said I can detect AD attacks but you can't.
188920	197540	I have to say the Microsoft ATA. Microsoft ATA may be the most famous and the best tools to
197540	206360	detect AD attacks. The main detection method of ATA is to analyze the traffic through an ATA
206360	216180	gateway or the deployed lightweight gateway directly on the DC. Addition, it can import and
216180	224860	analyze Windows event tool. Microsoft ATA can detect multiple suspicious activities and cover
224860	231920	most of the attack kill chance. To be honest, it's the first company to achieve such a great
231920	245380	effect. But is that all? First, the ATA is not cheap. It's price is $80 per user. I saw it on
245380	254840	their documents that to our company, there are more than 6,000 employees in the company.
255310	269660	It may cost about $500,000. Moreover, ATA has some limitations. They analyze traffic mainly
269660	278520	so we have some problems with encrypted traffic, the unmonitored protocols and the update to
278520	286600	detect new attacks and some bypassing and so on. So if you want to know more about ATA
286600	294300	bypass, you can refer to this Black Hat talk. So we decided to do it by ourself, although the
294300	306360	Microsoft ATA is really great. We do not use the traffic to detect attacks. The only thing we
306360	313640	focus on is the event log of the DC. The event log records all the user activities and the
313640	322640	object changes in active directory. Before we analyze the event log, we need to turn on all the
322640	334120	audit items in the local audit policy. So let's look at the format of the event log. There are 2
334120	340140	different parts in the event log. The first part is general information such as the system
340140	346740	information. The second part is detailed information of changes according to different event
346740	357880	IDs. We focus on those common IDs. You can see that different event ID uh represents different
357880	367480	interesting action. Okay, this picture is an architecture we designed. We collect the event
367480	377440	logs on all of the DCs by one log bit and send them to the log stash. Next, log stash will save
377440	387860	the logs to RabbitMQ. After that, the logs will be consumed to trials. One is saved to the
387880	399120	elastic search. Another one is analyzed by our detection algorithm. We learn the behavior of
399120	407480	users through logs and then generate alarms. Finally, we can see the detail alarm data on the
407480	417300	web console. Our architecture is very lightweight so just install the one log bit on all DCs.
417300	429660	There is no other impact on the domain environment. So let's punch the intruders. Then this is
429660	437880	an important part. According to the way of detections, we will explain this content through
438800	445840	5 kinds. The contents covers most common attacks and more detection methods are not listed
445840	457240	because of time. The first kind, incompleted Kerberos protocol. Let's review the Kerberos
457240	468400	process which is roughly divided to 3 steps. The first step is authentication service, aka AS.
469400	475820	The user generates the password hash and sends it to the KDC. After the KDC verifies the
475840	483340	user has verified it successfully, the TGT is encrypted by the password hash of the content
483340	493640	named the KRB TGT. And the final TGT is returned to the user. The second step is the TK
493640	502560	grant service. The user sends the TGT to the KDC, then the KDC does not verify whether the
502560	511540	user has permissions to the service. It only checks whether the TGT can be decrypted with the
511540	521680	password of the content named the KRB TGT. And the user then uses the machine password of the
521680	532540	target service to get the ST. Finally, the user uses ST to access the target service. The
532560	542360	last step is the TGS. In the previous 2 steps, the AS request will trigger the 4768 log and the TGS
542360	556360	request will trigger the 4769 log. So the complete Kerberos will have both 4768 and 4769 logs. We
556360	562540	can track each Kerberos TKT request by the event logs. So let's see the Kerberos TKT request.
562560	571060	This is a golden TKT. The TGT is encrypted using password hash of the account named the KRB TGT.
571060	581680	Once we got this hash, we can forge any user's TGT which is a golden TKT. Because the TGT is
581680	591200	forged, the user does not send a corresponding AS request from the machine and there is no 4768
591200	605540	log on the DC. And moreover, the default maximum lifetime for TGT and ST is 10 hours. So the
605540	617880	detection idea is very obvious. When we found the 4769 event log, we can search for the
617880	626360	corresponding TGT request record according to the time of the TGT maximum lifetime. For
626360	639940	example, we- we received a 4769 log whose source IP is xxx.12 and the target username is
639940	647860	hacker. Next, we need to find a 4768 log from the stored logs. So we need to find the
647880	657300	4769 log whose source IP is also xxx.12 and target username is hacker and the time is within 10
657300	664300	hours. Just like the picture. If you can't find one, maybe you have been attacked by the golden
664300	675920	TKT. Golden TKT is forged TGT but the silver TKT is forged ST. The ST is encrypted by the
675920	682480	password hash of the machine. If we have the machine password hash, we can forge the ST. So
682480	695760	the attacker will not send the boss AS request and there are neither 4768 nor 4769 logs left
695760	705280	on the DC. So how can we detect it? The detection idea is similar to the golden TKT. When the
706300	716980	4624 event is triggered on the DC, find the corresponding 4768 and 4769 event logs. For
716980	728100	example, we received a 4624 log whose source IP is xxx.12, target username is hacker. Next,
728100	735260	we will need to find a 4769 log from the stored logs. We need to find a 4769 log from the
735280	742460	stored logs. We need to find a 4769 log whose source IP is xxx.12, target username is hacker. If
742460	750020	you can't find one, maybe you have been attacked by a silver TKT. You can see that it seems
750020	759440	that we can only detect the silver TKT when attacking the DC use silver TKT. I will talk
759440	769340	about another way to detect the silver TKT in another part later. So only rely on the event
769340	781240	log, we can't exactly link the TGT and the ST according to a unique ID. I can't find such a
781240	789420	value in the log. Currently we only rely on source IP and target username and target
790420	798500	username to track the source of the TKT request. The source IP may change, causing some
798500	808280	false positives. In theory, there are- there is no false negative and you can reduce false
808800	819420	positives by add some filters. Okay, the second kind, login records. Login records are
819440	827160	very important. In addition to the Kerberos protocol introduced earlier, there is another
827160	837760	authentication protocol in the domain, NTLM. Here is how we detect positive hash. Attackers
837760	848520	can remotely access a target workstation with NTLM hash by using tools such as Mimikaz, WMIC,
848520	859700	SMB client and so on. If a domain account is used for authentication, the 4776 event log will
859700	867120	be triggered on the DC. The target account and the source workstation name are displayed in
867120	876860	the log. Although we can't analyze the abnormal protocol like ATA to track the PTH, but we
876860	887120	can establish a mapping of user names and the workstations by recording login event log.
887640	894320	Each domain account should log into its own machine and the cross machine login behavior is
894320	903040	not allowed. So when we found that the target user name and the computer name shown in the 4776
903040	909240	log are not the same as the known mapping, we need to pay attention to it. But
909240	917920	unfortunately, we found some false positives because many people use their own domain account
917920	927720	to log in a public computer. The third kind, sensitive action, includes some high risk
927720	943340	operations and activities that do not match the target's identity. Case 1, modify ACL. ACL is a
943340	951840	list of access control entries. The ACL determines who can access the objects in the AD and
951840	961120	each object have a property called security descriptor which store the information about it. ACL
961120	972200	is divided into DACL and SACL. The DACL lists the security information about who have access
972200	983280	rights to the object and his level of access. Here we mainly focus on DACL. The SACL
985720	997160	modification is recorded in detail in the 5136 log. The SS-SDDL syntax is used to describe the
997160	1005560	permission information in the log. It defines the SID of the AD object, the group ID, and the
1005560	1013280	flags of the DACL. It contains a list of ACE and each ACE defines the group ID and the flags of the
1013300	1028900	permissions of an object. Next, let me explain how to detect ACL-related attacks. CVE 2018 8581,
1028900	1038600	the popular exchange vulnerability at the beginning of the year. Attacker modifies the ACL by
1038600	1052280	NTLM relate to DC and then execute DC sync. The requirement to execute DC sync is to have the
1052280	1060020	replicating directory changes and the replicating directory changes all permissions. So the
1060020	1068580	attack use the exchange account to modify the ADCL and the ACL and add the permission to
1071340	1081280	modify the ACL we are 5136 event log. Then we can check the permissions after passing the
1081280	1092320	attribute value. Monitor all 5136 events and find out that someone add abnormal account access
1092320	1106080	to the ACL. Pay attention to the user who performs the modification- modify operation if it's a
1106080	1115620	default account like the exchange then the domain is likely to have been attacked because this
1115620	1128860	account rarely has active operations. Case 2, detect DC shadow. It can remotely modify the
1128860	1137660	object information in the domain without logging to the domain controllers. The actor
1137660	1145600	stimulates the machine as a DC sending a sync request to the real domain controller. The
1146620	1155760	technique is considered difficult to detect, however, the attack can be easily detected by
1155760	1166280	analyzing the event log. We select 2 of the event logs to introduce detection. First the DC
1166280	1175600	shadow. As the SPN to the current computer, the value is prefixed with the DIS interface
1175620	1193380	GUID like E3514235 dot dot here. So we detect 4742 event log and check the SPN value
1193380	1201260	modification of the computer account. If a special value in it and the computer is not a DC,
1201260	1212560	this is a DC shadow attack. Second, we check the replication monitoring event, the false
1212560	1224910	none to none log. If the source address is not a DC, this is also a DC shadow attack. Another
1224910	1233570	one, admin privilege granted. Attacks at compromised account to some client. The
1233590	1239010	attacker can use this group to keep persistence. These groups are not just domain
1239010	1249290	admins and administrators, but also include backup operators, DNS admins, server operators,
1249290	1255110	account operators, and so on. So we need to pay attention to the following event log like
1255110	1263110	this one. The member name is hacker and the target user name is domain admins. It seems that
1263110	1270210	the hacker will be added to the domain admins and have the administrator's privileges.
1274090	1283070	Constraint delegation. Adding to account to the administrator group is too obvious and easy to
1283070	1293090	find. So the attacker can access the DC by setting the constraint delegation on the target
1293630	1302230	DC for the compromised account. For example, setting the value of a log to delegate to is
1302910	1315710	LDAP slash DC dot DefCon dot org and you can execute DC sync to DC. The detection of the
1315710	1323090	constraint delegation is easy. Modify a user account where triggered by the attacker.
1323110	1333190	4, 7, 3, 8 event log. We can check a lot to delegate to field and find a sensitive value such
1333190	1349030	as LDAP, CIFS, and host to find the attacks. The fourth kind, honeypot account. We can
1349030	1357170	create accounts with administrator privileges that contain settings which are of interest to
1357170	1366910	the attackers. Those accounts don't look any different from the normal accounts, they just
1366910	1377490	have the attractive permissions. The first honeypot account have attractive SPN value.
1377970	1387110	Cobra hosting's first step is to find a service account which with a specific prefix value for
1387110	1400830	SPN or admin account equal to 1. The attackers attempts to request the ST using RC4
1400830	1407470	encryption and the local offline crack password. If the account has privileges such as
1407490	1417590	permissions, have administrator privileges, the attacker can quickly access. Pay close
1417590	1424350	attention to all activities related to the honeypot account such as SAM, Cobras, and
1426090	1437470	account login and so on. If the honeypot account with SPN value of the MS SQL server,
1437490	1446070	service prefix does not attract the attacker, set a constraint delegation with a value of LDAP
1446070	1461010	slash DC DEF CON organization for this account. Once the attacker crack this honeypot
1461010	1467470	account, he can got all the passwords from the account via DC sync. While it's so
1467470	1475190	great, the attacker can only need to request the ST and then have a cup of coffee waiting for
1475190	1483210	the password to be crashed successfully. But we are waiting for them to. The third honeypot
1483210	1494870	account not required pre-auth. If setting the do not require Cobras authentication, the
1494870	1504110	attacker can request the TGT for offline uh cracking. We can turn this option on to
1504110	1514910	induce uh attackers to request it so that we can detect malicious behaviors. Final pay
1514910	1521890	attention please. In your situation, the honeypot account will not be used so any related
1522370	1531490	locks will be triggered by the attacker. In order to prevent successful cracking the
1531490	1539670	honeypot account, must set a complex password and the password length is greater than 12 uh no
1539670	1548030	no no no, 25. Also in order to prevent and catch the TKs of being takeover by other
1548030	1561030	messers, do not log in and use the account. The fifth part, detect unknown threats. Case 1,
1561030	1572390	fake account info. Each user has a unique and unchanging SID in the domain. You can query the
1572390	1584660	information of account by username or SID. When an attacker use Mimikatz to create a silver
1584660	1594980	ticket, he can fill in any user and any ID parameters. This ticket is valid but the lock will
1594980	1604120	record all the information. So when the attackers use silver ticket to log in to the DC,
1605000	1616940	the following 4, 6, 2, 4 locks will be left on the DC. When the attacker randomly filled in the
1616940	1625760	username or SID, we can see that the username and SID can't match or can't be queried. So we
1625760	1636160	can use another way to detect the silver ticket when the hacker is not careful. Case 2,
1636180	1649140	privilege escalation. I think it's very worth to show. The 4, 6, 7, 2 event log is triggered on
1649140	1659860	the DC when the administrator logs in to the DC. In other words, only the administrator's
1659860	1666160	login can trigger the 4, 6, 7, 2 event log. The 3, 4, 6, 7, 2 event log can trigger the
1666180	1675160	subject username and the subject user SID fields show the current administrator's name and SID.
1675160	1685640	So what can we do? We found something interesting. After you successfully escalate
1685640	1696160	privilege with MS-1406A and you log in to the DC, it will trigger the 4, 6, 7, 2 event log.
1697480	1705000	But at this point, you are not an administrator. You just forged a PAC and got temporary
1707760	1716320	administrator privileges. So when we found the name in the 4, 6, 7, 2 log but he is not an
1716320	1726160	administrator, it must have been attacked. More than MS-14068, there may be other ways to
1727200	1737480	escalate privileges in the future. As long as it is a temporary privilege escalation, it must
1737480	1749140	not escape this detection. At the last, more detections. We can detect the co-hosting AS
1749140	1756160	request by monitoring the value of ticket encryption type in 4, 6, 7, 2 event log.
1756180	1765560	And 4, 7, 6, 8 and 4, 7, 6, 9 event log. We can recognize the attacker's tools by monitoring
1765560	1776460	the value of ticket options in 4, 7, 6, 8 and 4, 7, 6, 9 event log. There are many tricks
1776460	1786160	here but it needs a long time to describe them. So I won't talk about these tricks and many
1786180	1793360	other detections in detail this time. If you are interested in them, I can show you after I
1793360	1806660	finished the talk. Achievements here. There are some videos. It's so sorry that it only has
1806660	1816160	the Chinese version. So the first one is easy. It's an example that we detect the target
1816780	1827460	admin group enumeration. We executed the net group domain admin slash domain account
1827460	1841240	comment. Open our web console. We detect it. It shows that someone enumerated the domain
1841240	1857240	groups by using the account name test user 1. Okay, this is an example that we detect the
1857240	1878030	golden ticket attack. We use the minicast to create a golden ticket and then use it. Oh,
1878030	1888060	just wait. Okay, then we detect it. It shows that the computer 1 is requesting the ST and
1888060	1897620	never requested a TGT. So we regard it as a golden ticket attack. We can also get detailed
1897620	1911340	information on the web console. Okay, this is an example of a DC shadow. We also use the
1911340	1932740	minicast to do the DC shadow attack. Okay, we detect that the computer 0 to simulate the
1932740	1944520	domain controller 01 with the privileges of the account exchange 01 because it has modified the
1944520	1962600	value of computer 02's SPN value to the abnormal value. Okay, the last and complex one, CVE 2018
1963820	1974340	and 8581. We use the tools to relay the exchange's NTIM hash to the DC and modify the ACL.
1975240	2002380	Oh, wait a moment. It needs some time. No, no, no, no, no, no. Okay, succeed. Here we will
2002380	2015300	find the NTIM of the computer 02 which is exchange server has been relayed to the DC01.
2023050	2035310	It can show the detailed information of the machine and the user. Then the exchange server
2035310	2045290	modified the ACL. You can see the new alarm in the abnormal ACL modification. We detect it
2045290	2053030	successfully. At the last conclusion, this is the end of the presentation. Thank you.
2053050	2060690	There are some limitations with event log. First, there are some false positives in the detection
2060690	2070170	of lateral movement. But if you can collect local event logs, you can detect lateral movement
2070170	2081530	attacks more exactly. Second, if the attack methods do not trigger the event logs on DC, we
2081530	2090650	cannot detect them such as elevation to DA from DNS admin memberships, attacking circuit
2090650	2100930	server, pass the hash with local account, searching info by LDAP and so on. Although there are
2100930	2108650	some limitations, I think it's worth to do it. We only do the DC event log analysis. It's
2108650	2118290	lightweight and easy to deploy. And we have finished about 36 kinds of alarms belong to
2118290	2133790	different stages. We can detect most persistent attacks by analyzing event logs such as
2133790	2149570	admin SD holder, DSRM, group policy, DC shadow, SID history, modify ACL and so on. So in a
2149570	2159590	word, the process of attack generates traffic and the result of the attack is event log. Our
2159590	2168650	analysis is based on the results of the attack which is less likely to be bypassed or
2169430	2180530	confused than the process analysis. So I think if you have known the attack methods, you can
2180530	2189570	build your own ATA by analyzing event logs. It's not very hard. And the last one is the
2189590	2198230	Q&A. Okay, that's all. It's hard to do the Q&A directly for me. So if you have any questions, we
2198230	2206270	can chat face to face. You can also directly message us via Twitter or email. Okay, thank
2206270	2207690	you. Thank you all.
