kindedit编辑器和xxs攻击防护(BeautifulSoup)的简单使用
一、kindedit编辑器

就是上面这样的编辑输入文本的一个编辑器
这也是一个插件。那么怎么用呢?
1、下载:百度kindedit
2、引入:
<script src="/static/kindeditor/kindeditor-all.js"></script>
3、看官方提供的文档
在addarticle.html中
<script>
{# KindEditor编辑器的使用#}
KindEditor.ready(function (K) {
window.editor = K.create('#id_content', {
{# width:"1030px"#}
width: "90%",
height: "500px",
resizeType: 0,//编辑器不拉伸
uploadJson: "/uploadFile/", //上传图片路径
{# items:['preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',]#}
//items:你可以筛选你自己想要的
extraFileUploadParams: { #解决forbidden
csrfmiddlewaretoken: $("[name='csrfmiddlewaretoken']").val(),
}
});
});
</script>
当你把编辑器插入好的时候,你看似都可以设置大小,字体变粗等。。但是当你上传图片的时候就会想下面一样

这时候就需要 uploadJson: "/uploadFile/", 这个参数了。
url.py
url(r'^uploadFile/$', views.uploadFile),
views.py
def uploadFile(request):
'''上传图片路径'''
print(request.path) #返回的是当前请求的路径
print(request.FILES) #<MultiValueDict: {'imgFile': [<InMemoryUploadedFile: 44643.gif (image/gif)>]}>
file_obj = request.FILES.get("imgFile") #得到用户上传的文件对象
filename = file_obj.name #那到文件的文件名
path = os.path.join(settings.MEDIA_ROOT,"upload_article_img",filename) #拼接一个路径吧文件保存进去,一般上传文件的路径保存在media中
print("======",path)
with open(path,"wb") as f:#吧文件保存在本地
for line in file_obj: #也可以for i in chunks() 不是一行一行的读,而是有具体的大小64*2**10
f.write(line)
response = {
"error":0,
"url":"/media/upload_article_img/"+filename+"/" #前端图片文件预览
} return HttpResponse(json.dumps(response)) #需要注意的是上传文件返回的是一个json字符串
二、XSS攻击防护:
BeautifulSoup:是python的一个库,查你想要的数据的,但是只是针对标签字符串。主要用于从网页爬取数据
1、首先需要知道的一些基础知识
<html>
<head>
<title>
The Dormouse's story
</title>
</head>
<body>
<p class="title">
<b>
The Dormouse's story
</b>
</p>
<div id="d1" class="d1">
<b>
The Dormouse's story2
</b></div>
<p class="story">
Once upon a time there were three little sisters; and their names were
<a class="sister0" href="http://example.com/elsie" id="link1">
Elsie
</a>
,
<a class="sister1" href="http://example.com/lacie" id="link2">
Lacie
</a>
and
<a class="sister2" href="http://example.com/tillie" id="link3">
Tillie
</a>
;
and they lived at the bottom of a well.
</p>
<script>alert(1234)</script>
<p class="story sister2">
...
</p>
</body>
</html>
"""
# 第一步:实例化对象
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc,"html.parser")
# 第二步:美化
print(soup.prettify())
# 第三步:查找标签
print(soup.a) #只能找到符合条件的第一个标签
print(soup.find("a")) #只能找到符合条件的第一个标签
print(soup.find_all("a")) #找到所有的a标签
print(soup.a["class"]) #找到a标签的class属性
print(soup.find_all(name="a"))#找所有标签名是a标签的
print(soup.find_all(attrs={"class":"sister1"}))#找属性是class=sister1的
print(soup.find_all(name="a",attrs={"class":"sister1"}))#找a标签并且属性是class=sister1的 # ===========================
for ele_a in soup.find_all("a"):
print(ele_a.attrs) #找出a标签的所有的属性
print(ele_a["href"]) #找出所有的a标签的href属性
print(ele_a["class"]) #找出所有的a标签的class属性 for ele_a in soup.find_all("a"):
print(ele_a.attrs) #找出a标签的所有属性
del ele_a["class"] #删除a标签的class属性
#
for ele_a in soup.find_all("a"):
print(ele_a) #找出a标签 for ele in soup.find_all():
if ele.attrs:
'''如果有属性'''
if ele.attrs.get("class"):
'''如果得到class属性'''
print(ele.attrs)
del ele["class"]
print(soup) for ele_a in soup.find_all("script"): #soup是整个文档对象,循环整个文档的所有的script标签
print(ele_a.string) #所有a标签的文本
print(ele_a.text) #所有a标签的文本
ele_a.string.replace_with("//别瞎玩") #替换a标签的文本
print(soup)
四个对象:
1、comment对象:注释对象
2、Tag标签对象:相当于html中的一个标签对象
3、BeautifulSoup对象:相当于整个文档对象(Dom对象)
4、Navigablefetry文本对象
下面我们来具体应用一下:xss攻击防护。吧一些不安全的给删除或者替换了
def filter_xss(html_str):
valid_tag_list = ["p", "div", "a", "img", "html", "body", "br", "strong", "b"] #有效标签列表 valid_dict = {"img":["src","alt"],"p": ["id", "class"], "div": ["id", "class"]} #有效属性列表 from bs4 import BeautifulSoup soup = BeautifulSoup(html_str, "html.parser") # soup -----> document ######### 改成dict
for ele in soup.find_all():
# 过滤非法标签
if ele.name not in valid_dict:
ele.decompose()
# 过滤非法属性 else:
attrs = ele.attrs # p {"id":12,"class":"d1","egon":"dog"}
l = []
for k in attrs:
if k not in valid_dict[ele.name]:
l.append(k) for i in l:
del attrs[i] print(soup) return soup.decode()
kindedit编辑器和xxs攻击防护(BeautifulSoup)的简单使用的更多相关文章
- 局域网ARP攻击防护
通过借助一些安全软件来实现局域网ARP检测及防御功能. A.电脑管家 电脑管家--工具箱--下载ARP防火墙模块 不支持window2003 B.服务器安全狗 Windows版下载:http://fr ...
- 什么是高防服务器?如何搭建DDOS流量攻击防护系统
关于高防服务器的使用以及需求,从以往的联众棋牌到目前发展迅猛的手机APP棋牌,越来越多的游戏行业都在使用高防服务器系统,从2018年1月到11月,国内棋牌运营公司发展到了几百家. 棋牌的玩法模式从之前 ...
- Ddos攻击防护
Ddos攻击防护 首先我们说说ddos攻击方式,记住一句话,这是一个世界级的难题并没有解决办法只能缓解 DDoS(Distributed Denial of Service,分布式拒绝服务)攻击的主要 ...
- (转)网站DDOS攻击防护实战老男孩经验心得分享
网站DDOS攻击防护实战老男孩经验心得分享 原文:http://blog.51cto.com/oldboy/845349
- 几十万学费总结出来的Ddos攻击防护经验!
本人从事网络安全行业十余年年.有十年被骗经验.被骗了很多回(都说能防300G,500G,买完就防不住了),本文当然重点给大家说明,ddos攻击是什么,中小企业如何防护,用到成本等. 言归正传 首先我们 ...
- 爬虫基础库之beautifulsoup的简单使用
beautifulsoup的简单使用 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: ''' Beautiful Soup提供一些简单的.p ...
- python3 调用 beautifulSoup 进行简单的网页处理
python3 调用 beautifulSoup 进行简单的网页处理 from bs4 import BeautifulSoup file = open('index.html','r',encodi ...
- Nancy启用跨站攻击防护(CSRF)
什么是CSRF(跨站攻击) 可能很多人已经对CSRF有所了解,就简单的介绍下: CSRF全程是 Cross-Site Request Forgery .大概意思就是在登录用户不知情的情况下,由一个网站 ...
- 企业安全之APT攻击防护
现在针对企业APT[1]攻击越来越多了,企业安全也受到了严重的威胁,由于APT攻击比较隐匿的特性[2],攻击并不能被检测到,所以往往可以在企业内部网络潜伏很长时间. APT的攻击方式多种多样,导致企业 ...
随机推荐
- steps/train_mono.sh
<<单音素HMM的训练流程图.vsdx>> 定义拓扑结构.参数初始化 $ gmm-init-mono --shared-phones=$lang/phones/sets.int ...
- Luogu P2490「JSOI2016」黑白棋
我博弈基础好差.. Luogu P2490 题意 有一个长度为$ n$的棋盘,黑白相间的放$ k$个棋子,保证$ k$是偶数且最左边为白子 每次小$ A$可以移动不超过$ d$个白子,然后小$ B$可 ...
- Python 爬虫一 简介
什么是爬虫? 爬虫可以做什么? 爬虫的本质 爬虫的基本流程 什么是request&response 爬取到数据该怎么办 什么是爬虫? 网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间 ...
- .net+mvc,ueditor
.net+mvc的百度编辑器ueditor 一.下载百度编辑器:http://ueditor.baidu.com/website/download.html 选择.net版本 二.解压后在mvc项目中 ...
- #6278. 数列分块入门 2(询问区间内小于某个值 xx 的元素个数)
题目链接:https://loj.ac/problem/6278 题目大意:中文题目 具体思路:数列分块模板题,对于更新的时候,我们通过一个辅助数组来进行,对于原始的数组,我们只是用来加减,然后这个辅 ...
- 使用WinIo32绕过密码控件实现自动登录
通过winIO32绕过密码控件,实现自动登录 环境: vmware上安装windows 32位系统:windows xp / windows 7 selenium版本: 3.11.0 IEDriver ...
- Springboot Session集群处理
在集群环境下,常见的基于Session的身份认证就会有一个问题,因为Session是跟着服务器走的,当用户在服务器1登陆成功后,当用户在访问服务器2的时候会因为服务器2没有用户的身份信息而再次跳转到认 ...
- Elasticsearch 5.4.3实战--Java API调用:搜索建议
通常的搜索引擎,都会根据用户的输入,实时给予匹配的提示. 那么这个功能在elasticsearch中如何实现呢? Elasticsearch里设计了4种类别的Suggester,分别是: Term S ...
- Maya API Test
import maya.OpenMaya as OpenMaya import maya.OpenMayaMPx as OpenMayaMPx sl = OpenMaya.MSelectionList ...
- 效率较高的php下读取文本文件的代码
主要用下面这两个方法fread和 fgets的区别大家需要注意下 fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止. fgets :整行读取,遇 ...