1 00:00:09,700 --> 00:00:10,540 All right. 2 00:00:12,020 --> 00:00:13,840 Our next presenter is Brett Moore, 3 00:00:14,000 --> 00:00:16,000 CTO at securityassessment.com, 4 00:00:16,140 --> 00:00:17,720 who today will be presenting Shoot the Messenger 5 00:00:17,720 --> 00:00:21,460 using window messages to exploit Win32 applications. 6 00:00:22,460 --> 00:00:24,240 Without further ado, here is Brett. 7 00:00:26,500 --> 00:00:27,300 All right. 8 00:00:32,080 --> 00:00:33,620 So they told me I was going to present in the tent. 9 00:00:33,740 --> 00:00:34,920 I thought it was going to be really, really hot, 10 00:00:35,000 --> 00:00:36,280 but it's nice to be in Vegas. 11 00:00:36,340 --> 00:00:37,500 You actually go inside to cool down. 12 00:00:42,520 --> 00:00:43,300 You can't hear me? 13 00:00:47,380 --> 00:00:48,440 All right, that's cool. 14 00:00:48,600 --> 00:00:48,880 Okay. 15 00:00:51,560 --> 00:00:53,600 Okay, first of all, we're going to talk about some stuff, 16 00:00:53,640 --> 00:00:54,560 just to put it into context. 17 00:00:57,260 --> 00:00:59,040 When the first real shadow attack was made public 18 00:00:59,040 --> 00:00:59,680 back in 2010, 19 00:01:00,000 --> 00:01:01,320 so everybody can hear me? 20 00:01:01,740 --> 00:01:03,640 Sorry, everybody can hear me? 21 00:01:04,300 --> 00:01:04,740 Okay. 22 00:01:05,640 --> 00:01:08,940 Back in 2002, when the first shadow attack was made public, 23 00:01:09,140 --> 00:01:10,980 it was not really a huge security issue. 24 00:01:11,640 --> 00:01:13,800 Even Microsoft themselves took some time 25 00:01:13,800 --> 00:01:15,360 to realize that there were some problems here. 26 00:01:16,300 --> 00:01:17,520 If we look at the... 27 00:01:23,260 --> 00:01:24,000 I'll try again. 28 00:01:24,240 --> 00:01:24,540 All right. 29 00:01:24,640 --> 00:01:26,640 If we look at the Windows operating system, 30 00:01:26,800 --> 00:01:28,940 it's not historically been considered secure enough 31 00:01:28,940 --> 00:01:29,820 to be used in... 32 00:01:30,000 --> 00:01:30,920 highly secure networks. 33 00:01:32,300 --> 00:01:34,460 While other operating systems have gone through this 34 00:01:34,460 --> 00:01:36,460 vulnerability discovery phase, 35 00:01:37,260 --> 00:01:38,740 this was something new to Windows, 36 00:01:38,940 --> 00:01:40,460 and like any new system, 37 00:01:40,520 --> 00:01:42,820 it had holes big enough to drive a bus through. 38 00:01:44,020 --> 00:01:44,860 Does this make sense? 39 00:01:45,080 --> 00:01:46,020 Everyone can hear me? 40 00:01:46,920 --> 00:01:47,780 All right, okay. 41 00:01:51,100 --> 00:01:51,940 Next slide. 42 00:01:52,740 --> 00:01:54,460 Now, like most new exploitation methods, 43 00:01:54,740 --> 00:01:56,120 shadow attacks are maturing. 44 00:01:56,540 --> 00:01:59,980 It's now acknowledged they no longer just effect the WNB, 45 00:01:59,980 --> 00:02:00,640 it's now becoming a time of message. 46 00:02:01,420 --> 00:02:05,100 And the scope of the shadow attack problem is widening. 47 00:02:07,240 --> 00:02:09,700 We are starting to see some very solid moves 48 00:02:09,700 --> 00:02:10,940 from Microsoft towards security. 49 00:02:11,760 --> 00:02:13,280 They're releasing operating systems 50 00:02:13,280 --> 00:02:14,780 with default settings off. 51 00:02:15,560 --> 00:02:17,300 You've got built-in firewall now, 52 00:02:17,560 --> 00:02:19,280 and, of course, there's XP Source Pack 2. 53 00:02:20,380 --> 00:02:22,320 So with this advance in Windows security, 54 00:02:22,640 --> 00:02:24,200 there are going to be more and more Windows machines 55 00:02:24,200 --> 00:02:25,360 inside secure networks, 56 00:02:25,780 --> 00:02:27,640 and that's more and more untrusted users. 57 00:02:31,820 --> 00:02:35,280 Okay, so the shadow attack exploitation problem 58 00:02:35,280 --> 00:02:37,040 is going to widen in scope, 59 00:02:37,300 --> 00:02:39,340 and hopefully this presentation will discuss 60 00:02:39,340 --> 00:02:42,380 and demonstrate some of the areas in which it is heading. 61 00:02:45,020 --> 00:02:47,800 It will happen one day that the Windows operating system 62 00:02:47,800 --> 00:02:48,880 will be considered secure, 63 00:02:50,380 --> 00:02:52,860 and as such, they will be deployed everywhere 64 00:02:52,860 --> 00:02:53,980 throughout secure networks, 65 00:02:54,260 --> 00:02:56,500 and the restrictions that are put in place 66 00:02:56,500 --> 00:02:59,180 on the workstations will be considered enough 67 00:02:59,180 --> 00:03:01,660 to control the access to the network and the data, 68 00:03:01,800 --> 00:03:03,900 as well as restricting the user's privileges 69 00:03:03,900 --> 00:03:05,240 and what actions they can take. 70 00:03:07,780 --> 00:03:09,180 All right, okay. 71 00:03:09,580 --> 00:03:12,520 So shadow attacks or GUI attacks, 72 00:03:12,740 --> 00:03:14,040 Win32 messaging attacks, 73 00:03:14,380 --> 00:03:17,040 they affect more than just the core operating system. 74 00:03:17,560 --> 00:03:20,160 Any third-party application or service 75 00:03:20,160 --> 00:03:21,500 running with an elevated privilege 76 00:03:21,500 --> 00:03:23,300 may be vulnerable to these types of attacks. 77 00:03:24,640 --> 00:03:26,920 This means that even if Microsoft patched 78 00:03:26,920 --> 00:03:28,540 every vulnerable instance in their products, 79 00:03:29,240 --> 00:03:30,040 like, yeah, sure, 80 00:03:31,580 --> 00:03:32,900 your workstations that are running 81 00:03:32,900 --> 00:03:35,080 the Windows operating system may still be vulnerable. 82 00:03:36,460 --> 00:03:37,080 Excuse me. 83 00:03:37,300 --> 00:03:39,940 Now, it is possible that Microsoft will apply 84 00:03:39,940 --> 00:03:41,480 a fix at the core of the problem, 85 00:03:41,640 --> 00:03:42,600 the messaging system, 86 00:03:42,840 --> 00:03:44,360 but this is very unlikely, 87 00:03:44,520 --> 00:03:47,980 and even so, it would not be ready anytime soon. 88 00:03:51,600 --> 00:03:53,480 So in a real-world environment, 89 00:03:53,860 --> 00:03:55,540 how can shadow attacks affect you? 90 00:03:56,020 --> 00:03:57,620 Now, of course, privilege escalation 91 00:03:57,620 --> 00:03:59,060 is the major impact of these attacks, 92 00:04:00,160 --> 00:04:02,780 and in general scope, the most important. 93 00:04:04,440 --> 00:04:05,540 And there goes the jet. 94 00:04:06,220 --> 00:04:07,880 Now, currently they are restricted. 95 00:04:08,000 --> 00:04:10,840 I say currently they are restricted to local exploitation. 96 00:04:11,520 --> 00:04:13,780 Now, this also includes remote desktop sessions, 97 00:04:14,460 --> 00:04:16,800 as well as the possibility of worms, trojans, 98 00:04:16,880 --> 00:04:19,240 and other malicious programs utilizing these attacks 99 00:04:19,240 --> 00:04:21,080 to increase their access to a system. 100 00:04:22,480 --> 00:04:25,300 Now, commonly programs such as the personal firewalls, 101 00:04:25,300 --> 00:04:27,480 antivirus systems, and other monitoring software, 102 00:04:27,620 --> 00:04:28,760 that run invalidated rights, 103 00:04:29,740 --> 00:04:31,920 they have all been found vulnerable to these attacks. 104 00:04:32,940 --> 00:04:34,680 Most third-party applications, 105 00:04:34,960 --> 00:04:36,360 especially in the antivirus industry, 106 00:04:36,600 --> 00:04:38,220 are vulnerable to these attacks, 107 00:04:38,420 --> 00:04:40,500 so we will eventually see viruses 108 00:04:40,500 --> 00:04:42,920 that attack antivirus programs to gain system rights. 109 00:04:44,500 --> 00:04:46,340 Now, yes, so successful attacks 110 00:04:46,340 --> 00:04:48,960 can allow untrusted users to elevate their privileges 111 00:04:48,960 --> 00:04:49,780 to a higher level, 112 00:04:49,920 --> 00:04:51,840 allowing them to install a malicious program. 113 00:04:52,720 --> 00:04:53,920 Yeah, that's what I wrote. 114 00:04:55,280 --> 00:04:57,100 Keyloggers, sniffers, et cetera. 115 00:05:03,700 --> 00:05:07,900 Okay, so we talked about if an application runs at a higher rights, 116 00:05:08,080 --> 00:05:08,900 higher user account, 117 00:05:09,180 --> 00:05:12,060 a malicious person can gain elevated rights. 118 00:05:13,400 --> 00:05:16,200 All Windows programs include default handling 119 00:05:16,200 --> 00:05:19,600 for messages such as WM close, WM quit, 120 00:05:19,760 --> 00:05:20,980 NC destroy, et cetera. 121 00:05:21,400 --> 00:05:23,730 So this can allow people to shut down firewalls, 122 00:05:24,140 --> 00:05:27,600 personal firewalls, antivirus monitoring, 123 00:05:27,600 --> 00:05:30,240 so once again, we're going to find, 124 00:05:30,420 --> 00:05:33,000 we're going to have viruses that gain elevated rights, 125 00:05:33,200 --> 00:05:34,560 shut down antivirus software, 126 00:05:34,800 --> 00:05:35,940 and of course then spread. 127 00:05:37,680 --> 00:05:41,140 Now, other attacks can involve the manipulation of controls 128 00:05:41,140 --> 00:05:44,440 to allow access to thick client area, 129 00:05:45,080 --> 00:05:48,400 within thick client areas of the applications 130 00:05:48,400 --> 00:05:51,100 that are restricted by having a disabled button, 131 00:05:51,240 --> 00:05:52,780 disabled toolbar or a menu. 132 00:05:53,380 --> 00:05:55,680 A user can simply send an enable message, 133 00:05:55,940 --> 00:05:57,580 and then this could allow them 134 00:05:57,580 --> 00:05:58,040 to have access. 135 00:05:58,980 --> 00:06:00,940 We'll talk a little bit about thick clients later. 136 00:06:03,040 --> 00:06:06,540 If data from a user input is used, 137 00:06:06,800 --> 00:06:08,480 or data from a GUI controller is used, 138 00:06:09,260 --> 00:06:11,340 it could cause ESCAL injection attacks, 139 00:06:12,340 --> 00:06:14,320 file reading, file access attacks, 140 00:06:14,620 --> 00:06:16,400 and of course textbook buffer overflows. 141 00:06:18,280 --> 00:06:19,460 And now we're done with that. 142 00:06:26,380 --> 00:06:29,660 So the Windows operating system uses a mechanism 143 00:06:29,660 --> 00:06:31,280 known as Windows messaging. 144 00:06:31,740 --> 00:06:35,440 This is used to communicate events such as user input, 145 00:06:35,680 --> 00:06:37,980 system notifications, and control information 146 00:06:37,980 --> 00:06:38,840 between Windows. 147 00:06:40,180 --> 00:06:43,340 Unlike the old days, I was going to say the good old days, 148 00:06:43,400 --> 00:06:46,040 but I'm old, where an application would stop 149 00:06:46,040 --> 00:06:49,440 and wait for user input, Windows messaging allows an application 150 00:06:49,460 --> 00:06:52,300 to process input only when there is input waiting 151 00:06:52,300 --> 00:06:54,440 for a window owned by the application. 152 00:06:55,640 --> 00:06:57,540 Every window created on the desktop 153 00:06:57,540 --> 00:06:59,260 has a unique window handle, 154 00:06:59,440 --> 00:07:01,420 which is used to identify it within the system. 155 00:07:02,600 --> 00:07:04,220 Messages are passed to the system, 156 00:07:04,860 --> 00:07:06,500 which in turn directs the messages 157 00:07:06,500 --> 00:07:08,360 to the appropriate window to handle the message. 158 00:07:09,940 --> 00:07:11,820 The window then processes this message, 159 00:07:12,000 --> 00:07:13,420 depending on how it was sent 160 00:07:13,420 --> 00:07:15,500 and what parameters were passed with it. 161 00:07:17,040 --> 00:07:19,180 Now every control, such as the text box, 162 00:07:19,460 --> 00:07:20,660 a list box, or a form, 163 00:07:20,780 --> 00:07:23,060 it's all derived from the base window class. 164 00:07:23,700 --> 00:07:25,160 So throughout this presentation, 165 00:07:25,360 --> 00:07:26,560 when I'm referring to a window, 166 00:07:27,320 --> 00:07:29,300 I'm referring to any type of GUI control. 167 00:07:30,840 --> 00:07:34,480 So the problem with this method of sending messages 168 00:07:34,480 --> 00:07:36,740 is that the operating system allows any user 169 00:07:36,740 --> 00:07:39,480 to send any message to any application. 170 00:07:40,500 --> 00:07:43,260 And in most instances, the application will blindly 171 00:07:43,260 --> 00:07:45,400 accept the message and act on it accordingly. 172 00:07:46,680 --> 00:07:48,540 So by exploiting known weaknesses 173 00:07:48,540 --> 00:07:49,560 in the messaging system, 174 00:07:49,860 --> 00:07:51,840 an attacker can manipulate applications 175 00:07:51,840 --> 00:07:53,420 for an arbitrary advantage. 176 00:07:59,200 --> 00:08:01,980 So how does a message get from point A to point B? 177 00:08:02,840 --> 00:08:04,940 So there are two main API calls 178 00:08:04,940 --> 00:08:06,640 that are used to pass messages to windows 179 00:08:06,640 --> 00:08:09,420 and various sub-APIs underneath these. 180 00:08:10,560 --> 00:08:13,600 Like I said before, all of the API functions, 181 00:08:13,760 --> 00:08:14,980 they pass the message to the system, 182 00:08:15,120 --> 00:08:17,620 which in turn directs it to the appropriate place. 183 00:08:18,540 --> 00:08:20,180 Now post message and its related functions, 184 00:08:20,520 --> 00:08:23,000 they pass the message data to the message queue 185 00:08:23,400 --> 00:08:25,340 of the thread that owns the destination window. 186 00:08:26,060 --> 00:08:28,160 And the sending application then continues 187 00:08:28,160 --> 00:08:29,820 without awaiting a response. 188 00:08:30,800 --> 00:08:34,620 A thread's message loop is constantly called the message queue, 189 00:08:35,700 --> 00:08:37,800 removing and dispatching any messages 190 00:08:37,800 --> 00:08:39,600 to the appropriate window procedure 191 00:08:39,600 --> 00:08:43,000 for the window identified by the unique window handle 192 00:08:43,000 --> 00:08:44,320 passed through the API function. 193 00:08:44,760 --> 00:08:47,380 Now the send message family of functions 194 00:08:47,380 --> 00:08:50,040 is passes the message directly to the window procedure 195 00:08:50,040 --> 00:08:51,060 of the target window. 196 00:08:52,080 --> 00:08:54,540 And after the window procedure processes the message 197 00:08:54,540 --> 00:08:56,180 and returns, the sending application 198 00:08:56,180 --> 00:08:57,460 then continues execution. 199 00:08:58,220 --> 00:09:00,140 Cushion. Cushion. Okay, we're back. 200 00:09:00,460 --> 00:09:02,240 Right. Now the window procedure 201 00:09:02,240 --> 00:09:04,460 is where the message contents are processed. 202 00:09:05,240 --> 00:09:07,560 It is in this function where the decision is made 203 00:09:07,560 --> 00:09:10,260 based on the message type to handle a message 204 00:09:10,260 --> 00:09:12,740 or to ignore it and pass it up the handler chain. 205 00:09:15,620 --> 00:09:17,280 Every window has a window procedure 206 00:09:17,380 --> 00:09:19,600 and it's just derived from the base window procedure 207 00:09:19,600 --> 00:09:20,680 for the class of the control. 208 00:09:21,940 --> 00:09:24,460 Okay, it's going to eventuate that you can 209 00:09:27,680 --> 00:09:30,660 overwrite class structures, subclass classes 210 00:09:30,660 --> 00:09:32,020 before they're defined by the system, 211 00:09:32,180 --> 00:09:33,800 create your own window procedure, 212 00:09:33,960 --> 00:09:35,040 which are then going to be derived 213 00:09:35,040 --> 00:09:36,500 throughout the system applications. 214 00:09:38,220 --> 00:09:41,320 Every thread which uses a GDI function has a message queue 215 00:09:41,320 --> 00:09:44,040 and therefore every thread that creates a window 216 00:09:44,040 --> 00:09:44,840 has a message queue. 217 00:09:45,080 --> 00:09:47,360 So we need to keep this in mind when thinking about 218 00:09:47,380 --> 00:09:49,720 what sort of applications are vulnerable to these attacks. 219 00:09:51,360 --> 00:09:53,200 Some applications or services 220 00:09:53,200 --> 00:09:55,260 which do not normally have a window 221 00:09:55,260 --> 00:09:57,540 can be enticed to create one. 222 00:09:58,280 --> 00:10:00,520 We think about the net send, 223 00:10:00,800 --> 00:10:02,320 system will pop up a message box, 224 00:10:03,400 --> 00:10:05,080 the printer, print spooler, 225 00:10:05,120 --> 00:10:08,740 a system level window is created by that 226 00:10:10,320 --> 00:10:14,220 and various other services do the same sort of thing. 227 00:10:22,320 --> 00:10:23,740 I hope I'm making sense, 228 00:10:23,900 --> 00:10:26,700 because I can really hear my accent coming back at me. 229 00:10:28,260 --> 00:10:31,640 So to help with the understanding of how a message becomes exploitable, 230 00:10:31,860 --> 00:10:33,540 I broke them down into three categories. 231 00:10:33,880 --> 00:10:35,080 We have a type 1 message. 232 00:10:36,460 --> 00:10:38,160 Now, a type 1 message, 233 00:10:38,360 --> 00:10:40,880 the data is marshaled correctly, 234 00:10:41,120 --> 00:10:42,960 everyone behaves properly, it works. 235 00:10:43,680 --> 00:10:45,640 If we think about a WM set text, 236 00:10:45,640 --> 00:10:47,780 we pass a text string, 237 00:10:48,520 --> 00:10:50,440 it sets the caption of a window, etc. 238 00:10:50,840 --> 00:10:53,880 The data goes from one application to another one 239 00:10:53,880 --> 00:10:55,320 and everything works correctly. 240 00:10:56,060 --> 00:10:57,000 Now, a type 2 message, 241 00:10:58,160 --> 00:11:00,160 the data doesn't need any marshalling. 242 00:11:00,480 --> 00:11:02,080 It's a long value, 243 00:11:02,800 --> 00:11:04,420 it's a pointer, it's used directly. 244 00:11:05,140 --> 00:11:06,460 Sorry, excuse me, it's not a pointer, 245 00:11:06,560 --> 00:11:07,260 because they'd be marshalled. 246 00:11:08,620 --> 00:11:10,120 So these type of messages, 247 00:11:10,300 --> 00:11:14,840 they can be used to control GUI, 248 00:11:15,960 --> 00:11:17,380 properties, sizes, etc. 249 00:11:18,280 --> 00:11:20,780 And in some cases, they too can be exploitable. 250 00:11:20,920 --> 00:11:22,880 If we think about the WM timer message, 251 00:11:23,800 --> 00:11:25,860 it worked properly, everyone behaved, 252 00:11:26,180 --> 00:11:27,720 the data didn't need marshalling, 253 00:11:27,920 --> 00:11:30,220 it just was written in securely 254 00:11:30,220 --> 00:11:31,880 and allowed you to pass an address 255 00:11:31,880 --> 00:11:33,240 that was then used as a callback. 256 00:11:34,440 --> 00:11:38,380 So a type 3 message can be used to override arbitrary memory. 257 00:11:39,620 --> 00:11:42,200 It does not go through this marshalling process, 258 00:11:42,980 --> 00:11:44,000 but it should. 259 00:11:45,120 --> 00:11:47,840 A value is passed as an offset to a data structure, 260 00:11:48,100 --> 00:11:50,000 and because it is not marshalled, 261 00:11:50,100 --> 00:11:52,460 it allows us to control the area in memory 262 00:11:54,000 --> 00:11:56,480 where the receiving application writes the returned data. 263 00:11:58,340 --> 00:12:00,520 So what is message marshalling? 264 00:12:06,300 --> 00:12:08,560 So, message marshalling is the process 265 00:12:08,560 --> 00:12:11,320 of taking message parameters from one thread 266 00:12:11,320 --> 00:12:12,620 and passing them into another. 267 00:12:12,620 --> 00:12:15,660 Now, generally, messages between the same application, 268 00:12:16,620 --> 00:12:18,640 sorry, are passed between the same application, 269 00:12:18,880 --> 00:12:20,900 so accessing of memory is not a problem. 270 00:12:21,900 --> 00:12:25,340 When messages are passed between applications, though, 271 00:12:25,400 --> 00:12:26,240 from one to another, 272 00:12:27,080 --> 00:12:29,020 memory addresses, they need to be modified 273 00:12:29,620 --> 00:12:31,360 so that the data from the sending application 274 00:12:31,360 --> 00:12:32,720 is valid in the receiver. 275 00:12:33,520 --> 00:12:35,620 So I found this on MSDN, 276 00:12:36,180 --> 00:12:39,740 and it says any message with a value less than WM user 277 00:12:39,740 --> 00:12:41,920 is marshalled automatically by the system. 278 00:12:41,920 --> 00:12:43,680 There are system-defined messages, 279 00:12:44,280 --> 00:12:45,840 and the operating system is aware 280 00:12:45,840 --> 00:12:47,260 of what parameters need to be handled 281 00:12:47,260 --> 00:12:48,560 and how it should be modified. 282 00:12:49,500 --> 00:12:51,540 And as you can see here on the slide, 283 00:12:52,540 --> 00:12:56,000 any message above WM user is not marshalled automatically. 284 00:12:56,520 --> 00:12:58,920 If you think about the list view control, 285 00:12:59,160 --> 00:13:00,380 the tab view, the tree view, 286 00:13:00,480 --> 00:13:01,600 all the new common controls, 287 00:13:01,840 --> 00:13:03,960 all their messages are above WM user. 288 00:13:06,680 --> 00:13:08,660 So, yes, it's not surprisingly 289 00:13:08,660 --> 00:13:11,220 that there are a large number of these messages 290 00:13:11,220 --> 00:13:12,100 that are not marshalled. 291 00:13:12,820 --> 00:13:14,240 And some of them can be used 292 00:13:14,240 --> 00:13:15,460 for various methods of exploitation. 293 00:13:16,980 --> 00:13:18,700 So we've got a couple of examples here. 294 00:13:21,540 --> 00:13:23,900 Yeah, I think you guys probably all read better than me at the moment. 295 00:13:24,040 --> 00:13:25,640 We have the common control, 296 00:13:25,800 --> 00:13:26,780 we have HTML first, 297 00:13:27,540 --> 00:13:29,780 1,200, man, that's way above WM user, 298 00:13:29,900 --> 00:13:31,320 and you've got the item rigged. 299 00:13:32,420 --> 00:13:33,120 Way up there. 300 00:13:33,460 --> 00:13:35,240 You can find text with a rich edit control, 301 00:13:35,520 --> 00:13:36,700 WM user plus 56. 302 00:13:37,120 --> 00:13:38,640 If you've got Visual Studio, 303 00:13:38,800 --> 00:13:40,340 just look through your libraries, 304 00:13:40,340 --> 00:13:40,740 your includes, 305 00:13:41,720 --> 00:13:42,440 they're all there. 306 00:13:44,360 --> 00:13:44,960 Okay, so, 307 00:13:45,500 --> 00:13:48,400 so if the messages were an ID of less than WM user, 308 00:13:48,600 --> 00:13:50,620 marshalling depends on the function of the message. 309 00:13:51,920 --> 00:13:52,800 Like I was saying before, 310 00:13:53,020 --> 00:13:54,960 if the message is passing a numeric value, 311 00:13:55,100 --> 00:13:56,140 it's like a type 2 message, 312 00:13:57,240 --> 00:13:58,700 no marshalling is required. 313 00:13:59,820 --> 00:14:02,700 And we've got here an example of the WM timer. 314 00:14:02,860 --> 00:14:04,460 The timer proc is passed directly. 315 00:14:04,740 --> 00:14:06,060 It doesn't need updating, 316 00:14:06,140 --> 00:14:06,800 it doesn't need marshalling. 317 00:14:07,360 --> 00:14:10,220 But if the message is passing a block of data, 318 00:14:11,160 --> 00:14:12,600 such as a text string, 319 00:14:12,760 --> 00:14:15,100 then the block of data and the relevant pointer 320 00:14:15,100 --> 00:14:18,560 need to be managed so that the receiving application 321 00:14:18,560 --> 00:14:19,920 can access the data. 322 00:14:24,120 --> 00:14:25,480 If you think about it, 323 00:14:25,520 --> 00:14:27,340 if we've got one application here, 324 00:14:29,180 --> 00:14:31,140 and it's got a text string, 325 00:14:31,220 --> 00:14:32,920 and it wants to pass it over to this application, 326 00:14:33,380 --> 00:14:34,760 it can't just pass a pointer, 327 00:14:34,920 --> 00:14:36,760 because this application can't access 328 00:14:37,280 --> 00:14:38,560 the first application's memory. 329 00:14:40,580 --> 00:14:43,000 We did a bit of research to try and find out where this went. 330 00:14:46,740 --> 00:14:49,620 Okay, so the GDI shared handle table, 331 00:14:49,900 --> 00:14:51,760 it's a block of memory that is shared 332 00:14:51,760 --> 00:14:53,180 between all GUI threads. 333 00:14:55,460 --> 00:14:57,940 This table holds the handles of all opened objects 334 00:14:57,940 --> 00:14:59,600 from any GUI thread, 335 00:15:00,180 --> 00:15:02,940 and has enough space for 4,000 entries. 336 00:15:03,380 --> 00:15:04,760 And we thought that was really interesting. 337 00:15:04,900 --> 00:15:06,900 It's like, oh wow, so we can access a handle 338 00:15:06,900 --> 00:15:08,100 from any application 339 00:15:08,100 --> 00:15:10,720 for an opened control. 340 00:15:12,860 --> 00:15:15,360 We thought, oh, what if we start writing in there 341 00:15:15,360 --> 00:15:17,020 and overwriting stuff, 342 00:15:17,200 --> 00:15:18,680 but we found out it was read-only. 343 00:15:19,240 --> 00:15:20,160 So at this point, 344 00:15:21,860 --> 00:15:22,960 someone's got to look in there further. 345 00:15:23,180 --> 00:15:25,060 Anyway, so a pointer to this location 346 00:15:25,060 --> 00:15:26,640 can be found in the process environment block 347 00:15:26,640 --> 00:15:29,320 at 7FFDFO94. 348 00:15:29,900 --> 00:15:32,200 And at 60,000 bytes up from there 349 00:15:33,160 --> 00:15:35,020 is the start of the process mapped heap. 350 00:15:36,060 --> 00:15:38,080 Now, it was in this heap block that we found, 351 00:15:38,100 --> 00:15:39,540 that the system marshals the data into. 352 00:15:40,040 --> 00:15:41,820 Now, because every GUI thread 353 00:15:41,820 --> 00:15:44,600 has this heap block mapped into their address space, 354 00:15:45,020 --> 00:15:46,760 the system can copy the data into here, 355 00:15:46,980 --> 00:15:48,700 and any other GUI thread can, 356 00:15:48,820 --> 00:15:50,980 or any other GUI thread application process 357 00:15:50,980 --> 00:15:52,880 can then access this shared heap 358 00:15:52,880 --> 00:15:54,560 to retrieve the data from it. 359 00:15:56,100 --> 00:15:57,460 So what happens is, 360 00:15:58,060 --> 00:15:58,940 the system, 361 00:15:59,460 --> 00:16:01,860 the first attack application 362 00:16:02,660 --> 00:16:04,260 sends a message to the system. 363 00:16:04,380 --> 00:16:05,200 The system takes it, 364 00:16:05,240 --> 00:16:06,780 and it takes the data, 365 00:16:06,780 --> 00:16:08,360 and it moves it into the shared heap, 366 00:16:08,480 --> 00:16:09,740 and it updates the pointer, 367 00:16:09,880 --> 00:16:12,340 and it passes that pointer parameter 368 00:16:12,340 --> 00:16:13,720 to the receiving application. 369 00:16:19,840 --> 00:16:21,920 Okay, so every GUI thread, 370 00:16:22,020 --> 00:16:22,360 like I said, 371 00:16:22,420 --> 00:16:25,060 it has this memory mapped into their address space, 372 00:16:25,540 --> 00:16:27,140 but it's at a different base location. 373 00:16:29,000 --> 00:16:30,220 But the actual data 374 00:16:30,940 --> 00:16:33,120 remains at the same offset within that heap space. 375 00:16:34,420 --> 00:16:34,860 So... 376 00:16:37,800 --> 00:16:39,480 The process mapped to you, 377 00:16:39,480 --> 00:16:40,540 but it appears to be mapped 378 00:16:40,540 --> 00:16:43,300 at a static location per application, 379 00:16:44,440 --> 00:16:46,260 which allows us to calculate an offset 380 00:16:46,780 --> 00:16:47,880 between two applications. 381 00:16:48,860 --> 00:16:50,120 So what I'm trying to say is, 382 00:16:52,260 --> 00:16:53,620 your utility manager 383 00:16:53,620 --> 00:16:55,700 might have the base heap here, 384 00:16:55,880 --> 00:16:58,380 and the print spooler 385 00:16:58,380 --> 00:16:59,180 might have it here. 386 00:16:59,440 --> 00:17:01,940 But because it's a shared heap, 387 00:17:02,000 --> 00:17:02,860 so it's the same size, 388 00:17:03,080 --> 00:17:05,780 so if we can find the data 389 00:17:05,780 --> 00:17:07,060 in one application, 390 00:17:07,600 --> 00:17:08,740 by adjusting it, 391 00:17:08,800 --> 00:17:09,540 we can find the data, 392 00:17:09,680 --> 00:17:11,100 the exact location of that data, 393 00:17:11,200 --> 00:17:12,180 in another application. 394 00:17:13,480 --> 00:17:14,420 So, of course, 395 00:17:14,460 --> 00:17:16,000 this removes any guesswork involved 396 00:17:16,000 --> 00:17:18,680 in getting data into another application, 397 00:17:18,900 --> 00:17:20,460 and allows for exploitation 398 00:17:20,460 --> 00:17:21,780 of more complicated messages. 399 00:17:23,300 --> 00:17:25,900 So, I hope it's pretty self-explanatory. 400 00:17:27,320 --> 00:17:28,580 So in the attacking app, 401 00:17:28,620 --> 00:17:31,760 we've got the mapped heap at 49 hundred thousand, 402 00:17:32,000 --> 00:17:33,960 and the target app is up at 53. 403 00:17:33,960 --> 00:17:36,160 So that's the difference of A0000. 404 00:17:38,020 --> 00:17:40,360 But if we found our data at 53 SEO, 405 00:17:40,900 --> 00:17:42,840 we just simply add A0000, 406 00:17:43,520 --> 00:17:45,080 and we know exactly where it is 407 00:17:45,080 --> 00:17:45,920 in the other application. 408 00:17:51,860 --> 00:17:53,480 Okay, so we'll come back to that in a sec. 409 00:17:55,680 --> 00:17:56,880 Well, I don't know, man, 410 00:17:56,920 --> 00:17:57,720 this is going really fast. 411 00:17:59,320 --> 00:18:00,000 Okay, so, 412 00:18:00,740 --> 00:18:02,180 we'll mention some points on shellcode. 413 00:18:02,180 --> 00:18:03,440 When I'm talking about shellcode, 414 00:18:03,620 --> 00:18:07,100 it's any data that's been used in an exploit, 415 00:18:07,280 --> 00:18:08,800 structure block, text string, 416 00:18:10,880 --> 00:18:12,140 bytecode that runs a command shell. 417 00:18:13,300 --> 00:18:15,160 Now, if it is a command shell that's required, 418 00:18:15,880 --> 00:18:17,260 the exploit, the shellcode, 419 00:18:17,420 --> 00:18:19,000 it only needs to call the system API 420 00:18:19,740 --> 00:18:21,020 to give you a system shell. 421 00:18:22,360 --> 00:18:23,680 You can make it more robust 422 00:18:23,680 --> 00:18:24,740 by calling load library, 423 00:18:25,780 --> 00:18:29,500 and load the appropriate DLLs. 424 00:18:30,740 --> 00:18:32,160 But because the shellcode is there, 425 00:18:32,180 --> 00:18:33,480 and it was created and executed locally, 426 00:18:34,160 --> 00:18:37,000 any relocatable addresses can be correctly assigned 427 00:18:37,000 --> 00:18:38,700 before sending the exploit. 428 00:18:38,940 --> 00:18:41,960 Now, this removes the need for a function address lookup code, 429 00:18:42,100 --> 00:18:43,800 which is normally found in remote exploits, 430 00:18:43,860 --> 00:18:45,500 and it allows you to craft, 431 00:18:46,060 --> 00:18:46,320 you, 432 00:18:46,860 --> 00:18:48,940 allows an attacker to craft an exploit 433 00:18:48,940 --> 00:18:50,640 that is completely operating system 434 00:18:50,640 --> 00:18:51,780 and service pack independent. 435 00:18:56,100 --> 00:18:59,200 Now, all the APIs that are used to pass messages, 436 00:18:59,380 --> 00:19:01,760 they have wide character or Unicode equivalents. 437 00:19:02,220 --> 00:19:05,040 So this means that complete byte arrays can be passed, 438 00:19:05,260 --> 00:19:07,160 and in most cases they can contain null bytes. 439 00:19:07,780 --> 00:19:09,900 Now, the set window text W function, 440 00:19:10,140 --> 00:19:12,780 it's a wide character wrapper for the send message API 441 00:19:13,460 --> 00:19:15,340 to send the WM set text message. 442 00:19:16,060 --> 00:19:18,340 So this can be used to set the title caption of Windows, 443 00:19:18,540 --> 00:19:21,900 and it's an ideal way to pass our shellcode. 444 00:19:23,720 --> 00:19:26,100 Once again, I hope the slides are self-explanatory. 445 00:19:27,140 --> 00:19:29,800 Of course, the string is terminated by a wide character null. 446 00:19:29,960 --> 00:19:32,160 If the two nulls are in the wrong place, 447 00:19:33,500 --> 00:19:35,720 it's null termination of the string, 448 00:19:35,880 --> 00:19:37,000 and it won't be passed. 449 00:19:39,520 --> 00:19:40,800 The set window text W, 450 00:19:41,000 --> 00:19:43,900 it will use the same address space 451 00:19:44,680 --> 00:19:47,660 if the length of the text string is the same or less 452 00:19:47,660 --> 00:19:48,880 than what was previously used. 453 00:19:49,260 --> 00:19:51,860 So if it is required that we need to write shellcode, 454 00:19:52,060 --> 00:19:52,460 bytecode, 455 00:19:52,620 --> 00:19:55,540 or data structure into an application's address space 456 00:19:55,540 --> 00:19:58,280 that does contain wide character nulls, 457 00:19:58,300 --> 00:20:00,840 we can do it in a reverse manner. 458 00:20:02,580 --> 00:20:05,880 We can see here we want to write a wide character null, 459 00:20:06,060 --> 00:20:09,300 so we do it by writing the last part of the shellcode first, 460 00:20:09,460 --> 00:20:11,860 and then by sending smaller and smaller bits. 461 00:20:13,500 --> 00:20:17,540 The shellcode will be created properly as we need it. 462 00:20:25,300 --> 00:20:27,400 So there's been various methods that are used 463 00:20:27,400 --> 00:20:29,980 to locate the shellcode for shadow attacks, 464 00:20:30,140 --> 00:20:32,100 and while these can all be successful, 465 00:20:32,100 --> 00:20:33,620 there have been downfalls in the past. 466 00:20:34,200 --> 00:20:36,080 So this guessing the address technique 467 00:20:36,080 --> 00:20:37,780 makes it difficult to exploit messages 468 00:20:37,780 --> 00:20:40,160 that require even the simplest of data structures. 469 00:20:41,880 --> 00:20:43,060 There's been brute force, 470 00:20:43,300 --> 00:20:44,320 arbitrary byte writing, 471 00:20:44,440 --> 00:20:44,980 memory reading, 472 00:20:45,140 --> 00:20:46,040 et cetera, et cetera. 473 00:20:46,480 --> 00:20:47,340 Now, Chris Padgett, 474 00:20:47,400 --> 00:20:49,900 he released something I think last year at Black Hat, 475 00:20:49,960 --> 00:20:51,700 and he knows that when you create a message box, 476 00:20:52,880 --> 00:20:54,520 that text in the message box 477 00:20:54,520 --> 00:20:56,020 is copied to every application. 478 00:20:56,300 --> 00:20:57,920 Now, what I think he was saying, 479 00:20:58,060 --> 00:20:59,580 or what I think he was seeing, 480 00:20:59,720 --> 00:21:01,380 was the process mapped heap 481 00:21:01,380 --> 00:21:02,480 that I explained before. 482 00:21:05,380 --> 00:21:07,740 So we can use the process mapped heap 483 00:21:08,260 --> 00:21:10,180 to pass our data, our shellcode, 484 00:21:10,340 --> 00:21:11,360 into another application 485 00:21:12,380 --> 00:21:14,620 and find the exact location of it. 486 00:21:15,680 --> 00:21:17,480 So for the target application, 487 00:21:17,780 --> 00:21:19,600 we simply open the process, 488 00:21:19,880 --> 00:21:21,020 read it from the PEB, 489 00:21:21,160 --> 00:21:22,200 and adjust it. 490 00:21:22,520 --> 00:21:24,440 Now, of course, this requires debug rights, 491 00:21:24,540 --> 00:21:27,260 but so does it when you're creating a remote exploit. 492 00:21:27,420 --> 00:21:29,380 So that's done on a computer 493 00:21:29,380 --> 00:21:31,080 under control of the attacker. 494 00:21:31,380 --> 00:21:32,760 Like I said before, 495 00:21:33,020 --> 00:21:35,160 the application has the base 496 00:21:35,820 --> 00:21:37,180 mapped at a static location. 497 00:21:37,560 --> 00:21:39,640 So if we find it on our computer, 498 00:21:39,840 --> 00:21:40,960 it's the same on that computer 499 00:21:40,960 --> 00:21:41,960 or that computer. 500 00:21:44,260 --> 00:21:46,840 The base address for the exploit 501 00:21:46,840 --> 00:21:47,780 or the attacking application 502 00:21:48,600 --> 00:21:50,080 can, of course, just be read locally 503 00:21:50,080 --> 00:21:51,380 at run time from the PEB 504 00:21:51,380 --> 00:21:52,120 and adjusted. 505 00:21:52,400 --> 00:21:53,860 And this thing gives us an offset 506 00:21:54,240 --> 00:21:55,300 between the two applications. 507 00:21:57,840 --> 00:21:58,460 All right. 508 00:21:58,500 --> 00:21:59,780 So like I said before, 509 00:21:59,820 --> 00:22:01,020 using the set window text, 510 00:22:01,020 --> 00:22:01,620 W function, 511 00:22:01,920 --> 00:22:03,660 it's a great way to place our shellcode 512 00:22:03,660 --> 00:22:04,460 into the map's heap. 513 00:22:05,120 --> 00:22:06,060 Now, on this graphic, 514 00:22:06,240 --> 00:22:07,960 we've shown the set window text, 515 00:22:08,020 --> 00:22:08,440 W message 516 00:22:08,920 --> 00:22:10,580 being sent to the target application. 517 00:22:11,040 --> 00:22:11,860 That's not necessary. 518 00:22:12,000 --> 00:22:13,060 We're going to send it to ourselves 519 00:22:13,060 --> 00:22:14,660 and set our own caption. 520 00:22:15,120 --> 00:22:15,960 Either way, 521 00:22:16,080 --> 00:22:18,680 the data will be in the map's heap 522 00:22:18,680 --> 00:22:20,820 and therefore accessible to all GUI threads. 523 00:22:22,400 --> 00:22:23,420 The attacking application 524 00:22:23,940 --> 00:22:25,760 then simply looks through its map's heap, 525 00:22:26,700 --> 00:22:28,000 finds the offset of the data, 526 00:22:28,700 --> 00:22:29,920 adjusts with that offset 527 00:22:29,920 --> 00:22:31,660 that we discovered on the previous slide, 528 00:22:31,860 --> 00:22:33,540 giving us the exact memory location 529 00:22:33,540 --> 00:22:35,240 in the target application 530 00:22:35,660 --> 00:22:36,500 where our data is. 531 00:22:37,680 --> 00:22:39,380 So to recap, 532 00:22:39,500 --> 00:22:43,180 we can now place arbitrary data 533 00:22:43,180 --> 00:22:44,180 containing any values 534 00:22:44,180 --> 00:22:45,440 into a known location 535 00:22:45,440 --> 00:22:46,440 in any application. 536 00:22:47,080 --> 00:22:48,400 So this forms the basis 537 00:22:48,400 --> 00:22:50,280 for all messaging attacks going forward 538 00:22:50,280 --> 00:22:52,020 and allows us to exploit messages 539 00:22:52,020 --> 00:22:54,280 that require complex data structures, 540 00:22:54,460 --> 00:22:56,080 including pointers into pointers. 541 00:22:58,120 --> 00:22:59,760 So the callback attack 542 00:22:59,920 --> 00:23:01,120 is the classic shatter attack 543 00:23:01,120 --> 00:23:01,980 back in 2002, 544 00:23:02,320 --> 00:23:03,080 WM Timer. 545 00:23:03,960 --> 00:23:05,260 These sort of attacks 546 00:23:05,260 --> 00:23:05,980 exploit messages 547 00:23:05,980 --> 00:23:08,760 that pass a function address 548 00:23:08,760 --> 00:23:10,400 to be used as a callback. 549 00:23:11,060 --> 00:23:11,820 That's why they're called 550 00:23:11,820 --> 00:23:12,360 callback addresses. 551 00:23:13,140 --> 00:23:14,220 Okay, so Microsoft denounced 552 00:23:14,220 --> 00:23:14,980 this was a problem 553 00:23:14,980 --> 00:23:16,040 with the WM Timer 554 00:23:16,040 --> 00:23:18,220 and they released a patch. 555 00:23:18,300 --> 00:23:18,860 Their patch was 556 00:23:19,820 --> 00:23:21,300 we won't accept messages 557 00:23:21,300 --> 00:23:22,000 for addresses 558 00:23:22,000 --> 00:23:23,420 that are not previously registered. 559 00:23:23,800 --> 00:23:24,600 So far, 560 00:23:24,660 --> 00:23:25,480 it seems to be working. 561 00:23:26,180 --> 00:23:27,120 But since then, 562 00:23:27,140 --> 00:23:28,040 a number of other messages 563 00:23:28,040 --> 00:23:29,100 have been found vulnerable 564 00:23:29,100 --> 00:23:29,680 to these attacks. 565 00:23:29,840 --> 00:23:29,900 So, 566 00:23:29,900 --> 00:23:31,020 of course, 567 00:23:31,100 --> 00:23:32,160 we've got EM-set web break proc, 568 00:23:32,380 --> 00:23:33,320 LVM sort items, 569 00:23:34,040 --> 00:23:35,200 and we've got a few others 570 00:23:35,200 --> 00:23:36,440 that accept a callback 571 00:23:36,440 --> 00:23:37,240 within a structure. 572 00:23:40,200 --> 00:23:41,420 So it should be realized 573 00:23:41,420 --> 00:23:42,460 that any message 574 00:23:42,460 --> 00:23:43,300 that takes a callback 575 00:23:43,300 --> 00:23:43,880 as a parameter 576 00:23:44,820 --> 00:23:46,140 is possibly susceptible 577 00:23:46,140 --> 00:23:47,020 to these type of attacks. 578 00:23:48,200 --> 00:23:49,280 So the attack starts, 579 00:23:49,480 --> 00:23:49,660 yeah, 580 00:23:49,720 --> 00:23:50,480 we get the shellcode 581 00:23:50,480 --> 00:23:52,060 into the known location 582 00:23:52,060 --> 00:23:53,100 of the application. 583 00:23:53,740 --> 00:23:54,900 And as we explained before, 584 00:23:55,000 --> 00:23:56,180 we can use the process map to eat, 585 00:23:56,660 --> 00:23:57,500 and then we simply 586 00:23:57,500 --> 00:23:58,600 just send the callback message 587 00:23:58,600 --> 00:23:59,640 passing the address 588 00:23:59,640 --> 00:23:59,880 that we want to send 589 00:23:59,900 --> 00:24:00,280 that we've discovered, 590 00:24:00,480 --> 00:24:01,880 and that's it. 591 00:24:02,000 --> 00:24:02,920 There's no guesswork. 592 00:24:03,080 --> 00:24:03,340 It's all, 593 00:24:03,440 --> 00:24:05,100 it's all sweet as. 594 00:24:06,500 --> 00:24:06,900 Yeah, 595 00:24:06,940 --> 00:24:07,620 so the callback message 596 00:24:07,620 --> 00:24:08,000 is sent, 597 00:24:08,120 --> 00:24:09,220 specifying the location 598 00:24:09,220 --> 00:24:09,920 of the shellcode 599 00:24:09,920 --> 00:24:10,720 as the callback function. 600 00:24:11,400 --> 00:24:12,380 And in most cases, 601 00:24:12,420 --> 00:24:12,820 the application 602 00:24:12,820 --> 00:24:14,000 will blindly accept it, 603 00:24:14,040 --> 00:24:14,720 and the shellcode 604 00:24:14,720 --> 00:24:15,200 is executed. 605 00:24:18,520 --> 00:24:18,920 So, 606 00:24:18,980 --> 00:24:19,640 not too long ago, 607 00:24:19,780 --> 00:24:19,980 I, 608 00:24:19,980 --> 00:24:21,100 I video mailed, 609 00:24:21,220 --> 00:24:21,880 I released a package 610 00:24:21,880 --> 00:24:22,360 under the name 611 00:24:22,360 --> 00:24:23,000 of EasyShatter. 612 00:24:23,760 --> 00:24:24,380 And I thought 613 00:24:24,380 --> 00:24:24,660 this was, 614 00:24:24,680 --> 00:24:25,480 this was quite funky 615 00:24:25,480 --> 00:24:26,100 when I found this. 616 00:24:27,640 --> 00:24:28,620 What I realized 617 00:24:28,620 --> 00:24:29,360 was that 618 00:24:29,360 --> 00:24:29,880 the callback message 619 00:24:29,900 --> 00:24:30,240 was a callback function 620 00:24:30,240 --> 00:24:32,020 for the emsetwordbreakproc 621 00:24:32,020 --> 00:24:32,720 ex message. 622 00:24:33,360 --> 00:24:34,320 It took a pointer 623 00:24:34,320 --> 00:24:34,980 to a text string 624 00:24:34,980 --> 00:24:35,780 as its first parameter. 625 00:24:36,180 --> 00:24:37,320 And he realized 626 00:24:37,320 --> 00:24:38,480 that the load library function 627 00:24:38,480 --> 00:24:40,000 also took a pointer 628 00:24:40,000 --> 00:24:40,680 to a text string 629 00:24:40,680 --> 00:24:41,400 as its first parameter. 630 00:24:42,680 --> 00:24:43,460 So his, 631 00:24:43,460 --> 00:24:43,880 his exploit 632 00:24:43,880 --> 00:24:44,760 involved typing 633 00:24:44,760 --> 00:24:45,420 or pasting 634 00:24:45,420 --> 00:24:45,760 the name 635 00:24:45,760 --> 00:24:46,580 of a DLL file 636 00:24:46,580 --> 00:24:47,520 into a text box 637 00:24:47,520 --> 00:24:48,700 and sending 638 00:24:48,700 --> 00:24:50,000 the emsetwordbreakproc 639 00:24:50,000 --> 00:24:50,880 ex message 640 00:24:50,880 --> 00:24:52,060 with the address 641 00:24:52,060 --> 00:24:53,100 of the load library function 642 00:24:53,100 --> 00:24:54,400 as the callback address. 643 00:24:56,580 --> 00:24:57,560 So what this meant 644 00:24:57,560 --> 00:24:58,040 was that 645 00:24:58,040 --> 00:24:58,980 any DLL 646 00:24:58,980 --> 00:24:59,420 that he had 647 00:24:59,420 --> 00:24:59,880 sent 648 00:24:59,900 --> 00:25:00,840 typed into this text box 649 00:25:00,840 --> 00:25:01,760 was then loaded 650 00:25:01,760 --> 00:25:02,560 by the app, 651 00:25:02,560 --> 00:25:03,260 the target application 652 00:25:03,740 --> 00:25:05,140 and any initialization code 653 00:25:05,140 --> 00:25:05,800 in the DLL 654 00:25:05,800 --> 00:25:06,240 was run. 655 00:25:06,800 --> 00:25:07,740 So this removes 656 00:25:07,740 --> 00:25:08,100 the need 657 00:25:08,100 --> 00:25:08,780 to write 658 00:25:08,780 --> 00:25:09,220 or find 659 00:25:09,220 --> 00:25:09,860 any shell code 660 00:25:09,860 --> 00:25:10,800 in the target application. 661 00:25:11,360 --> 00:25:12,520 And it's pretty much 662 00:25:12,520 --> 00:25:13,480 your typical return 663 00:25:13,480 --> 00:25:14,620 to libc type exploit. 664 00:25:15,360 --> 00:25:15,880 Sorry. 665 00:25:21,560 --> 00:25:22,480 So if we look 666 00:25:22,480 --> 00:25:23,040 for other APIs 667 00:25:23,040 --> 00:25:23,640 that sort of fit 668 00:25:23,640 --> 00:25:24,000 this mold, 669 00:25:24,540 --> 00:25:25,200 we've got 670 00:25:25,200 --> 00:25:26,140 set unhandled 671 00:25:26,140 --> 00:25:26,780 exception filter 672 00:25:26,780 --> 00:25:28,380 and the system API. 673 00:25:29,900 --> 00:25:30,020 Let me quickly 674 00:25:30,020 --> 00:25:30,660 spring to mind now. 675 00:25:31,300 --> 00:25:31,960 The set unhandled 676 00:25:31,960 --> 00:25:32,800 exception filter 677 00:25:33,840 --> 00:25:34,720 would involve 678 00:25:34,720 --> 00:25:35,960 sending the shell code 679 00:25:35,960 --> 00:25:36,660 to a text box 680 00:25:36,660 --> 00:25:37,760 and then sending 681 00:25:37,760 --> 00:25:38,440 the callback message 682 00:25:38,440 --> 00:25:39,020 with the address 683 00:25:39,020 --> 00:25:39,940 of the set unhandled 684 00:25:39,940 --> 00:25:40,560 exception filter 685 00:25:40,560 --> 00:25:41,240 as the callback. 686 00:25:42,320 --> 00:25:43,040 That would then 687 00:25:43,040 --> 00:25:43,800 set the top level 688 00:25:43,800 --> 00:25:44,420 exception filter 689 00:25:44,420 --> 00:25:45,000 to the address 690 00:25:45,000 --> 00:25:45,580 of our shell code 691 00:25:45,580 --> 00:25:46,300 would then cause 692 00:25:46,300 --> 00:25:46,680 an exception 693 00:25:46,680 --> 00:25:47,400 and the shell code 694 00:25:47,400 --> 00:25:47,680 is run. 695 00:25:48,720 --> 00:25:49,640 The system API 696 00:25:49,640 --> 00:25:50,460 would be much easier 697 00:25:50,460 --> 00:25:51,400 to use 698 00:25:51,400 --> 00:25:52,160 and simply involve 699 00:25:52,160 --> 00:25:53,320 typing command exe 700 00:25:53,320 --> 00:25:53,820 in a text box 701 00:25:53,820 --> 00:25:54,900 and sending 702 00:25:54,900 --> 00:25:57,080 the emsetwordbreakproc ex message 703 00:26:07,940 --> 00:26:09,420 So this is what 704 00:26:09,420 --> 00:26:09,800 we've done here 705 00:26:09,800 --> 00:26:10,200 to exploit 706 00:26:10,200 --> 00:26:11,120 the emstreamin message. 707 00:26:11,980 --> 00:26:13,760 Now the emstreamin message 708 00:26:13,760 --> 00:26:14,560 takes a pointer 709 00:26:14,560 --> 00:26:15,480 to an edit stream structure 710 00:26:15,480 --> 00:26:16,480 that holds 711 00:26:16,480 --> 00:26:17,040 a cookie value 712 00:26:17,680 --> 00:26:18,240 and the address 713 00:26:18,240 --> 00:26:19,000 of the callback function. 714 00:26:19,980 --> 00:26:20,880 So using 715 00:26:20,880 --> 00:26:22,400 the setwindowtextw API 716 00:26:22,400 --> 00:26:22,920 we're able 717 00:26:22,920 --> 00:26:23,240 to create 718 00:26:23,240 --> 00:26:24,260 this valid structure 719 00:26:24,760 --> 00:26:25,880 in the process map heap 720 00:26:25,880 --> 00:26:26,380 and find 721 00:26:26,380 --> 00:26:27,140 the exact location 722 00:26:27,140 --> 00:26:27,460 of it. 723 00:26:28,200 --> 00:26:29,280 Now the actual 724 00:26:29,900 --> 00:26:30,600 callback function 725 00:26:30,600 --> 00:26:31,780 is passed the 726 00:26:31,780 --> 00:26:32,200 cookie value 727 00:26:32,200 --> 00:26:33,080 as its first parameter. 728 00:26:34,300 --> 00:26:35,240 So by setting the 729 00:26:35,240 --> 00:26:35,900 cookie in the 730 00:26:35,900 --> 00:26:36,560 edit stream structure 731 00:26:36,560 --> 00:26:37,220 to the address 732 00:26:37,220 --> 00:26:37,620 of the string 733 00:26:37,620 --> 00:26:38,060 to execute 734 00:26:40,020 --> 00:26:41,180 and the callback 735 00:26:41,180 --> 00:26:41,660 address to the 736 00:26:41,660 --> 00:26:42,260 system function 737 00:26:42,900 --> 00:26:43,480 we're able to 738 00:26:43,480 --> 00:26:44,280 cause the rich text box 739 00:26:44,280 --> 00:26:45,160 to open a command shell. 740 00:26:46,080 --> 00:26:47,160 Now the chance 741 00:26:47,160 --> 00:26:47,880 of a system application 742 00:26:47,880 --> 00:26:49,060 having a rich text box 743 00:26:49,060 --> 00:26:49,620 is about zero 744 00:26:49,620 --> 00:26:50,820 but what we're 745 00:26:50,820 --> 00:26:51,520 trying to show here 746 00:26:51,520 --> 00:26:52,200 is that it's now 747 00:26:52,200 --> 00:26:53,200 possible to exploit 748 00:26:53,200 --> 00:26:53,860 more complicated 749 00:26:53,860 --> 00:26:54,240 messages 750 00:26:54,240 --> 00:26:55,100 that require 751 00:26:55,100 --> 00:26:56,180 complex data structures 752 00:26:56,180 --> 00:26:57,360 even including 753 00:26:57,360 --> 00:26:57,700 putting pointers 754 00:26:57,700 --> 00:26:58,160 into themselves. 755 00:27:03,740 --> 00:27:04,860 So back 756 00:27:04,860 --> 00:27:05,660 in 2003 757 00:27:05,660 --> 00:27:07,020 it was discovered 758 00:27:07,020 --> 00:27:07,540 that various 759 00:27:07,540 --> 00:27:08,280 messages could 760 00:27:08,280 --> 00:27:08,580 be used 761 00:27:08,580 --> 00:27:08,880 to write 762 00:27:08,880 --> 00:27:09,500 arbitrary data 763 00:27:09,500 --> 00:27:11,040 to memory 764 00:27:11,040 --> 00:27:11,320 locations. 765 00:27:12,160 --> 00:27:13,160 The exploitable 766 00:27:13,160 --> 00:27:14,120 messages revolved 767 00:27:14,120 --> 00:27:14,520 around the use 768 00:27:14,520 --> 00:27:15,060 of two different 769 00:27:15,060 --> 00:27:15,380 types of 770 00:27:15,380 --> 00:27:15,600 message. 771 00:27:16,000 --> 00:27:16,580 You know 772 00:27:16,580 --> 00:27:17,360 the set 773 00:27:18,460 --> 00:27:18,880 the size 774 00:27:18,880 --> 00:27:19,300 retrieve 775 00:27:19,300 --> 00:27:19,840 the size 776 00:27:19,840 --> 00:27:20,320 into a 777 00:27:20,320 --> 00:27:20,760 into a 778 00:27:20,760 --> 00:27:21,060 location. 779 00:27:24,060 --> 00:27:24,900 So some 780 00:27:24,900 --> 00:27:25,160 people 781 00:27:25,160 --> 00:27:25,420 discovered 782 00:27:25,420 --> 00:27:25,860 that the 783 00:27:27,360 --> 00:27:27,800 get item 784 00:27:27,800 --> 00:27:28,120 structure 785 00:27:28,120 --> 00:27:29,200 or message 786 00:27:29,200 --> 00:27:29,980 it was not 787 00:27:29,980 --> 00:27:30,560 martialed properly 788 00:27:30,560 --> 00:27:31,440 so it could be used 789 00:27:31,440 --> 00:27:31,800 to write a 790 00:27:31,800 --> 00:27:32,120 structure 791 00:27:32,120 --> 00:27:33,220 to arbitrary 792 00:27:33,220 --> 00:27:33,680 locations. 793 00:27:34,960 --> 00:27:35,760 This was used 794 00:27:35,760 --> 00:27:36,180 in conjunction 795 00:27:36,180 --> 00:27:37,000 with the 796 00:27:37,000 --> 00:27:37,560 set column 797 00:27:37,560 --> 00:27:37,780 width 798 00:27:37,780 --> 00:27:38,180 message 799 00:27:39,680 --> 00:27:40,600 to achieve 800 00:27:40,600 --> 00:27:40,980 arbitrary 801 00:27:40,980 --> 00:27:41,240 writing. 802 00:27:41,720 --> 00:27:43,240 So what we've 803 00:27:43,240 --> 00:27:43,480 got here 804 00:27:43,480 --> 00:27:43,840 is a head 805 00:27:43,840 --> 00:27:44,260 on the screen 806 00:27:44,260 --> 00:27:45,440 but behind 807 00:27:45,440 --> 00:27:45,640 that 808 00:27:46,340 --> 00:27:47,360 if we set 809 00:27:47,360 --> 00:27:48,240 the width 810 00:27:48,240 --> 00:27:48,660 of the first 811 00:27:48,660 --> 00:27:49,040 column 812 00:27:49,040 --> 00:27:50,800 that adjusts 813 00:27:50,800 --> 00:27:51,120 the left 814 00:27:51,120 --> 00:27:51,680 member 815 00:27:51,680 --> 00:27:52,560 of the 816 00:27:52,560 --> 00:27:53,060 second column. 817 00:27:53,740 --> 00:27:54,600 So by setting 818 00:27:54,600 --> 00:27:54,900 the width 819 00:27:54,900 --> 00:27:55,320 to five 820 00:27:55,320 --> 00:27:56,760 and then retrieving 821 00:27:56,760 --> 00:27:57,000 the 822 00:27:57,000 --> 00:27:57,900 structure 823 00:27:57,900 --> 00:27:58,400 of the 824 00:27:58,400 --> 00:27:58,920 second column 825 00:27:58,920 --> 00:27:59,680 we can have 826 00:27:59,680 --> 00:28:00,200 five written 827 00:28:00,200 --> 00:28:00,700 wherever we 828 00:28:00,700 --> 00:28:00,900 like. 829 00:28:01,780 --> 00:28:02,420 It's all 830 00:28:02,420 --> 00:28:02,960 documented 831 00:28:02,960 --> 00:28:03,460 in papers. 832 00:28:04,280 --> 00:28:04,840 So by 833 00:28:05,520 --> 00:28:06,060 using 834 00:28:06,060 --> 00:28:06,460 multiple 835 00:28:06,460 --> 00:28:06,800 calls 836 00:28:06,800 --> 00:28:07,220 we can 837 00:28:07,220 --> 00:28:07,460 write 838 00:28:10,620 --> 00:28:11,700 our shell 839 00:28:11,700 --> 00:28:11,900 code 840 00:28:11,900 --> 00:28:12,540 to a 841 00:28:12,540 --> 00:28:12,960 line location. 842 00:28:13,420 --> 00:28:14,480 So that's 843 00:28:14,480 --> 00:28:15,000 all right 844 00:28:15,000 --> 00:28:15,660 but we use 845 00:28:15,660 --> 00:28:16,000 the process 846 00:28:16,000 --> 00:28:16,460 map heap 847 00:28:16,460 --> 00:28:17,200 now so we 848 00:28:17,200 --> 00:28:17,540 know where 849 00:28:17,540 --> 00:28:17,840 our shell 850 00:28:17,840 --> 00:28:18,260 code is 851 00:28:18,260 --> 00:28:19,860 so it's 852 00:28:20,300 --> 00:28:20,840 not that 853 00:28:20,840 --> 00:28:21,120 important 854 00:28:21,120 --> 00:28:21,460 anymore. 855 00:28:22,400 --> 00:28:23,040 So we've 856 00:28:23,040 --> 00:28:23,200 got a 857 00:28:23,200 --> 00:28:23,380 whole lot 858 00:28:23,380 --> 00:28:23,700 of messages. 859 00:28:24,020 --> 00:28:24,440 These are 860 00:28:24,440 --> 00:28:24,720 all public 861 00:28:24,720 --> 00:28:25,180 exploit 862 00:28:25,180 --> 00:28:26,020 code and 863 00:28:26,020 --> 00:28:26,640 you can 864 00:28:26,640 --> 00:28:26,920 see it 865 00:28:26,920 --> 00:28:27,080 affects 866 00:28:27,080 --> 00:28:27,420 quite a 867 00:28:27,420 --> 00:28:27,580 few 868 00:28:27,580 --> 00:28:28,140 mainly 869 00:28:28,140 --> 00:28:28,360 the 870 00:28:28,360 --> 00:28:28,520 common 871 00:28:28,520 --> 00:28:28,780 control, 872 00:28:29,040 --> 00:28:29,660 the new 873 00:28:29,660 --> 00:28:29,800 one, 874 00:28:29,880 --> 00:28:30,000 common 875 00:28:30,000 --> 00:28:30,140 control 876 00:28:30,140 --> 00:28:30,380 32. 877 00:28:30,920 --> 00:28:31,580 But right 878 00:28:31,580 --> 00:28:31,900 down to 879 00:28:31,900 --> 00:28:32,040 the 880 00:28:32,040 --> 00:28:32,580 buttons 881 00:28:32,580 --> 00:28:32,980 under 882 00:28:32,980 --> 00:28:33,420 XP, 883 00:28:34,360 --> 00:28:34,840 we 884 00:28:34,840 --> 00:28:35,120 thought it 885 00:28:35,120 --> 00:28:35,200 was 886 00:28:35,200 --> 00:28:35,400 really 887 00:28:35,400 --> 00:28:35,780 neat 888 00:28:35,780 --> 00:28:36,240 when 889 00:28:36,240 --> 00:28:36,520 Oliver 890 00:28:36,520 --> 00:28:37,460 released 891 00:28:37,460 --> 00:28:37,680 that 892 00:28:37,680 --> 00:28:37,920 code 893 00:28:37,920 --> 00:28:38,160 where 894 00:28:38,160 --> 00:28:38,960 a 895 00:28:38,960 --> 00:28:39,280 button 896 00:28:39,280 --> 00:28:39,780 allows 897 00:28:39,780 --> 00:28:40,020 you 898 00:28:40,020 --> 00:28:40,200 to write 899 00:28:40,200 --> 00:28:40,680 arbitrary 900 00:28:41,120 --> 00:28:41,480 bytes 901 00:28:41,480 --> 00:28:42,140 into an 902 00:28:42,140 --> 00:28:42,660 arbitrary 903 00:28:42,660 --> 00:28:43,020 location. 904 00:28:46,500 --> 00:28:47,100 All right. 905 00:28:50,080 --> 00:28:50,440 Okay. 906 00:28:50,540 --> 00:28:51,260 So like 907 00:28:51,260 --> 00:28:51,420 I said 908 00:28:51,420 --> 00:28:51,660 before, 909 00:28:51,760 --> 00:28:52,140 we use 910 00:28:52,140 --> 00:28:52,740 process map 911 00:28:52,740 --> 00:28:52,960 heap 912 00:28:52,960 --> 00:28:53,560 now to 913 00:28:54,200 --> 00:28:54,640 find out 914 00:28:54,640 --> 00:28:54,840 where our 915 00:28:54,840 --> 00:28:55,000 shell 916 00:28:55,000 --> 00:28:55,340 code is. 917 00:28:55,440 --> 00:28:55,580 So the 918 00:28:55,580 --> 00:28:55,840 arbitrary 919 00:28:55,840 --> 00:28:56,100 byte 920 00:28:56,100 --> 00:28:56,460 writing is 921 00:28:56,460 --> 00:28:56,700 not such 922 00:28:56,700 --> 00:28:56,900 a big 923 00:28:56,900 --> 00:28:57,140 deal. 924 00:28:57,740 --> 00:28:58,220 But we 925 00:28:58,220 --> 00:28:58,520 still need 926 00:28:58,520 --> 00:28:58,740 to get 927 00:28:58,740 --> 00:28:59,380 our code 928 00:28:59,380 --> 00:28:59,820 to execute. 929 00:29:01,660 --> 00:29:02,540 So what 930 00:29:02,540 --> 00:29:02,900 can we 931 00:29:02,900 --> 00:29:03,120 execute? 932 00:29:03,360 --> 00:29:03,720 What can 933 00:29:03,720 --> 00:29:03,800 we 934 00:29:03,800 --> 00:29:04,140 overwrite 935 00:29:04,140 --> 00:29:04,660 to gain 936 00:29:04,660 --> 00:29:04,960 execution? 937 00:29:05,300 --> 00:29:06,080 So the 938 00:29:06,080 --> 00:29:06,380 top level 939 00:29:06,380 --> 00:29:06,660 exception 940 00:29:06,660 --> 00:29:07,520 handler or 941 00:29:07,520 --> 00:29:07,680 the 942 00:29:07,680 --> 00:29:08,020 unhandled 943 00:29:08,020 --> 00:29:08,220 exception 944 00:29:08,220 --> 00:29:08,840 filter is 945 00:29:08,840 --> 00:29:09,120 commonly 946 00:29:09,120 --> 00:29:09,700 used in 947 00:29:09,700 --> 00:29:09,920 remote 948 00:29:09,920 --> 00:29:10,460 exploits. 949 00:29:10,580 --> 00:29:13,520 So we 950 00:29:13,520 --> 00:29:13,760 can use 951 00:29:13,760 --> 00:29:14,140 the same 952 00:29:14,140 --> 00:29:14,400 method. 953 00:29:15,200 --> 00:29:15,720 We 954 00:29:15,720 --> 00:29:15,900 write 955 00:29:15,900 --> 00:29:16,000 our 956 00:29:16,000 --> 00:29:16,180 shell 957 00:29:28,740 --> 00:29:29,340 But in 958 00:29:29,340 --> 00:29:29,820 some cases 959 00:29:29,820 --> 00:29:30,060 the 960 00:29:30,060 --> 00:29:30,880 SEH method 961 00:29:30,880 --> 00:29:31,260 may not 962 00:29:31,260 --> 00:29:31,560 work. 963 00:29:31,860 --> 00:29:32,540 So an 964 00:29:32,540 --> 00:29:33,000 attacker can 965 00:29:33,000 --> 00:29:33,340 overwrite 966 00:29:33,340 --> 00:29:33,760 memory 967 00:29:34,940 --> 00:29:35,540 locations 968 00:29:35,540 --> 00:29:36,280 such as 969 00:29:36,280 --> 00:29:36,440 the 970 00:29:36,440 --> 00:29:37,120 PEB lock 971 00:29:37,120 --> 00:29:37,600 and unlock 972 00:29:37,600 --> 00:29:37,880 pointers. 973 00:29:42,020 --> 00:29:43,220 But we 974 00:29:43,220 --> 00:29:43,660 are not 975 00:29:43,660 --> 00:29:43,960 able to 976 00:29:43,960 --> 00:29:44,320 overwrite 977 00:29:44,320 --> 00:29:44,480 the 978 00:29:44,480 --> 00:29:44,900 PEB 979 00:29:44,900 --> 00:29:45,600 byte 980 00:29:45,600 --> 00:29:45,760 by 981 00:29:45,760 --> 00:29:46,080 byte 982 00:29:46,080 --> 00:29:46,820 because it 983 00:29:46,820 --> 00:29:47,020 will be 984 00:29:47,020 --> 00:29:47,800 used between 985 00:29:47,800 --> 00:29:48,860 our message 986 00:29:48,860 --> 00:29:49,160 sends. 987 00:29:49,360 --> 00:29:50,240 So what 988 00:29:50,240 --> 00:29:50,540 we need to 989 00:29:50,540 --> 00:29:50,800 do is 990 00:29:50,800 --> 00:29:51,300 write it 991 00:29:51,300 --> 00:29:51,420 to a 992 00:29:51,420 --> 00:29:51,980 location in 993 00:29:51,980 --> 00:29:52,260 the heap 994 00:29:52,260 --> 00:29:53,740 that contains 995 00:29:53,740 --> 00:29:54,160 the 996 00:29:54,160 --> 00:29:54,980 lowest 997 00:29:54,980 --> 00:29:55,320 significant 998 00:29:55,320 --> 00:29:56,220 word of 999 00:29:56,220 --> 00:29:56,360 the 1000 00:29:56,360 --> 00:29:56,660 original 1001 00:29:56,660 --> 00:29:57,380 PEB pointer. 1002 00:29:58,540 --> 00:29:59,360 And then 1003 00:29:59,360 --> 00:29:59,920 by 1004 00:29:59,920 --> 00:30:00,880 overwriting 1005 00:30:00,880 --> 00:30:01,280 the third 1006 00:30:01,280 --> 00:30:02,560 byte we 1007 00:30:02,560 --> 00:30:02,720 will have 1008 00:30:02,720 --> 00:30:02,960 zero 1009 00:30:02,960 --> 00:30:03,740 automatically 1010 00:30:03,740 --> 00:30:04,420 written to 1011 00:30:04,420 --> 00:30:04,700 the end. 1012 00:30:04,840 --> 00:30:05,960 So I 1013 00:30:05,960 --> 00:30:06,460 hope that 1014 00:30:06,460 --> 00:30:06,980 makes sense. 1015 00:30:07,120 --> 00:30:07,580 We write 1016 00:30:07,580 --> 00:30:07,860 our shell 1017 00:30:07,860 --> 00:30:08,180 code to 1018 00:30:08,180 --> 00:30:08,420 the heap 1019 00:30:08,420 --> 00:30:10,120 somewhere that 1020 00:30:10,120 --> 00:30:10,720 you can see 1021 00:30:10,720 --> 00:30:11,020 like a 1022 00:30:11,020 --> 00:30:11,180 7 1023 00:30:13,560 --> 00:30:14,280 9103 and 1024 00:30:14,280 --> 00:30:15,280 then we 1025 00:30:15,280 --> 00:30:15,740 use the 1026 00:30:15,740 --> 00:30:16,040 original 1027 00:30:16,740 --> 00:30:17,460 9103 of 1028 00:30:17,460 --> 00:30:17,600 the 1029 00:30:17,600 --> 00:30:17,880 original 1030 00:30:17,880 --> 00:30:18,540 PEB pointer 1031 00:30:18,540 --> 00:30:19,320 and just 1032 00:30:19,320 --> 00:30:19,700 overwrite 1033 00:30:19,700 --> 00:30:19,960 the other 1034 00:30:19,960 --> 00:30:20,140 part. 1035 00:30:22,540 --> 00:30:22,980 So we 1036 00:30:22,980 --> 00:30:23,120 have a 1037 00:30:23,120 --> 00:30:23,380 graphic 1038 00:30:23,380 --> 00:30:23,540 here, 1039 00:30:23,980 --> 00:30:24,340 messages 1040 00:30:24,340 --> 00:30:25,020 flying 1041 00:30:25,020 --> 00:30:25,620 around 1042 00:30:26,180 --> 00:30:26,660 somewhere. 1043 00:30:28,100 --> 00:30:28,740 All right, 1044 00:30:28,780 --> 00:30:29,260 but in 1045 00:30:29,260 --> 00:30:29,760 some cases 1046 00:30:29,760 --> 00:30:30,120 you can't 1047 00:30:30,120 --> 00:30:30,420 overwrite 1048 00:30:30,420 --> 00:30:30,780 the PEB. 1049 00:30:30,920 --> 00:30:31,780 They don't 1050 00:30:31,780 --> 00:30:32,260 exist on 1051 00:30:32,260 --> 00:30:32,580 some operating 1052 00:30:32,580 --> 00:30:32,900 systems. 1053 00:30:33,960 --> 00:30:34,600 So we 1054 00:30:34,600 --> 00:30:34,900 can overwrite 1055 00:30:34,900 --> 00:30:35,240 the GDI 1056 00:30:35,240 --> 00:30:35,480 dispatch 1057 00:30:35,480 --> 00:30:35,860 table 1058 00:30:35,860 --> 00:30:36,220 pointer. 1059 00:30:37,360 --> 00:30:37,840 This 1060 00:30:37,840 --> 00:30:38,520 point is 1061 00:30:38,520 --> 00:30:38,940 the location 1062 00:30:38,940 --> 00:30:39,340 of a 1063 00:30:39,340 --> 00:30:39,700 table of 1064 00:30:39,700 --> 00:30:41,000 functions and 1065 00:30:41,000 --> 00:30:41,320 can be 1066 00:30:41,320 --> 00:30:41,600 overwritten 1067 00:30:41,600 --> 00:30:41,840 in a 1068 00:30:41,840 --> 00:30:42,080 similar 1069 00:30:42,080 --> 00:30:42,380 manner. 1070 00:30:54,340 --> 00:30:54,780 put our 1071 00:30:54,780 --> 00:30:55,000 shell 1072 00:30:55,000 --> 00:30:55,160 code 1073 00:30:55,160 --> 00:30:55,440 somewhere 1074 00:30:55,440 --> 00:30:58,400 and into 1075 00:30:58,400 --> 00:30:58,900 the heap 1076 00:30:58,900 --> 00:30:59,640 like using 1077 00:30:59,640 --> 00:30:59,920 the 1078 00:31:00,920 --> 00:31:01,440 lowest 1079 00:31:01,440 --> 00:31:01,720 significant 1080 00:31:01,720 --> 00:31:02,660 word of 1081 00:31:02,660 --> 00:31:02,820 the 1082 00:31:02,820 --> 00:31:03,060 original 1083 00:31:03,060 --> 00:31:03,420 GDI 1084 00:31:03,420 --> 00:31:03,660 dispatch 1085 00:31:03,660 --> 00:31:04,060 table, 1086 00:31:04,680 --> 00:31:05,200 we 1087 00:31:05,200 --> 00:31:05,940 write a 1088 00:31:05,940 --> 00:31:06,060 whole 1089 00:31:06,060 --> 00:31:06,380 block of 1090 00:31:06,380 --> 00:31:06,720 pointers 1091 00:31:06,720 --> 00:31:07,340 to our 1092 00:31:07,340 --> 00:31:07,540 shell 1093 00:31:07,540 --> 00:31:07,700 code. 1094 00:31:08,800 --> 00:31:09,580 And then we 1095 00:31:09,580 --> 00:31:09,940 overwrite 1096 00:31:09,940 --> 00:31:10,280 the GDI 1097 00:31:10,280 --> 00:31:10,500 dispatch 1098 00:31:10,500 --> 00:31:10,740 table. 1099 00:31:11,020 --> 00:31:11,520 The system 1100 00:31:11,520 --> 00:31:11,880 will come 1101 00:31:11,880 --> 00:31:12,460 back and 1102 00:31:12,460 --> 00:31:12,860 say I 1103 00:31:12,860 --> 00:31:13,020 want to 1104 00:31:13,020 --> 00:31:13,440 make a GDI 1105 00:31:13,440 --> 00:31:13,800 call at 1106 00:31:13,800 --> 00:31:13,960 user 1107 00:31:13,960 --> 00:31:14,160 land, 1108 00:31:14,340 --> 00:31:14,840 so give 1109 00:31:14,840 --> 00:31:14,980 us the 1110 00:31:14,980 --> 00:31:15,220 table, 1111 00:31:16,100 --> 00:31:16,500 where's 1112 00:31:16,500 --> 00:31:16,560 the 1113 00:31:16,560 --> 00:31:16,840 function, 1114 00:31:17,040 --> 00:31:17,580 call our 1115 00:31:17,580 --> 00:31:17,800 shell 1116 00:31:17,800 --> 00:31:17,980 code. 1117 00:31:27,860 --> 00:31:28,420 It's also 1118 00:31:28,420 --> 00:31:28,960 possible to 1119 00:31:28,960 --> 00:31:29,280 overwrite 1120 00:31:29,280 --> 00:31:29,740 the C 1121 00:31:30,220 --> 00:31:30,620 run 1122 00:31:30,620 --> 00:31:30,760 time 1123 00:31:30,760 --> 00:31:31,280 terminators. 1124 00:31:31,900 --> 00:31:32,580 These are 1125 00:31:32,580 --> 00:31:32,900 called from 1126 00:31:32,900 --> 00:31:33,180 the exit 1127 00:31:33,180 --> 00:31:33,760 routine on 1128 00:31:33,760 --> 00:31:34,340 normal or 1129 00:31:34,340 --> 00:31:34,960 abnormal 1130 00:31:34,960 --> 00:31:35,720 application 1131 00:31:35,720 --> 00:31:36,220 shutdown. 1132 00:31:36,680 --> 00:31:37,420 So even 1133 00:31:37,420 --> 00:31:37,680 though we're 1134 00:31:37,680 --> 00:31:37,860 talking 1135 00:31:37,860 --> 00:31:38,100 local 1136 00:31:38,100 --> 00:31:38,460 attacks 1137 00:31:38,460 --> 00:31:38,740 here, 1138 00:31:38,840 --> 00:31:39,500 these 1139 00:31:39,500 --> 00:31:39,940 pointers can 1140 00:31:39,940 --> 00:31:40,460 be overwritten 1141 00:31:40,460 --> 00:31:40,840 by remote 1142 00:31:40,840 --> 00:31:41,320 exploits 1143 00:31:41,320 --> 00:31:41,580 as well. 1144 00:31:49,920 --> 00:31:51,040 As you 1145 00:31:51,040 --> 00:31:51,360 can see 1146 00:31:51,360 --> 00:31:51,560 here, 1147 00:31:51,640 --> 00:31:51,880 these are 1148 00:31:51,880 --> 00:31:52,340 static 1149 00:31:52,340 --> 00:31:52,700 pointers. 1150 00:31:54,320 --> 00:31:54,880 Okay, 1151 00:31:54,940 --> 00:31:55,540 so what 1152 00:31:55,540 --> 00:31:56,040 happens if 1153 00:31:56,040 --> 00:31:56,560 we 1154 00:31:56,560 --> 00:31:57,060 overwrite 1155 00:31:57,060 --> 00:31:57,940 the 1156 00:31:57,940 --> 00:31:58,200 address 1157 00:31:58,200 --> 00:31:58,840 of our 1158 00:31:58,840 --> 00:31:59,060 shell 1159 00:31:59,060 --> 00:31:59,260 code, 1160 00:31:59,500 --> 00:32:00,120 like we 1161 00:32:00,120 --> 00:32:00,400 write it 1162 00:32:00,400 --> 00:32:00,500 to 1163 00:32:01,480 --> 00:32:01,920 7803014C, 1164 00:32:02,780 --> 00:32:03,640 then when 1165 00:32:03,640 --> 00:32:03,920 the app 1166 00:32:03,920 --> 00:32:04,100 shuts 1167 00:32:04,100 --> 00:32:04,460 down, 1168 00:32:04,600 --> 00:32:04,940 either 1169 00:32:04,940 --> 00:32:05,100 by 1170 00:32:05,100 --> 00:32:05,320 sending 1171 00:32:05,320 --> 00:32:05,440 it 1172 00:32:05,440 --> 00:32:05,740 WM 1173 00:32:05,740 --> 00:32:06,280 close or 1174 00:32:06,280 --> 00:32:06,580 causing 1175 00:32:06,580 --> 00:32:06,720 an 1176 00:32:06,720 --> 00:32:06,960 exception, 1177 00:32:07,320 --> 00:32:07,760 abnormal 1178 00:32:07,760 --> 00:32:08,140 or 1179 00:32:08,140 --> 00:32:08,420 normal 1180 00:32:08,420 --> 00:32:08,720 shutdown, 1181 00:32:09,060 --> 00:32:09,520 our 1182 00:32:09,520 --> 00:32:09,720 shell 1183 00:32:09,720 --> 00:32:10,060 code will 1184 00:32:10,060 --> 00:32:10,200 once 1185 00:32:10,200 --> 00:32:10,460 again be 1186 00:32:10,460 --> 00:32:10,740 called. 1187 00:32:12,600 --> 00:32:13,120 Okay, 1188 00:32:13,160 --> 00:32:13,880 so we 1189 00:32:13,880 --> 00:32:14,140 can place 1190 00:32:14,140 --> 00:32:14,460 our shell 1191 00:32:14,460 --> 00:32:14,860 code at 1192 00:32:14,860 --> 00:32:15,000 a known 1193 00:32:15,000 --> 00:32:15,260 location. 1194 00:32:15,720 --> 00:32:16,180 There are 1195 00:32:16,180 --> 00:32:16,620 multiple ways 1196 00:32:16,620 --> 00:32:16,880 of having 1197 00:32:16,880 --> 00:32:17,160 execution, 1198 00:32:17,500 --> 00:32:17,680 either 1199 00:32:17,680 --> 00:32:17,880 through 1200 00:32:17,880 --> 00:32:18,140 arbitrary 1201 00:32:18,140 --> 00:32:18,440 bite 1202 00:32:18,440 --> 00:32:18,980 writing or 1203 00:32:18,980 --> 00:32:19,500 callback 1204 00:32:19,500 --> 00:32:19,740 attacks. 1205 00:32:21,660 --> 00:32:22,180 There's 1206 00:32:22,180 --> 00:32:22,740 not much 1207 00:32:22,740 --> 00:32:23,140 more to 1208 00:32:23,140 --> 00:32:23,440 go. 1209 00:32:25,340 --> 00:32:26,120 Just like 1210 00:32:26,940 --> 00:32:27,560 any of 1211 00:32:27,560 --> 00:32:27,880 the numerous 1212 00:32:27,880 --> 00:32:28,180 security 1213 00:32:28,180 --> 00:32:28,640 vulnerabilities 1214 00:32:28,640 --> 00:32:29,160 that are 1215 00:32:40,200 --> 00:32:40,680 present 1216 00:32:40,680 --> 00:32:40,880 be 1217 00:32:40,880 --> 00:32:41,040 safe 1218 00:32:41,040 --> 00:32:41,360 from 1219 00:32:41,360 --> 00:32:41,760 exploitable 1220 00:32:41,760 --> 00:32:42,060 conditions. 1221 00:32:42,800 --> 00:32:43,560 So the 1222 00:32:43,560 --> 00:32:44,040 buffer 1223 00:32:44,040 --> 00:32:44,360 overflow 1224 00:32:44,360 --> 00:32:44,720 in 1225 00:32:44,720 --> 00:32:45,100 user 1226 00:32:45,100 --> 00:32:45,920 32 DLL 1227 00:32:45,920 --> 00:32:47,120 could be 1228 00:32:47,120 --> 00:32:47,320 caused 1229 00:32:47,320 --> 00:32:47,460 by 1230 00:32:47,460 --> 00:32:47,680 sending 1231 00:32:47,680 --> 00:32:47,800 a 1232 00:32:47,800 --> 00:32:48,020 large 1233 00:32:48,020 --> 00:32:48,700 directory name 1234 00:32:48,700 --> 00:32:49,040 to a 1235 00:32:49,040 --> 00:32:49,400 list box 1236 00:32:49,400 --> 00:32:49,780 through the 1237 00:32:49,780 --> 00:32:50,140 message. 1238 00:32:53,620 --> 00:32:54,400 So sending 1239 00:32:54,400 --> 00:32:54,800 this attack 1240 00:32:54,800 --> 00:32:55,520 against the 1241 00:32:55,520 --> 00:32:56,140 list box 1242 00:32:56,140 --> 00:32:56,340 with the 1243 00:32:56,340 --> 00:32:56,560 utility 1244 00:32:56,560 --> 00:32:56,980 manager 1245 00:32:57,660 --> 00:32:58,320 allowed an 1246 00:32:58,320 --> 00:32:58,780 attacker to 1247 00:32:58,780 --> 00:32:59,360 escape the 1248 00:32:59,360 --> 00:32:59,560 privilege. 1249 00:32:59,780 --> 00:33:00,260 You can get 1250 00:33:00,260 --> 00:33:00,440 root, 1251 00:33:00,540 --> 00:33:00,760 get your 1252 00:33:00,760 --> 00:33:01,060 system, 1253 00:33:01,160 --> 00:33:01,260 that's 1254 00:33:01,260 --> 00:33:01,440 cool. 1255 00:33:02,520 --> 00:33:02,920 So, 1256 00:33:05,560 --> 00:33:05,960 yeah, 1257 00:33:06,200 --> 00:33:06,400 I don't 1258 00:33:06,400 --> 00:33:06,580 know how 1259 00:33:06,580 --> 00:33:06,800 many of 1260 00:33:06,800 --> 00:33:07,000 you have 1261 00:33:07,000 --> 00:33:07,020 ever 1262 00:33:07,020 --> 00:33:07,260 read, 1263 00:33:07,800 --> 00:33:08,200 written, 1264 00:33:08,360 --> 00:33:09,060 if you've 1265 00:33:09,060 --> 00:33:09,640 read writing 1266 00:33:09,640 --> 00:33:10,240 secure code 1267 00:33:10,240 --> 00:33:10,800 from Microsoft, 1268 00:33:11,060 --> 00:33:11,420 which is 1269 00:33:12,140 --> 00:33:13,080 not too 1270 00:33:13,080 --> 00:33:13,300 bad, 1271 00:33:13,780 --> 00:33:14,520 includes a 1272 00:33:14,520 --> 00:33:14,920 couple of 1273 00:33:14,920 --> 00:33:15,520 paragraphs about 1274 00:33:15,520 --> 00:33:16,000 some dangerous 1275 00:33:16,000 --> 00:33:16,380 messages. 1276 00:33:17,320 --> 00:33:18,180 Michael Howard 1277 00:33:18,180 --> 00:33:20,020 stresses that 1278 00:33:20,020 --> 00:33:20,360 if you're 1279 00:33:20,360 --> 00:33:20,440 going to 1280 00:33:20,440 --> 00:33:20,740 use any 1281 00:33:20,740 --> 00:33:20,940 of these 1282 00:33:20,940 --> 00:33:21,360 messages, 1283 00:33:21,860 --> 00:33:22,460 that you 1284 00:33:22,460 --> 00:33:22,680 need to 1285 00:33:22,680 --> 00:33:23,040 send the 1286 00:33:23,040 --> 00:33:23,540 get text 1287 00:33:23,540 --> 00:33:24,440 or the 1288 00:33:24,440 --> 00:33:24,800 get length 1289 00:33:24,800 --> 00:33:25,160 messages, 1290 00:33:28,400 --> 00:33:28,880 the 1291 00:33:28,900 --> 00:33:29,600 What makes 1292 00:33:29,600 --> 00:33:30,120 these messages 1293 00:33:30,120 --> 00:33:31,040 stand out is 1294 00:33:31,040 --> 00:33:32,340 that there's 1295 00:33:32,340 --> 00:33:33,920 no way to 1296 00:33:33,920 --> 00:33:35,040 pass the 1297 00:33:35,040 --> 00:33:36,640 length to 1298 00:33:36,640 --> 00:33:37,880 restrict the 1299 00:33:37,880 --> 00:33:39,000 data, the 1300 00:33:39,000 --> 00:33:39,760 length of the 1301 00:33:39,760 --> 00:33:40,100 data that 1302 00:33:40,100 --> 00:33:40,400 you're getting 1303 00:33:40,400 --> 00:33:40,580 back. 1304 00:33:41,940 --> 00:33:42,440 That's all 1305 00:33:42,440 --> 00:33:43,480 cool, that's 1306 00:33:43,480 --> 00:33:43,900 good advice, 1307 00:33:44,080 --> 00:33:45,760 but as you 1308 00:33:45,760 --> 00:33:46,020 can see, 1309 00:33:46,120 --> 00:33:46,500 they're all 1310 00:33:46,500 --> 00:33:47,380 above WM 1311 00:33:47,380 --> 00:33:47,780 user anyway, 1312 00:33:47,960 --> 00:33:48,800 so most of 1313 00:33:48,800 --> 00:33:49,060 them can be 1314 00:33:49,060 --> 00:33:49,380 used for 1315 00:33:49,380 --> 00:33:49,680 arbitrary 1316 00:33:49,680 --> 00:33:50,200 byte writing. 1317 00:33:51,980 --> 00:33:52,760 So this 1318 00:33:52,760 --> 00:33:53,400 whole thing 1319 00:33:53,400 --> 00:33:53,820 about the 1320 00:33:53,820 --> 00:33:54,880 request the 1321 00:33:54,880 --> 00:33:55,140 length, 1322 00:33:55,420 --> 00:33:56,200 allocate your 1323 00:33:56,200 --> 00:33:56,440 buffer, 1324 00:33:56,620 --> 00:33:57,360 and then 1325 00:33:57,360 --> 00:33:58,020 request the 1326 00:33:58,020 --> 00:33:59,240 data, this is 1327 00:33:59,240 --> 00:33:59,820 just like race 1328 00:33:59,820 --> 00:34:00,380 condition stuff. 1329 00:34:02,160 --> 00:34:03,340 So if you 1330 00:34:03,340 --> 00:34:03,540 go into 1331 00:34:03,540 --> 00:34:04,040 lengths to 1332 00:34:04,040 --> 00:34:04,260 try and 1333 00:34:04,260 --> 00:34:04,640 protect your 1334 00:34:04,640 --> 00:34:05,000 applications, 1335 00:34:05,460 --> 00:34:06,240 you need to 1336 00:34:06,240 --> 00:34:06,880 be aware that 1337 00:34:07,780 --> 00:34:08,620 if you request 1338 00:34:08,620 --> 00:34:09,120 length and 1339 00:34:09,120 --> 00:34:09,720 then create a 1340 00:34:09,720 --> 00:34:10,040 buffer of 1341 00:34:10,040 --> 00:34:10,240 100, 1342 00:34:10,420 --> 00:34:10,880 it's too 1343 00:34:10,880 --> 00:34:11,320 late because 1344 00:34:11,320 --> 00:34:11,480 the 1345 00:34:11,480 --> 00:34:11,860 attack has 1346 00:34:11,860 --> 00:34:12,080 already 1347 00:34:12,080 --> 00:34:13,140 increased the 1348 00:34:13,140 --> 00:34:13,440 length of 1349 00:34:13,440 --> 00:34:13,480 the 1350 00:34:13,480 --> 00:34:13,980 text to 1351 00:34:13,980 --> 00:34:14,440 500. 1352 00:34:14,800 --> 00:34:15,380 If you 1353 00:34:15,380 --> 00:34:16,100 read that 1354 00:34:16,100 --> 00:34:16,620 through one of 1355 00:34:16,620 --> 00:34:16,780 those 1356 00:34:16,780 --> 00:34:17,080 messages, 1357 00:34:18,600 --> 00:34:19,560 you have 1358 00:34:19,560 --> 00:34:19,980 text book 1359 00:34:19,980 --> 00:34:20,180 buffer 1360 00:34:20,180 --> 00:34:20,480 overflow 1361 00:34:20,480 --> 00:34:20,760 stuff. 1362 00:34:30,120 --> 00:34:31,080 So spy 1363 00:34:31,080 --> 00:34:31,280 plus 1364 00:34:31,280 --> 00:34:31,520 plus, 1365 00:34:31,740 --> 00:34:31,820 which 1366 00:34:31,820 --> 00:34:32,360 comes with 1367 00:34:32,360 --> 00:34:32,800 Visual Studio, 1368 00:34:33,580 --> 00:34:34,060 that's 1369 00:34:34,060 --> 00:34:34,400 probably the 1370 00:34:34,400 --> 00:34:34,920 utility we've 1371 00:34:34,920 --> 00:34:35,160 used the 1372 00:34:35,160 --> 00:34:35,540 most during 1373 00:34:35,540 --> 00:34:35,980 our research. 1374 00:34:37,240 --> 00:34:37,920 It allows 1375 00:34:37,920 --> 00:34:38,160 you to 1376 00:34:38,160 --> 00:34:38,740 quickly list 1377 00:34:38,740 --> 00:34:39,220 all the 1378 00:34:39,220 --> 00:34:39,580 windows that 1379 00:34:39,580 --> 00:34:39,840 are open, 1380 00:34:40,140 --> 00:34:40,820 find out the 1381 00:34:40,820 --> 00:34:41,180 thread, the 1382 00:34:41,180 --> 00:34:41,720 process that 1383 00:34:41,720 --> 00:34:42,140 owns them, 1384 00:34:42,260 --> 00:34:42,860 and grab the 1385 00:34:42,860 --> 00:34:43,300 window handle. 1386 00:34:43,680 --> 00:34:44,640 It also shows 1387 00:34:44,640 --> 00:34:44,900 you a few 1388 00:34:44,900 --> 00:34:46,220 various window 1389 00:34:46,220 --> 00:34:46,580 properties, 1390 00:34:47,360 --> 00:34:48,000 which are 1391 00:34:48,000 --> 00:34:49,100 starting to get 1392 00:34:49,100 --> 00:34:49,500 interesting. 1393 00:34:50,080 --> 00:34:50,860 This whole 1394 00:34:50,860 --> 00:34:51,300 thing about 1395 00:34:51,300 --> 00:34:51,780 how you 1396 00:34:51,780 --> 00:34:55,240 can look at 1397 00:34:55,240 --> 00:34:55,520 a window 1398 00:34:55,520 --> 00:34:56,440 that any 1399 00:34:56,440 --> 00:34:56,760 application 1400 00:34:56,760 --> 00:34:57,500 owns and 1401 00:34:57,500 --> 00:34:57,980 start 1402 00:34:58,560 --> 00:34:59,080 discovering 1403 00:34:59,080 --> 00:34:59,640 stuff about 1404 00:34:59,640 --> 00:35:00,400 it, that 1405 00:35:00,400 --> 00:35:00,900 just sounds 1406 00:35:00,900 --> 00:35:01,420 wrong already. 1407 00:35:01,760 --> 00:35:02,920 So there's a 1408 00:35:02,920 --> 00:35:03,240 lot of stuff 1409 00:35:03,240 --> 00:35:03,620 there to look 1410 00:35:03,620 --> 00:35:04,800 at, but 1411 00:35:06,420 --> 00:35:07,000 someone just 1412 00:35:07,000 --> 00:35:07,320 needs to look 1413 00:35:07,320 --> 00:35:07,580 at it. 1414 00:35:07,840 --> 00:35:10,000 So on 1415 00:35:10,000 --> 00:35:10,780 Windows 2000, 1416 00:35:11,120 --> 00:35:11,560 the task 1417 00:35:11,560 --> 00:35:12,320 manager doesn't 1418 00:35:12,320 --> 00:35:13,080 show you what 1419 00:35:13,540 --> 00:35:14,220 user the 1420 00:35:14,220 --> 00:35:14,540 app is 1421 00:35:14,540 --> 00:35:14,960 running under. 1422 00:35:15,700 --> 00:35:16,360 But if it's 1423 00:35:16,360 --> 00:35:16,660 running under 1424 00:35:16,660 --> 00:35:17,140 system, you 1425 00:35:17,140 --> 00:35:17,580 can't close 1426 00:35:17,580 --> 00:35:17,780 it. 1427 00:35:19,240 --> 00:35:20,300 Under Windows XP, 1428 00:35:20,460 --> 00:35:20,800 of course, 1429 00:35:20,920 --> 00:35:21,440 it does 1430 00:35:24,520 --> 00:35:25,400 show you 1431 00:35:26,220 --> 00:35:26,660 the 1432 00:35:26,660 --> 00:35:26,880 user 1433 00:35:26,880 --> 00:35:27,000 the 1434 00:35:27,000 --> 00:35:28,100 application is 1435 00:35:30,400 --> 00:35:30,660 sort by 1436 00:35:30,660 --> 00:35:31,000 user. 1437 00:35:31,600 --> 00:35:32,340 There's still 1438 00:35:32,340 --> 00:35:33,660 a dozen 1439 00:35:34,920 --> 00:35:35,720 service-level 1440 00:35:35,720 --> 00:35:35,980 apps. 1441 00:35:37,560 --> 00:35:38,940 So once a 1442 00:35:38,940 --> 00:35:39,400 target window 1443 00:35:39,400 --> 00:35:39,800 has been 1444 00:35:39,800 --> 00:35:41,040 acquired, you 1445 00:35:41,040 --> 00:35:41,440 can run a 1446 00:35:41,440 --> 00:35:41,780 message 1447 00:35:41,780 --> 00:35:42,320 fuzzer against 1448 00:35:42,320 --> 00:35:42,520 it. 1449 00:35:42,620 --> 00:35:43,040 A message 1450 00:35:43,040 --> 00:35:43,680 fuzzer is 1451 00:35:43,680 --> 00:35:44,420 just like any 1452 00:35:44,420 --> 00:35:44,820 other type of 1453 00:35:44,820 --> 00:35:45,060 fuzzer. 1454 00:35:46,680 --> 00:35:47,780 It should be 1455 00:35:47,780 --> 00:35:49,120 on the CD or 1456 00:35:49,120 --> 00:35:49,880 on the website. 1457 00:35:50,100 --> 00:35:50,180 There's a 1458 00:35:50,180 --> 00:35:50,420 whole lot of 1459 00:35:50,420 --> 00:35:50,660 code. 1460 00:35:52,220 --> 00:35:52,820 So it 1461 00:35:52,820 --> 00:35:53,460 iterates 1462 00:35:53,460 --> 00:35:53,700 through a 1463 00:35:53,700 --> 00:35:54,020 range of 1464 00:35:54,020 --> 00:35:54,360 messages, 1465 00:36:00,400 --> 00:36:00,520 one, 1466 00:36:00,520 --> 00:36:00,760 one, 1467 00:36:00,760 --> 00:36:00,920 one, 1468 00:36:01,080 --> 00:36:01,140 one, 1469 00:36:01,140 --> 00:36:01,220 one, 1470 00:36:01,360 --> 00:36:01,820 And 1471 00:36:01,820 --> 00:36:02,540 it's 1472 00:36:04,540 --> 00:36:05,260 really quite 1473 00:36:05,260 --> 00:36:05,580 interesting 1474 00:36:05,580 --> 00:36:07,200 because you 1475 00:36:07,200 --> 00:36:07,480 can kill 1476 00:36:07,480 --> 00:36:07,800 anything. 1477 00:36:08,240 --> 00:36:09,180 Every application 1478 00:36:09,180 --> 00:36:09,740 is vulnerable 1479 00:36:09,740 --> 00:36:10,120 to a 1480 00:36:10,120 --> 00:36:10,620 message fuzzer. 1481 00:36:10,620 --> 00:36:10,800 You just 1482 00:36:10,800 --> 00:36:11,220 run it and 1483 00:36:11,220 --> 00:36:11,620 things start 1484 00:36:11,620 --> 00:36:11,960 dying. 1485 00:36:13,820 --> 00:36:14,740 Now, if 1486 00:36:14,740 --> 00:36:15,540 you do 1487 00:36:15,540 --> 00:36:15,840 want to 1488 00:36:15,840 --> 00:36:16,180 write a 1489 00:36:28,260 --> 00:36:28,720 fuzzer, 1490 00:36:28,720 --> 00:36:33,500 messages because it's shut down. And also your fuzzer might send messages that cause 1491 00:36:33,500 --> 00:36:39,340 local exceptions. If you send WM set text with one as the parameter, well, it's not 1492 00:36:39,340 --> 00:36:47,860 going anywhere. And check the event log. The MSO 3045, I think it was, we ran the fuzzer 1493 00:36:47,860 --> 00:36:52,200 against the list box on utility manager and it was like, oh, wait, man, utility manager 1494 00:36:52,200 --> 00:36:56,160 died? What's happening? And we couldn't work it out. Have a look at the event log. It's 1495 00:36:56,160 --> 00:37:00,540 like crash, crash, crash, crash. Sweet. So you've got to sit your bugger on it and start 1496 00:37:00,540 --> 00:37:02,660 reverse engineering. What's going on? Have a look at it. 1497 00:37:06,500 --> 00:37:16,240 So it's kind of what we did here to exploit the WinHelp 32. I think, yeah. Okay, so I 1498 00:37:16,240 --> 00:37:22,740 haven't got notes on this, so I'm going to try. What happened is we realized that the 1499 00:37:24,760 --> 00:37:26,140 context-sensitive help from utility manager, the context-sensitive help from utility manager 1500 00:37:26,160 --> 00:37:33,640 was that tooltip that pops up. It's actually WinHelp 32. And that's what task manager is. 1501 00:37:34,020 --> 00:37:39,100 We could see that it was WinHelp 32 has now been loaded as system. It's like, oh, great. 1502 00:37:39,240 --> 00:37:43,440 So what it is, it's like another attack avenue. We've got another app that's running a system 1503 00:37:43,440 --> 00:37:47,900 that shouldn't be. So we ran a fuzzer against it, just passing one. Oh, we found this message. 1504 00:37:48,240 --> 00:37:56,140 We passed one as the parameter. So, yeah. So what you can see is, you can see that it's 1505 00:37:56,160 --> 00:38:06,160 running. It calls an exception. Pretty basic stuff. Trying to access a four. Jesus. Which 1506 00:38:06,160 --> 00:38:10,460 is like EDI plus three. So that's cool. It's like we passed this message and we control 1507 00:38:10,460 --> 00:38:16,820 EDI. But EDI didn't get your execution. So what we did, we wrote a whole block of ones 1508 00:38:16,820 --> 00:38:24,520 up in the PEB and we updated EDI to point to our block of ones. And then we continued 1509 00:38:24,520 --> 00:38:24,900 running. 1510 00:38:26,160 --> 00:38:30,000 And then we got another exception. And this time, we got the registers over there. And 1511 00:38:30,000 --> 00:38:34,560 you see ESI points to 11111. So it's like, oh, we're cool, man. We loaded ESI with the 1512 00:38:34,560 --> 00:38:38,820 value from our block of data that we pointed EDI to and we control EDI. So in theory, we 1513 00:38:38,820 --> 00:38:45,960 control ESI. But it still doesn't help us. So what we then did is we updated ESI to point 1514 00:38:45,960 --> 00:38:50,340 to our block of ones again and continued running. And as you can see in the call stack down 1515 00:38:50,340 --> 00:38:56,140 there, execution ended up at 11111. And it's like, aha. So we control EDI. And then we 1516 00:38:56,160 --> 00:38:59,060 さ property . And through that, we control ESI. And through that, we now control EIP. 1517 00:39:01,180 --> 00:39:08,160 So right. So, what we—what we try to craft is it's a callback attack using undocumented 1518 00:39:08,160 --> 00:39:09,760 message against an application. 1519 00:39:11,780 --> 00:39:18,580 Yeah. So what we had to do is create an exploit structure consisting of a block of pointers 1520 00:39:19,500 --> 00:39:25,480 pointing to another block of pointers, pointing to the shell code. And we get that up in the 1521 00:39:25,480 --> 00:39:30,620 the process map to heap, find out where it was, send a message passing the address of 1522 00:39:30,620 --> 00:39:37,440 our structure, so we're sending EDI to the address of our pointer 1 block, which would 1523 00:39:37,440 --> 00:39:42,080 be accepted, great, and then it would show the previous slides, ESI would then be loaded 1524 00:39:42,080 --> 00:39:47,760 with the address of the pointer 2 block, and then as before when it does the call ESI plus 1525 00:39:47,760 --> 00:39:51,060 36, it loads the address of the shellcode, the shellcode is executed. 1526 00:39:51,060 --> 00:39:58,100 That was great, Cesar Ceruto, he does really cool stuff on following up with this, and 1527 00:39:58,100 --> 00:40:02,900 he's found this much easier, you just need a WM command help message, but we thought 1528 00:40:02,900 --> 00:40:09,920 this was, it was kind of strange because what we were trying to do was find new stuff, yeah, 1529 00:40:10,980 --> 00:40:16,180 and this is like undocumented messages against applications, so that's what I'm really trying 1530 00:40:16,180 --> 00:40:20,300 to say here is like there's more messages out there than just the ones that are in the 1531 00:40:21,060 --> 00:40:28,800 library, every application can have its own custom messages, and of course this opens 1532 00:40:28,800 --> 00:40:42,200 up the avenues for more and more and more attacks, okay, all right, so another thing 1533 00:40:42,200 --> 00:40:49,760 that programmers or hackers, all of us, need to be aware of is default behavior that some 1534 00:40:49,760 --> 00:40:50,380 controls exhibit. 1535 00:40:50,580 --> 00:40:51,040 Okay. 1536 00:40:59,800 --> 00:41:03,360 So you've got things like the list box and the combo box, for example, I mean, I like 1537 00:41:03,360 --> 00:41:08,420 utility manager, I mean, Microsoft are finally one day going to kill it, but by default, 1538 00:41:08,560 --> 00:41:13,480 the LB do and the CB do message can be used to display a directory listing, so what we've 1539 00:41:13,480 --> 00:41:17,680 got here is got the list box of utility manager, I mean, we've sent messages to resize it, 1540 00:41:17,680 --> 00:41:23,100 so that's cool, but we've got sender and LB do, and we can read any directory as system, 1541 00:41:24,060 --> 00:41:30,180 whoopee, you know, but it's things to be aware of that that's a list box that we can use 1542 00:41:30,180 --> 00:41:31,840 to view any directory. 1543 00:41:32,460 --> 00:41:35,940 What about when you get stuff that you can like load files, so you're like loading files 1544 00:41:35,940 --> 00:41:36,440 as system? 1545 00:41:38,140 --> 00:41:38,500 Okay. 1546 00:41:39,880 --> 00:41:43,540 So you've got like system apps that display an about screen with a hyperlink, you know, 1547 00:41:43,540 --> 00:41:46,760 come to our website, they might load the browser as system. 1548 00:41:47,300 --> 00:41:47,660 Okay. 1549 00:41:47,680 --> 00:41:49,340 Because then you can browse local drive. 1550 00:41:50,420 --> 00:41:54,140 Right mouse clip, open with command XE, you've got a system-level shell again. 1551 00:41:57,220 --> 00:42:03,140 Any system application that allows you to load files, right mouse clip, open with, 1552 00:42:03,300 --> 00:42:03,580 blah, blah. 1553 00:42:03,920 --> 00:42:04,360 Okay. 1554 00:42:04,380 --> 00:42:11,940 We've got ‑‑ we tested one recently, and they tried to avoid this problem by using 1555 00:42:11,940 --> 00:42:16,700 the older file dialog type box, which is the one down the bottom left there, but guess 1556 00:42:16,700 --> 00:42:16,900 what? 1557 00:42:17,020 --> 00:42:20,040 You know, your right mouse clip has got what's this, that's a tooltip, that's one help 32, 1558 00:42:20,240 --> 00:42:22,120 loaded as system again, exploit it. 1559 00:42:24,000 --> 00:42:27,780 So I don't know if you guys are ‑‑ any of you do write system-level applications 1560 00:42:27,780 --> 00:42:30,880 you want to protect, but these are some of the things that you may want to be aware of 1561 00:42:30,880 --> 00:42:34,220 that there's more to this stuff than what meets the eye. 1562 00:42:34,400 --> 00:42:39,040 There's a lot of stuff in the background that just happens by default. 1563 00:42:40,260 --> 00:42:46,880 And like I said before, Cesar Ceruto, I mean, we talked about it, but ‑‑ what was his 1564 00:42:46,880 --> 00:42:57,460 latest exploit that he put out, it's pretty much any system-level app that has a context-sensitive 1565 00:42:57,460 --> 00:43:00,280 help, you can send this exploit against it, give you a command shell. 1566 00:43:05,360 --> 00:43:06,540 I had something but I forgot. 1567 00:43:06,960 --> 00:43:07,740 What was it? 1568 00:43:09,480 --> 00:43:10,780 Anyway, we'll keep going. 1569 00:43:11,820 --> 00:43:12,300 Okay. 1570 00:43:12,300 --> 00:43:12,480 Okay. 1571 00:43:18,260 --> 00:43:25,840 So what happened, just a bit of history on that problem is, you know, like I said before, 1572 00:43:25,940 --> 00:43:29,860 we discovered that utility manager was loading one help 32 as system, it could be exploited, 1573 00:43:30,220 --> 00:43:34,700 Microsoft patched that, but all they did was they removed the question mark button, I mean, 1574 00:43:34,740 --> 00:43:38,200 they forgot about this default behavior. 1575 00:43:39,020 --> 00:43:42,220 All forms will accept a W command help message. 1576 00:43:42,260 --> 00:43:42,460 Okay. 1577 00:43:42,480 --> 00:43:50,420 And give you tooltips help, if there's a help file set up when you compile your application, 1578 00:43:50,940 --> 00:43:54,100 I mean, because Microsoft just removed the question mark, it's like, yeah, we'll just 1579 00:43:54,100 --> 00:43:54,500 hide it. 1580 00:43:54,680 --> 00:43:57,500 And I mean, it took him like 20 seconds to re‑break it. 1581 00:43:58,540 --> 00:44:03,860 But what was kind of interesting about his thing was that, first of all, you had to send 1582 00:44:03,860 --> 00:44:08,420 a ‑‑ I can't remember exactly what it is, but it's just a message to pop up the 1583 00:44:08,420 --> 00:44:12,020 system menu, you know, like right click on the control button. 1584 00:44:12,020 --> 00:44:12,600 Control bar. 1585 00:44:13,860 --> 00:44:15,460 But you had to like post message that. 1586 00:44:15,960 --> 00:44:18,500 And then send message the W command help. 1587 00:44:19,120 --> 00:44:20,340 So that's something else. 1588 00:44:20,440 --> 00:44:23,620 I mean, if you're running fuzzers and whatnot, you've got to be aware that, mate, different 1589 00:44:27,000 --> 00:44:30,180 messages will have different effects maybe used in conjunction. 1590 00:44:30,740 --> 00:44:31,100 Okay. 1591 00:44:32,500 --> 00:44:33,040 All right. 1592 00:44:35,720 --> 00:44:36,080 Okay. 1593 00:44:36,180 --> 00:44:39,260 So where are we going to go with these GUI-based attacks, right? 1594 00:44:39,300 --> 00:44:40,200 The scope is going to widen. 1595 00:44:40,500 --> 00:44:42,000 The attacks will ‑‑ they will become public. 1596 00:44:42,020 --> 00:44:45,240 They will no longer depend on these controls and messages. 1597 00:44:46,560 --> 00:44:51,060 Exploits, they'll focus on the APIs that can be used to manipulate GDI data, not just Windows 1598 00:44:51,060 --> 00:44:51,420 messages. 1599 00:44:53,260 --> 00:44:56,920 We've done some research into the cross‑wind station desktop tech, you know, if you've 1600 00:44:56,920 --> 00:44:59,460 got an IOM user shell, can you get system? 1601 00:44:59,560 --> 00:45:00,420 So far, not. 1602 00:45:00,660 --> 00:45:03,560 We're running out of time, and that's kind of boring. 1603 00:45:04,960 --> 00:45:05,440 Okay. 1604 00:45:05,540 --> 00:45:10,020 So we looked at these other APIs, these other manipulation ones. 1605 00:45:11,520 --> 00:45:12,000 Okay. 1606 00:45:15,020 --> 00:45:16,100 Oh, you can read. 1607 00:45:16,800 --> 00:45:16,860 Sorry. 1608 00:45:19,060 --> 00:45:22,620 MSDN states, you know, the set parent, the new parent in the child window must belong 1609 00:45:22,620 --> 00:45:23,340 to the same application. 1610 00:45:24,360 --> 00:45:25,120 That's not right. 1611 00:45:25,300 --> 00:45:28,680 You know, any application become ‑‑ can set the parent of any other window. 1612 00:45:28,800 --> 00:45:33,300 Now, like I said before, you know, we haven't been able to exploit this against a system‑level 1613 00:45:33,300 --> 00:45:33,720 app yet. 1614 00:45:33,840 --> 00:45:38,240 We haven't been able to exploit it against just apps running, you know, our test apps, 1615 00:45:38,380 --> 00:45:39,780 and normal apps running on our desktop. 1616 00:45:41,180 --> 00:45:41,980 But, yeah. 1617 00:45:42,000 --> 00:45:43,200 This is the theory. 1618 00:45:43,480 --> 00:45:47,560 You know, the exploit becomes the parent, the window or the application, requests the 1619 00:45:47,560 --> 00:45:50,140 parent through a get parent, and then asks the parent for some data. 1620 00:45:50,380 --> 00:45:54,180 So the exploit just returns corrupt data, causing exploitable conditions. 1621 00:45:56,080 --> 00:45:56,760 All right. 1622 00:45:58,480 --> 00:46:03,560 So Windows properties, yeah, I mean, every window can store a whole list of data that's 1623 00:46:03,560 --> 00:46:04,180 relevant to itself. 1624 00:46:04,840 --> 00:46:09,800 I've got an example, it's like an MDI application might store a unique ID associated with each 1625 00:46:09,800 --> 00:46:10,080 window. 1626 00:46:10,080 --> 00:46:11,820 That's a link back into the database. 1627 00:46:12,440 --> 00:46:13,820 See our get prop and set prop. 1628 00:46:14,100 --> 00:46:15,060 Now, it's the same problem. 1629 00:46:15,180 --> 00:46:23,940 Any application can get and set ‑‑ can get and set the properties of any other application's 1630 00:46:23,940 --> 00:46:24,080 window. 1631 00:46:25,300 --> 00:46:30,280 So we weren't able to exploit this against any core Windows OS services in our one week 1632 00:46:30,280 --> 00:46:34,640 of testing before we came here, but the first third‑party application we tested was vulnerable. 1633 00:46:35,720 --> 00:46:40,060 As can be seen here, Windows subclasses, all non‑FC‑derived Windows, to have a 1634 00:46:40,080 --> 00:46:43,500 command or specific activation issues, again, it stores it in a window prop, we can overwrite 1635 00:46:43,500 --> 00:46:46,440 the window prop, and it's chained because it's the subclass thing. 1636 00:46:46,800 --> 00:46:50,040 So we simply overwrite the window prop with the address of our shell code, which is in 1637 00:46:50,040 --> 00:46:52,460 the process map tape, and once again we're getting control. 1638 00:46:52,800 --> 00:46:58,460 And this is like through a non‑message‑based GUI attack, or shatter attack, or whatever 1639 00:46:58,460 --> 00:47:00,520 the name's going to end up being. 1640 00:47:02,420 --> 00:47:03,860 So we've got some thoughts on protection. 1641 00:47:04,720 --> 00:47:07,840 You know, there's been discussions about, you know, filter messages, only allow some, 1642 00:47:08,020 --> 00:47:08,700 don't allow others. 1643 00:47:09,060 --> 00:47:10,020 It's not just messages. 1644 00:47:10,560 --> 00:47:15,060 You know, I mean, these things are going to expand, hopefully, you know, I want people 1645 00:47:15,060 --> 00:47:16,360 to go out there and look for stuff. 1646 00:47:16,520 --> 00:47:19,840 It's like, it's not just this, man, it's now this, that, that. 1647 00:47:20,020 --> 00:47:22,360 So there's a lot of stuff out there to look for. 1648 00:47:23,500 --> 00:47:25,820 Windows shouldn't be created with prior privileges, blah, blah, blah. 1649 00:47:26,860 --> 00:47:27,740 Application to find messages. 1650 00:47:27,880 --> 00:47:30,780 If you write your own application that uses custom messages, can they be exploited? 1651 00:47:33,600 --> 00:47:37,820 MSDN, again, service should talk to GUI using RPC, sockets, name pipes. 1652 00:47:38,160 --> 00:47:38,680 That'll be fine. 1653 00:47:38,700 --> 00:47:41,180 All right, and we've got a registry sitting here. 1654 00:47:41,360 --> 00:47:43,560 You can turn off interactive services. 1655 00:47:44,000 --> 00:47:47,400 Yeah, I thought, I mean, I found this, I had to fill in some slides before I came here, 1656 00:47:47,540 --> 00:47:51,760 and I thought it was, it was kind of a cool way, you know, you turn this registry setting 1657 00:47:51,760 --> 00:47:56,660 off, and what happens is you now have services popping up error boxes with system‑level 1658 00:47:57,260 --> 00:47:57,620 access. 1659 00:47:57,860 --> 00:47:59,500 I mean, what's the point in that? 1660 00:48:00,540 --> 00:48:05,540 And understanding the threat, the problem, getting out there and finding some stuff. 1661 00:48:06,900 --> 00:48:07,360 That's it. 1662 00:48:07,360 --> 00:48:08,580 Okay. 1663 00:48:13,340 --> 00:48:14,540 Sorry. 1664 00:48:14,700 --> 00:48:16,880 Are there any questions? 1665 00:48:18,220 --> 00:48:19,420 Okay. 1666 00:48:20,640 --> 00:48:21,920 Are there any questions? 1667 00:48:21,920 --> 00:48:22,180 That's it. 1668 00:48:22,260 --> 00:48:23,460 Okay. 1669 00:48:23,520 --> 00:48:25,540 So we've got time for questions and we'll be continue on. 1670 00:48:25,540 --> 00:48:26,400 One more question. 1671 00:48:26,400 --> 00:48:34,360 One more question. 1672 00:48:36,860 --> 00:48:36,980 Where are you going to go next? 1673 00:48:37,280 --> 00:48:37,340 Okay. 1674 00:48:42,580 --> 00:48:43,980 Thank you. 1675 00:49:19,080 --> 00:49:20,480 .