The examples in this article describe common SQL attack regular expressions in PHP. Share it with everyone for your reference. The specific analysis is as follows:
We all already know that in MYSQL 5+, the information_schema library stores all library names, indications and field name information. Therefore, the attack method is as follows:
1. Determine whether the first character of the first table name is a character in a-z, where blind_sqli is an assumed known library name.
Note: ^[a-z] in the regular expression means that the starting character in the string is in the range of a-z
2. Determine whether the first character is a character in a-n
3. Make sure the character is n
4. The expression is replaced as follows
5. Next, guess the other tables. You only need to modify limit 1,1 -> limit 2,1 to make blind injections for the next tables.
For example:
SQL attack code:
如果使用这个函数的话,这个函数会绕开PHP的标准出错处理,所以说得自己定义报错处理程序(die())。
其次,如果代码执行前就发生了错误,那个时候用户自定义的程序还没有执行,所以就不会用到用户自己写的报错处理程序。
那么,PHP里有一套错误处理机制,可以使用set_error_handler()接管PHP错误处理,也可以使用trigger_error()函数主动抛出一个错误。
set_error_handler()函数设置用户自定义的错误处理函数。函数用于创建运行期间的用户自己的错误处理方法。它需要先创建一个错误处理函数,然后设置错误级别。
关于的用法:
Summary
When PHP encounters an error, it will give the location, line number and reason of the error script. Many people say that this is not a big deal. But the consequences of leaking the actual path are unimaginable. For some intruders, this information is very important. In fact, many servers now have this problem. Some network administrators simply set display_errors in the PHP configuration file to Off to solve the problem, but I think this method is too negative. Sometimes, we really need PHP to return error information for debugging. And when something goes wrong, you may also need to give the user an explanation or even navigate to another page. But with set_error_handler(), these contradictions can be resolved. But I found that this function is rarely used.
I hope this article will be helpful to everyone’s PHP programming design.
$sql='
CREATE TABLE IF NOT EXISTS uploadtype(
id int(11) NOT NULL AUTO_INCREMENT,
title varchar(20) DEFAULT '0',
sydefault char(1) DEFAULT '0' ,
PRIMARY KEY (id)
) ENGINE=MyISAM
';
preg_match('#CREATE TABLE.*\(.*\)ENGINE=MyISAM#isU',$ sql,$typefile);
var_dump($typefile);
SQL classification:
DDL—Data Definition Language (CREATE, ALTER, DROP, DECLARE)
DML—Data Manipulation Language (SELECT, DELETE, UPDATE, INSERT)
DCL—Data Control Language (GRANT) , REVOKE, COMMIT, ROLLBACK)
First, briefly introduce the basic statements:
1. Description: Create database
CREATE DATABASE database-name
2. Description: Delete database
drop database dbname
3. Description: Backup sql server
--- Create backup data device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat '
--- Start backup
BACKUP DATABASE pubs TO testBack
4. Description: Create a new table
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null ],..)
Create a new table based on an existing table:
A: create table tab_new like tab_old (use the old table to create a new table)
B: create table tab_new as select col1,col2… from tab_old definition only
5. Description: Delete a new table drop table tabname
6. Description: Add a column
Alter table tabname add column col type
Note: Once a column is added, it cannot be deleted. In DB2, the data type cannot be changed after the column is added. The only thing that can be changed is to increase the length of the varchar type.
7. Instructions: Add primary key: Alter table tabname add primary key(col)
Instructions: Delete primary key: Alter table tabname drop primary key(col)
8. Instructions: Create index: create [unique] index idxname on tabname(col….)
Delete index: drop index idxname
Note: The index cannot be changed. If you want to change it, you must delete it and rebuild it.
9. Instructions: Create a view: create view viewname as select statement
Delete a view: drop view viewname
10. Instructions: A few simple basic sql statements
Select: select * from table1 where Range
insert: insert into table1(field1,field2) values(value1,value2)
delete: delete from table1 where range
update: update table1 set field1=value1 where range
find: select * from table1 where field1 like '%value1%' ---like's syntax is very sophisticated, check the information!
Sort: select * from table1 order by field1,field2 [desc]
Total: select count(*) as totalcount from table1
Sum: select sum(field1) as sumvalue from table1
Average: select avg(field1) as avgvalue from table1
Maximum...The rest of the full text>>