Table of Contents
php防注入式攻击心得
Home php教程 php手册 php防注入式攻击心得

php防注入式攻击心得

Jun 13, 2016 am 10:11 AM
php one exist Experience attack injection this

php防注入式攻击心得

 

一:

这个话题太老生常谈了.
在PHP.INI中将magic_quotes_gpc = On
确实能防得住一些注入式攻击,但这是不是万能的?
我们现在是将POST或者GET收到的变量,将其中的空格转换掉,标点符号,特殊字符全部转换为HTML编码.
演示的时候再将他还原.请问大家是如何做的?交流一下代码啊.

不过还是没有用的.防不了union语句,当你的SQL写得不规范的时候.
比如select * from news where id=$Id,这个变量$Id没有用小引号括起来,而且又没有判断这个$Id是不是数字字符串的时候,就肯定会被注入,就算magic_quotes_gpc = On也一样.
彻底的防注入的方法只有在SQL语句内将变量用小引号括起来,然后
magic_quotes_gpc = On,然后将空格转换掉,标点符号,特殊字符全部转换为HTML编码.
这样我认为就一劳永逸了,不知道有无漏网之鱼,请高手指教,我们现在开发的系统杜绝了注入的话,我才能睡上好觉.哈哈.

一般我是直接在每个页面用函数将_get,_post,_session等数据初步过滤

在具体写入数据库时候强制检查数据类型~

基本这些对一般的注入效果还是不错的

1\ SQL语句最好通过sprintf格式化,再query
2\ 登陆检测之类的时候,最好通过一个值取出另一个值,然后进行比对

 

举例说明:

哈哈,那是我举的一个例子啊。我仔细的总结了一下,不被注入很容易。
总结如下:
magic_quotes_gpc = On这个打开,然后变量用小引号括住,别人想注入的话,得突破引号,所以他得在变量内加入小引号,加入小引号又会被magic_quotes_gpc = On给转义掉了,突破小引号失败。就干不了坏事。
还有一点就是在MYSQL中有两个注释标记,#和/*,通过这个能将后面的SQL语名注释掉,将这俩字符给转成ASC码或者HTML码。
然后就是注入攻击的爸妈是空格。
如select * from news where id=1 union select * from admin,如果我将空格给删除或者转换掉。
就成了select * from news where id=1unionselect*fromadmin,这是偷窃数据的下场。
select * from news where id=1; drop table news这里将空格弄掉.
select * from news where id=1; droptablenews无法执行。
所以说注入式攻击的爸妈是空格。空格被替换掉之后。真的是能安心睡觉了

Statement of this Website
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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles