sql防注入的常见方法
sql防注入的常见方法
sql防注入的常见方法
种数据验证的途径可以分类为以下几种:
1)整理数据使之变得有效
2)拒绝已知的非法输入
3)只接受已知的合法的输入
方法1有很多概念上的问题;首先,开发者没有必要知道非法数据由什么组成,因为新形式的非法数据随时都可能产生。第二,改变数据会改变它的长度,这样会导致前面提到的问题。最后,还有需要对系统已有数据的重用的话有二次注入的问题.
解决方案2也会遇到和1的一些相似的问题,了解非法数据会过时,因为新的攻击技术也在发展。
解决方案3可能是三种方法中最好的,但是比较难于执行。
从安全角度来考虑可能最好多解决方法是把解决方案2和3结合起来只允许合法的输入,然后再寻找非法字符。
一个必须结合这两种途径的例子是带有连字符的名字的问题:
Question Bassington-Bassington
我们必须在合法输入里允许连字符号,但是也要明白字符串'--'在SQL-Server里意味着什么。
当数据整理结合了非法字符验证时另一个问题就会发生。假设我们应用“非法字符探测器”来探测'--','select'和'union'”后使用“数据整理过滤器”删除单引号,攻击者就可以指定这样的输入:
uni'on sel'ect @@version-'-
因为单引号被过滤器删除了,攻击者可以把单引号散布于它的已知的非法字符串里来躲避检查。
下面是一些验证的代码:
方法1-躲避单引号
function escape( input )
input = replace(input, "'", "''")
escape = input
end function
方法2-抵制已知的非法输入
function validate_string( input )
know_bad = array( "select", "insert", "update", "delete", "drop", "--", "'")
validate_string = true
for i = lbound( know_bad ) to ubound( known_bad )
if( instr( 1, input, known_bad(i), vbtextcompare) 0 )
validate_string = false
exit function
end if
next
end function
方法3-只允许合法输入
function validatepassword( input )
good_password_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
validatepassword = true
for i = 1 to len( input )
c = mid( input, i, 1 )
if ( instr( good_password_chars, c ) = 0 ) then
validatepassword = false
exit function
end if
next
end function
[SQL Server 防御]
最重要的一点是必须防范SQLServer,’out of the box’并不安全。这里有一当创建SQL-Server构架要做的事情的简明清单:
1.决定连接到服务器的方法
a.使用’Network utility’检验你使用的网络库是可用的
2.检查哪些帐号存在
a.为程序创建低权限帐号
b.删除不需要的帐号
c.确保所有的帐号都有一个健壮的密码;在一个正常运行一个密码审计脚本(比如附录里提供了一个)。
3.检查哪些对象存在
a.许多扩展存储可以安全的删除,如果这些已经做了考虑删除一些包含扩展存储的dll
b.删除所有的数据库实例-比如'northwind'和'pubs'数据库
4.检查哪些帐号可以访问对象
a.应用程序用户所使用的访问数据库的帐号应该只拥有对所需要的对象的最小访问权限
5.检查服务器的补丁状况
a.有一些针对SQL-Server的缓冲区溢出[3],[4]和格式字符串[5]攻击(大部分是作者自己发现的)和一些其他的安全补丁,可能还有更多的漏洞存在
6.检验日志记录些什么,和日志可以做些什么。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

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.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

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.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

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.

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.
