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