相关推荐recommended
xss攻击详解
作者:mmseoamin日期:2023-11-30

https://blog.csdn.net/weixin_44268918/article/details/xss攻击详解

  • https://blog.csdn.net/weixin_44268918/article/details/1 XSS详解
    • https://blog.csdn.net/weixin_44268918/article/details/1.https://blog.csdn.net/weixin_44268918/article/details/1 https://blog.csdn.net/weixin_44268918/article/details/xss简介
    • https://blog.csdn.net/weixin_44268918/article/details/1.2 https://blog.csdn.net/weixin_44268918/article/details/xss原理
    • https://blog.csdn.net/weixin_44268918/article/details/1.3 https://blog.csdn.net/weixin_44268918/article/details/xss危害
    • https://blog.csdn.net/weixin_44268918/article/details/1.4 https://blog.csdn.net/weixin_44268918/article/details/xss发生及挖掘
      • https://blog.csdn.net/weixin_44268918/article/details/1.4.https://blog.csdn.net/weixin_44268918/article/details/1 https://blog.csdn.net/weixin_44268918/article/details/xss发生过程
      • https://blog.csdn.net/weixin_44268918/article/details/1.4.2 https://blog.csdn.net/weixin_44268918/article/details/xss挖掘
        • https://blog.csdn.net/weixin_44268918/article/details/1.4.2.https://blog.csdn.net/weixin_44268918/article/details/1黑盒测试
        • https://blog.csdn.net/weixin_44268918/article/details/1.4.2.2 白盒测试
        • https://blog.csdn.net/weixin_44268918/article/details/1.5 https://blog.csdn.net/weixin_44268918/article/details/xss分类
          • https://blog.csdn.net/weixin_44268918/article/details/1.5.https://blog.csdn.net/weixin_44268918/article/details/1 反射型
            • https://blog.csdn.net/weixin_44268918/article/details/1.5.https://blog.csdn.net/weixin_44268918/article/details/1.https://blog.csdn.net/weixin_44268918/article/details/1 原理
            • https://blog.csdn.net/weixin_44268918/article/details/1.5.https://blog.csdn.net/weixin_44268918/article/details/1.2攻击位置
            • https://blog.csdn.net/weixin_44268918/article/details/1.5.https://blog.csdn.net/weixin_44268918/article/details/1.3案例
            • https://blog.csdn.net/weixin_44268918/article/details/1.5.2 存储型
              • https://blog.csdn.net/weixin_44268918/article/details/1.5.2.https://blog.csdn.net/weixin_44268918/article/details/1 原理
              • https://blog.csdn.net/weixin_44268918/article/details/1.5.2.2 攻击位置
              • https://blog.csdn.net/weixin_44268918/article/details/1.5.2.3案例
              • https://blog.csdn.net/weixin_44268918/article/details/1.5.3 DOM型
                • https://blog.csdn.net/weixin_44268918/article/details/1.5.3.https://blog.csdn.net/weixin_44268918/article/details/1原理
                • https://blog.csdn.net/weixin_44268918/article/details/1.5.3.2攻击位置
                • https://blog.csdn.net/weixin_44268918/article/details/1.5.3.3案例
                • https://blog.csdn.net/weixin_44268918/article/details/1.6 XSS攻击常用标签
                  • https://blog.csdn.net/weixin_44268918/article/details/1.6.https://blog.csdn.net/weixin_44268918/article/details/1 ``
                  • https://blog.csdn.net/weixin_44268918/article/details/1.6.2 ``
                  • https://blog.csdn.net/weixin_44268918/article/details/1.6.3 ``
                  • https://blog.csdn.net/weixin_44268918/article/details/1.6.4 ``
                  • https://blog.csdn.net/weixin_44268918/article/details/1.6.5 `

                    2 XSS平台

                    2.https://blog.csdn.net/weixin_44268918/article/details/1 XSS平台介绍

                      由于XSS的各种payload语句构建起来比较复杂,所以一般情况下都是使用XSS平台自动生成的payload去获取相关的cookie。但是在XSS平台使用过程中也需要注意平台否存在其他的恶意代码,同时在你测试某一个网站的时候信息会发送到这个平台,平台有就会知道这个漏洞,所以还是需要注意。

                      至于XSS平台的话,网上有很多的XSS平台,这里就不推荐了。

                    2.2 XSS平台使用

                    2.2.https://blog.csdn.net/weixin_44268918/article/details/1 注册XSS平台

                      当找到一个XSS平台后注册即可,当然也需要注意安全。

                    xss攻击详解,在这里插入图片描述,第10张

                    2.2.2 创建项目

                    2.2.2.https://blog.csdn.net/weixin_44268918/article/details/1 创建项目名称

                      点击左边的我的项目然后创建,在界面中输入项目名称,项目描述,然后下一步。

                    xss攻击详解,在这里插入图片描述,第11张

                    2.2.2.2 创建项目类型

                      选择你想要的项目类型然后勾选,勾选后点击配置。

                      需要注意的是在里面可能会存在一些无法使用的,多次获取如果获取不到可能存在配置问题或者拦截,也有可能就是这个项目无法使用。

                    xss攻击详解,在这里插入图片描述,第12张

                    2.2.2.3 查看代码

                      在右上角会有一个查看代码,进去就可以将生成的代码,插入到你挖掘到的XSS漏洞位置,后期当有人去访问的时候,XSS平台就会收到相关的信息。

                    xss攻击详解,在这里插入图片描述,第13张xss攻击详解,在这里插入图片描述,第14张

                      当然XSS平台中还存在很多的可选择的配置项目,都可以进行测试。但是总之还是那句话,由于XSS平台是别人搭建的,当你去进行XSS测试的时候,不单单你获取到这个cookie值,XSS平台的管理人员也能获取到这个cookie值,所以需要注意,若是内部测试,尽量还是不要使用XSS平台,可以自己搭建一个XSS平台。若想测试公网上的位置,那么自己搭建XSS平台的话需要有一个公网地址。具体如何搭建XSS平台,百度上有很多。

                    2.2.2.4 案例Flash弹窗钓鱼

                      在项目中点击配置,找到Flash弹窗钓鱼,输入跳转的URL。这里输入的是百度的网址,注意URL需要输入完整,如:https://www.baidu.com。然后点击配置。

                    xss攻击详解,在这里插入图片描述,第15张

                      然后查看代码,把生成的代码复制,插入https://blog.csdn.net/weixin_44268918/article/details/xss漏洞位置。

                    xss攻击详解,在这里插入图片描述,第16张

                      可以使用代码进行测试以下。使用pikachu中的反射型,如果使用存储型后面还需要删除,比较麻烦就使用反射型测试一下。可以看到一个flash的弹窗点击升级后会跳转到百度页面。

                    xss攻击详解,在这里插入图片描述,第17张xss攻击详解,在这里插入图片描述,第18张

                    3 Beef工具

                    3.https://blog.csdn.net/weixin_44268918/article/details/1 Beef工具介绍

                      BeEF是日前最强大的浏览器开源渗透测试框架,通过X55漏洞配合JS脚本和 Metasploit进行渗透; BeEF是基于Ruby语言编写的,并且支持图形化界面,操作简单。

                      新版的kail已经不自带beef工具了,需要自己下载。并且目前只支持macos和Linuhttps://blog.csdn.net/weixin_44268918/article/details/x系统。

                    3.2 Beef工具安装

                      在安装Beef工具之前建议更新一下源,免得出现错误。

                      apt-get update

                      apt-get install beef-https://blog.csdn.net/weixin_44268918/article/details/xss

                      当然在更新源的时候会比较慢,所以可以暂时去干别的事,等到更新好了,就可以安装beef工具了。

                    xss攻击详解,在这里插入图片描述,第19张

                    3.3 Beef工具启动

                      启动:beef-https://blog.csdn.net/weixin_44268918/article/details/xss

                      关闭:beef-https://blog.csdn.net/weixin_44268918/article/details/xss-stop

                    xss攻击详解,在这里插入图片描述,第20张

                    3.4 BeefWEB登录

                      登录地址:http://ip:3000/ui/panel。

                      账户密码:beef/beef

                      若在刚开始启动beef的时候设定了密码的话,那么密码就是你设置的那个登录密码,账户还是beef。

                    xss攻击详解,在这里插入图片描述,第21张

                    3.5 Beef案例测试

                    3.5.https://blog.csdn.net/weixin_44268918/article/details/1 插入构造代码

                      将代码插入pikache靶场的存储型https://blog.csdn.net/weixin_44268918/article/details/xss中。

                    xss攻击详解,在这里插入图片描述,第22张

                    3.5.2 靶机上线

                      通过从Beef工具上看,已经获取到靶机的相关信息了。

                    xss攻击详解,在这里插入图片描述,第23张

                    3.5.3 弹窗测试

                      在"Brower"下面的"Hooked Domain"的create Alert Dialog(弹窗 ),在alert thttps://blog.csdn.net/weixin_44268918/article/details/xt中输入你想要弹出来的内容,然后进行执行。

                    xss攻击详解,在这里插入图片描述,第24张

                      弹窗效果

                    xss攻击详解,在这里插入图片描述,第25张

                    4 WAF绕过

                    4.https://blog.csdn.net/weixin_44268918/article/details/1 大小写绕过

                      html对于大小写不敏感,可以利用大小写混淆过去。

                      示例:

                      

                      替换:

                      

                    4.2 双写绕过

                      在一些特定的情况下可能会存在某个关键字过滤,就可以尝试使用双写绕过。

                      示例:

                    $str2=str_replace("script","",$str);
                    $str3=str_replace("on","",$str2);
                    $str4=str_replace("src","",$str3);
                    $str5=str_replace("data","",$str4);
                    $str6=str_replace("href","",$str5);
                    

                      上述中对on替换为空。

                      

                    4.3 空格回车TAB绕过

                      由于js通常是以分号为结尾,当解析到完整语句并且行尾存在换行符的情况下就可以忽略掉分号,若解析确定不是完整语句,则会继续处理,直到语句结束或出现分号。

                    4.3.https://blog.csdn.net/weixin_44268918/article/details/1 空格绕过

                      示例:

                      xss攻击详解,第26张

                      替换:

                      xss攻击详解,第27张

                    4.3.2 回车绕过

                      示例:

                      xss攻击详解,第26张

                      替换:

                      xss攻击详解,第29张

                    4.3.3 TAB绕过

                      示例:

                      xss攻击详解,第26张

                      替换:

                      xss攻击详解,第31张

                    4.4 注释绕过

                      示例:

                      

                      替换:

                      pt>alert()ript>

                    4.5 字符拼接

                      利用eval:eval是Javascript内置函数,用于计算字符串表达式的值。

                      示例:

                      xss攻击详解,第32张

                      利用top

                      示例:

                      

                    4.6 编码绕过

                    4.6.https://blog.csdn.net/weixin_44268918/article/details/1 Unicode编码绕过

                      示例:

                      xss攻击详解,第26张

                      替换:

                      xss攻击详解,第34张

                    4.6.2 url 编码绕过

                      示例:

                      xss攻击详解,第26张

                      替换:

                      xss攻击详解,第36张

                    4.6.3 ascii码绕过

                      示例:

                      xss攻击详解,第26张

                      替换:

                      xss攻击详解,第38张

                    4.6.4 base64绕过

                      示例:

                      xss攻击详解,第26张

                      替换:

                      xss攻击详解,第40张

                    4.7 过滤URL绕过

                    4.7.https://blog.csdn.net/weixin_44268918/article/details/1 url编码绕过

                      示例:

                      xss攻击详解,第41张

                      替换:

                      xss攻击详解,第42张

                    4.7.2 IP绕过

                    4.7.2.https://blog.csdn.net/weixin_44268918/article/details/1 十进制

                      示例:

                      xss攻击详解,第41张

                      替换:

                      xss攻击详解,第44张

                    4.7.2.2 八进制

                      示例:

                      xss攻击详解,第41张

                      替换:

                      xss攻击详解,第46张

                    4.8 过滤双引号、单引号

                      如果是html标签中,我们可以不用引号。如果是在js中,我们可以用反引号代替单双引号

                      示例:

                      xss攻击详解,第47张

                      替换:

                      xss攻击详解,第48张

                    4.9 javascript伪协议绕过

                      将javascript代码添加到客户端的方法是把它放置在伪协议说明符javascript:后的URL中。这个特殊的协议类型声明了URL的主体是任意的javascript代码,它由javascript的解释器运行。如果javascript:URL中的javascript代码含有多个语句,必须使用分号将这些语句分隔开。

                    javascript:var now = new Date(); "The time is:" + now;

                      javascript URL还可以含有只执行动作,但不返回值的javascript语句。javascript:alert(“hello world!”)

                    4.9.https://blog.csdn.net/weixin_44268918/article/details/1 标签

                     &emsp说明:

                      标签定义超链接,用于从一个页面链接到另一个页面。

                      元素最重要的属性是href属性,它指定链接的目标。

                      示例:

                      https://blog.csdn.net/weixin_44268918/article/details/xss);">https://blog.csdn.net/weixin_44268918/article/details/xss

                    4.9.2 标签

                      说明:

                       标签定义 HTML 页面中的图像

                       标签有两个必需的属性:src 和 alt

                      示例:

                      //IE7以下

                    4.https://blog.csdn.net/weixin_44268918/article/details/10 绕过大全链接

                      链接:XSS攻击绕过过滤方法大全

                    5 https://blog.csdn.net/weixin_44268918/article/details/xss防御

                      整体思路:对用户输入的内容及访问的URL进行过滤,对输出内容进行编码,简单来说就是将用户提交的所有内容都进行过滤,排除关键字,敏感内容,对URL的参数也进行一定的过滤,并且对动态输出到页面的内容进行html编码,转换为html实体,使其用户输入的恶意代码无法在浏览器中执行。

                    5.https://blog.csdn.net/weixin_44268918/article/details/1 内容过滤

                      对其内容进行过滤,可以分为白名单和黑名单过滤。

                    5.https://blog.csdn.net/weixin_44268918/article/details/1.https://blog.csdn.net/weixin_44268918/article/details/1 白名单过滤

                      白名单过滤通过允许放行的内容进行过滤,这种情况下确实可以基本杜绝很多的XSS攻击,但是在现实环境中,可能会造成误拦截。

                    5.https://blog.csdn.net/weixin_44268918/article/details/1.2 黑名单过滤

                      黑名单过滤是对相关关键字进行拦截,黑名单输入可能杜绝绝大XSS攻击,但是依旧存在被绕过的可能。

                    5.2 http only属性

                      在服务端中设置会话cookie的HTTP only属性,这样客户端JS脚本就不能获取cookie信息。

                    5.3 明确输入内容

                      对用户输入的内容进行明确类型,如个人信息电话、数字、密码、邮箱地址等都位置都过滤一些不符合的内容。

                    5.4 输入内容长度控制

                      对不可信的内容都应该进行长度限制,例如电话号码https://blog.csdn.net/weixin_44268918/article/details/1https://blog.csdn.net/weixin_44268918/article/details/1位,那么就设置https://blog.csdn.net/weixin_44268918/article/details/1https://blog.csdn.net/weixin_44268918/article/details/1位,这样虽然不能百分百防止XSS攻击,但是可以增加XSS攻击实现的难度。

                    5.5 安全措施

                      添加验证码、开启相关防护软件、WAF软硬件。