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)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24
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,

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.

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.

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

Lenovo has issued a patch in May, Phoenix UEFI firmware vulnerability disclosed: affecting hundreds of Intel PC CPU models Lenovo has issued a patch in May, Phoenix UEFI firmware vulnerability disclosed: affecting hundreds of Intel PC CPU models Jun 22, 2024 am 10:27 AM

According to news from this site on June 21, the Phoenix Secure Core UEFI firmware was exposed to a security vulnerability, affecting hundreds of Intel CPU devices. Lenovo has released a new firmware update to fix the vulnerability. This site learned from reports that the vulnerability tracking number is CVE-2024-0762, known as "UEFICANHAZBUFFEROVERFLOW", which exists in the Trusted Platform Module (TPM) configuration of Phoenix UEFI firmware. It is a buffer overflow vulnerability that can be Exploit to execute arbitrary code on a vulnerable device. The vulnerability was discovered by Eclypsium in Lenovo ThinkPad X1 Carbon 7th generation and X1Yoga 4th generation

Hack an assassin's phone in 40 minutes Hack an assassin's phone in 40 minutes Jul 20, 2024 pm 06:11 PM

According to people familiar with the matter, Cellebrite, an Israeli mobile device forensics company, provided the FBI with an evaluation version of a mobile phone cracking program that has not yet been released and is still undergoing internal testing. The FBI used it to unlock the special device in less than 40 minutes. The cellphone of Trump assassin Thomas Matthew Crooks. Agents from the FBI's Pittsburgh office initially used a commercially available Cellebrite tool to unlock Crooks' phone, but were unsuccessful. So the phone was sent to the FBI's Quantico headquarters that day. After headquarters personnel contacted key account support, Cellebrite provided an unreleased unlocking tool, allowing investigators to unlock the phone at 40

How to interact with JSON data using SQL in Golang? How to interact with JSON data using SQL in Golang? Jun 03, 2024 am 11:47 AM

There are the following steps for interacting with JSON data through SQL in Golang: Use the json.Unmarshal function to parse JSON data into a Go structure and convert JSON to a structure. Use the database/sql package to access and operate SQL databases and perform operations such as inserts and queries. Combining the above steps, you can build an application based on SQL and JSON in Go to implement functions such as user registration and login.

See all articles