473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Preventing form injection on Classic ASP pages

I've seen plenty of articles and utilities for preventing form injections for
ASP.NET, but not too much for classic ASP. Are there any good input validation
scripts that you use to avoid form injection attacks? I'm looking for good
routines I can reuse on all of my form processing pages. Thanks.

Feb 10 '06 #1
10 23857
bregent wrote:
I've seen plenty of articles and utilities for preventing form
injections for ASP.NET, but not too much for classic ASP. Are there
any good input validation scripts that you use to avoid form
injection attacks? I'm looking for good routines I can reuse on all
of my form processing pages. Thanks.


"form injection"?
Do you mean cross-site scripting (XSS)?
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 10 '06 #2
bregent wrote on 10 feb 2006 in microsoft.public.inetserver.asp.general:
I've seen plenty of articles and utilities for preventing form
injections for ASP.NET, but not too much for classic ASP. Are there
any good input validation scripts that you use to avoid form injection
attacks? I'm looking for good routines I can reuse on all of my form
processing pages. Thanks.


If you do not mind loosing non-alphanumeric characters,
and don't have a user named O'Brien:

<script runat=server language=jscript>
function DesInjectString(s){
return s.replace(/[^a-z\d\.,-]+/ig,'?')
}
</script>

Not tested.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 10 '06 #3
Here are some rules to follow which will prevent injection attack.

Never build SQL code by string concatenation with input from the client.
Apply the above rule to code found inside Stored procedures.
Always pass input data to SQL code via Command object parameters.

Always call Server.HTMLEncode on data retrieved from the data base before
sending to the client.

Avoid using hidden fields to carry meaningful state that only the server
needs.
Instead store the state somewhere on the server (like in the DB) and send to
the client a unique (preferable use once only) ID.

Anthony.
Feb 10 '06 #4
In article <#y**************@TK2MSFTNGP15.phx.gbl>, Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> says...

bregent wrote:
I've seen plenty of articles and utilities for preventing form
injections for ASP.NET, but not too much for classic ASP. Are there
any good input validation scripts that you use to avoid form
injection attacks? I'm looking for good routines I can reuse on all
of my form processing pages. Thanks.


"form injection"?
Do you mean cross-site scripting (XSS)?


No, I'm not too worried about XSS, just mainly sql and email injection.

Feb 10 '06 #5
bregent wrote:
In article <#y**************@TK2MSFTNGP15.phx.gbl>, Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> says...

bregent wrote:
I've seen plenty of articles and utilities for preventing form
injections for ASP.NET, but not too much for classic ASP. Are there
any good input validation scripts that you use to avoid form
injection attacks? I'm looking for good routines I can reuse on all
of my form processing pages. Thanks.


"form injection"?
Do you mean cross-site scripting (XSS)?


No, I'm not too worried about XSS, just mainly sql and email
injection.


For sql injection, simply avoid using concatenation to insert input values
into sql statements. use parameters instead. I strongly advise encapsulating
your queries in stored procedures, using parameters to pass the values to
them. However, if you are phobic about using stored procedures, you can use
this technique:
http://groups-beta.google.com/group/...e36562fee7804e

I still validate server-side, but that's mainly to discover the attack.
Using parameters prevents the attack even if my validation misses it.

For email-injection, I know of no way to prevent that outside of validation.
I'm surprised you haven't come up with any scripts in your google searches,
but the same techniques that work in .Net can usually be revised to work in
vbscript.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Feb 13 '06 #6
In article <u1**************@TK2MSFTNGP12.phx.gbl>, Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> says...

bregent wrote:
In article <#y**************@TK2MSFTNGP15.phx.gbl>, Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> says...

bregent wrote:
I've seen plenty of articles and utilities for preventing form
injections for ASP.NET, but not too much for classic ASP. Are there
any good input validation scripts that you use to avoid form
injection attacks? I'm looking for good routines I can reuse on all
of my form processing pages. Thanks.

"form injection"?
Do you mean cross-site scripting (XSS)?


No, I'm not too worried about XSS, just mainly sql and email
injection.


For sql injection, simply avoid using concatenation to insert input values
into sql statements. use parameters instead. I strongly advise encapsulating
your queries in stored procedures, using parameters to pass the values to
them. However, if you are phobic about using stored procedures, you can use
this technique:
http://groups-beta.google.com/group/...e36562fee7804e


Thanks Bob, I read that and the linked articles and am beginning to understand
how to implement these techniques. However, having never used the command
object, what I still don't understand is exactly HOW these methods protect
against an attack. How exactly do they prevent an attacker from inserting single
quotes and comment marks and other malicious code into a parameter?

Feb 13 '06 #7
bregent wrote:
Thanks Bob, I read that and the linked articles and am beginning to
understand how to implement these techniques. However, having never
used the command object, what I still don't understand is exactly HOW
these methods protect against an attack. How exactly do they prevent
an attacker from inserting single quotes and comment marks and other
malicious code into a parameter?


They don't.
However, the fact that they are values being passed via parameter means that
they will be treated as values instead of pieces of strings that need to be
interpreted, so the inserted malicious code will simply be inserted into the
database table - the query engine will make no attempt to interpret or
execute the data.

To see this in action, use SQL Profiler to trace what occurs when using both
techniques.

Do not use the fact that you are using parameters to eliminate doing
validation. For one thing, you probably don't want that crappy data to be
inserted into your database. For another, the attempt to insert it may raise
an error (datatype mismatch, constraint violation, etc.) which you probably
should avoid. For another, you might want to consider "punishing" blatant
attacks - maybe redirect them to a page that takes 10 min. to load, etc.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 13 '06 #8
Bob Barrows [MVP] wrote:
bregent wrote:
Thanks Bob, I read that and the linked articles and am beginning to
understand how to implement these techniques. However, having never
used the command object, what I still don't understand is exactly HOW
these methods protect against an attack. How exactly do they prevent
an attacker from inserting single quotes and comment marks and other
malicious code into a parameter?


They don't.
However, the fact that they are values being passed via parameter
means that they will be treated as values instead of pieces of
strings that need to be interpreted, so the inserted malicious code
will simply be inserted into the database table - the query engine
will make no attempt to interpret or execute the data.


I just thought of an analogy that may help.
vbscript has a method called Execute() which attempts to execute a string
passed to it. Create a page with this code and run it to see what i'm
talking about:

<%
Sub WriteText(sometext, moretext)
response.write server.HTMLEncode(sometext) & "<BR>" & _
server.HTMLEncode(moretext)
End Sub
dim s1, s2
s1="try"
s2="this "":response.write ""<script type='text/javascript'>" & _
"alert('something bad')</script>"" '"
WriteText s1,s2

Response.Write "<BR><BR>Now see the difference " & _
"using Execute()<BR><BR>"
dim stmt
stmt="WriteText """ & s1 & """, """ & s2 & """"
'Response.Write server.HTMLEncode(stmt) & "<BR><BR>"
Execute(stmt)
%>

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 13 '06 #9
Bob Barrows [MVP] wrote:
bregent wrote:
Thanks Bob, I read that and the linked articles and am beginning to
understand how to implement these techniques. However, having never
used the command object, what I still don't understand is exactly HOW
these methods protect against an attack. How exactly do they prevent
an attacker from inserting single quotes and comment marks and other
malicious code into a parameter?


They don't.
However, the fact that they are values being passed via parameter
means that they will be treated as values instead of pieces of
strings that need to be interpreted, so the inserted malicious code
will simply be inserted into the database table - the query engine
will make no attempt to interpret or execute the data.


Not sure if this went through the first time. Even if it did, I've revised
it to help make the distinction clearer:

<%
Response.Buffer=true
Sub WriteText(sometext, moretext)
response.write server.HTMLEncode(sometext) & "<BR>" & _
server.HTMLEncode(moretext)
End Sub
dim s1, s2
s1="try"
s2="this "":response.write ""<script type='text/javascript'>" & _
"alert('something bad')</script>"" '"
Response.Write "First, see the result of just calling the " & _
"sub, passing the text as argument values:<BR>"
WriteText s1,s2
Response.Write "<BR>See? No alert - text is simply written to page."
Response.Flush
dim i,t
t=now
do until datediff("s",t,now)>=4
loop
Response.Flush

Response.Write "<BR><BR>Now see the difference " & _
"using Execute()<BR><BR>"
Response.Flush
t=now
do until datediff("s",t,now)>=2
loop
dim stmt
stmt="WriteText """ & s1 & """, """ & s2 & """"
'Response.Write server.HTMLEncode(stmt) & "<BR><BR>"
Execute(stmt)
%>
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 13 '06 #10
Makes sense now. Thanks for the help Bob!
In article <eb**************@TK2MSFTNGP09.phx.gbl>, Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> says...

Bob Barrows [MVP] wrote:
bregent wrote:
Thanks Bob, I read that and the linked articles and am beginning to
understand how to implement these techniques. However, having never
used the command object, what I still don't understand is exactly HOW
these methods protect against an attack. How exactly do they prevent
an attacker from inserting single quotes and comment marks and other
malicious code into a parameter?


They don't.
However, the fact that they are values being passed via parameter
means that they will be treated as values instead of pieces of
strings that need to be interpreted, so the inserted malicious code
will simply be inserted into the database table - the query engine
will make no attempt to interpret or execute the data.


Not sure if this went through the first time. Even if it did, I've revised
it to help make the distinction clearer:

<%
Response.Buffer=true
Sub WriteText(sometext, moretext)
response.write server.HTMLEncode(sometext) & "<BR>" & _
server.HTMLEncode(moretext)
End Sub
dim s1, s2
s1="try"
s2="this "":response.write ""<script type='text/javascript'>" & _
"alert('something bad')</script>"" '"
Response.Write "First, see the result of just calling the " & _
"sub, passing the text as argument values:<BR>"
WriteText s1,s2
Response.Write "<BR>See? No alert - text is simply written to page."
Response.Flush
dim i,t
t=now
do until datediff("s",t,now)>=4
loop
Response.Flush

Response.Write "<BR><BR>Now see the difference " & _
"using Execute()<BR><BR>"
Response.Flush
t=now
do until datediff("s",t,now)>=2
loop
dim stmt
stmt="WriteText """ & s1 & """, """ & s2 & """"
'Response.Write server.HTMLEncode(stmt) & "<BR><BR>"
Execute(stmt)
%>


Feb 13 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin Lucas-Smith | last post by:
Can anyone provide any suggestions/URLs for best-practice approaches to preventing SQL injection? There seems to be little on the web that I can find on this. Martin Lucas-Smith ...
7
by: Robb Meade | last post by:
Hi all, A recent project that I had finished and went live with no apparant problems. My client received an email from a user who mentioned that by accident they had been typing (over the...
7
by: aaj | last post by:
Hi all We had a small problem when an ASP web page had a missing 'where' statement and updated all the records in the table. Luckily we could retrieve all the data from the backups. How do...
5
by: www.douglassdavis.com | last post by:
I have an idea for preventing sql injection attacks, however it would have to be implemented by the database vendor. Let me know if I am on the right track, this totally off base, or already...
6
by: Simon | last post by:
Hi, I have a site where users have been granted a lot of flexibility when it comes to entries. They cannot add any code as far as I can see that would harm the server, but they could add...
8
by: stirrell | last post by:
Hello, One problem that I had been having is stopping email injections on contact forms. I did some research, read up on it and felt like I had created a working solution. I hadn't gotten any...
6
by: javelin | last post by:
In ASP classic pages, I want to know if it's possible to prevent session variables from becoming zero length strings? I have tried setting the Session.Timeout to a large value, but alwas, after 20...
2
by: Keith G Hicks | last post by:
I have a site that is made up of sevearl aspx pages. It was recently attacked by sql injection. I downloaded the tool described here: http://support.microsoft.com/kb/954476 but can't seem to run it...
13
by: RJ_32 | last post by:
looking here: http://www.devarticles.com/c/a/PHP/Getting-Intimate-With-PHPs-Mail-Function/2/ it says that I have to be careful about what I send to the sendmail process via popen(). Does that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.