Pages

Showing posts with label Security. Show all posts
Showing posts with label Security. Show all posts

Blind SQL Injection

SQL Injection can be avoided using HTML encoding. Please find the list of characters which needs to be handled which getting user inputs especially in multi-line text boxes.

[1] | (pipe sign)
[2] & (ampersand sign)
[3] ; (semicolon sign)
[4] $ (dollar sign)
[5] % (percent sign)
[6] @ (at sign)
[7] ' (single apostrophe)
[8] " (quotation mark)
[9] \' (backslash-escaped apostrophe)
[10] \" (backslash-escaped quotation mark)
[11] <> (triangular parenthesis)
[12] () (parenthesis)
[13] + (plus sign)
[14] CR (Carriage return, ASCII 0x0d)
[15] LF (Line feed, ASCII 0x0a)
[16] , (comma sign)
[17] \ (backslash)

Their is always a chance of manupulating the SQL script as part of form inputs and also end user can prepare a request dynamically and hit the target url's. If we use the HTML encode and decode this can be avoided.

Example:

While getting the input values from the form and before processing that. 
string data = HTTPUtility.HTMLEncode(Textbox1.Text)
While rendering the data to UI 
Textbox1.Text = HTTPUtility.HTMLDecode(data)
This is simple and one of the best practice to avoid SQL injection.




Cross Site Scripting : Validating Query string parameters string

1. We need to validate the request by setting the ValidateRequest="true" on the @ Pages element.

2. We need to take care while using query string parameter. We need to cast the query string value to the respective data type to avoid this. Please check the below code snippet to avoid this. This will help us to check whether user end is manipulating something in the URL, if so then we cannot create a new GUID the catch block will be executed and generic error message will display. the same logic can be applied for any data type.
try
{
string Key = Request.QueryString["e"];
Guid ErrorGUID = new Guid(Key);
lblError.Text = string.Format("Please provide the following error code {0}.", ErrorGUID.ToString();
}
catch ()
{
//handle exceptions accordingy
}

ADGroup Verification in ASP.NET Web Applications

Normally in Enterprise level , users will be provided access at the ADGroup level for the application that are hosted at the intranet and internet. The web application will contains the access related code. There are two to check this access at ADGroup.
1. LDAP QUERY
2. Net inbuilt method

The first one LDAP approach is more time consumable. Also to add more value, we will be using a service account to pull the Active Directory information. This is risk, we are pulling firm sensitive data from the Active Directory. Moreover to check a single ADGroup, we are pulling all the existing and verifying it via loop. This is a bad practice. And causes Performance issues.

The Dotnet inbuilt function IsInRole is simplest way to achieve this. we need to know the domain name where the ADGroup is in place. The syntax for this goes like this.

bool IsHavingAccess = HttpContext.Current.User.Identity.IsInRole(domain\Adgroup);


This will help us to just verify the access security and provide the result. So by using this method, we are nowhere pulling sensitive information and logic will be very fast. Hope this helps.

Online Resources Available, Use It and Celebrate

Some of the Resource Sites, where we can learn..
[Contribution is not Mine, original link]

ASP.NET Quickstart Tutorial
http://www.asp.net/QuickStart/aspnet/doc/whatsnew.aspx

Virtual Labs
http://msdn.microsoft.com/virtuallabs/asp2/http://msdn.microsoft.com/virtuallabs/fritzonion/
“How Do I” Video Series
ASP.NET HOW DO I Video Series: Caching (Part 1)
ASP.NET HOW DO I Video Series: Caching (Part 2)
ASP.NET HOW DO I Video Series: Create a Full-Featured Customer Login Portal
ASP.NET HOW DO I Video Series: Data
ASP.NET HOW DO I Video Series: Form Building for a "Contact Us" Page
ASP.NET HOW DO I Video Series: Localization
ASP.NET HOW DO I Video Series: Master Pages and Site Navigation
ASP.NET HOW DO I Video Series: Membership and Roles
ASP.NET HOW DO I Video Series: Profiles and Themes
ASP.NET HOW DO I Video Series: Tips and Tricks
ASP.NET HOW DO I Video Series: Web Parts and Personalization

How-To MSDN Articles
How To: Configure the Machine Key in ASP.NET 2.0
How To: Connect to SQL Server Using SQL Authentication in ASP.NET 2.0
How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0
How To: Create a Service Account for an ASP.NET 2.0 Application
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA
How To: Instrument ASP.NET 2.0 Applications for Security
How To: Improve Security When Hosting Multiple Applications in ASP.NET 2.0
How To: Perform a Security Deployment Review for ASP.NET 2.0
How To: Prevent Cross-Site Scripting in ASP.NET
How To: Protect Forms Authentication in ASP.NET 2.0
How To: Protect From Injection Attacks in ASP.NET
How To: Protect From SQL Injection in ASP.NET
How To: Use ADAM for Roles in ASP.NET 2.0
How To: Use Authorization Manager (AzMan) with ASP.NET 2.0
How To: Use Code Access Security in ASP.NET 2.0
How To: Use Forms Authentication with Active Directory in ASP.NET 2.0
How To: Use Forms Authentication with Active Directory in Multiple Domains in ASP.NET 2.0
How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
How To: Use Health Monitoring in ASP.NET 2.0
How To: Use Impersonation and Delegation in ASP.NET 2.0
How To: Use Membership in ASP.NET 2.0
How To: Use the Network Service Account to Access Resources in ASP.NET
How To: Use Protocol Transition and Constrained Delegation in ASP.NET 2.0
How To: Use Regular Expressions to Constrain Input in ASP.NET
How To: Use Role Manager in ASP.NET 2.0
How To: Use Windows Authentication in ASP.NET 2.0

Authentication and Authorization
How To: Connect to SQL Server Using SQL Authentication in ASP.NET 2.0
How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0
How To: Create GenericPrincipal Objects with Forms Authentication
How To: Protect Forms Authentication in ASP.NET 2.0
How To: Use Authorization Manager (AzMan) with ASP.NET 2.0
How To: Use Forms Authentication with Active Directory
How To: Use Forms Authentication with Active Directory in ASP.NET 2.0
How To: Use Forms Authentication with Active Directory in Multiple Domains in ASP.NET 2.0
How To: Use Forms Authentication with SQL Server 2000
How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
How To: Use Windows Authentication in ASP.NET 2.0

Code Access Security
How To: Create a Custom Encryption Permission
How To: Use Code Access Security in ASP.NET 2.0
How To: Use Code Access Security Policy to Constrain an Assembly

Code Review
How To: Perform a Security Code Review for Managed Code (Baseline Activity)

Communications Security
How To: Call a Web Service Using Client Certificates from ASP.NET
How To: Call a Web Service Using SSL
How To: Set Up SSL on a Web Server
How To: Set Up Client Certificates
How To: Use IPSec for Filtering Ports and Authentication
How To: Use IPSec to Provide Secure Communication Between Two Servers
How To: Use SSL to Secure Communication with SQL Server 2000

Configuration
How To: Create a Custom Account To Run ASP.NET
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI
How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA

Cryptography
How To: Create a DPAPI Library
How To: Create an Encryption Library
How To: Store an Encrypted Connection String in the Registry
How To: Use DPAPI (Machine Store) from ASP.NET
How To: Use DPAPI (User Store) from ASP.NET with Enterprise Services

Deployment Review
How To: Perform a Security Deployment Review for ASP.NET 2.0

Impersonation and Delegation
How To: Implement Kerberos Delegation for Windows 2000
How To: Use Impersonation and Delegation in ASP.NET 2.0

Input and Data Validation
How To: Prevent Cross-Site Scripting in ASP.NET
How To: Protect From Injection Attacks in ASP.NET
How To: Protect From SQL Injection in ASP.NET
How To: Use Regular Expressions to Constrain Input in ASP.NET

Patching and Updating
How To: Implement Patch Management

SQL Server 2000
How To: Connect to SQL Server Using SQL Authentication in ASP.NET 2.0
How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0
How To: Protect From SQL Injection in ASP.NET
How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
How To: Use SSL to Secure Communication with SQL Server 2000

Threat Modeling
How To: Create a Threat Model for a Web Application at Design Time

ATLAS (ASP.NET AJAX)
Quickstart Developer Tasks
http://ajax.asp.net/

“How Do I?” Videos
http://ajax.asp.net/default.aspx?tabid=47&subtabid=478#howdoi

Preview Videos
http://ajax.asp.net/default.aspx?tabid=47&subtabid=478#atlas

Samples
http://go.microsoft.com/fwlink/?LinkId=62605

Control Toolkit
http://atlas.asp.net/default.aspx?tabid=47&subtabid=477

Enjoy by doing R&D