search
HomeDatabaseMysql Tutorial关于SQL注入的几类错误和产生

对于注入而言,错误提示是极其重要。所谓错误提示是指和正确页面不同的结果反馈,高手是很重视这个一点的,这对于注入点的精准判断至关重要。本问讨论下关于几类错误和他产生的原理,希望对读者有所帮助。 错误提示主要有逻辑错误和语法错误以及脚本运行错误

  对于注入而言,错误提示是极其重要。所谓错误提示是指和正确页面不同的结果反馈,高手是很重视这个一点的,这对于注入点的精准判断至关重要。本问讨论下关于几类错误和他产生的原理,希望对读者有所帮助。

错误提示主要有逻辑错误和语法错误以及脚本运行错误三类。

一:逻辑错误

简单的例子是1=1 1=2这两个,1=1与1=2页面不同的原理是什么?以$sql = “select * from news where id=$_GET[id]”为例。

select * from news where id=1 and 1=2产生的结果集为NULL,然后程序取值得时候,就会去出空值,无法显示。当然有的程序发现SQL执行结果集为空,就立即跳转,效果就不显鸟。值得注意的是,有的如Oracle Postgresql的数据库在结果集为空情况下会再页面上表现字符型null字样,这算是个特点。如果使用or条件,比如
3lian素材  
select * from news where id=1 or 1=1

和and 1=2得结果正好相反,他的结果集十分庞大。如果SQL语句如此,再加上程序是循环读取结果集(一些编程上的陋习)那么会取出所有结果,结果可能运行很慢,在数据量巨大的oracle上容易出现。这个例子会出现什么呢,一般程序取出结果集中的第一条结果,那么很可能已经不是id=1的那条新闻了,这就是由些小菜奇怪有时候or 1=1页面会发生变化的原因。

归根到底,都是结果集不同造成的,灵活掌握是关键,这并非单纯的经验问题。

二:语法错误

语法错误时比较熟悉的,比如对于SQL Server,PgSQL,Sybase的注入错误提示都很重要,因为利用它的特性来获取信息很快速。语法错误造成的结果可能是SQL错误而中断脚本执行,但是脚本或服务器设置屏蔽错误的情况下,程序得到继续执行,但是结果集不存在,连NULL都算不上,反馈给攻击者的很可能就是结果集为空的情况,其实这是脚本的处理结果。当然Oracle PgSQL表现null。

三:运行错误不用说了,典型的就是利用mysql注入benchmark让脚本运行超时得到物理路径,,以及利用超时来获得不同的表征进行盲注入。

四:逻辑错误和语法错误的结合。

当表征极不明显的时候,利用类似iff这样的函数进行正确与否的区分有时候会成救命稻草。因为语法错误和逻辑错误的表征大多数情况都会有不同。

iff(1=1,1,‘no’)这个会产生结果1 注意是数字,而iff(1=2,1,‘no’)这个会产生‘no’ 是字符。那么

id=1 and 1=iff(1=1,1‘no’)正确是必然成立的,而id=1 and 1=iff(1=2,1,‘no’)会因为类型不同发生语法错误。不过可惜的是似乎支持iff函数的数据库不多,呵呵。

现在讲结果集在注入中的利用原理。

一:从‘or’‘=’开始

这是学习SQL注入的初级课程,登陆漏洞。我简略从SQL结果集上分析。

$sql = “select top 1 * from admin where username=‘$username’ and password=md5(‘$password’)”;

显而易见,‘or’‘=’的加入使SQL语句返回了一条记录,这才使验证通过。

二:再看现在的验证中的SQL

$sql = “select top 1 * from admin where username=‘$username’”;

结果集不为空才根据抽取的记录集中的密码值与用户提交的密码MD5值进行比对来进行验证。这样,你突然发现‘or’‘=’的计策失败鸟,但是后台明明有注入,这就是验证方法造成的。跟进这个验证过程,‘or’‘=’的确产生了一个结果集(admin表中的第一行记录)但是遗憾的事,后来的密码比对没法通过,验证无法成功。

思路很简单,网上有案例,我重在原理,利用union来产生想要的结果集。比如‘and(1=2)union select top 1 username,’123456得md5值‘,id from admin where username=’admin

这样产生了admin的记录信息,但是记录集中的密码那个位置的值被替换成了123456的md5值,这样,使用admin 123456通过验证并且继承他的权利。

更有甚者全部用‘xxx’的方法来盲狙,这就很“过分”鸟。不过在sql2000 sybase这些严格要求类型匹配的数据库来说,这样不能撼动“管理员登陆”的,因为执行时发生了语法错误,结果集为NULL。另外以前 ewebeditor注入漏洞来上传马也是这个union操作结果集来达到目的的经典案例。
 

Statement
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
Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Apr 15, 2025 am 12:11 AM

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL vs. Other Databases: Comparing the OptionsMySQL vs. Other Databases: Comparing the OptionsApr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools