1 00:00:00,840 --> 00:00:02,720 All right, what do we do, boys? 2 00:00:03,960 --> 00:00:04,560 Thanks, man. 3 00:00:05,500 --> 00:00:07,400 Hi, Defcon. Hi, Defcon. 4 00:00:07,640 --> 00:00:09,340 Thanks for sticking with us today. 5 00:00:09,940 --> 00:00:11,060 This Sunday is a bit more chill. 6 00:00:11,240 --> 00:00:12,780 Some of us are already flying home. 7 00:00:13,080 --> 00:00:15,560 Some of us are recovering from Engover. 8 00:00:16,080 --> 00:00:17,880 And the last of us are here. 9 00:00:18,620 --> 00:00:19,840 Thanks for sticking with us. 10 00:00:20,040 --> 00:00:21,440 There's also some zombies there. 11 00:00:21,560 --> 00:00:25,560 Okay, so today we are presenting the results of our research, 12 00:00:26,220 --> 00:00:32,340 which is, and we will present a new approach for stack spoofing targeting Windows on, 13 00:00:32,420 --> 00:00:35,600 like, specifically 64-bit architecture of Windows. 14 00:00:36,680 --> 00:00:37,580 Who we are? 15 00:00:37,980 --> 00:00:39,180 We are three friends. 16 00:00:39,460 --> 00:00:41,020 I'm Alessandro Magnosi. 17 00:00:41,380 --> 00:00:47,300 I'm a principal security consultant in BSI, where I do mostly red teaming, offensive tool development, 18 00:00:47,440 --> 00:00:49,060 and white box assessments. 19 00:00:49,340 --> 00:00:51,700 So source code review, fuzzing, and stuff like that. 20 00:00:51,900 --> 00:00:53,920 In my free time, I work for, 21 00:00:54,100 --> 00:00:55,540 I maintain a company. 22 00:00:55,560 --> 00:00:57,800 I'm also working in some tools, some offensive tools in project industry, 23 00:00:58,140 --> 00:01:05,680 which is an initiative by Marcello Salvari to support open source developers. 24 00:01:06,040 --> 00:01:10,840 And in the rest of my time, I'm a bug hunter for Sinegra team. 25 00:01:12,220 --> 00:01:13,320 Then there is my colleague. 26 00:01:15,120 --> 00:01:16,960 Hey, my name is Arash. 27 00:01:17,360 --> 00:01:19,420 I work at CyberArk. 28 00:01:19,520 --> 00:01:20,840 I have kind of a dual role there. 29 00:01:20,980 --> 00:01:21,820 I'm very fortunate. 30 00:01:22,040 --> 00:01:24,720 I get to do a lot of threat hunting, detection engineering, 31 00:01:25,560 --> 00:01:27,740 and I get to do red teaming when time allows for it. 32 00:01:29,580 --> 00:01:33,300 And our friend, Thanos, unfortunately couldn't be here today. 33 00:01:33,480 --> 00:01:35,160 He also contributed to this work. 34 00:01:35,360 --> 00:01:37,640 He's a red teamer at Netitude. 35 00:01:37,880 --> 00:01:40,140 He was also great, and he contributed a lot here. 36 00:01:40,260 --> 00:01:42,000 So we want to make sure he's mentioned. 37 00:01:44,140 --> 00:01:45,480 So here we are. 38 00:01:45,940 --> 00:01:47,960 So a bit of story about this. 39 00:01:48,240 --> 00:01:50,280 All of this started back in 2022 40 00:01:50,280 --> 00:01:51,920 when Namazo, 41 00:01:52,160 --> 00:01:54,060 a security researcher and developer, 42 00:01:54,940 --> 00:01:55,540 released this. 43 00:01:55,560 --> 00:01:56,440 He released a POC on Twitter, 44 00:01:56,600 --> 00:01:57,380 like an image, 45 00:01:57,720 --> 00:01:59,820 where it was showing a technique 46 00:01:59,820 --> 00:02:02,600 which then we popularized 47 00:02:02,600 --> 00:02:05,580 and fixed also a bit. 48 00:02:08,880 --> 00:02:11,300 We were very interested in his research 49 00:02:11,300 --> 00:02:12,420 and his work. 50 00:02:12,640 --> 00:02:14,120 So we reached down to it. 51 00:02:14,260 --> 00:02:16,800 We started developing this in-house. 52 00:02:17,900 --> 00:02:19,400 Of course, we didn't know a lot 53 00:02:19,400 --> 00:02:22,040 about what was involved with the technique. 54 00:02:22,180 --> 00:02:23,200 So we started this 55 00:02:23,200 --> 00:02:25,400 research and development project. 56 00:02:25,920 --> 00:02:27,560 We developed our own 57 00:02:27,560 --> 00:02:29,420 version of the 58 00:02:29,420 --> 00:02:30,820 technique 59 00:02:30,820 --> 00:02:32,060 showed by Namazo. 60 00:02:32,220 --> 00:02:35,360 And after that, we continued researching 61 00:02:35,360 --> 00:02:36,740 on this technique. 62 00:02:37,080 --> 00:02:38,520 We will also present 63 00:02:38,520 --> 00:02:41,060 the detection part 64 00:02:41,060 --> 00:02:42,740 for this technique 65 00:02:42,740 --> 00:02:44,140 and other additional 66 00:02:44,920 --> 00:02:47,040 research avenues that we researched. 67 00:02:47,780 --> 00:02:49,500 So just to give you 68 00:02:49,500 --> 00:02:50,100 a bit of background, 69 00:02:50,400 --> 00:02:52,340 let's define what stack spoofing is. 70 00:02:53,200 --> 00:02:54,200 What we mean with stack spoofing. 71 00:02:54,260 --> 00:02:55,380 So of course you know that 72 00:02:55,380 --> 00:02:56,760 when you start a process on Windows, 73 00:02:56,980 --> 00:02:58,720 when you execute a binary, 74 00:02:58,920 --> 00:03:01,460 you create a process in Windows 75 00:03:01,460 --> 00:03:02,180 which is a container 76 00:03:02,180 --> 00:03:03,660 and then one or more threads 77 00:03:03,660 --> 00:03:05,380 are tasked with executing the real code 78 00:03:05,380 --> 00:03:06,960 of the program. 79 00:03:07,660 --> 00:03:09,640 Every thread maintains a call stack 80 00:03:09,640 --> 00:03:11,160 which is an area of memory 81 00:03:11,160 --> 00:03:12,380 organized as a stack 82 00:03:12,380 --> 00:03:14,280 that maintains the information 83 00:03:14,280 --> 00:03:15,800 about all active subroutines 84 00:03:15,800 --> 00:03:17,640 in a given time for a given thread. 85 00:03:23,200 --> 00:03:25,680 to substitute the frames 86 00:03:25,680 --> 00:03:26,520 with fake ones 87 00:03:26,520 --> 00:03:28,480 and this is usually never done 88 00:03:28,480 --> 00:03:30,580 for non-malicious activity. 89 00:03:30,800 --> 00:03:32,880 This is always done for malware 90 00:03:32,880 --> 00:03:35,400 to hide the execution flow 91 00:03:35,400 --> 00:03:37,020 or similar stuff. 92 00:03:37,580 --> 00:03:39,160 So you will see here 93 00:03:39,160 --> 00:03:41,080 four different frames 94 00:03:41,080 --> 00:03:42,980 and why I put this here 95 00:03:42,980 --> 00:03:44,040 is just to let you know 96 00:03:44,040 --> 00:03:46,700 what a call stack is 97 00:03:46,700 --> 00:03:48,380 and you will see that there are 98 00:03:48,380 --> 00:03:49,940 certain things that are like 99 00:03:53,200 --> 00:03:53,560 a call stack. 100 00:03:53,760 --> 00:03:56,080 For example, we define these first 101 00:03:56,080 --> 00:03:58,140 two threads for this talk 102 00:03:58,140 --> 00:04:00,020 we will just talk about these two frames 103 00:04:00,020 --> 00:04:02,140 as thread initialization frames 104 00:04:02,140 --> 00:04:04,320 which are usually at the bottom 105 00:04:04,320 --> 00:04:05,520 of the call stack 106 00:04:06,480 --> 00:04:08,140 like at the top actually 107 00:04:08,140 --> 00:04:09,460 of the call stack. 108 00:04:09,620 --> 00:04:11,320 Then you have internal frames 109 00:04:11,320 --> 00:04:12,580 of a specific program 110 00:04:12,580 --> 00:04:14,400 that we will refer to this 111 00:04:14,400 --> 00:04:17,120 during the talk as main modules frames 112 00:04:17,120 --> 00:04:19,080 and then you have the 113 00:04:19,920 --> 00:04:21,600 frames related to 114 00:04:23,200 --> 00:04:23,980 a call API 115 00:04:23,980 --> 00:04:25,180 an API call. 116 00:04:25,860 --> 00:04:28,480 So why this is 117 00:04:28,480 --> 00:04:31,360 how this is calculated by Windows 118 00:04:31,360 --> 00:04:32,960 so the stack is 119 00:04:32,960 --> 00:04:34,860 evaluated by Windows using 120 00:04:34,860 --> 00:04:35,700 an unwinding algorithm 121 00:04:37,080 --> 00:04:38,640 and this is 122 00:04:38,640 --> 00:04:40,620 this uses the information contained 123 00:04:40,620 --> 00:04:42,320 in the pdata section of a binary 124 00:04:42,320 --> 00:04:43,740 or related DLL 125 00:04:43,740 --> 00:04:45,660 and in this pdata section 126 00:04:45,660 --> 00:04:48,040 you usually have an exception directory 127 00:04:48,040 --> 00:04:50,400 we contain all the information about the function 128 00:04:50,400 --> 00:04:51,080 specifically 129 00:04:53,900 --> 00:04:55,020 like every 130 00:04:55,020 --> 00:04:57,120 entry, runtime function 131 00:04:57,120 --> 00:04:58,940 entry in this table contains information 132 00:04:58,940 --> 00:05:00,640 about the begin address of a function 133 00:05:00,640 --> 00:05:02,800 the end address and a pointer to a structure 134 00:05:02,800 --> 00:05:04,600 which is the unwinding infrastructure 135 00:05:04,600 --> 00:05:05,520 that contains 136 00:05:06,940 --> 00:05:09,180 information about the size of the prologue 137 00:05:09,180 --> 00:05:10,540 the count of codes and all the 138 00:05:11,100 --> 00:05:11,660 operations 139 00:05:12,540 --> 00:05:14,940 that were performed in a prologue 140 00:05:14,940 --> 00:05:15,940 of a specific function. 141 00:05:17,220 --> 00:05:18,980 Now, why this is important 142 00:05:18,980 --> 00:05:20,640 I mean this is used by 143 00:05:20,640 --> 00:05:23,020 by Windows to manage 144 00:05:23,200 --> 00:05:23,460 all the exceptions 145 00:05:23,460 --> 00:05:26,120 but what we are interested in is 146 00:05:26,120 --> 00:05:27,920 the usage that this is done 147 00:05:27,920 --> 00:05:30,500 to calculate the call stack at runtime 148 00:05:30,500 --> 00:05:31,820 and to calculate that 149 00:05:31,820 --> 00:05:33,060 what happens is that Windows 150 00:05:33,060 --> 00:05:34,920 evaluate the frame 151 00:05:34,920 --> 00:05:37,080 a call frame size 152 00:05:37,080 --> 00:05:39,820 dynamically using 153 00:05:39,820 --> 00:05:41,000 collecting the codes 154 00:05:41,000 --> 00:05:43,560 so the operation in the prologue 155 00:05:43,560 --> 00:05:44,380 that actually affected 156 00:05:44,380 --> 00:05:47,640 that impacted the frame size 157 00:05:47,640 --> 00:05:49,860 and the operation are usually 158 00:05:49,860 --> 00:05:51,600 push of course 159 00:05:53,200 --> 00:05:54,420 you are subbing 8 160 00:05:54,420 --> 00:05:56,260 on the stack and 161 00:05:56,260 --> 00:05:58,840 if you allocate memory 162 00:05:58,840 --> 00:06:00,300 you are subbing from the 163 00:06:00,300 --> 00:06:02,600 from RSP so you allocate 164 00:06:02,600 --> 00:06:05,120 stake on the stack so these two main operations 165 00:06:05,120 --> 00:06:06,860 are what modify the 166 00:06:06,860 --> 00:06:08,940 frame size and then there is the push 167 00:06:08,940 --> 00:06:10,820 MAC frame which is really not 168 00:06:10,820 --> 00:06:12,620 interesting for our talk but 169 00:06:12,620 --> 00:06:14,420 yeah it's another operation 170 00:06:14,960 --> 00:06:16,120 that impact the frame size 171 00:06:16,820 --> 00:06:19,140 and this is important, this is needed 172 00:06:19,140 --> 00:06:20,740 in Windows because 173 00:06:20,740 --> 00:06:22,460 if you remember 32 bit architecture 174 00:06:23,200 --> 00:06:25,120 in the prologue you always have 175 00:06:25,120 --> 00:06:26,780 like a push EBP and then you 176 00:06:27,480 --> 00:06:29,340 save the base pointer 177 00:06:29,340 --> 00:06:31,180 so you have the base pointer pointed to 178 00:06:31,180 --> 00:06:33,420 the top of the 179 00:06:33,420 --> 00:06:34,420 to the top of the frame 180 00:06:34,420 --> 00:06:37,080 and then you have the ESP 181 00:06:37,080 --> 00:06:39,460 pointing to the bottom of the stack 182 00:06:39,460 --> 00:06:41,060 and this is 183 00:06:41,060 --> 00:06:41,460 useful 184 00:06:42,840 --> 00:06:44,860 like the contrary but yeah 185 00:06:44,860 --> 00:06:45,800 this is used for 186 00:06:46,600 --> 00:06:49,260 this is very useful to evaluate 187 00:06:49,260 --> 00:06:50,880 the call stack because you can just 188 00:06:50,880 --> 00:06:53,180 navigate back the chain of EBP 189 00:06:53,200 --> 00:06:54,400 that are pushed on the stack 190 00:06:54,400 --> 00:06:56,520 but in 64 bit this is not possible 191 00:06:56,520 --> 00:06:58,880 because RSP is used both as a base pointer 192 00:06:58,880 --> 00:07:01,020 and a stack pointer so to evaluate the call stack 193 00:07:01,020 --> 00:07:01,660 we need to 194 00:07:02,900 --> 00:07:05,060 recursively get the size of 195 00:07:05,060 --> 00:07:06,620 of a stack frame 196 00:07:06,620 --> 00:07:08,740 and then recover the return address 197 00:07:08,740 --> 00:07:10,720 and then evaluate again the 198 00:07:10,720 --> 00:07:12,440 call stack frame and then 199 00:07:12,440 --> 00:07:15,140 the return address and traverse it back like this 200 00:07:15,620 --> 00:07:16,860 so why we are 201 00:07:16,860 --> 00:07:19,160 interested in the call stack? We are interested in the 202 00:07:19,160 --> 00:07:21,040 call stack because when you execute malware on Windows 203 00:07:21,040 --> 00:07:22,860 you can generate some anomalies that can 204 00:07:23,200 --> 00:07:24,200 help with detection 205 00:07:24,200 --> 00:07:26,860 so we have in memory execution can be detected 206 00:07:26,860 --> 00:07:29,120 because when you inject 207 00:07:29,120 --> 00:07:30,600 code in memory if you're using especially 208 00:07:31,200 --> 00:07:32,860 to run a malware 209 00:07:32,860 --> 00:07:35,260 you do process injection for example 210 00:07:35,260 --> 00:07:37,320 or code injection and you're using an executable 211 00:07:37,320 --> 00:07:38,840 section on the heap 212 00:07:38,840 --> 00:07:40,640 what happens is that that 213 00:07:41,130 --> 00:07:43,060 section will not have a module 214 00:07:43,060 --> 00:07:44,500 associated so that 215 00:07:45,200 --> 00:07:46,800 executable memory is not backed by a 216 00:07:46,800 --> 00:07:49,120 file on disk if there is no file there is 217 00:07:49,120 --> 00:07:50,920 no pdata section if there is no pdata section 218 00:07:50,920 --> 00:07:52,180 there is no exception directory 219 00:07:53,200 --> 00:07:55,840 there is no way 220 00:07:55,840 --> 00:07:57,080 there is no information that the 221 00:07:57,080 --> 00:07:57,660 unwinding algorithm 222 00:07:58,980 --> 00:08:00,600 can use to 223 00:08:01,760 --> 00:08:02,880 dynamically get 224 00:08:02,880 --> 00:08:04,520 the size of that specific code 225 00:08:04,520 --> 00:08:06,400 so what will happen 226 00:08:06,980 --> 00:08:07,740 is that 227 00:08:07,740 --> 00:08:10,220 too much sorry 228 00:08:10,220 --> 00:08:12,940 what will happen is that you will have 229 00:08:12,940 --> 00:08:15,140 something like this so you will have a 230 00:08:15,140 --> 00:08:17,240 frame at a certain point that is not resolvable 231 00:08:17,240 --> 00:08:18,800 and this is associated 232 00:08:18,800 --> 00:08:20,360 associated with 233 00:08:20,360 --> 00:08:22,140 an unbacked memory region 234 00:08:23,200 --> 00:08:24,440 the other thing you can 235 00:08:24,440 --> 00:08:26,980 you can the other anomaly that you can 236 00:08:26,980 --> 00:08:29,100 detect from the cold stack is when you use 237 00:08:29,100 --> 00:08:31,040 directory indirect syscalls 238 00:08:31,040 --> 00:08:32,940 and we are referring to 239 00:08:32,940 --> 00:08:34,800 direct system calls actually direct 240 00:08:34,800 --> 00:08:36,960 antifunction execution like get proc 241 00:08:36,960 --> 00:08:38,740 address ntdll antifunction 242 00:08:38,740 --> 00:08:41,020 and then execute the function pointer is 243 00:08:41,020 --> 00:08:42,580 calling directly the antifunction 244 00:08:43,010 --> 00:08:44,920 and this will generate a cold stack that 245 00:08:44,920 --> 00:08:45,920 misses the 246 00:08:47,340 --> 00:08:48,660 that misses 247 00:08:48,660 --> 00:08:49,060 the 248 00:08:49,060 --> 00:08:50,340 why 249 00:08:53,200 --> 00:08:53,720 sorry for that 250 00:08:53,720 --> 00:08:55,540 that misses the 251 00:08:56,540 --> 00:08:59,180 what we the frames associated with 252 00:08:59,180 --> 00:09:00,720 high level api call 253 00:09:00,720 --> 00:09:02,600 this stack frame is also 254 00:09:02,980 --> 00:09:04,940 generated if you are using an indirect system 255 00:09:04,940 --> 00:09:06,920 call so if you are just locating the syscall 256 00:09:06,920 --> 00:09:09,020 instruction in ntdll and then you 257 00:09:09,020 --> 00:09:10,960 jump to it so the frame the stack 258 00:09:10,960 --> 00:09:12,740 the stack is pretty much 259 00:09:12,740 --> 00:09:14,400 the same and it misses 260 00:09:14,400 --> 00:09:16,960 the high level api frames of 261 00:09:16,960 --> 00:09:18,060 course but 262 00:09:18,060 --> 00:09:20,820 these are the anomalies when you want to detect 263 00:09:20,820 --> 00:09:22,700 this well you can do a periodic 264 00:09:23,200 --> 00:09:24,880 scan so you have a tool that stop 265 00:09:24,880 --> 00:09:27,160 the frames that stop the 266 00:09:27,160 --> 00:09:28,420 threads system wide 267 00:09:28,420 --> 00:09:30,660 get the context and unlike the stack frame 268 00:09:31,200 --> 00:09:32,760 you can have a conditional scan 269 00:09:32,760 --> 00:09:35,100 which is a periodic scan with another filter 270 00:09:35,100 --> 00:09:36,700 to filter for specific 271 00:09:36,700 --> 00:09:38,860 kind of threads that are in specific weight states 272 00:09:38,860 --> 00:09:40,720 for example or you can use 273 00:09:40,720 --> 00:09:42,740 hooking or kernel tracing which is 274 00:09:42,740 --> 00:09:44,760 instead done dynamically 275 00:09:44,760 --> 00:09:46,980 when a system call is involved you can use something like 276 00:09:46,980 --> 00:09:48,180 wti or another 277 00:09:48,180 --> 00:09:51,020 kind of driver to 278 00:09:51,020 --> 00:09:53,000 get the to get the 279 00:09:53,200 --> 00:09:55,080 user mode call stack and 280 00:09:55,080 --> 00:09:56,280 and for detections 281 00:09:57,360 --> 00:09:58,880 so to 282 00:09:58,880 --> 00:10:01,000 like as tax proofing 283 00:10:01,000 --> 00:10:02,940 previous research on the topic 284 00:10:02,940 --> 00:10:05,180 lead to the development 285 00:10:05,180 --> 00:10:06,340 of techniques to defend 286 00:10:06,920 --> 00:10:09,160 from specific scan periodic 287 00:10:09,160 --> 00:10:10,920 scan like stack truncation 288 00:10:10,920 --> 00:10:12,640 stack cloning and stack hiding or 289 00:10:13,200 --> 00:10:15,300 to defend against specific 290 00:10:16,340 --> 00:10:17,100 specific 291 00:10:17,100 --> 00:10:19,100 specific rule based 292 00:10:19,100 --> 00:10:20,940 detection on the call stack when executing 293 00:10:20,940 --> 00:10:23,060 a specific api so stack 294 00:10:23,200 --> 00:10:25,120 truncation was probably the first one used and 295 00:10:25,120 --> 00:10:25,720 it's an evolution 296 00:10:26,890 --> 00:10:28,920 it's a variation of normal 297 00:10:28,920 --> 00:10:30,060 return address proofing 298 00:10:30,760 --> 00:10:32,880 where the where we 299 00:10:32,880 --> 00:10:35,000 replace the malicious frame with a 300 00:10:35,000 --> 00:10:37,060 with a trampoline usually 301 00:10:37,060 --> 00:10:39,120 in a dll or an executable 302 00:10:39,120 --> 00:10:40,680 and then we nullify 303 00:10:41,030 --> 00:10:42,860 the return the return 304 00:10:42,860 --> 00:10:45,040 address prior to the 305 00:10:45,040 --> 00:10:46,700 to the trampoline 306 00:10:46,700 --> 00:10:49,080 this way we have a cut call 307 00:10:49,080 --> 00:10:51,060 stack like this which 308 00:10:51,060 --> 00:10:52,820 is surely better than having 309 00:10:53,200 --> 00:10:55,040 garbage in the call stack 310 00:10:55,040 --> 00:10:56,080 but it still 311 00:10:56,080 --> 00:10:58,820 it still has a defect which is 312 00:10:58,820 --> 00:11:00,640 this this stack is not 313 00:11:01,200 --> 00:11:03,100 unwindable so we still can 314 00:11:03,100 --> 00:11:04,920 have a detection for this reason 315 00:11:05,860 --> 00:11:06,920 then we have 316 00:11:06,920 --> 00:11:09,060 stack crafting stack crafting instead is 317 00:11:09,060 --> 00:11:10,680 a technique that is usually asynchronous 318 00:11:11,080 --> 00:11:12,420 like we have a system 319 00:11:12,420 --> 00:11:14,920 there is a specific function that get 320 00:11:14,920 --> 00:11:16,480 called and 321 00:11:16,480 --> 00:11:18,860 there are specific processes using 322 00:11:18,860 --> 00:11:20,900 that function in a legitimate 323 00:11:20,900 --> 00:11:22,820 way so what we do is that we 324 00:11:23,200 --> 00:11:25,040 record that execution that call stack 325 00:11:25,040 --> 00:11:26,900 at that point and when we need to call 326 00:11:26,900 --> 00:11:28,880 our target function we just craft 327 00:11:28,880 --> 00:11:30,880 the same kind 328 00:11:30,880 --> 00:11:33,020 of of call stack 329 00:11:33,020 --> 00:11:34,980 so that we can in this way we can 330 00:11:34,980 --> 00:11:36,960 bypass detection like sysmon hunting for 331 00:11:36,960 --> 00:11:38,940 specific call stack phrase or 332 00:11:38,940 --> 00:11:40,940 similar similar detection 333 00:11:42,120 --> 00:11:42,920 then we have 334 00:11:42,920 --> 00:11:44,940 stack cloning this as well has been developed 335 00:11:44,940 --> 00:11:46,700 to defend from conditional 336 00:11:46,700 --> 00:11:49,040 scanning and the idea is simple usually 337 00:11:49,040 --> 00:11:51,160 our implants go to sleep for most 338 00:11:51,160 --> 00:11:53,020 of like usually sleep most of the 339 00:11:53,200 --> 00:11:55,180 time so when I want to sleep using 340 00:11:55,180 --> 00:11:57,020 a delay execution 341 00:11:57,020 --> 00:11:59,000 like wait delay execution using a sleep 342 00:11:59,000 --> 00:12:01,100 or using a wait user requested wait 343 00:12:01,100 --> 00:12:03,020 state using wait for single object 344 00:12:03,020 --> 00:12:05,220 what I need to do is just hunt for 345 00:12:05,220 --> 00:12:06,980 a thread that is already with that 346 00:12:06,980 --> 00:12:08,920 state that is sleeping with that state and then 347 00:12:08,920 --> 00:12:10,940 clone its call stack 348 00:12:10,940 --> 00:12:12,900 this will make the call stack perfect 349 00:12:12,900 --> 00:12:14,060 perfectly legitimate 350 00:12:14,060 --> 00:12:16,740 or apparently legitimate so 351 00:12:16,740 --> 00:12:19,120 we will be defended by 352 00:12:19,120 --> 00:12:21,140 conditional scan that hunt for sleeping 353 00:12:21,140 --> 00:12:21,800 beacons 354 00:12:23,200 --> 00:12:25,200 stack hiding is similar but it uses 355 00:12:25,200 --> 00:12:27,220 another another kind of approach 356 00:12:27,220 --> 00:12:29,180 so the approach is 357 00:12:29,180 --> 00:12:30,940 that I will transform my thread 358 00:12:30,940 --> 00:12:32,580 in a I have a malicious 359 00:12:33,020 --> 00:12:34,340 code executing in memory 360 00:12:34,340 --> 00:12:37,100 I transform my thread in a fiber so I 361 00:12:37,100 --> 00:12:39,140 have a fiber thread now and then I create 362 00:12:39,140 --> 00:12:41,100 another fiber with a legitimate call 363 00:12:41,100 --> 00:12:43,080 stack that I use just for sleeping so when I need 364 00:12:43,080 --> 00:12:45,220 to sleep I just switch to the fiber 365 00:12:45,220 --> 00:12:47,100 thread to the other fiber that I created 366 00:12:47,100 --> 00:12:49,100 for sleeping and then this 367 00:12:49,100 --> 00:12:51,200 process gets repeated when I need to 368 00:12:51,200 --> 00:12:52,160 go back from sleep 369 00:12:53,200 --> 00:12:54,980 and this is what you have like this is the 370 00:12:54,980 --> 00:12:57,400 this is the fiber with a legitimate 371 00:12:57,400 --> 00:12:58,900 call stack and this is the 372 00:12:58,900 --> 00:13:01,300 code in in memory 373 00:13:01,300 --> 00:13:03,140 so they you can see that 374 00:13:03,140 --> 00:13:05,160 there are two different area two different 375 00:13:05,160 --> 00:13:06,220 memory area for the stacks 376 00:13:06,220 --> 00:13:09,220 and just one is active at a time 377 00:13:10,220 --> 00:13:11,160 so what is our 378 00:13:11,160 --> 00:13:13,120 contribution today we want to present two 379 00:13:13,120 --> 00:13:15,160 techniques full moon and half 380 00:13:15,160 --> 00:13:16,620 moon that are designed to 381 00:13:17,240 --> 00:13:18,860 obfuscate the stack at run time 382 00:13:19,400 --> 00:13:20,880 to avoid detection 383 00:13:20,880 --> 00:13:22,400 kernel based detection 384 00:13:23,200 --> 00:13:25,100 mostly or hooking detection 385 00:13:25,100 --> 00:13:27,020 so stack moving has 386 00:13:27,020 --> 00:13:29,260 some properties like it hides the caller from memory 387 00:13:29,260 --> 00:13:31,040 it obfuscates the stack so it's 388 00:13:31,040 --> 00:13:33,100 difficult to understand which kind of call 389 00:13:33,100 --> 00:13:35,140 stack was actually taken was 390 00:13:35,140 --> 00:13:36,800 actually generated when executing a specific 391 00:13:36,800 --> 00:13:38,900 system call and then it has 392 00:13:38,900 --> 00:13:41,040 an auto restore another restore technique 393 00:13:41,040 --> 00:13:42,960 so usually we use ROP 394 00:13:42,960 --> 00:13:45,180 to restore the stack we will see this 395 00:13:45,180 --> 00:13:47,000 is not always possible but 396 00:13:47,000 --> 00:13:48,860 yeah most of 397 00:13:48,860 --> 00:13:51,180 them uses like for the 398 00:13:51,180 --> 00:13:53,180 most part is use ROP to restore the stack 399 00:13:53,200 --> 00:13:54,700 so full moon 400 00:13:54,700 --> 00:13:57,080 is the first technique and it operates 401 00:13:57,080 --> 00:13:59,080 like that we have a function that we want to 402 00:13:59,080 --> 00:14:01,100 spoof an API or whatever and 403 00:14:01,100 --> 00:14:03,100 what we do of course we are executing 404 00:14:03,100 --> 00:14:04,840 this from our main module 405 00:14:04,840 --> 00:14:06,920 that can be in memory or can be 406 00:14:06,920 --> 00:14:09,040 like in this case it seems like it's a 407 00:14:09,040 --> 00:14:11,220 program but it can be even injected in memory 408 00:14:11,220 --> 00:14:12,940 there is no there is no problem 409 00:14:14,000 --> 00:14:14,960 this is 410 00:14:14,960 --> 00:14:16,880 for main module if you remember I'm 411 00:14:16,880 --> 00:14:18,800 referring to all the frames 412 00:14:19,800 --> 00:14:21,060 generated by the main 413 00:14:21,060 --> 00:14:22,820 module so it's the like I just 414 00:14:23,200 --> 00:14:25,120 deduct all the all the internal 415 00:14:25,120 --> 00:14:26,280 frames for the main module 416 00:14:26,280 --> 00:14:29,140 and what I do is I select 417 00:14:29,140 --> 00:14:31,140 three frames well actually 418 00:14:31,140 --> 00:14:33,160 four to be a bit more 419 00:14:33,160 --> 00:14:34,800 stealthy in our intentions but 420 00:14:34,800 --> 00:14:36,780 the needed are three and 421 00:14:36,780 --> 00:14:38,480 these are as an 422 00:14:38,480 --> 00:14:40,700 set set fpreg frame 423 00:14:40,700 --> 00:14:43,100 a pushreg frame other same frame and 424 00:14:43,100 --> 00:14:44,900 then yeah we added a concealed 425 00:14:44,900 --> 00:14:46,520 frame just to be a bit more stealthy 426 00:14:47,160 --> 00:14:48,960 and what they do is 427 00:14:48,960 --> 00:14:51,080 just at a certain point in the set 428 00:14:51,080 --> 00:14:53,000 fpreg frame what we are doing is that 429 00:14:53,200 --> 00:14:54,820 we are restoring the base pointer again 430 00:14:54,820 --> 00:14:57,080 and so this happens 431 00:14:57,080 --> 00:14:59,040 through this kind of call which is 432 00:14:59,040 --> 00:15:01,260 movrbprsp where we save 433 00:15:01,260 --> 00:15:02,440 our current rsp 434 00:15:02,960 --> 00:15:04,500 which contains the 435 00:15:04,980 --> 00:15:06,960 address on the stack that can say the return 436 00:15:06,960 --> 00:15:08,580 address of this frame 437 00:15:09,200 --> 00:15:10,960 and then with the second frame 438 00:15:10,960 --> 00:15:12,740 the pushfpreg frame 439 00:15:12,740 --> 00:15:14,900 the pushreg frame we push 440 00:15:14,900 --> 00:15:16,820 rbp on the stack 441 00:15:16,820 --> 00:15:19,000 now what happens this creates an opportunity 442 00:15:19,000 --> 00:15:20,600 for us to modify 443 00:15:21,080 --> 00:15:22,680 the address that was 444 00:15:23,200 --> 00:15:25,000 pushed in memory because that 445 00:15:25,000 --> 00:15:26,360 rbp now is on the stack 446 00:15:26,360 --> 00:15:28,920 if you modify it this will 447 00:15:28,920 --> 00:15:30,940 be evaluated by the 448 00:15:30,940 --> 00:15:32,840 unwinding algorithm as the address 449 00:15:32,840 --> 00:15:35,200 that should be used to restore rsp 450 00:15:35,200 --> 00:15:37,020 and this gives us an 451 00:15:37,020 --> 00:15:38,980 opportunity to tamper with this 452 00:15:38,980 --> 00:15:41,100 so that if this rsp points 453 00:15:41,100 --> 00:15:43,300 back to our thread initialization 454 00:15:43,300 --> 00:15:44,400 frame 455 00:15:45,560 --> 00:15:47,060 practically what happens is that 456 00:15:47,060 --> 00:15:48,940 the main module will completely disappear 457 00:15:48,940 --> 00:15:50,580 from the call stack 458 00:15:50,580 --> 00:15:52,880 ok this doesn't solve the memory problem 459 00:15:53,200 --> 00:15:54,700 so if you have you know unbacked 460 00:15:54,700 --> 00:15:56,960 memory section this will not 461 00:15:56,960 --> 00:15:58,980 resolve that ok but from 462 00:15:58,980 --> 00:16:00,520 the call stack is not visible anymore 463 00:16:01,580 --> 00:16:03,080 because doing just 464 00:16:03,080 --> 00:16:04,800 this will of course corrupt 465 00:16:04,800 --> 00:16:07,000 the execute the return flow of the program 466 00:16:07,000 --> 00:16:09,000 we use the sync gadget 467 00:16:09,000 --> 00:16:11,340 which is a job gadget here a jumprbx 468 00:16:11,340 --> 00:16:12,920 to hijack 469 00:16:12,920 --> 00:16:14,920 the return flow so that 470 00:16:14,920 --> 00:16:17,100 we can execute a restore 471 00:16:17,100 --> 00:16:18,220 function which is 472 00:16:18,220 --> 00:16:21,000 under our control and this restore 473 00:16:21,000 --> 00:16:22,660 function will reset 474 00:16:23,200 --> 00:16:24,340 the main module to what it was 475 00:16:24,340 --> 00:16:26,700 and just remove the fake frames 476 00:16:27,380 --> 00:16:28,600 so this is the 477 00:16:29,640 --> 00:16:30,200 the 478 00:16:30,200 --> 00:16:32,940 the technique in a nutshell 479 00:16:32,940 --> 00:16:35,000 and this is how 480 00:16:35,000 --> 00:16:36,400 the call stack is set up 481 00:16:37,000 --> 00:16:38,900 and as you can see there are the 482 00:16:38,900 --> 00:16:40,940 thread initialization frames and then there is 483 00:16:40,940 --> 00:16:42,860 no executable there is just 484 00:16:42,860 --> 00:16:44,900 kernel base and these frames 485 00:16:44,900 --> 00:16:46,360 are all generated 486 00:16:46,360 --> 00:16:48,860 by our algorithm now 487 00:16:48,860 --> 00:16:50,260 these frames have 488 00:16:50,260 --> 00:16:52,740 some logical inconsistencies 489 00:16:53,200 --> 00:16:54,180 that can be used for detection 490 00:16:54,180 --> 00:16:55,820 and my colleague will 491 00:16:57,580 --> 00:16:58,620 sure so 492 00:16:59,140 --> 00:17:00,960 I'll talk to you guys a little bit about the 493 00:17:00,960 --> 00:17:02,760 IOCs and why this 494 00:17:02,760 --> 00:17:04,860 doesn't necessarily create a perfect stack 495 00:17:04,860 --> 00:17:06,920 but does create a good looking stack 496 00:17:07,520 --> 00:17:08,980 so if we look at the 497 00:17:08,980 --> 00:17:10,240 slide we have currently 498 00:17:10,240 --> 00:17:12,620 you can see the spoofed frame 499 00:17:12,620 --> 00:17:14,620 the kernel base dot dll 500 00:17:14,620 --> 00:17:17,140 open state explicit and you actually 501 00:17:17,140 --> 00:17:18,940 see a location that plus zero 502 00:17:18,940 --> 00:17:20,760 x three nine d that's an offset 503 00:17:20,760 --> 00:17:22,860 so what's going to happen is that's the 504 00:17:23,200 --> 00:17:25,080 return address we would return to in order to 505 00:17:25,080 --> 00:17:27,040 continue execution within 506 00:17:27,040 --> 00:17:28,920 the stack now why 507 00:17:28,920 --> 00:17:31,000 is this relevant and why is this in 508 00:17:31,000 --> 00:17:32,720 IOC because 509 00:17:32,720 --> 00:17:35,100 technically if we well let's 510 00:17:35,100 --> 00:17:37,280 talk about what a call stack is based on the name 511 00:17:37,280 --> 00:17:39,080 a call stack is of course a series 512 00:17:39,080 --> 00:17:40,880 of calls so you will see 513 00:17:40,880 --> 00:17:42,900 an API call making another API 514 00:17:42,900 --> 00:17:44,680 call making another API call 515 00:17:44,960 --> 00:17:46,960 and this is often so you can debug and you can 516 00:17:46,960 --> 00:17:49,100 see at what API you may have crashed 517 00:17:49,100 --> 00:17:51,100 at what section you may have issues etc 518 00:17:51,100 --> 00:17:53,040 so it is supposed to show a 519 00:17:53,200 --> 00:17:54,520 series of calls to other functions 520 00:17:55,200 --> 00:17:57,040 now if we look at that spoofed frame 521 00:17:57,040 --> 00:17:58,900 the kernel base dot dll open state 522 00:17:58,900 --> 00:18:00,980 explicit we go to the return 523 00:18:00,980 --> 00:18:02,760 address but the return address 524 00:18:02,760 --> 00:18:04,860 isn't going to have a call because the return address 525 00:18:04,860 --> 00:18:06,940 is going to be after the call that's where we 526 00:18:06,940 --> 00:18:08,500 continue execution or we return 527 00:18:09,040 --> 00:18:11,040 so what we do is we actually go 528 00:18:11,040 --> 00:18:12,920 before the return address 529 00:18:12,920 --> 00:18:14,820 and we try to look at 530 00:18:14,820 --> 00:18:17,100 that little move byte pointer that we 531 00:18:17,100 --> 00:18:18,940 see there for the open state explicit function 532 00:18:18,940 --> 00:18:20,980 we can see that that is 533 00:18:20,980 --> 00:18:22,800 not a call and not 534 00:18:23,200 --> 00:18:25,100 only is that not a call to another function 535 00:18:25,100 --> 00:18:27,200 it is certainly not a call to create 536 00:18:27,200 --> 00:18:29,080 private object security with multiple 537 00:18:29,080 --> 00:18:31,060 inheritance so immediately 538 00:18:31,060 --> 00:18:32,340 this becomes suspicious 539 00:18:33,160 --> 00:18:35,020 and this isn't something a legitimate dev 540 00:18:35,020 --> 00:18:37,180 would ever do because it would just hinder 541 00:18:37,180 --> 00:18:39,160 their debugging process it would impact them 542 00:18:39,160 --> 00:18:41,180 negatively so this is something we 543 00:18:41,180 --> 00:18:42,800 would only see an attacker 544 00:18:42,800 --> 00:18:45,280 wanting to perform now while I say 545 00:18:45,280 --> 00:18:46,360 this is an IOC 546 00:18:46,920 --> 00:18:49,180 it's really kind of a difficult IOC 547 00:18:49,180 --> 00:18:51,040 you know it's hard to deploy at 548 00:18:51,040 --> 00:18:53,180 scale it's not really something you 549 00:18:53,200 --> 00:18:54,940 can hunt in your EDRs 550 00:18:54,940 --> 00:18:57,140 and if you observe this on every 551 00:18:57,140 --> 00:18:59,160 single function there would 552 00:18:59,160 --> 00:19:01,120 be very massive performance 553 00:19:01,120 --> 00:19:03,080 hits so while this is 554 00:19:03,080 --> 00:19:04,980 an IOC we're not necessarily 555 00:19:04,980 --> 00:19:07,020 sure there's a realistic detection method 556 00:19:07,020 --> 00:19:09,160 yet outside of the possibility of 557 00:19:09,160 --> 00:19:11,280 a utility such as Intel pin tracer 558 00:19:11,280 --> 00:19:13,140 which does it a little lower level than 559 00:19:13,140 --> 00:19:14,200 the operating system itself 560 00:19:16,140 --> 00:19:17,160 so if we 561 00:19:17,160 --> 00:19:19,080 look here we can tell you what we're looking for 562 00:19:19,080 --> 00:19:20,780 these are the call 563 00:19:20,780 --> 00:19:22,820 opcodes this is basically the assembly 564 00:19:23,200 --> 00:19:24,900 that we're looking for in our 565 00:19:24,900 --> 00:19:27,040 eclipse detector to observe full 566 00:19:27,040 --> 00:19:29,080 moon lock so we're looking 567 00:19:29,080 --> 00:19:30,780 for specific types of calls 568 00:19:31,600 --> 00:19:32,640 that mod 569 00:19:33,160 --> 00:19:35,100 rexw basically determines if it's like 570 00:19:35,100 --> 00:19:36,940 a long call or a short call for example 571 00:19:36,940 --> 00:19:38,980 and then we can see a relative 572 00:19:38,980 --> 00:19:40,940 32 call the call 573 00:19:40,940 --> 00:19:42,780 r64 calls a register 574 00:19:42,780 --> 00:19:45,220 and then of course the system call 575 00:19:45,220 --> 00:19:47,100 the NTDLL lowest level call 576 00:19:47,100 --> 00:19:48,200 that you will often see 577 00:19:48,200 --> 00:19:51,180 because NTDLL often makes the sys call for you 578 00:19:51,180 --> 00:19:52,960 but if we were to 579 00:19:53,200 --> 00:19:54,920 observe there we would see a sys call instruction 580 00:19:56,600 --> 00:19:58,800 so this is the algorithm 581 00:19:58,800 --> 00:20:00,920 for all you PhD people out there 582 00:20:01,520 --> 00:20:03,020 basically the idea is 583 00:20:03,020 --> 00:20:05,020 we're looking for very specific things in our 584 00:20:05,020 --> 00:20:07,060 algorithm not just for stack spoofing 585 00:20:07,060 --> 00:20:09,040 but the detector is looking for an invalid 586 00:20:09,040 --> 00:20:11,220 stack period and not just 587 00:20:11,220 --> 00:20:13,080 by unwinding because 588 00:20:13,080 --> 00:20:14,540 as we know we can actually fool 589 00:20:14,540 --> 00:20:16,720 the unwinder as previously shown 590 00:20:16,720 --> 00:20:18,560 so what do we look for 591 00:20:19,030 --> 00:20:21,020 we're looking for unbacked memory regions 592 00:20:21,020 --> 00:20:22,720 that's the reflective injection detected 593 00:20:23,200 --> 00:20:25,020 unbacked memory means some injection 594 00:20:25,020 --> 00:20:26,940 was performed a private rx 595 00:20:26,940 --> 00:20:28,620 commit memory region was created 596 00:20:28,620 --> 00:20:30,720 this isn't backed to any files on disk 597 00:20:30,720 --> 00:20:32,420 no DLLs no EXCs 598 00:20:32,420 --> 00:20:34,740 so we consider this malicious 599 00:20:34,740 --> 00:20:36,960 often we consider some injection of some sort 600 00:20:36,960 --> 00:20:38,780 there can be false positives 601 00:20:38,780 --> 00:20:40,000 with this to be clear 602 00:20:40,000 --> 00:20:43,020 JITS browsers you know C sharp 603 00:20:43,020 --> 00:20:44,960 you'll see these private commit memory 604 00:20:44,960 --> 00:20:46,820 regions getting created and executing code 605 00:20:46,820 --> 00:20:48,800 so while this does help it's not 606 00:20:48,800 --> 00:20:50,000 foolproof to be clear 607 00:20:50,910 --> 00:20:52,920 the next is we actually look for the desync 608 00:20:53,200 --> 00:20:54,780 gadget because what full moonwalk 609 00:20:54,780 --> 00:20:56,920 actually does is it desyncs 610 00:20:56,920 --> 00:20:58,780 the stack with basically a ROP gadget 611 00:20:58,780 --> 00:21:01,100 in order to be able to effectively craft its own 612 00:21:01,100 --> 00:21:02,920 stack for restoration as well 613 00:21:02,920 --> 00:21:04,720 so we can just look for that gadget 614 00:21:04,720 --> 00:21:06,700 and often that can be an IOC as well 615 00:21:07,480 --> 00:21:09,220 additionally the call mismatch 616 00:21:09,220 --> 00:21:10,800 detected as previously stated 617 00:21:11,740 --> 00:21:13,060 message box A 618 00:21:13,060 --> 00:21:14,900 is going to make a very specific 619 00:21:14,900 --> 00:21:16,220 call to the next function 620 00:21:16,220 --> 00:21:18,660 if we look at message box A 621 00:21:19,060 --> 00:21:20,400 we look at the previous instruction 622 00:21:20,400 --> 00:21:23,020 and it's not the right call to the next function 623 00:21:23,200 --> 00:21:24,280 that's an IOC 624 00:21:25,320 --> 00:21:27,180 and the wrong address 625 00:21:27,180 --> 00:21:28,360 detected as well 626 00:21:28,360 --> 00:21:31,100 if the address is just not 627 00:21:31,100 --> 00:21:33,060 a call if it's not strict if it's not 628 00:21:33,060 --> 00:21:34,940 correct you know it has to be a call 629 00:21:34,940 --> 00:21:36,860 and it has to be a call in the correct order 630 00:21:36,860 --> 00:21:37,840 I actually think I 631 00:21:37,840 --> 00:21:40,920 mixed up the mismatch and the wrong address 632 00:21:40,920 --> 00:21:42,040 but the idea is the same 633 00:21:42,040 --> 00:21:44,840 in one we're basically looking for a call 634 00:21:44,840 --> 00:21:47,100 that's not a call or we're basically 635 00:21:47,100 --> 00:21:49,320 looking is it actually calling the next function 636 00:21:49,320 --> 00:21:51,240 because that's what a call stack is supposed to do 637 00:21:51,240 --> 00:21:53,180 this function calls that function calls that function 638 00:21:53,200 --> 00:21:54,280 for investigation 639 00:21:54,280 --> 00:21:58,860 so this is full 640 00:21:58,860 --> 00:22:00,040 moonwalk running 641 00:22:00,040 --> 00:22:03,020 we have a successfully spoofed message 642 00:22:03,020 --> 00:22:05,080 box A we've been telling you 643 00:22:05,080 --> 00:22:06,660 we're spoofing this message box A 644 00:22:08,120 --> 00:22:08,840 now 645 00:22:08,840 --> 00:22:10,040 we run our detector 646 00:22:10,880 --> 00:22:12,840 on the left you can see our 647 00:22:12,840 --> 00:22:14,320 four spoofed frames 648 00:22:14,320 --> 00:22:16,640 8, 9, 10, and 11 649 00:22:17,200 --> 00:22:19,240 our detector first catches 650 00:22:19,240 --> 00:22:20,520 create file internal 651 00:22:21,200 --> 00:22:22,860 as a spoofed call because 652 00:22:23,200 --> 00:22:25,100 the previous address does not the previous 653 00:22:25,100 --> 00:22:26,160 instruction is not a call 654 00:22:26,980 --> 00:22:28,600 and here's what's interesting 655 00:22:28,600 --> 00:22:30,800 we also get PSS query snapshot 656 00:22:30,800 --> 00:22:32,720 now if you look at the 657 00:22:32,720 --> 00:22:35,060 addresses as I said before 658 00:22:35,060 --> 00:22:36,920 this does unwind 659 00:22:36,920 --> 00:22:39,040 if you look at the PC 660 00:22:39,040 --> 00:22:40,920 address for PSS query 661 00:22:40,920 --> 00:22:43,060 snapshot it matches the 662 00:22:43,060 --> 00:22:45,180 return address for the create file function 663 00:22:45,180 --> 00:22:47,040 so an unwinder is 664 00:22:47,040 --> 00:22:49,000 going to think this is legitimate this is in 665 00:22:49,000 --> 00:22:51,080 fact what was called this is in fact 666 00:22:51,080 --> 00:22:53,100 where it needs to return but our detector 667 00:22:53,200 --> 00:22:55,200 knows better our detector goes 668 00:22:55,200 --> 00:22:57,180 there and says not only is there 669 00:22:57,180 --> 00:22:59,060 no call there's absolutely 670 00:22:59,060 --> 00:23:01,000 no call to create file W 671 00:23:01,000 --> 00:23:02,920 all we've done is 672 00:23:02,920 --> 00:23:05,340 fooled the Microsoft unwinder 673 00:23:05,340 --> 00:23:07,020 into thinking this looks 674 00:23:07,020 --> 00:23:09,080 legitimate so if you actually 675 00:23:09,080 --> 00:23:11,160 use Microsoft's built in unwinding 676 00:23:11,160 --> 00:23:13,160 this is what we did here it looks 677 00:23:13,160 --> 00:23:15,040 legitimate we only 678 00:23:15,040 --> 00:23:17,200 caught this because our detector is looking for 679 00:23:17,200 --> 00:23:17,440 more 680 00:23:19,880 --> 00:23:21,240 now there are 681 00:23:21,240 --> 00:23:23,000 a few false positives as mentioned before 682 00:23:23,200 --> 00:23:24,840 we see this a lot with JITs 683 00:23:24,840 --> 00:23:27,160 specifically we saw this in WinDBG 684 00:23:27,160 --> 00:23:28,840 it seemed to be have 685 00:23:28,840 --> 00:23:31,240 a lot of JITing going on we can see 686 00:23:31,240 --> 00:23:33,360 right here one of the processes for WinDBG 687 00:23:33,360 --> 00:23:35,040 has just these two entirely 688 00:23:35,040 --> 00:23:36,460 unbacked memory regions 689 00:23:37,080 --> 00:23:39,020 for reasons unknown to us it appears 690 00:23:39,020 --> 00:23:41,200 JITs don't always fully unwind and 691 00:23:41,200 --> 00:23:43,000 that these memory regions just always exist 692 00:23:43,000 --> 00:23:45,040 and so there will be false positives 693 00:23:45,040 --> 00:23:46,560 with JIT processes as 694 00:23:47,200 --> 00:23:47,520 usual 695 00:23:49,480 --> 00:23:50,960 so we did testing 696 00:23:50,960 --> 00:23:52,960 to see what the false positive rate 697 00:23:53,200 --> 00:23:54,940 actually was we wanted to determine 698 00:23:54,940 --> 00:23:57,120 is this feasible is this something 699 00:23:57,120 --> 00:23:58,880 we can actually do without 700 00:23:58,880 --> 00:24:00,600 you know overloading a team 701 00:24:01,160 --> 00:24:02,840 and we determined kind of 702 00:24:02,840 --> 00:24:04,320 you know it's not too bad 703 00:24:04,320 --> 00:24:07,080 so we'll see we tested this on five different 704 00:24:07,080 --> 00:24:08,600 machines standard 705 00:24:09,100 --> 00:24:10,900 just means it was a standard 706 00:24:10,900 --> 00:24:13,240 Windows user machine this is not a developer 707 00:24:13,240 --> 00:24:15,080 this is just a person who 708 00:24:15,080 --> 00:24:17,020 logs on watches video does work on 709 00:24:17,020 --> 00:24:18,160 Word documents and that's it 710 00:24:19,140 --> 00:24:21,000 dev is actually a 711 00:24:21,000 --> 00:24:22,720 developer somebody who installs visual 712 00:24:23,200 --> 00:24:25,060 studio sets up postman installs 713 00:24:25,060 --> 00:24:26,980 WinDBG preview and again 714 00:24:26,980 --> 00:24:29,060 you know it makes sense the developer is going to 715 00:24:29,060 --> 00:24:30,840 have a higher false positive rate 716 00:24:30,840 --> 00:24:33,140 they have more JITs they're developing more tools 717 00:24:33,140 --> 00:24:35,080 that are going to have weird unbacked 718 00:24:35,080 --> 00:24:36,960 memory regions you know no programming 719 00:24:36,960 --> 00:24:39,100 isn't really perfect and there's really no catch all 720 00:24:39,100 --> 00:24:41,040 for this we can 721 00:24:41,040 --> 00:24:42,840 see on Win10 the 722 00:24:42,840 --> 00:24:45,100 false positive rate is actually a 723 00:24:45,100 --> 00:24:47,100 little lower than Win11 Enterprise 724 00:24:48,120 --> 00:24:49,160 but you know 725 00:24:49,160 --> 00:24:51,180 we do see that for the dev machines it actually 726 00:24:51,180 --> 00:24:53,060 decreased a bit as far as 727 00:24:53,200 --> 00:24:55,040 Windows server goes we see a pretty high false 728 00:24:55,040 --> 00:24:56,920 positive rate that's likely associated 729 00:24:56,920 --> 00:24:59,160 with you know you're deploying your web servers on this 730 00:24:59,160 --> 00:25:00,640 you're deploying your dot net applications 731 00:25:00,640 --> 00:25:03,140 you're deploying all sorts of stuff that's going to sort of 732 00:25:03,140 --> 00:25:04,740 increase that rate of false positives 733 00:25:06,140 --> 00:25:07,060 and you know 734 00:25:07,060 --> 00:25:09,100 just to end this as far as detecting all 735 00:25:09,100 --> 00:25:11,080 this goes it's like I said 736 00:25:11,080 --> 00:25:12,680 for a hunter behind an EDR 737 00:25:12,680 --> 00:25:14,580 this isn't really telemetry we get 738 00:25:15,700 --> 00:25:16,960 some EDR provide 739 00:25:16,960 --> 00:25:18,980 call stacks for very specific 740 00:25:18,980 --> 00:25:21,000 functions so as to not 741 00:25:21,000 --> 00:25:23,140 be too intensive and we can sort 742 00:25:23,200 --> 00:25:25,240 of hunt on that and look for unbacked memory regions 743 00:25:25,240 --> 00:25:27,140 but as far as it goes for full moonwalk 744 00:25:27,140 --> 00:25:28,960 we just don't really have an effective 745 00:25:28,960 --> 00:25:31,180 way to check every single function 746 00:25:31,180 --> 00:25:33,000 call and ensure that this call is 747 00:25:33,000 --> 00:25:35,200 actually a valid call so in a 748 00:25:35,200 --> 00:25:36,980 way this unwindability is pretty 749 00:25:36,980 --> 00:25:38,100 effective in today's age 750 00:25:42,340 --> 00:25:45,060 So after developing the 751 00:25:45,060 --> 00:25:47,260 detection we actually talked about 752 00:25:47,260 --> 00:25:48,760 other kind of avenues 753 00:25:48,760 --> 00:25:50,220 that we could actually 754 00:25:50,220 --> 00:25:52,880 make use of this 755 00:25:53,200 --> 00:25:55,100 kind of knowledge and so 756 00:25:55,100 --> 00:25:56,960 as we've seen on except 757 00:25:56,960 --> 00:25:59,180 for the execute like in memory 758 00:25:59,180 --> 00:26:01,220 execution there was another problem which was 759 00:26:01,220 --> 00:26:03,240 the correct stack frames 760 00:26:03,240 --> 00:26:05,200 allocated when we execute 761 00:26:05,200 --> 00:26:06,620 an i-level API instead of 762 00:26:07,060 --> 00:26:09,100 going with the indirect syscode so we 763 00:26:09,100 --> 00:26:11,000 developed this additional technique which is an 764 00:26:11,000 --> 00:26:12,820 extension and it's half moonwalk 765 00:26:12,820 --> 00:26:15,120 half moonwalk is because we're just doing half of 766 00:26:15,120 --> 00:26:16,960 the technique we are just considering 767 00:26:16,960 --> 00:26:17,640 what is 768 00:26:17,640 --> 00:26:21,040 what we are calling and not really the 769 00:26:21,040 --> 00:26:23,100 caller and so what half moonwalk does 770 00:26:23,200 --> 00:26:24,920 is that we can always 771 00:26:24,920 --> 00:26:27,100 go to like we can 772 00:26:27,100 --> 00:26:28,880 always match an 773 00:26:28,880 --> 00:26:31,100 i-level API to a 774 00:26:31,100 --> 00:26:31,520 syscode 775 00:26:31,520 --> 00:26:34,980 so half moonwalk takes as 776 00:26:34,980 --> 00:26:36,840 input an 777 00:26:36,840 --> 00:26:38,820 i-level API name and 778 00:26:38,820 --> 00:26:41,020 it's relevant syscode 779 00:26:41,020 --> 00:26:42,600 instruction and 780 00:26:43,120 --> 00:26:44,820 it will trace 781 00:26:44,820 --> 00:26:47,160 all like 782 00:26:47,160 --> 00:26:48,140 it will trace the 783 00:26:48,800 --> 00:26:51,040 execution flow from the 784 00:26:51,040 --> 00:26:52,820 i-level API until it finds 785 00:26:53,200 --> 00:26:54,000 the relevant 786 00:26:55,400 --> 00:26:56,800 antifunction and 787 00:26:56,800 --> 00:26:58,860 what we're doing is that doing 788 00:26:58,860 --> 00:27:00,860 this tracing we also collect 789 00:27:00,860 --> 00:27:02,840 all the information all the exception 790 00:27:02,840 --> 00:27:05,040 information so all the information in 791 00:27:05,040 --> 00:27:06,980 the pdata section related to the 792 00:27:06,980 --> 00:27:09,080 prologue and what we do is that we 793 00:27:09,080 --> 00:27:11,140 recreate the frames 794 00:27:11,140 --> 00:27:12,900 of the i-level APIs 795 00:27:12,900 --> 00:27:14,800 before executing an indirect 796 00:27:14,800 --> 00:27:16,320 system call so 797 00:27:17,070 --> 00:27:18,740 how we do that we just need to 798 00:27:18,740 --> 00:27:21,000 literally emulate the prologue 799 00:27:21,000 --> 00:27:22,800 of the i-level API 800 00:27:23,200 --> 00:27:25,040 and what happens doing this is 801 00:27:25,040 --> 00:27:26,580 that we can recreate 802 00:27:27,180 --> 00:27:29,020 the same kind of 803 00:27:29,020 --> 00:27:30,620 call stack 804 00:27:31,200 --> 00:27:32,980 perfectly legit 805 00:27:32,980 --> 00:27:34,800 this time so we also 806 00:27:34,800 --> 00:27:36,360 respect the 807 00:27:37,200 --> 00:27:39,000 location of the return address 808 00:27:39,000 --> 00:27:41,040 which is placed after the call 809 00:27:41,040 --> 00:27:42,520 and the call is actually 810 00:27:42,900 --> 00:27:45,020 matching what is being called but 811 00:27:45,020 --> 00:27:47,080 we never call the i-level API so this is 812 00:27:47,080 --> 00:27:49,000 literally a syswhisper 813 00:27:49,000 --> 00:27:51,100 type of indirect system call just 814 00:27:51,100 --> 00:27:52,940 with added spoofed 815 00:27:53,200 --> 00:27:54,120 frame for the i-level API 816 00:27:54,120 --> 00:27:56,940 so now we have a little problem that we will 817 00:27:56,940 --> 00:27:58,820 solve afterward for the emulate 818 00:27:58,820 --> 00:28:00,640 system call which of course is a function 819 00:28:00,640 --> 00:28:02,700 that will do this spoofing and it's 820 00:28:02,700 --> 00:28:04,920 visible as for now so we will 821 00:28:04,920 --> 00:28:05,900 solve this later but 822 00:28:07,240 --> 00:28:08,820 so we are concerned 823 00:28:08,820 --> 00:28:10,700 about the return flow though 824 00:28:10,700 --> 00:28:12,760 if we have these frames they will 825 00:28:12,760 --> 00:28:14,860 return back to where they are supposed 826 00:28:14,860 --> 00:28:17,100 to return but we didn't 827 00:28:17,100 --> 00:28:18,600 actually execute the i-level API 828 00:28:18,600 --> 00:28:20,820 we just emulated the 829 00:28:20,820 --> 00:28:22,640 prologue would that be enough 830 00:28:23,200 --> 00:28:25,060 to actually ensure that 831 00:28:25,060 --> 00:28:26,280 the return flow is correct 832 00:28:26,950 --> 00:28:28,820 well yes and no so 833 00:28:28,820 --> 00:28:30,640 there are three strategies we can use 834 00:28:31,200 --> 00:28:33,020 one is the return 835 00:28:33,020 --> 00:28:34,880 place the return on unwinding 836 00:28:34,880 --> 00:28:36,480 so this is terribly worded 837 00:28:36,480 --> 00:28:38,860 what I mean is that we place the return 838 00:28:38,860 --> 00:28:40,580 address of the epilogue 839 00:28:41,360 --> 00:28:43,200 which of course is 840 00:28:43,200 --> 00:28:44,760 just deallocating the 841 00:28:44,760 --> 00:28:47,020 prologue it's just like literally rolling 842 00:28:47,020 --> 00:28:49,000 by the prologue so that will work 843 00:28:49,000 --> 00:28:51,140 but we will be detected 844 00:28:51,140 --> 00:28:52,760 by Eclipse again then because 845 00:28:53,720 --> 00:28:55,220 we need to move the 846 00:28:55,220 --> 00:28:56,980 return address not after the call 847 00:28:56,980 --> 00:28:58,300 but on the epilogue itself 848 00:28:59,060 --> 00:29:01,060 the other and this is what 849 00:29:01,060 --> 00:29:03,120 it happens instead we have the call 850 00:29:03,120 --> 00:29:05,060 to empty protected 851 00:29:05,060 --> 00:29:07,200 memory in this case instead of placing 852 00:29:07,200 --> 00:29:09,140 the return here where it's supposed to 853 00:29:09,140 --> 00:29:11,020 do because there are all these tests 854 00:29:11,020 --> 00:29:13,100 we just move it to the 855 00:29:13,100 --> 00:29:15,060 epilogue and 856 00:29:15,060 --> 00:29:17,340 this works of course 857 00:29:17,340 --> 00:29:18,900 but as I said we can 858 00:29:18,900 --> 00:29:21,180 be detected again by Eclipse 859 00:29:21,180 --> 00:29:22,960 with this because if we analyze 860 00:29:23,200 --> 00:29:25,100 the instruction before this return address 861 00:29:25,100 --> 00:29:26,220 it won't be a call anymore 862 00:29:26,840 --> 00:29:28,940 so we have a second strategy 863 00:29:28,940 --> 00:29:30,880 which is the targeted setup that 864 00:29:30,880 --> 00:29:33,180 works even better but it doesn't scale 865 00:29:33,180 --> 00:29:35,100 and the targeted setup is just like 866 00:29:35,100 --> 00:29:36,880 I can analyze what are the 867 00:29:36,880 --> 00:29:38,900 post call checks 868 00:29:38,900 --> 00:29:41,100 what I call post call checks are 869 00:29:41,100 --> 00:29:43,160 literally all these checks all these 870 00:29:43,160 --> 00:29:44,960 if that are executed 871 00:29:44,960 --> 00:29:45,720 after the call 872 00:29:45,720 --> 00:29:48,900 and to avoid them 873 00:29:48,900 --> 00:29:50,620 from you know branching 874 00:29:50,980 --> 00:29:52,600 to avoid the branching I just 875 00:29:53,800 --> 00:29:55,140 say what I need 876 00:29:55,140 --> 00:29:56,880 to patch I just see what I need to patch 877 00:29:56,880 --> 00:29:59,040 and then I patch it before actually executing 878 00:29:59,040 --> 00:30:00,240 the call now this is 879 00:30:00,240 --> 00:30:02,400 this is pretty much it works 880 00:30:03,020 --> 00:30:05,040 but you can't do it anytime and 881 00:30:05,040 --> 00:30:06,860 honestly it doesn't scale at all 882 00:30:06,860 --> 00:30:08,900 because you would need to know what 883 00:30:08,900 --> 00:30:11,000 thing to patch every time you execute 884 00:30:11,000 --> 00:30:12,920 an arbitrary function this doesn't scale 885 00:30:12,920 --> 00:30:15,120 at all so the latest thing 886 00:30:15,120 --> 00:30:16,100 we can do is 887 00:30:16,100 --> 00:30:18,860 I don't know what is happening I'm sorry 888 00:30:20,880 --> 00:30:22,680 another thing I can do 889 00:30:23,200 --> 00:30:24,920 is using other breakpoints 890 00:30:24,920 --> 00:30:27,000 so what it happens 891 00:30:27,000 --> 00:30:28,960 is that I place a 892 00:30:28,960 --> 00:30:30,700 breakpoint on return and 893 00:30:30,700 --> 00:30:33,120 we actually say sliding other breakpoints 894 00:30:33,120 --> 00:30:34,560 because we don't know how many 895 00:30:35,080 --> 00:30:36,280 frames we need to emulate 896 00:30:36,280 --> 00:30:38,800 so if they are more than four 897 00:30:38,800 --> 00:30:40,980 of course I need a strategy to 898 00:30:40,980 --> 00:30:42,780 out update the other breakpoints 899 00:30:42,780 --> 00:30:44,440 otherwise I will miss some frame 900 00:30:44,980 --> 00:30:46,860 anyway what it happens is that I place 901 00:30:46,860 --> 00:30:49,240 another breakpoint at the return 902 00:30:49,240 --> 00:30:51,080 address when the function returns 903 00:30:51,080 --> 00:30:52,920 back I just execute 904 00:30:53,200 --> 00:30:54,900 an exception handler that just execute 905 00:30:54,900 --> 00:30:56,840 the epilogue 906 00:30:56,840 --> 00:30:58,840 emulate the epilogue and then 907 00:30:58,840 --> 00:31:01,280 force the instruction pointers to return 908 00:31:01,280 --> 00:31:03,000 and that this way 909 00:31:03,000 --> 00:31:04,860 this scales well but 910 00:31:05,840 --> 00:31:07,160 I need always 911 00:31:07,160 --> 00:31:09,000 executable I always need 912 00:31:09,000 --> 00:31:11,080 executable memory because I always need to 913 00:31:11,080 --> 00:31:12,120 make the 914 00:31:12,120 --> 00:31:14,960 the exception handler like somewhere 915 00:31:14,960 --> 00:31:16,580 I need to store the exception handler somewhere so 916 00:31:16,580 --> 00:31:18,660 I always need some executable memory 917 00:31:18,990 --> 00:31:19,940 floating around 918 00:31:20,760 --> 00:31:21,380 so 919 00:31:23,200 --> 00:31:24,000 as I said before 920 00:31:24,800 --> 00:31:27,000 we also had sort of a 921 00:31:27,000 --> 00:31:29,000 problem with the emulate system call 922 00:31:29,000 --> 00:31:30,940 because we said well there is no 923 00:31:30,940 --> 00:31:32,760 function if you remember 924 00:31:32,760 --> 00:31:33,340 before 925 00:31:34,760 --> 00:31:37,100 there is no like this thing is 926 00:31:37,100 --> 00:31:39,160 actually pushing this frame and then 927 00:31:39,160 --> 00:31:40,680 jumping to the syscall instruction 928 00:31:40,900 --> 00:31:43,020 here so if someone is 929 00:31:43,020 --> 00:31:45,120 looking at this emulate system call it can be 930 00:31:45,120 --> 00:31:46,940 problematic so what we can 931 00:31:46,940 --> 00:31:48,580 create is an opaque architecture 932 00:31:49,660 --> 00:31:50,780 that as 933 00:31:50,780 --> 00:31:53,020 this is a if but you can place 934 00:31:53,200 --> 00:31:54,340 a switch case for example 935 00:31:55,600 --> 00:31:56,800 that just 936 00:31:56,800 --> 00:31:59,180 will when this is executed 937 00:31:59,180 --> 00:32:01,080 it will execute so now we are 938 00:32:01,080 --> 00:32:01,960 stepping through here 939 00:32:02,560 --> 00:32:04,420 to emulate system call w 940 00:32:04,420 --> 00:32:06,280 this is a frameless function 941 00:32:06,280 --> 00:32:09,040 it will execute something on the stack 942 00:32:09,040 --> 00:32:10,820 it will corrupt the stack doing this 943 00:32:10,820 --> 00:32:13,080 but it will grab the 944 00:32:13,080 --> 00:32:14,540 position of this frame function 945 00:32:15,180 --> 00:32:17,060 and it will just swap itself 946 00:32:17,680 --> 00:32:19,000 swap the frame of the 947 00:32:19,000 --> 00:32:20,900 frame function with the frame function 948 00:32:20,900 --> 00:32:22,860 this way it will restore the stack 949 00:32:23,200 --> 00:32:24,560 that will appear legitimate 950 00:32:25,200 --> 00:32:27,240 and here we have 951 00:32:27,240 --> 00:32:28,800 what legitimates this 952 00:32:28,800 --> 00:32:31,260 sequence of call is that we have a jump 953 00:32:31,260 --> 00:32:32,520 here to the restore 954 00:32:33,200 --> 00:32:35,260 proc of course this is 955 00:32:35,260 --> 00:32:37,040 opaque it's not that great 956 00:32:37,040 --> 00:32:39,120 but what we want what is really important about 957 00:32:39,120 --> 00:32:41,060 this is that even if we have 958 00:32:41,060 --> 00:32:42,520 something with no 959 00:32:43,820 --> 00:32:45,020 frame information 960 00:32:45,020 --> 00:32:47,080 associated as 961 00:32:47,080 --> 00:32:48,700 long as the stack 962 00:32:48,700 --> 00:32:51,300 size so the modification on the stack 963 00:32:51,300 --> 00:32:52,540 are equal 964 00:32:53,200 --> 00:32:55,080 to something that we are creating and is 965 00:32:55,080 --> 00:32:57,300 framed we can always replace 966 00:32:57,300 --> 00:32:58,860 it and fix the cold stack 967 00:32:58,860 --> 00:33:01,100 why this is important because there 968 00:33:01,100 --> 00:33:02,380 are ways we can do that 969 00:33:03,200 --> 00:33:05,200 using standard windows 970 00:33:05,200 --> 00:33:06,860 dlls so 971 00:33:06,860 --> 00:33:09,100 we selected this in 972 00:33:09,100 --> 00:33:10,500 particular because it's very 973 00:33:11,030 --> 00:33:12,500 it was already abused 974 00:33:12,970 --> 00:33:14,700 in exploit development to bypass 975 00:33:16,160 --> 00:33:16,860 exploit 976 00:33:16,860 --> 00:33:17,600 mitigation 977 00:33:19,440 --> 00:33:21,120 it's part of the exploit mitigation 978 00:33:21,120 --> 00:33:22,520 developed by windows 979 00:33:23,200 --> 00:33:25,180 dlls and it's the call it's 980 00:33:25,180 --> 00:33:26,900 the call to ndr server call to 981 00:33:26,900 --> 00:33:29,080 so we can use this 982 00:33:29,080 --> 00:33:30,700 kind of architecture here 983 00:33:30,700 --> 00:33:33,180 to completely hide our 984 00:33:33,180 --> 00:33:35,140 caller again so how this may 985 00:33:35,140 --> 00:33:36,960 work so if we can enforce in our 986 00:33:36,960 --> 00:33:39,100 implant maybe a stage zero 987 00:33:39,100 --> 00:33:40,860 if we can enforce in our 988 00:33:40,860 --> 00:33:42,340 implant this constraint 989 00:33:43,280 --> 00:33:43,960 so 990 00:33:46,120 --> 00:33:47,080 we want 991 00:33:47,080 --> 00:33:49,000 our implant at any time 992 00:33:49,000 --> 00:33:51,140 the internal the size of the 993 00:33:51,140 --> 00:33:53,080 frames of the internal 994 00:33:53,200 --> 00:33:55,100 frames of our implant they should 995 00:33:55,100 --> 00:33:56,840 always match the size 996 00:33:56,840 --> 00:33:58,860 of the under 997 00:33:58,860 --> 00:34:01,140 stop call to stack as you 998 00:34:01,140 --> 00:34:02,920 can see here you have a lot of space 999 00:34:02,920 --> 00:34:05,100 allocated on the spy on on the stack for 1000 00:34:05,100 --> 00:34:06,960 this function if we can enforce 1001 00:34:06,960 --> 00:34:08,960 this uh this 1002 00:34:08,960 --> 00:34:09,360 constraint 1003 00:34:10,520 --> 00:34:13,160 we can start a thread 1004 00:34:13,160 --> 00:34:15,040 pointing to our shell 1005 00:34:15,040 --> 00:34:17,040 code in memory which is our implant we 1006 00:34:17,040 --> 00:34:19,000 can force these first two 1007 00:34:19,000 --> 00:34:21,040 frames in the thread itself 1008 00:34:21,040 --> 00:34:22,820 then we can start our 1009 00:34:23,200 --> 00:34:25,340 implant and when the 1010 00:34:25,340 --> 00:34:26,900 implant needs to spoof a function 1011 00:34:26,900 --> 00:34:28,600 what we can do is 1012 00:34:29,200 --> 00:34:31,200 call the call 1013 00:34:31,200 --> 00:34:32,580 alt moon execute alt moon 1014 00:34:33,200 --> 00:34:35,200 where whereby the first 1015 00:34:35,200 --> 00:34:37,360 uh frame spoofed 1016 00:34:37,360 --> 00:34:39,160 is the invoke function which is an 1017 00:34:39,160 --> 00:34:40,980 arbitrary call to 1018 00:34:40,980 --> 00:34:43,260 anything and then 1019 00:34:43,260 --> 00:34:45,280 execute alt moon with the rest of the 1020 00:34:45,280 --> 00:34:47,120 a high level api frame and 1021 00:34:47,120 --> 00:34:49,140 eventually call the spoof function 1022 00:34:49,140 --> 00:34:51,160 so what this 1023 00:34:51,160 --> 00:34:53,000 creates is a completely legitimate 1024 00:34:53,200 --> 00:34:53,860 call stack 1025 00:34:54,560 --> 00:34:57,080 where we have the frame in the 1026 00:34:57,080 --> 00:34:59,300 thread frame the the thread initialization 1027 00:34:59,300 --> 00:35:01,040 frames then we have the 1028 00:35:01,040 --> 00:35:02,840 first two call to ndr stop 1029 00:35:02,840 --> 00:35:04,980 call ndr server call to 1030 00:35:04,980 --> 00:35:07,020 ndr stop call to then we have 1031 00:35:07,020 --> 00:35:08,640 the execution of our implant 1032 00:35:09,200 --> 00:35:11,020 we have the return address 1033 00:35:11,020 --> 00:35:13,140 spoofed with ndr 1034 00:35:13,140 --> 00:35:15,140 stop call to stack which 1035 00:35:15,140 --> 00:35:17,040 completely hides our implant 1036 00:35:17,040 --> 00:35:19,080 frames and then we have alt 1037 00:35:19,080 --> 00:35:20,820 moon executed with invoke 1038 00:35:20,820 --> 00:35:23,100 and with and all the island 1039 00:35:23,200 --> 00:35:25,080 level all the all the remaining uh 1040 00:35:25,080 --> 00:35:27,060 high level api frames and 1041 00:35:27,060 --> 00:35:28,900 then we have the system call again 1042 00:35:28,900 --> 00:35:31,120 executed this will hide completely 1043 00:35:31,120 --> 00:35:32,840 the um the caller 1044 00:35:32,840 --> 00:35:34,940 as well so we are just we're just 1045 00:35:34,940 --> 00:35:37,060 going back and try to you 1046 00:35:37,060 --> 00:35:39,000 know complete what alt moon was not 1047 00:35:39,000 --> 00:35:40,980 doing so hiding the caller 1048 00:35:40,980 --> 00:35:42,900 now the only 1049 00:35:42,900 --> 00:35:45,120 drawback of this is that you 1050 00:35:45,120 --> 00:35:46,900 always in order to restore the 1051 00:35:46,900 --> 00:35:49,120 functionality of the program on 1052 00:35:49,120 --> 00:35:50,480 return you always need 1053 00:35:50,960 --> 00:35:52,980 uh another breakpoint place 1054 00:35:53,200 --> 00:35:55,020 on invoke so you can 1055 00:35:55,020 --> 00:35:57,120 handle these two frames as much 1056 00:35:57,120 --> 00:35:58,920 as as you want as we've shown before 1057 00:35:58,920 --> 00:36:00,440 so target that setup 1058 00:36:00,920 --> 00:36:03,260 uh or um or 1059 00:36:03,260 --> 00:36:05,100 uh return on epilogue 1060 00:36:05,100 --> 00:36:07,220 or um or exception 1061 00:36:07,220 --> 00:36:08,340 or exception enders 1062 00:36:08,880 --> 00:36:11,020 but this in invoke function you always 1063 00:36:11,020 --> 00:36:12,920 need an exception ender to actually restore 1064 00:36:12,920 --> 00:36:14,880 the return address 1065 00:36:14,880 --> 00:36:17,080 of the ndr stop call to 1066 00:36:17,080 --> 00:36:19,160 stack and return to our 1067 00:36:19,160 --> 00:36:19,520 implant 1068 00:36:20,880 --> 00:36:23,040 just a word about chat uh 1069 00:36:23,200 --> 00:36:25,400 we are studying a lot 1070 00:36:25,400 --> 00:36:27,180 uh into chat with 1071 00:36:27,180 --> 00:36:28,940 shadow stack mitigation and indirect 1072 00:36:28,940 --> 00:36:30,960 branching tracing entire 1073 00:36:30,960 --> 00:36:32,760 branch tracing and 1074 00:36:32,760 --> 00:36:35,100 so far we didn't find a way around 1075 00:36:35,100 --> 00:36:36,920 chat uh it's not surprising 1076 00:36:36,920 --> 00:36:39,100 so what happens with chat 1077 00:36:39,100 --> 00:36:41,240 is that there is a shadow stack of course a clone 1078 00:36:41,240 --> 00:36:43,260 like it maintains a list of all the return 1079 00:36:43,260 --> 00:36:45,280 address uh that are placed 1080 00:36:45,280 --> 00:36:47,000 just after a call and 1081 00:36:47,000 --> 00:36:49,260 when on return it will check 1082 00:36:49,260 --> 00:36:50,880 if this return addresses matches 1083 00:36:50,880 --> 00:36:52,880 the user mode um 1084 00:36:53,200 --> 00:36:55,240 like the user mode the uh writeable 1085 00:36:55,240 --> 00:36:57,180 normal call stack and 1086 00:36:57,180 --> 00:36:59,220 if they don't match there will be 1087 00:36:59,220 --> 00:37:00,720 a cp fault uh 1088 00:37:00,720 --> 00:37:02,780 that will crash the problem that will 1089 00:37:02,780 --> 00:37:04,820 exit the problem um 1090 00:37:04,820 --> 00:37:07,040 there is another another thing 1091 00:37:07,040 --> 00:37:09,160 that is concerning about intel chat is that 1092 00:37:09,160 --> 00:37:10,820 uh with indirect branch tracing 1093 00:37:10,820 --> 00:37:13,080 there is no easy way to 1094 00:37:13,080 --> 00:37:14,980 modify the instruction pointer as well 1095 00:37:14,980 --> 00:37:16,940 we can't just use exception handler 1096 00:37:16,940 --> 00:37:19,200 as as much as we do now 1097 00:37:19,200 --> 00:37:21,180 uh but the good 1098 00:37:21,180 --> 00:37:23,000 thing is that even in 1099 00:37:23,200 --> 00:37:25,140 uh machine supporting chat so far 1100 00:37:25,140 --> 00:37:27,340 uh there will there are always 1101 00:37:27,340 --> 00:37:29,100 uh processes that are not 1102 00:37:29,100 --> 00:37:30,460 chat enabled like browsers 1103 00:37:30,920 --> 00:37:32,680 and stuff like that that we can still abuse 1104 00:37:33,040 --> 00:37:34,620 for executing this technique 1105 00:37:35,540 --> 00:37:37,140 so key takeaways you 1106 00:37:37,140 --> 00:37:38,640 will you always have the 1107 00:37:38,940 --> 00:37:40,640 public POC available here uh 1108 00:37:40,640 --> 00:37:43,020 this will be enhanced with additional 1109 00:37:43,020 --> 00:37:45,020 uh POCs after this 1110 00:37:45,020 --> 00:37:46,560 talk so in the coming days 1111 00:37:47,200 --> 00:37:49,020 um this POC 1112 00:37:49,020 --> 00:37:51,000 of course is uh like both 1113 00:37:51,000 --> 00:37:52,860 of the techniques are usually like 1114 00:37:53,200 --> 00:37:55,020 have been developed and designed to 1115 00:37:55,020 --> 00:37:56,700 obfuscate the stack at runtime 1116 00:37:57,200 --> 00:37:59,100 so if you're planning of obfuscate 1117 00:37:59,100 --> 00:38:00,520 the stack when you're going on sleep 1118 00:38:01,180 --> 00:38:03,180 probably i'd rather use the stack 1119 00:38:03,180 --> 00:38:05,180 cloning or the stack hiding and the reason is 1120 00:38:05,180 --> 00:38:07,100 well as you see there 1121 00:38:07,100 --> 00:38:09,280 are certain logical inconsistencies 1122 00:38:09,280 --> 00:38:10,960 in this stack so if you leave it 1123 00:38:10,960 --> 00:38:12,880 there for a long period of time 1124 00:38:12,880 --> 00:38:15,080 you're increasing the chance of being detected by 1125 00:38:15,080 --> 00:38:16,980 eclipse etc that an answer is just 1126 00:38:16,980 --> 00:38:19,160 just go there and see it and 1127 00:38:19,160 --> 00:38:20,580 do a bit more um 1128 00:38:21,280 --> 00:38:23,020 analysis manual analysis on 1129 00:38:23,200 --> 00:38:24,360 on the thread called stack 1130 00:38:24,980 --> 00:38:27,040 um of course 1131 00:38:27,040 --> 00:38:29,120 another another another point 1132 00:38:29,120 --> 00:38:31,040 is that this technique uh can 1133 00:38:31,040 --> 00:38:33,080 be used wherever you use return address proofing 1134 00:38:33,080 --> 00:38:35,100 as an arrangement you can use sleep 1135 00:38:35,100 --> 00:38:36,700 encryption and release the POC uh 1136 00:38:36,700 --> 00:38:38,920 not not long ago about 1137 00:38:38,920 --> 00:38:40,680 how to you can integrate 1138 00:38:40,920 --> 00:38:43,200 uh sleep encryption technique to 1139 00:38:43,200 --> 00:38:44,800 to to this to this 1140 00:38:44,800 --> 00:38:47,020 um to this technique to this stack 1141 00:38:47,020 --> 00:38:49,060 spoofing technique uh but it 1142 00:38:49,060 --> 00:38:50,860 adds a layer of 1143 00:38:50,860 --> 00:38:52,380 complexity which is 1144 00:38:53,220 --> 00:38:55,280 not uh always easy 1145 00:38:55,280 --> 00:38:57,140 to manage so a word of 1146 00:38:57,140 --> 00:38:59,160 cautions if you are trying to integrate this 1147 00:38:59,160 --> 00:38:59,940 in your own implant 1148 00:39:01,780 --> 00:39:03,120 and yeah i 1149 00:39:03,120 --> 00:39:04,380 think pretty much it's 1150 00:39:05,070 --> 00:39:07,000 everything um thanks a lot 1151 00:39:07,000 --> 00:39:09,240 for joining us and if you have any questions 1152 00:39:09,940 --> 00:39:10,540 thank you 1153 00:39:19,760 --> 00:39:21,060 if you want 1154 00:39:21,060 --> 00:39:22,940 we are at the start sorry 1155 00:39:23,200 --> 00:39:25,080 yeah so uh if there's time 1156 00:39:25,080 --> 00:39:27,000 we're happy to take questions but i think he's also 1157 00:39:27,000 --> 00:39:29,160 saying if you want to meet up with us after the talk we'll be 1158 00:39:29,160 --> 00:39:31,120 happy to talk to anyone who wants to ask any 1159 00:39:31,120 --> 00:39:32,860 questions excellent yeah thanks 1160 00:39:32,860 --> 00:39:34,680 thanks guys thanks a lot