473,385 Members | 1,325 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,385 software developers and data experts.

Protection against SQL Injection Attack

sashi
1,754 Expert 1GB
hi everyone,

Below is a simple function that will give you some protection against an SQL Injection attempt.

what is SQL injection?
SQL injection is a security vulnerability that occurs in the database layer of an application. Its source is the incorrect escaping of variables embedded in SQL statements. It is in fact an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another.

Expand|Select|Wrap|Line Numbers
  1. 'Function IllegalChars to guard against SQL injection
  2. Function IllegalChars(sInput) 
  3. 'Declare variables 
  4. Dim sBadChars, iCounter 
  5. 'Set IllegalChars to False 
  6. IllegalChars=False
  7. 'Create an array of illegal characters and words 
  8. sBadChars=array("select", "drop", ";", "--", "insert", "delete", "xp_", _
  9. "#", "%", "&", "'", "(", ")", "/", "\", ":", ";", "<", ">", "=", "[", "]", "?", "`", "|") 
  10. 'Loop through array sBadChars using our counter & UBound function
  11. For iCounter = 0 to uBound(sBadChars) 
  12. 'Use Function Instr to check presence of illegal character in our variable
  13. If Instr(sInput,sBadChars(iCounter))>0 Then
  14. IllegalChars=True
  15. End If
  16. Next 
  17. End function
  18.  
sample usage..
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. 'Declare variables 
  3. Dim sUsername, sPassword
  4. 'retrieve our form textbox values and assign to variables 
  5. sUsername=Request.Form("txtUsername")
  6. sPassword=Request.Form("txtPassword")
  7.  
  8. 'Call the function IllegalChars to check for illegal characters
  9. If IllegalChars(sUsername)=True OR IllegalChars(sPassword)=True Then
  10. Response.redirect("no_access.asp")
  11. End If
  12. %>
  13.  
Jul 19 '06 #1
2 10643
vladnz
1
hi everyone,

Below is a simple function that will give you some protection against an SQL Injection attempt.

what is SQL injection?
SQL injection is a security vulnerability that occurs in the database layer of an application. Its source is the incorrect escaping of variables embedded in SQL statements. It is in fact an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another.

Expand|Select|Wrap|Line Numbers
  1. 'Function IllegalChars to guard against SQL injection
  2. Function IllegalChars(sInput) 
  3. 'Declare variables 
  4. Dim sBadChars, iCounter 
  5. 'Set IllegalChars to False 
  6. IllegalChars=False
  7. 'Create an array of illegal characters and words 
  8. sBadChars=array("select", "drop", ";", "--", "insert", "delete", "xp_", _
  9. "#", "%", "&", "'", "(", ")", "/", "\", ":", ";", "<", ">", "=", "[", "]", "?", "`", "|") 
  10. 'Loop through array sBadChars using our counter & UBound function
  11. For iCounter = 0 to uBound(sBadChars) 
  12. 'Use Function Instr to check presence of illegal character in our variable
  13. If Instr(sInput,sBadChars(iCounter))>0 Then
  14. IllegalChars=True
  15. End If
  16. Next 
  17. End function
  18.  
sample usage..
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. 'Declare variables 
  3. Dim sUsername, sPassword
  4. 'retrieve our form textbox values and assign to variables 
  5. sUsername=Request.Form("txtUsername")
  6. sPassword=Request.Form("txtPassword")
  7.  
  8. 'Call the function IllegalChars to check for illegal characters
  9. If IllegalChars(sUsername)=True OR IllegalChars(sPassword)=True Then
  10. Response.redirect("no_access.asp")
  11. End If
  12. %>
  13.  

could you please be more detailed? i mean just write php code please?
Jun 18 '07 #2
Here's a very light ASP function to help protect against these attacks.

ASP sql injection prevention
Aug 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

75
by: Massimo | last post by:
I'm planning to develop a .NET application using C#, in order to sell it as a shareware and/or as a full package, so I'll need a good way to protect it against piracy. I know some ways to protect...
11
by: Bã§TãRÐ | last post by:
I have been working on this particular project for a little over 2 weeks now. This product contains between 700-900 stored procedures to handle just about all you can imagine within the product. I...
13
by: Ioannis Vranos | last post by:
If we want our programs to be protected against buffer overflows, must we check the size of the various containers explicitly? E.g. #include <iostream> #include <string> int main()
7
by: joshsackett | last post by:
All, I am trying to test an attack against a web page. The VBScript runs 2 queries against the database; the first must succeed before the second runs. Here is the code: 1st- select * from...
4
by: poppy | last post by:
I think a site I developed has been the victim of a sql injection attack.I know how to stop this happening in future but: Is there any way I can trace such an attack?
10
by: bregent | last post by:
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...
1
by: Doug | last post by:
Hi, I have a question on sql injection attacks. I am building a tool that will be used exclusively by our other developers and will generate stored procs for them dynamically based off input...
17
by: anojjona | last post by:
Hi, I need to figure out what some code that was maliciously executed against a database does. However, it's in a very strange format. It simply declares a variable and sets it equal to a huge...
16
by: ChipR | last post by:
Since we're talking about filters, make sure you also use a filter for semicolons (at the minimum) on any input that is going directly into an SQL statement to prevent your entire database from being...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.