Skip to content

Eduguru

  • Tutorial and Training
    • SQL Server
    • Linux Tutorial
    • PHP Tutorial
    • Asterisk Tutorial
    • MySQL Tutorial
    • JavaScript Tutorial
    • C Tutorial
    • Who Breaks into Computer Systems
    • Planning and Performing Hacking Attacks
    • Maintaining Anonymity
    • Selecting Security Assessment Tools
    • Scanning Systems
  • Contact Us
    • Feedback
  • Business
    • Solutions
      • Job : Dialer Support
    • ViciDial – GoautoDial Support
    • Domain Registration
    • Web Hosting
    • Consultancy
    • Dialer Support
  • About Us
  • News
  • Donate Online
  • Offers
  • Newsletter
  • Jobs
  • Sale
    • Amazon
    • Get Computer Books
    • Amazon Sale Offer
  • Search
  • Python Tutorial
  • Search
  • WPMS HTML Sitemap
  • Log In
  • Log Out
  • Register
  • Lost Password
  • Reset Password
  • Download
  • Result
  • Newsletter
  • search
  • MySQL – Video Tutorial
  • Products Page
    • Checkout
    • Transaction Results
    • Your Account
  • Privacy

Injecting into SQL

May 6, 2020 by Krishna

Almost every web application employs a database to store the various kinds of information that it needs in order to operate. For example, a web application deployed by an online retailer might use a database to store the following information:
■ User accounts, credentials, and personal information
■ Descriptions and prices of goods for sale
■ Orders, account statements, and payment details
■ The privileges of each user within the application

The means of accessing information within the database is Structured Query Language, or SQL. SQL can be used to read, update, add, and delete information held within the database.

SQL is an interpreted language, and web applications commonly construct SQL statements that incorporate user-supplied data. If this is done in an unsafe way, then the application may be vulnerable to SQL injection. This flaw is one of the most notorious vulnerabilities to have afflicted web applications. In the most serious cases, SQL injection can enable an anonymous attacker to read and modify all data stored within the database, and even take full control of the server on which the database is running.

As awareness of web application security has evolved, SQL injection vulnerabilities have become gradually less widespread, and more difficult to detect and exploit. A few years ago, it was very common to encounter SQL injection vulnerabilities that could be detected simply by entering an apostrophe into a HTML form field, and reading the verbose error message that the application returned. Today, vulnerabilities are more likely to be tucked away in data fields that users cannot normally see or modify, and error messages are likely to be generic and uninformative. As this trend has developed, methods for finding and exploiting SQL injection flaws have evolved, using more subtle indicators of vulnerabilities, and more refined and powerful exploitation techniques. We will begin by examining the most basic cases and then go on to describe the latest techniques for blind detection and exploitation.

There is a very wide range of databases in use to support web applications. While the fundamentals of SQL injection are common to the vast majority of these, there are many differences. These range from minor variations in syntax through to significant divergences in behavior and functionality that can affect the types of attack that you can pursue. For reasons of space and sanity, we will restrict our actual examples to the three most common databases you are likely to encounter, namely Oracle, MS-SQL, and MySQL. Wherever applicable, we will draw attention to the differences between these three platforms. Equipped with the techniques we describe here, you should be able to identify and exploit SQL injection flaws against any other database, by performing some quick additional research.

Exploiting a Basic Vulnerability

Consider a web application deployed by a book retailer that enables users to search for products based on author, title, publisher, and so on. The entire book catalog is held within a database, and the application uses SQL queries to retrieve details of different books based on the search terms supplied by users. When a user searches for all books published by Wiley, the application performs the following query:

SELECT author,title,year FROM books WHERE publisher = ‘Wiley’ This query causes the database to check every row within the books table, extract each of the records where the publisher column has the value Wiley , and return the set of all these records. This record set is then processed by the application and presented to the user within an HTML page.

In this query, the words to the left of the equals sign comprise SQL key- words and the names of tables and columns within the database. All of this portion of the query was constructed by the programmer at the time the application was created. The expression Wiley , of course, is supplied by the user, and its significance is as an item of data. String data in SQL queries must be encapsulated within single quotation marks, to separate it from the rest of the query.

Now, consider what happens when a user searches for all books published by O’Reilly. This causes the application to perform the following query:

SELECT author,title,year FROM books WHERE publisher = ‘O’Reilly’

In this case, the query interpreter reaches the string data in the same way as before. It parses this data, which is encapsulated within single quotation marks, and obtains the value O . It then encounters the expression Reilly’ , which is not valid SQL syntax and so generates an error:

Incorrect syntax near ‘Reilly’.
Server: Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark before the character string ‘

When an application behaves in this way, it is wide open to SQL injection. An attacker can supply input containing a quotation mark to terminate the string that he controls, and can then write arbitrary SQL to modify the query that the developer intended the application to execute. In this situation, for example, the attacker can modify the query to return every single book in the retailer’s catalog, by entering the search term:

Wiley’ OR 1=1–

This causes the application to perform the following query:

SELECT author,title,year FROM books WHERE publisher = ‘Wiley’ OR 1=1–‘

This modifies the WHERE clause of the developer’s query to add a second condition. The database will check every row within the books table and extract each record where the publisher column has the value Wiley or where 1 is equal to 1. Because 1 is always equal to 1, the database will return every record within the books table.

Bypassing a Login

In some situations, a simple SQL injection vulnerability may have an immediately critical impact, regardless of any further attacks that could be built upon it. Many applications that implement a forms-based login function use a database to store user credentials and perform a simple SQL query to validate each login attempt. A typical example of this query is:

SELECT * FROM users WHERE username = ‘marcus’ and password = ‘secret’

This query causes the database to check every row within the users table and extract each record where the username column has the value marcus and the password column has the value secret . If a user’s details are returned to the application, then the login attempt is successful, and the application creates an authenticated session for that user.

As with the search function, an attacker can inject into either the username or the password field to modify the query performed by the application, and so subvert its logic. For example, if an attacker knows that the username of the application administrator is admin , he can log in as that user by supplying any password and the following username:

admin’–

This causes the application to perform the following query:

SELECT * FROM users WHERE username = ‘admin’–‘ AND password = ‘foo’

which because of the comment symbol is equivalent to

SELECT * FROM users WHERE username = ‘admin’

and so the password check has been bypassed altogether.

Suppose that the attacker does not know the username of the administrator. In most applications, the first account in the database is an administrative user, because this account is normally created manually and then used to generate all other accounts via the application. Further, if the query returns the details for more than one user, most applications will simply process the first user whose details are returned. An attacker can often exploit this behavior to log in as the first user in the database by supplying the username:
‘ OR 1=1–

This causes the application to perform the query

SELECT * FROM users WHERE username = ‘’ OR 1=1–‘ AND password = ‘foo’

which because of the comment symbol is equivalent to

SELECT * FROM users WHERE username = ‘’ OR 1=1

which will return the details of all application users.


NEXT is..Finding SQL Injection Bugs……………..,.,.,.,.,.,.,,.

Categories Tutorial, Web Hosting, Website Tags Bypassing a Login, Exploiting a Basic Vulnerability, http, Injecting Code, Injecting into SQL, Linux, PHP, SQL injection, web, web hacking, web-app, web-app-hack, web-site
Injecting Code
Finding SQL Injection Bugs

Recent Posts

  • How to resolve -bash: netstat: command not found centos stream 9
  • python script to STT output in a text file
  • New Install Asterisk 18 from source on CentOS Stream 8
  • How to save audio stream from Asterisk to a file via WebSocket
  • create web socket and save data in a text file
  • How to capture and analyze traffic with tcpdump
  • Installing Asterisk 20 From source On Rocky 9
  • html drop down with search from table php mysql
  • How to Install and Use FFmpeg on CentOS 8
  • How to get duration of MP3 or wav any audio File in PHP
  • How to Change location Of MariaDB Data Directory
  • How to check partition details of MySQL table
  • internal server error when download large file php
  • iostat : How to monitor disk activity and CPU load average
  • Webrtc with Asterisk 16 : complete configuration with SIP
  • What is inode and where this is stored
  • How to create Bootstrap Dropdown button/link
  • How to check supported RAM type in Linux System
  • MySQL update table based on value of another table Join
  • How to check the Public IP: Mera Wala IP
  • How to fix WordPress 404 Errors, requested URL was not found on this server: Home Page works
  • How to create Round Buttons and Square Buttons
  • Basic and Simple Examples of Skills with CSS
  • How to SUM Columns value in MYSQL
  • How to create a data table in bootstrap PHP and MySQL ?
  • How to DELETE Data Into MySQL Database Using PHP ?
  • How to Create MySQL user and Grant permission ?
  • What is XML & HTML ? What is Difference Between XML & HTML?
  • What is MySQL Binary logs ,their usages and how to purge binary logs ?
  • How to Select Data Into MySQL Database Using PHP ?
  • How to Remove spaces from string in MySQL ?
  • What is Different Between CHAR & VARCHAR ?
  • How to Insert Data Into MySQL Database Using PHP
  • What is MySQL SELECT Statement And Example of MySQL SELECT Query
  • What is INSERT Statement And Example of INSERT Query ?
  • What is MySQL Cluster vs Replication ?
  • How to Protect your computer from viruses and malware ?
  • What is the Use of Motherboard in a Computer ?
  • Happy Teacher’s Day 2022 – Quotes and Greetings on Teachers’ Day
  • NDA exam date question paper 2022 download and solution
  • What is Need of Information Security?
  • What is Information Security ?
  • How to Secure Web server ?
  • What is JSP ?
  • What is DDoS Attack ? & How Google Stopped the Largest -ever DDoS Attack ?
  • what is Malware ? And How to Stay Protected from Malware Attacks?
  • Best Practices to secure from DDoS Attack
  • How to protect Your Site Against DDoS Attack
  • How to secure from DDoS Attack
  • What is DDoS Attack. Basic introduction of DDoS

Recent Post

  • How to resolve -bash: netstat: command not found centos stream 9
  • python script to STT output in a text file
  • New Install Asterisk 18 from source on CentOS Stream 8
  • How to save audio stream from Asterisk to a file via WebSocket
  • create web socket and save data in a text file
© 2026 Eduguru • Built with GeneratePress