How SQL Injection Works?
How SQL Injection Works?
• SQL injection is a type of code injection technique that might destroy the
databases.
• In this technique the malicious code in SQL statement is placed via web page
input. These statements control a database server behind a web application.
• Attackers can use SQL injection vulnerabilities to bypass application security
measures. They can go around authentication and authorization of a web page
or web application and retrieve the content of the entire SQL database. They can
also use SQL injection to add, modify and delete records in the database.
• An SQL injection vulnerability may affect any website or web application that
uses an SQL database such as MySQL, Oracle, SQL Server or others.
How SQL Injection Works?
• To make an SQL injection attack, an attacker must first find vulnerable user
inputs ad to within the web page or web application. A web page or web
application that has an ses SQL injection vulnerability uses such user input
directly in an SQL query. The attacker can create input content. Such content is
often called a malicious payload and is the key part of the attack. After the
attacker sends this content, malicious SQL commands are executed in the
database.
• SQL is a query language that was designed to manage data stored in relational
Sup databases. You can use it to access, modify and delete data. Many web
applications and websites store all the data in SQL databases. In some cases,
you can also use SQL commands to run operating system commands.
Therefore, a successful SQL Injection attack can have very serious
consequences.
Example of SQL Injection
• Following is an example of SQL injection vulnerability works around a simple
rid web application having two input fields - One for user name and another for
password.
• This example has a table named users with the columns username
and password
uname-request.POST['username']
passwd=request.POST['password']
query="SELECT id FROM users WHERE username='"+ uname +"'
ANDpassword='"+ passwd +"'
database.execute(query)
• Here the two input fields - One for user name and another for password is
vulnerable to SQL injection.
• The attacker can attack using these fields and alter the SQL query to get the
access to the database.
• They could use a trick on password field. They could add
OR 1 = 1
Statement to the password field.
• As a result the query would becomes (assuming username as 'user1' and
password='password')
• SELECT id FROM users WHERE username='user1' AND
password='password' OR 1 = 1
• Because of OR 1 = 1 statement, the WHERE clause returns the first id from
the users table no matter what the username and password are. That means
even-if we enter any wrong username or password still the query will get
executed because of OR 1 = 1 part which comes out to be true.
• The first id is returned by the above query for users table and we know that the
first id is normally administrator. In this way, the attacker not only bypasses
authentication but also gains administrator privileges.
How to prevent SQL injection?
• The only way to prevent SQL injection is to validate every input field.
• Another method is to make use of parameterized query. This parameterized
query is called prepared statement. By this ways, application code never use the
input directly.
• The Web Application Firewalls (WAF) are also used to filter out the SQL.
3)Distributed Databases
Architecture
• Following is an architecture of distributed databases. In this architecture the
local database is maintained by each site.
• Each site is interconnected by communication network.
When user makes a request for particular data at site Si then it is first searched
at the local database. If the data is not present in the local database then the
request for that data is passed to all the other sites via communication network.
Each site then searches for that data at its local database. When data is found at
particular site say Sj then it is transmitted to site Si via communication network.
Data Storage
There are two approaches of storing relation r in distributed database -
4) Flow Control
• Flow control is a mechanism that regulates the flow of information among
accessible objects.
• A flow between two objects obj1 and obj2 occurs when program reads values
from obj1 and writes values to the object obj2.
• The flow control checks that the information contained in one object should
not get transferred to the less protected object.
• The flow policy specifies the channels along which the information is allowed
to move.
• The simple flow policy specifies two classes of information - Confidential(C)
and non confidential(N). According to flow policy only the information flow
from confidential to non confidential class is not allowed.
Convert Channel
• A covert channel is a type of attack that creates a capability to transfer
information objects between processes that are not supposed to be allowed to
communicate.
• This convert channel violates the security or the policy.
• The convert channel allows information to pass from higher classification
level to lower classification level through improper means.
• The security experts believe that one way to avoid convert channels is for as
programmers to not gain the access to sensitive data.
5) Encryption and Public Key Infrastructures
Cryptology is a technique of encoding and decoding messages, so that they
cannot be understood by anybody except the sender and the intended recipient.
There are various encoding and decoding schemes which are called as
encryption schemes. The sender and recipient of the message decide on an
encoding and decoding scheme and use it for communication.
The process of encoding messages is known as encryption. The sender sends the
original text. The original text called plaintext, The encrypted form of plaintext
it is called as ciphertext. This encrypted text travel through the network. When
it reaches at the receiving computer, the recipient understands the meaning and
decodes the message to extract the correct meaning out of it. This process is
called as decryption.
The sender applies the encryption algorithm and recipient applies the decryption
algorithm. Both the sender and the receiver must agree on this algorithm for any
meaningful communication. The algorithm basically takes one text as input and
produces another as the output. Therefore, the algorithm contains the
intelligence for transforming message.
Types of Cryptography
There are two types encryption schemes based in key used for encryption and
decryption.
1. Symmetric key encryption: It is also known as secret key encryption. In this
method, only one key is used. The same key is shared by sender and receiver for
encryption and decryption of messages. Hence both parties must agree upon the
key before any transmission begins and nobody else should know about it. At
the sender's end, the key is used to change the original message into an encoded
form. At the receiver's end using the same key the encoded message is
decrypted and original message is obtained. Data Encryption Standard (DES)
uses this approach. The problem with this approach is that of key agreement and
distribution.
2. Asymmetric key encryption: It is also known as public key encryption. In
this method, different keys are used. One key is used for encryption and other
key must be used for decryption. No other key can decrypt the message-not
even the original key used for encryption.
One of the two keys is known as public key and the other is the private key.
Suppose there are two users X and Y. The
• X wants to send a message to Y. Then X will convey its public key to Y but
the private key of X will be known to X only.
• Y should know the private key of Y and X should know the Y's public key.