PHP full-site anti-injection program

Source: Internet
Author: User
This is a comprehensive anti-injection program for php and SQL. in php, it mainly filters get, post, Coke, and files. in SQL, we delete the files, update some query commands for detection and filtering .... this is a comprehensive anti-injection program for php and SQL. in php, it mainly filters get, post, Coke, and files. in SQL, we delete the files, update some query commands for detection and filtering.

General Idea of SQL injection attacks

Locate the SQL injection location, determine the background database type, determine the xp_mongoshell executable status, and find the WEB virtual directory to upload ASP, php, and jsp Trojans; and obtain the administrator privilege;

The PHP full-site anti-injection program instance code is as follows:

 $ V) {$ array [$ k] = sec ($ v);} // open source code phprm.com} else if (is_string ($ array )) {// use the addslashes function to process $ array = addslashes ($ array);} else if (is_numeric ($ array) {$ array = intval ($ array );} return $ array ;}?>

1. integer parameter judgment

When the input parameter YY is an integer, the SQL statement in abc. asp is generally as follows:

Select * from table name where field = YY, so you can use the following steps to test whether SQL injection exists.

① HTTP: // xxx. xxx. xxx/abc. asp? P = YY '(with a single quotation mark attached), the SQL statement in abc. ASP becomes

Select * from table name where field = YY ', abc. asp running exception;

② HTTP: // xxx. xxx. xxx/abc. asp? P = YY and 1 = 1, abc. asp is running normally, and it works properly with HTTP: // xxx. xxx. xxx/abc. asp? P = YY: The running result is the same;

③ HTTP: // xxx. xxx. xxx/abc. asp? P = YY and 1 = 2, abc. asp running exception;

If the preceding three steps are fully met, the SQL injection vulnerability exists in abc. asp.

In summary, we write an integer filter function. the code is as follows:

 $ Max) {die ('maximum $ max Byte ');} return stripslashes_array ($ str) ;}?>

When the input parameter YY is a string, the SQL statement in abc. asp is generally as follows:

Select * from table name where field = 'yy', so you can use the following steps to test whether SQL injection exists.

① HTTP: // xxx. xxx. xxx/abc. asp? P = YY '(with a single quotation mark attached), the SQL statement in abc. ASP becomes

Select * from table name where field = YY ', abc. asp running exception;

② HTTP: // xxx. xxx. xxx/abc. asp? P = YY &; nb... 39; 1' = '1', abc. asp runs normally, and it works with HTTP: // xxx. xxx. xxx/abc. asp? P = YY: The running result is the same;

③ HTTP: // xxx. xxx. xxx/abc. asp? P = YY &; nb... 39; 1' = '2', abc. asp running exception;

If the preceding three steps are fully met, the SQL injection vulnerability exists in abc. asp. the code is as follows:

 $ V) {$ array [$ k] = stripslashes_array ($ v) ;}} else if (is_string ($ array) {$ array = stripslashes ($ array );} return $ array ;}?>

The anti-injection solution introduced in this article is comprehensive. you can test the solution or use a better method.


Address:

Reprinted at will, but please attach the article address :-)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.