Child-Application Attacks

If you use the Shell statement or some other mechanism to dynamically load other applications (child applications) at run time, you need to take defensive measures to prevent unwanted applications from being loaded and executed. For example, if you’re attempting to run an application where the path to the application contains spaces such as ‘C:PROGRAM FILESMyApplicationMyApp.Exe’ or ‘C:DOCUMENTS and SETTINGSMySubApplicationSubApp.Exe’, your application could end up loading any application that matches a portion of the path. This is similar to how you could inadvertently open a file in an unexpected location if the path is not in canonical form, as you learned earlier. If an application named C:PROGRAM.EXE exists, the following Shell statement would inadvertently execute it:

Shell("C:PROGRAM FILESMyApplicationMyApp.Exe")

The reason this happens is that the space separating PROGRAM from FILES leaves the path statement open to interpretation. If Windows is presented a path such as this, its lookup strategy for that path is as follows:

  1. Take the name preceding the space (C:PROGRAM), and check for a program named C:PROGRAM.EXE and pass FILEMyApplicationMyApp.Exe as a command-line parameter to PROGRAM.EXE.

  2. Proceed to the next space in the path, and check whether there is an executable associated with the name preceding the space (as in the previous step).

  3. Repeat the previous step until the end of the string is reached and no executable programs are found.

  4. If the end of the string is reached, attempt to execute the full path and file name given—in this case, "C:PROGRAM FILESMyApplicationMyApp.Exe".

If an attacker could install a program named C:PROGRAM.EXE on your computer, the program would lay dormant until you ran your Visual Basic .NET application (and the Shell statement contained within it). When the Shell statement executed, C:PROGRAM.EXE would spring to life, unleashing whatever ill will the (PROGRAM.EXE) program’s author had in mind.

Note

The amount of damage the attacker’s application can unleash in this situation is dependent on the privileges your logged-on user account has. For example, if you are logged on as the system administrator, the attacker’s application could do extensive damage to the system. If you are logged on using a local user account, the potential for damage might be much less, depending on the operating system and configuration settings. See Chapter 11 for more information on changing configuration settings to adopt a least-privilege approach by giving yourself no more permissions than you need.

Defensive Technique for Child-Application Attacks

The following defensive technique can be used to prevent a child-application attack.

Use Quotes Around All Path Names

To prevent the path from being subject to interpretation, put double quotes around all path and file names. For example, the Shell statement shown previously should be changed to:

Shell("""C:PROGRAM FILESMyApplicationMyApp.Exe""")

With double quotes surrounding the filename, the Shell statement (and Windows) will be left to interpret the path and file name one way, as "C:PROGRAM FILESMyApplicationMyApp.Exe", avoiding the execution of other applications along the way.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.72.162