php中防xss攻击和sql注入详解
本文章简单的讲述了关于在php中防xss攻击和sql注入详解,有需了解的朋友可以参考一下下.
XSS攻击实例代码如下:
1 2 3 |
|
关于SQL攻击有很多文章还有各种防注入脚本,但是都不能解决SQL注入的根本问题
实例代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
很简单的一段代码,功能是用于检测用户名或密码是否正确,可是在一些恶意攻击者中提交一些敏感代码.后果可想而知.. post判断注入的方式有2种.
1.在form表单的文本框输入 "or'1'=1"或者"and 1=1"
在查询数据库的语句就应该是:
SELECT admin from where login = `user`=''or'1'=1' or `pass`='xxxx'
当然也不会出现什么错误,因为or在sql的语句中代表和,或的意思.当然也会提示错误.
当时我们已经发现了可以执行SQL语句之后就可以查询当前表的所有信息.例如:正确的管理员账户和密码进行登录入侵..
修复方式1:
使用javascript脚本过滤特殊字符(不推荐,指标不治本)
如果攻击者禁用了javascript还是可以进行SQL注入攻击..
修复方式2:
使用mysql的自带函数进行过滤.
实例代码如下:
1 2 3 4 5 |
|
既然前面说道了xss攻击,我们再来说说XSS攻击以及防范吧..
提交表单实例代码如下:
1 2 3 4 |
|
接收文件实例代码如下:
1 2 3 |
|
很简单的一段代码,在这里只是模拟了下使用场景..
加入攻击者提交实例代码如下:
<script>alert(document.cookie);</script>
在返回的页面就应该显示当前页面的cookie信息.
我们可以运用到某些留言板上(提前是没过滤的),然后当管理员审核改条信息时盗取COOKIE信息,并发送到攻击者的空间或者邮箱..攻击者可以使用cookie修改器进行登陆入侵了..
当然解决方案也有很多..下面就介绍一个最常用的方式吧.
修复方案1:使用javascript进行转义
修复方案2:使用php内置函数进行转义
实例代码如下:
1 2 3 4 5 |
|
好了,关于SQL注入攻击和XSS攻击的案例与修复方法就讲的差不多了.
文章地址:
转载随意^^请带上本文地址!

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

AI Hentai Generator
Generate AI Hentai for free.

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



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

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

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

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

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

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

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

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
