捕获提交请求 Payload —— 反推隐藏字段名称与当前值(拦截 fetch / XMLHttpRequest)
适用于前端调试、接口分析、表单逆向、安全测试等场景。
🎯 功能说明
通过拦截 fetch 和 XMLHttpRequest 的请求发送过程,捕获提交的请求 payload(如 POST 数据),自动输出:
- 请求地址(URL)
- 请求体内容(body)
- 可从中反推出隐藏字段的名称与当前值(如 token, csrf, timestamp 等)
特别适合在无法查看源码或表单结构时,快速定位隐藏字段。
🔧 使用方法
- 打开浏览器开发者工具(F12)。
- 切换到 Console 选项卡。
- 粘贴以下脚本并执行:
(function () {
const origFetch = window.fetch;
window.fetch = async (...args) => {
const res = await origFetch.apply(this, args);
try {
const [url, config] = args;
if (config && config.body) {
console.group('[提交请求拦截]');
console.log('URL:', url);
console.log('Payload:', config.body);
console.groupEnd();
}
} catch (e) {
console.warn('捕获请求时出错:', e);
}
return res;
};
// 可选:同时拦截 XMLHttpRequest(兼容性更强)
const origOpen = window.XMLHttpRequest.prototype.open;
const origSend = window.XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.open = function (method, url, async) {
this._method = method;
this._url = url;
this._async = async;
return origOpen.call(this, method, url, async);
};
window.XMLHttpRequest.prototype.send = function (body) {
this._body = body;
const self = this;
const originalOnload = this.onload;
this.onload = function () {
if (self.status >= 200 && self.status < 300) {
console.group('[XMLHttpRequest 请求拦截]');
console.log('URL:', self._url);
console.log('Method:', self._method);
console.log('Payload:', self._body);
console.groupEnd();
}
if (originalOnload) originalOnload.call(self);
};
return origSend.call(this, body);
};
console.info('✅ 请求拦截已启用:fetch & XMLHttpRequest');
})();
