Question

Directory Security issue in IIS using .asp pages

Asked by: gormly

I need some help with security.

I have a website that stores all invoices in a virtual invoice folder.
Usuers cannot browse the invoices but they can substitute a number and see an invoice not meant for them.

I need to fix this and I am not sure how.

Current;y users log in on the website with a user/pass and that is checked against an access database, they are shown data that belongs to them.  When they want to view an invoice, they click on a link and that lionk spawns a script that resides on the server that checks to see if the invoice they are requesting belongs to them.

The link is something like this:

www.mysite.com/getinvoice.asp?INV=999999.pdf

However, if they type
www.mysite.com/invoices/999998.pdf
they will get the invoice that doesn't belong to them regardless.

I also have to send out notices that tell members that they have new invoices and I have tio list them like so:
www.mysite.com/invoices/999997.pdf
www.mysite.com/invoices/999998.pdf
www.mysite.com/invoices/999999.pdf

that aslo can be "hacked" to show any invoice.

How can I secure this so that they are :
1. Required to go to my login page at least once during the session
2. Denied access to other invoices.

I have a script that checks for that but I do not know how to get it to fire when someone has a direct address.

HELP!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-08-09 at 12:02:40ID22752988
Topics

Web Development

,

Miscellaneous Security

,

Visual Basic Programming

Participating Experts
1
Points
125
Comments
26

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Beginner's java inv prog.
    Hello, Need help with simple program Invoice.java and (Inv.java) - written to display a few items in an invoice and their price, quatity and total cost. I had to create 2 classes. Inv.java pasted below Invoice.java Why won't it compile? Thanks! Lee //Programmer: Lee Ware...
  2. invoice
    Some how i can't get this to compile. Please Help public class Invoice { public static void main(String[] args) { System.out.println("Mo2luv cleaning Crews"); System.out.println("5001 College St"); System.out.println("Easygoing, NSW 2653"); Syst...
  3. HTML an Invoice
    I am trying to Email an invoice after an order has been completed. The invoice is pretty deataled HTML layout. How do I take the Page that displaces the invoice and shove that into the body of an email. I can send the emails already just can't get the html into the Message. I...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: PaulHewsPosted on 2007-08-09 at 12:36:04ID: 19665192

>Current;y users log in on the website with a user/pass and that is checked against an access database

If users log in using windows domain usernames (turn off anonymous access in IIS, and use Basic Authentication with SSL over the Internet or Integrated Windows Authentication on your local network) then you can use Windows NTFS permissions on separate files or folders to control who has access to what.

The other way is to restrict access to the files and only allow download through the ASP script.  So the files will be in a folder that is restricted from your web site, but you can validate the download through a script similar to this:

if Check(strUser, strFilename) = True Then  'Whatever logic you have to validate users for filenames...

    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objTS = objFSO.OpenTextFile(Server.MapPath("InvoiceFolder/" & strFile))

    Response.Buffer = True

    Response.ContentType = "application/pdf"
    Response.AddHeader "Content-disposition", "attachment; filename=" & strFile

    Do While Not objTS.AtEndOfStream
      strChunk = objTS.Read(32)
      strTmp = ""
      For i = 1 to Len(strChunk)
          strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
      Next
      Response.BinaryWrite strTmp
      Response.Flush
    loop

    objTS.Close
    Set objTS = Nothing
    Set objFSO = Nothing
Else
    Response.Redirect "noaccess.html"
End If

 

by: gormlyPosted on 2007-08-09 at 12:41:45ID: 19665240

The probelm with that is I HAVE to use the link:  http://www.mysite.com/invoices/999999.pdf


My boss is adament about it, how do I redirect http://www.mysite.com/invoices/999999.pdf to a script file?

 

by: PaulHewsPosted on 2007-08-09 at 13:53:03ID: 19665893

>The probelm with that is I HAVE to use the link:
Then start authenticating against Windows users and lock everything down with NTFS.  Bonus, it's a very secure method.

OR

Use a custom 404 page script to redirect to the authentication script.  I would Google some examples for you, but right now my Internet connection is connecting very selectively....  The basic idea is that instead of a HTML page for 404 errors, you put in an ASP script... You detect what the incoming requests are, and when they match a certain pattern (like http://www.mysite.com/invoices/999999.pdf) then you extract the numeric portion from the request URL, do your checking as above, and serve up the bytes as above...

 

by: PaulHewsPosted on 2007-08-10 at 04:55:34ID: 19668967

Using URL rewrites
http://evolvedcode.net/content/code_smart404/guide-rewrites.asp


Note this next article uses server.transfer... You would not use that if you want the URL to look like invoices/999999.pdf.  Instead, handle the full request in your custom 404 script.

Extending Your Page Names
http://www.asp101.com/articles/wayne/extendingnames/default.asp

 

by: gormlyPosted on 2007-08-10 at 05:00:49ID: 19668995

Hello Paul
I appreciate the attempt but really, that is the problem I am having in a nutshell.

I HAVE an asp script that will do that, my trouble is I don't know how to fire it from a 404.
I said above,
>>"I have a script that checks for that but I do not know how to get it to fire when someone has a direct address."


How can I get a 404 file to get the variable of the invoice number and store it?

when someone types http://www.mysite.com/invoices/999999.pdf and they are not logged in I need them to log in and then be redirected to the invoice.  

One idea is to have the \invoice folder empty and fire the 404 which will strip the invoice number save to a session variable and then redirect to a login.. the login will redirect to the invoice if the login correctly.

Great Idea.. I just dont know how to implement it.

 

by: PaulHewsPosted on 2007-08-10 at 05:38:45ID: 19669188

>I HAVE an asp script that will do that, my trouble is I don't know how to fire it from a 404.

What you have is a script that redirects to an unsecured file resource on your server.  In order to secure those resources, you have to remove them from the path of the web server, and serve them up as bytes when a request comes in and doesn't find them...

>I don't know how to fire it from a 404.

You do that from IIS.  It is explained in the second article.

>How can I get a 404 file to get the variable of the invoice number and store it?

In the custom 404 script, you get the request.  That's going to look like this:

<%
 Dim strPage, strID
 strPage = Request.ServerVariables("SCRIPT_NAME")
'Check for URL http://www.mysite.com/invoices/999999.pdf
If LCase(Left(strPage, Len(strStart))) = strStart And LCase(Right(strPage, Len(strEnd))) = strEnd Then
    strID = Mid(strPage, Len(strStart) + 1, Len(strPage) - Len(strStart) - Len(strEnd))
    'This is the number.  Now check user credentials and get the file
   
End If
 
%>

 

by: PaulHewsPosted on 2007-08-10 at 05:42:28ID: 19669222

Correction, missing a couple of pieces:

<%
Dim strPage, strID, strStart, strEnd
'Some say QUERY_STRING... I can only get this to work in IIS6.
 strPage = Request.ServerVariables("SCRIPT_NAME")  
'Check for URL /invoices/999999.pdf
strStart = "/invoices/"
strEnd = ".pdf"
If LCase(Left(strPage, Len(strStart))) = strStart And LCase(Right(strPage, Len(strEnd))) = strEnd Then
    strID = Mid(strPage, Len(strStart) + 1, Len(strPage) - Len(strStart) - Len(strEnd))
    'This is the number.  Now get the user credentials, and the file if valid.

End If
 
%>

 

by: gormlyPosted on 2007-08-10 at 06:55:48ID: 19669808

Ok, this works... I made a system that does the redirect but the security problem still exists.
That fixed the email issue, now they must login to get an invoice.

but once they get one invoice.. and if they are set to open PDFs in a browser (most are) they now see the location of the invoices in the browser bar and can still change the numbers to get others members invoices, becasue the addres bar shows the normally redirected directory name

arrggh! back to square one!

I guess the problem is how do I get around showing the user what the address to the pdf is?


 

by: gormlyPosted on 2007-08-10 at 07:05:26ID: 19669901

Note:  I tried using server.transer but it turns up junk like the pdf is opening in the browser as a text file.

 

by: PaulHewsPosted on 2007-08-10 at 07:07:38ID: 19669916

>I guess the problem is how do I get around showing the user what the address to the pdf is?

You don't.   Don't give access to the PDF's except through the script.  Take the invoice folder out of the web path.

 

by: gormlyPosted on 2007-08-10 at 07:09:19ID: 19669933

are you serious?
there is no method to allow access and hide the urls?

if so that stinks.

 

by: PaulHewsPosted on 2007-08-10 at 10:07:02ID: 19671678

>are you serious?
>there is no method to allow access and hide the urls?

I've described two methods you can use to secure the files.  Both allow you to enter the URL as http://www.mysite.com/invoices/999999.pdf and both allow the user only to open the files that they are approved for.  So, what was your question again?

 

by: gormlyPosted on 2007-08-10 at 10:24:10ID: 19671847

Paul

with all respect, I don't see how you have given me two methods.

yes, I can now make sure only autheticated users can access their invoices by using a direct link like:
http://www.mysite.com/invoices/999999.pdf

But the problem is that once they get to the link http://www.mysite.com/invoices/999999.pdf
all they need to do is change the 999999.pdf in the browser toolbar to get another file because any 404 redirect script I use in the http://www.mysite.com/invoices folder with return the "true" address when the pdf opens in the users browser.

in other words

The link they getnin email is: http://www.mysite.com/invoices/999999.pdf
They go to that link and it fires the 404 script, the script grabs the invoice number (999999) and checks to see if the user is logged in, if not, it redirects to the login which then sends them to the real invoice: http://www.mysite.com/realinvoicefolder/999999.pdf

The Problem is that on the last step the browser now displays http://www.mysite.com/realinvoicefolder/999999.pdf  instead of http://www.mysite.com/invoices/999999.pdf
and all they have to do to get another invoice that doesn't belong to them is change the invoice number in the address bar URL

http://www.mysite.com/realinvoicefolder/8888888.pdf

do you see what I mean?
There is no way to hide the last step.. the real address of the pdf file.

unless I missed something???

 

by: PaulHewsPosted on 2007-08-10 at 10:48:28ID: 19672043

>The link they getnin email is: http://www.mysite.com/invoices/999999.pdf
They go to that link and it fires the 404 script, the script grabs the invoice number (999999) and checks to see if the user is logged in, if not, it redirects to the login which then sends them to the real invoice: http://www.mysite.com/realinvoicefolder/999999.pdf <

The problem is that you are sending them to a file resource.  That is not what I suggested.  There should be no real invoice folder on the web server.

When the 404 script gets the request, it sends back the bytes of the PDF, that are retrieved by the script.  Redirecting in any way will cause the URL rewriting to fail and the new address will likely be revealed.

I just ran a test locally, not as a 404 script, but this ASP script sends back a PDF file to the browser.  Note that the IIS user has to have read permissions on the PDF folder, or you will get permission errors.




<%
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objTS = objFSO.OpenTextFile("C:\Temp\Test.pdf")

    Response.Buffer = True

    Response.ContentType = "applications/vnd.pdf"
    Response.AddHeader "Content-disposition", "attachment; filename=test.pdf"

    Do While Not objTS.AtEndOfStream
      strChunk = objTS.Read(32)
      strTmp = ""
      For i = 1 to Len(strChunk)
          strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
      Next
      Response.BinaryWrite strTmp
      Response.Flush
    loop

    objTS.Close
    Set objTS = Nothing
    Set objFSO = Nothing

%>

 

by: gormlyPosted on 2007-08-10 at 11:47:02ID: 19672528

Oh, I see... I did miss that  : <
I will test it and see what happens.

Thanks Paul.

 

by: PaulHewsPosted on 2007-08-10 at 12:01:08ID: 19672663

I just noticed you mentioned above that you were getting the file sent back as text in the browser.  I think having the right content type defined is the key... applications/vnd.pdf works okay.  Also, the filename in the Content-Disposition header has to end in PDF.

 

by: gormlyPosted on 2007-08-13 at 05:59:58ID: 19683516

Paul

This is not working for me, I am still getting "text" sent to the browsers.
If you have a moment... Here is the code:
      
If Session("LOGIN") = False then

      ' not logged in, send them to login and save some
      session("INVOICE")=request("INVOICE")
      session("referer") =Request.ServerVariables ("URL")
      response.redirect("http://www.mywebsite.com/login.asp")
      
else

      INVOICE=Request("INVOICE")
      'this checks to see if the request is coming from a link
      if INVOICE = "" or ISNULL(INVOICE) then
            'otherwise we need to get the invoice number from the saved session varible in login.asp
            INVOICE=session("INVOICE")
      else
      end if
      
end if

INVOICEstrip=replace(INVOICE,".pdf","")

set objConn = server.createobject("adodb.connection")
objConn.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=c:\databases\;" & _
       "Extended Properties=""DBASE IV;"";"
            sqlstat="SELECT *  FROM MyDatabase WHERE INVOICE= '"+INVOICEstrip+"' and ACCO='" + session("user") + "'"
set rs = objConn.execute (sqlstat)


if Not rs.eof then'

while not.rs.eof
      pdf = INVOICEstrip
      
            Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
            Set objTS = objFSO.OpenTextFile("C:\invoices\" & INVOICEstrip & ".pdf")
            Response.Buffer = True
            Response.ContentType = "applications/vnd.pdf"
            Response.AddHeader "Content-disposition", "attachment; filename=" & INVOICEstrip & ".pdf"
            Do While Not objTS.AtEndOfStream
              strChunk = objTS.Read(32)
              strTmp = ""
              For i = 1 to Len(strChunk)
                    strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
              Next
              Response.BinaryWrite strTmp
              Response.Flush
            loop
            objTS.Close
            Set objTS = Nothing
            Set objFSO = Nothing
                  
      rs.movenext
      wend
      
else
response.redirect("99999z.pdf")
end if





I even tried this totally seperate from any other code to see what I would get and I still get the text....
I know the "text" is the actual pdf, but the browser is not seeing it as a pdf.

 

by: PaulHewsPosted on 2007-08-13 at 07:29:10ID: 19684325

Is the code above the full script?   Nothing else above or below?

 

by: gormlyPosted on 2007-08-13 at 07:49:59ID: 19684540

yes.. full
nothing else above or below.


I am testing a copy to temp then redirect directory solution right now and although it works like a charm, it still isn't the cats meow. I have to dump all the copied pdfs on a regular basis and thats not a great solution.

I would love to get this working correctly, but I have almost lost hope.
:<

 

by: PaulHewsPosted on 2007-08-13 at 08:02:03ID: 19684676

Does this cause the same problem?

http://notbono.dnsalias.com/temp/test.asp

 

by: gormlyPosted on 2007-08-13 at 08:12:23ID: 19684788

no it opened fine.

I assume you're using the same code?

 

by: PaulHewsPosted on 2007-08-13 at 08:24:32ID: 19684923

Yes, so this rules out that it's a browser issue at least.  What version of IIS are you using?

>while not.rs.eof

Why are you doing looping through the recordset?  Don't you expect only a single record?

 

by: gormlyPosted on 2007-08-13 at 08:33:42ID: 19685002

I am using IIS 6.0

and the "while not" is just a left over from copied code, once it works I will make it a bit tighter.

 

by: PaulHewsPosted on 2007-08-13 at 08:51:01ID: 19685168

IIS 6 will work fine with this.  Try to get the simplest example working first.  You might try clearing the cache before running it.  

 

by: gormlyPosted on 2007-08-13 at 09:02:04ID: 19685262

I am going to try it from a complely different system.
I am running to another office to remove any local influences thast might be screwing things up.

I know this should work

 

by: gormlyPosted on 2008-12-23 at 07:01:15ID: 31407613

This first answer is a working solution for most situations.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...