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 | ||||||||
`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; |
代码如下 | 复制代码 |
http://127.0.0.1/marcofly/phpstudy/sqlinsert/showart.php?id=1 |
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 = "";
Drag library using SQL injection vulnerability ";
if (!$row){
echo "The record does not exist";
exit;
}
echo "title ";
echo "Content "; ?> |
The code is as follows | Copy code |
http://127.0.0.1/marcofly/phpstudy/sqlinsert/showart.php?id=1 |
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:
The code is as follows
|
Copy code
|
||||||||
After careful analysis, we can construct the SQL statement like this:
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.
|
http: //www.bkjia.com/PHPjc/632941.html