Unstoppable Domains

Anatomy of a SQL injection attack

Spacemail by SpaceshipSpacemail by Spaceship
Watch
Impact
815
Oct 21, 2008
By Ryan Barnett
Network World Asia

While there are a number of security risks in the world of electronic commerce, SQL injection is one of the most common Web site attack techniques used to steal customer data such as credit card numbers, hold customer data hostage by encrypting it or destroy data outright.

Where a Web server only understands and speaks the HTTP protocol, a database's native tongue is Structured Query Language (SQL), which is essentially a set of command statements that instruct a database to execute specific actions. Every database server has a similar series of commands to query its tables, narrow down results to a few specific entries, and combine information from one table to another.

Here is an example SQL query:

SELECT -- FROM users WHERE Email = '" + Email + "' AND Password = '" + Password + "';

The WHERE specifies a condition, that an e-mail address and password combination match data present in the "users" table. When this command is given to the database server, it returns true if a match is found and a false if there is no match.

When clients send data on the Web, they use URLs and forms to assemble the database query statements. The following URL represents an example login page for a Web application:

GET /shopping_cart/[email protected]&Password=$ecret123 HTTP/1.1

This URL shows that the destination application is a Microsoft ASP page and it is accepting two parameters, one called "Email" and the other called "Password." If the user credentials are correct then the result of this query will provide response data that represents a successful authentication and will be used to allow the client to proceed to the corresponding Web page.

Developers of traditional application code generally trust user input. They believe that database queries are coming from a trusted source, namely the database server itself, rather than from an untrusted user's Web browser. SQL injection is an attack technique where an untrusted user inserts SQL query data into input fields sent to back-end databases in an attempt to trick the database into executing the commands.

The Web application firewall in the example was configured in a "detection only" mode where it was logging alerts and events but not blocking any inbound attacks or outbound data leakages. Due to this configuration, the inbound SQL injection attack from the previous section was allowed to continue on to the vulnerable Web application when it would have been blocked.

The Web page returned indicates that the SQL injection reconnaissance probe was successful, giving the hacker valuable information, including the exact version of the database and the database user. Armed with this information, the attacker can fine tune the attack and execute further reconnaissance probes to enumerate more information about the database itself, such as the table and column names. After a number of intermediary reconnaissance probes, the attacker has the information needed to send a complex SQL injection attack, attempting to extract customer record details. By targeting specific customer data such as credit card name, expiration data and security code, the attacker can extract a vast amount of sensitive customer data.

Criminals once had a tough time creating programs that could mass exploit Web applications because most sites were running custom coded applications.

http://www.networksasia.net/article.php?type=article&id_article=4652
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
"Developers of traditional application code generally trust user input."

Actually, I have always been taught the opposite...never trust user input. That's pretty standard so I don't know where this guy is getting that from.
 
0
•••
Well said.

My few sites were recently hacked and few sites datanase were injected
I complained with hosting providers but to a little help.

After I got it right, one of the providers sent a confirmation after 6 1/2 months that it seems there are no issues now with the site (possibly while their audit might be going on ;) )

I was so upset that I within a span of a month changed the service provider. (But this is a solution only post getting you affected database right).

To ensure there are no possible attacks, i as mentioned in such a wonderful article above, checked all the user inputs and the possiblities where user can (which we cannot assume easily) pass on the values through any dynamic variables like querystrings (addressbar of browser)

As from the beginning, i keep the headers common for all the user displayed pages and that too are com based.

So, I put in the code to the header file and voila.. no injects till date (1 year)

All my sites are ASP based and have found a wonderful piece of code .

If any one requires this so that such attacjks can be avoided (as much we can do), let me know, i will paste it here.
 
0
•••
I'm curious

Yes, please post the code.
 
0
•••
That article is extremely vague, not very helpful, and downright incorrect sometimes.

As tiawood said, no developer has ever been taught to trust user input. Also, the article doesn't even give an example of an injected query.
 
0
•••
intheflow said:
Yes, please post the code.

HTML:
<%
call CheckSecure() 
'##########################################################################*###############' 
'######################### Security Function #######################################' 
'##########################################################################*###############' 
function CheckSecure() 
        For Each Item in Request.QueryString 
                if instr(LCASE(Item),"varchar")then injection="True" 
                if instr(LCASE(Item),"nvarchar") then injection="True" 
                if Request.QueryString(Item).Count>=1 then 
                        For iCount = 1 to Request.QueryString(Item).Count 
                                varcheck=LCASE(Request.QueryString(Item)(iCount)) 
                                if instr(varcheck,"<script") then injection="True" 
                                if instr(varcheck,"xtype") then injection="True" 
                                if instr(varcheck,"convert(") then injection="True" 
                                if instr(varcheck,"set @") then injection="True" 
                                if instr(varcheck,"exec(") then injection="True" 
                                if instr(varcheck,"exec (") then injection="True" 
                                if instr(varcheck,"declare @") then injection="True" 
                                if instr(varcheck,"function") then injection="True" 
                                if instr(varcheck,"varchar") then injection="True" 
                                if instr(varcheck,"nvarchar") then injection="True" 
                                if instr(varcheck,"cast(") then injection="True" 
                                if instr(varcheck,"0x") then injection="True" 
                                if instr(varcheck,"ipt src") then injection="True" 
                                if instr(varcheck,"ipt+src") then injection="True" 


                                qs=qs&"&"&Item&"="&Request.QueryString(Item)(iCount) 
                        Next 
                end if 
        Next 


        For Each Item in Request.Form 
                if instr(LCASE(Item),"varchar")then injection="True" 
                if instr(LCASE(Item),"nvarchar") then injection="True" 
                if Request.Form(Item).Count>=1 then 
                        For iCount = 1 to Request.Form(Item).Count 
                        varcheck=LCASE(Request.Form(Item)(iCount)) 
                        if instr(varcheck,"<script") then injection="True" 
                                if instr(varcheck,"xtype") then injection="True" 
                                if instr(varcheck,"convert(") then injection="True" 
                                if instr(varcheck,"function") then injection="True" 
                                if instr(varcheck,"varchar") then injection="True" 
                                if instr(varcheck,"exec(") then injection="True" 
                                if instr(varcheck,"exec (") then injection="True" 
                                if instr(varcheck,"set @") then injection="True" 
                                if instr(varcheck,"nvarchar") then injection="True" 
                                if instr(varcheck,"nvarchar") then injection="True" 
                                if instr(varcheck,"cast(") then injection="True" 
                                if instr(varcheck,"0x") then injection="True" 
                                if instr(varcheck,"ipt src") then injection="True" 
                                if instr(varcheck,"ipt+src") then injection="True" 
                                qf=qf&"&"&Item&"="&Request.Form(Item)(iCount) 
                        Next 
                end if 
        Next 
        if injection="True" then 


                url="http://www.fatherstorm.com/attacklog.php? agent="&Request.ServerVariables("http_user_agent")&"&addr="&Request.ServerV*ariables("remote_addr")&"&host="&Request.ServerVariables("remote_host")&"&s*erver="&Request.ServerVariables("server_name")&qs&qf 
                response.end 
        end if 
end function 

%>

hyped said:
That article is extremely vague, not very helpful, and downright incorrect sometimes.

As tiawood said, no developer has ever been taught to trust user input. Also, the article doesn't even give an example of an injected query.

Understanding this might have been posted by the user for non-techies :)
 
0
•••
It's very useful for me. In my work i have to test web sites security.
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back