Fun With Http Handlers - Miguel A. Castro

1,643 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,643
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
26
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • MGB 2003 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • Fun With Http Handlers - Miguel A. Castro

    1. 1. FUN WITH HTTP HANDLERS Miguel A. Castro [email_address]
    2. 2. <ul><li>.NET Architect, Developer, & Trainer </li></ul><ul><li>Microsoft MVP </li></ul><ul><li>ASP Insider </li></ul><ul><li>Member of the INETA Speakers Bureau </li></ul><ul><li>Conference Speaker </li></ul><ul><li>Creator of CodeBreeze </li></ul><ul><li>In IT business since 1986 </li></ul>ineta
    3. 3. Agenda <ul><li>Identifying the Problem </li></ul><ul><li>Methods of securing </li></ul><ul><li>Setting up a Bulletproof Technique </li></ul><ul><li>More about Handlers </li></ul><ul><li>Summary </li></ul>
    4. 4. Identifying The Problem <ul><li>Reasons: </li></ul><ul><ul><li>User has not purchased your product </li></ul></ul><ul><ul><li>You want to track downloads (even on freeware) </li></ul></ul><ul><ul><li>You want to hide file locations on your site </li></ul></ul>Require the ability to prevent unauthorized downloading of files from your web site.
    5. 5. Common Protection <ul><li>Zip-file Password Protection </li></ul><ul><ul><li>Zip file can be spread but cannot be unlocked </li></ul></ul><ul><ul><li>If password gets out, you’re SOL </li></ul></ul><ul><li>Emails </li></ul><ul><ul><li>Sending user file link in an email </li></ul></ul><ul><ul><li>Provide download for limited time </li></ul></ul><ul><ul><li>Insufficient for client account with download list </li></ul></ul><ul><ul><li>Usually accompanied by a temporary file name </li></ul></ul>
    6. 6. Common Protection <ul><li>Temporary / Cryptic File Names </li></ul><ul><ul><li>Usually GUID-based </li></ul></ul><ul><ul><li>Sometimes cryptic URLs are used, then rewritten </li></ul></ul><ul><ul><li>Usually accompanied by a download time limitation </li></ul></ul>
    7. 7. <ul><li>All of these are Crackable or Abusable </li></ul>
    8. 8. ASP.NET’s Request Line (brief) Browser makes request (may also be made from within a page) Requested extension is located in registered extensions in IIS Appropriate DLL handles the file Default.aspx *.aspx, *.asmx, *.ashx, *.html, *.config, etc. aspnet_isapi.dll ASP.NET Extension is located in <httpHandlers> section of the Config file chain. The proper handler is loaded and request is sent into it for processing. Processing result may be sent to browser (html) or rerouted elsewhere. During the Pipeline Processing
    9. 9. <ul><li>Show IIS Configuration and machine.config HTTP Handlers </li></ul>
    10. 10. Bulletproof Technique (step 1) <ul><li>Add “zip” extension to IIS for specified application. </li></ul><ul><ul><li>Will cause all “zip” files to be routed through standard ASP.NET channels where they can be dealt with under controlled environment. </li></ul></ul>
    11. 11. IIS6 Registration
    12. 12. IIS6 Registration
    13. 13. IIS7 Registration
    14. 14. IIS7 Registration
    15. 15. IIS7 Registration Note: IIS 7 stores its registrations in the <system.webServer> section of appropriate config file.
    16. 16. Bulletproof Technique (step 2) <ul><li>Develop HTTP Handler that simply redirects to an “Access Denied” page. </li></ul><ul><li>Install handler in web.config and assign it to any *.zip path. </li></ul><ul><ul><li>Will cause all direct navigation to zip files to be denied. </li></ul></ul><ul><ul><li>*.config extensions use this technique with System.Web.HttpForbiddenHandler </li></ul></ul>
    17. 17. ASHX Files <ul><li>Navigating to an ASPX file causes the PageHandlerFactory class to invoke a “Page” handler and start the events in the page lifecycle. </li></ul><ul><li>ASHX files are HTTP Handlers exposed as direct ASP.NET navigation points. </li></ul><ul><ul><li>They are intercepted by the SimpleHandlerFactory class. </li></ul></ul>
    18. 18. Bulletproof Technique (step 3) <ul><li>Develop ASHX handler to be used to download files. </li></ul><ul><ul><li>Receive product ID in query string variable. </li></ul></ul><ul><ul><li>Confirm authenticated user. </li></ul></ul><ul><ul><li>Check user products for product requested. </li></ul></ul><ul><ul><li>Download product by streaming the file. </li></ul></ul><ul><ul><ul><li>Cannot redirect to it because of previous security. </li></ul></ul></ul>
    19. 19. Other Uses For Handlers <ul><li>URL Rewriting </li></ul><ul><ul><li>A must for good search engine incorporation </li></ul></ul><ul><ul><li>ASP.NET 4.0 includes routing engine </li></ul></ul><ul><li>Image Watermarking </li></ul><ul><ul><li>Intercepting all images and embedding watermark </li></ul></ul><ul><li>RSS Syndication </li></ul><ul><li>ASHX useful in image paths for resource extraction </li></ul>
    20. 20. More About Handlers <ul><li>Handler Factories </li></ul><ul><ul><li>IHttpHandlerFactory interface </li></ul></ul><ul><ul><ul><li>Can serve different handlers based on conditioning. </li></ul></ul></ul><ul><ul><ul><li>Installs in config EXACTLY the same as a handler. </li></ul></ul></ul><ul><li>Asynchronous Handlers </li></ul><ul><ul><li>IHttpAsyncHandler interface </li></ul></ul><ul><ul><li>Uses familiar Begin/End pattern for asynchronous processing. </li></ul></ul>
    21. 21. Summary <ul><li>Secure technique against unauthorized file downloading. </li></ul><ul><li>Can be combined with additional techniques. </li></ul><ul><li>Lets you track downloads, even if they’re free. </li></ul><ul><li>Handlers are a great tool for intercepting requests for advanced manipulation. </li></ul><ul><li>IIS7’s a pain-in-the-butt. </li></ul>
    22. 22. <ul><li>Programming Microsoft ASP.NET {and} Advanced Topics </li></ul><ul><ul><li>Dino Esposito – Microsoft Press </li></ul></ul><ul><li>Essential ASP.NET 2.0 </li></ul><ul><ul><li>Fritz Onion – Addison-Wesley </li></ul></ul><ul><li>ASP.NET Architecture </li></ul><ul><ul><li>http://www.code-magazine.com/Article.aspx?quickid=0511061 </li></ul></ul><ul><ul><li>Rick Strahl, et.al. – CoDe Magazine </li></ul></ul>

    ×