Commit c2613581 authored by Mr6's avatar Mr6 Committed by Medicean

(Enhancement: Module) request 增加垃圾数据填充功能 (thx: @yzddmr6)

支持 form-data 和 multipart 模式
parent a273062b
......@@ -118,7 +118,7 @@ class Request {
_request.set(_, opts.headers[_]);
}
// 自定义body
const _postData = Object.assign({}, opts.body, opts.data);
let _postData = Object.assign({}, opts.body, opts.data);
if (opts['useChunk'] == 1) {
logger.debug("request with Chunked");
let _postarr = [];
......@@ -199,6 +199,13 @@ class Request {
}
}
} else {
if(opts['addMassData']==1){
for (let i = 0; i < randomInt(num_min, num_max); i++) { //将混淆流量放入到payload数组中
_postData[randomString(randomInt(varname_min, varname_max))] = randomString(randomInt(data_min, data_max));
}
_postData=randomDict(_postData);
//logger.debug(_postData);
}
_request.send = old_send;
for (var key in _postData) {
if (_postData.hasOwnProperty(key)) {
......@@ -208,6 +215,8 @@ class Request {
_postarr.push(`${key}=${_tmp}`);
}
}
//console.log(_postarr);
//logger.debug(_postarr);
_postarr = _postarr.join('&');
}
_request
......@@ -292,7 +301,7 @@ class Request {
_request.set(_, opts.headers[_]);
}
// 自定义body
const _postData = Object.assign({}, opts.body, opts.data);
let _postData = Object.assign({}, opts.body, opts.data);
if (opts['useChunk'] == 1) {
logger.debug("request with Chunked");
let _postarr = [];
......@@ -346,6 +355,13 @@ class Request {
_request.send = _request.field;
_postarr = _postData;
} else {
if(opts['addMassData']==1){
for (let i = 0; i < randomInt(num_min, num_max); i++) { //将混淆流量放入到payload数组中
_postData[randomString(randomInt(varname_min, varname_max))] = randomString(randomInt(data_min, data_max));
}
_postData=randomDict(_postData);
//logger.debug(_postData);
}
_request.send = old_send;
for (var key in _postData) {
if (_postData.hasOwnProperty(key)) {
......@@ -573,5 +589,37 @@ class AntRead extends Readable {
}
}
}
let varname_min = 5; //变量名最小长度
let varname_max = 15; // 变量名最大长度
let data_min = 200; // 变量值最小长度
let data_max = 250; // 变量值最大长度
let num_min = 150; // 变量最小个数
let num_max = 250; // 变量最大个数
function randomString(length) { // 生成随机字符串
//let chars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let result = '';
for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
function randomInt(min, max) { //生成指定范围内的随机数
return parseInt(Math.random() * (max - min + 1) + min, 10);
}
function randomDict(dic){
let tmparray=[]
for(let i in dic){
tmparray.push(i)
}
tmparray=tmparray.sort((a, b)=> { return Math.random() > 0.5 ? -1 : 1; })
let finaldata={}
tmparray.forEach(i => {
finaldata[i]=dic[i]
});
return finaldata
}
module.exports = Request;
\ No newline at end of file
......@@ -330,6 +330,7 @@ class Base {
chunkStepMin: (this.__opts__['otherConf'] || {})['chunk-step-byte-min'] || 2,
chunkStepMax: (this.__opts__['otherConf'] || {})['chunk-step-byte-max'] || 3,
useMultipart: (this.__opts__['otherConf'] || {})['use-multipart'] === 1,
addMassData: (this.__opts__['otherConf'] || {})['add-MassData'] === 1,
useRandomVariable: (this.__opts__['otherConf'] || {})['use-random-variable'] === 1,
timeout: parseInt((this.__opts__['otherConf'] || {})['request-timeout']),
headers: (this.__opts__['httpConf'] || {})['headers'] || {},
......@@ -382,6 +383,7 @@ class Base {
chunkStepMin: (this.__opts__['otherConf'] || {})['chunk-step-byte-min'] || 2,
chunkStepMax: (this.__opts__['otherConf'] || {})['chunk-step-byte-max'] || 3,
useMultipart: (this.__opts__['otherConf'] || {})['use-multipart'] === 1,
addMassData: (this.__opts__['otherConf'] || {})['add-MassData'] === 1,
useRandomVariable: (this.__opts__['otherConf'] || {})['use-random-variable'] === 1,
timeout: parseInt((this.__opts__['otherConf'] || {})['request-timeout']),
headers: (this.__opts__['httpConf'] || {})['headers'] || {},
......
......@@ -176,6 +176,7 @@ module.exports = {
otherConf: {
nohttps: 'Ignore HTTPS certificate',
usemultipart: 'Use Multipart send payload',
addMassData: 'Add garbage data in payload',
userandomvariable: 'Use random English word variables',
chunk: {
title: 'Chunked Transfer (Experimentally)',
......
......@@ -179,6 +179,7 @@ module.exports = {
nohttps: '忽略HTTPS证书',
usemultipart: '使用 Multipart 发包',
userandomvariable: '使用随机英文单词变量',
addMassData: '增加垃圾数据',
chunk: {
title: '分块传输(实验性功能)',
usechunk: '开启分块传输发包',
......
......@@ -177,6 +177,7 @@ module.exports = {
otherConf: {
nohttps: '忽略HTTPS證書',
usemultipart: '使用 Multipart 發包',
addMassData: '增加垃圾數據',
userandomvariable: '使用隨機英文單詞變量',
chunk: {
title: '分塊傳輸(實驗性功能)',
......
......@@ -177,6 +177,7 @@ module.exports = {
otherConf: {
nohttps: '忽略HTTPS證書',
usemultipart: '使用 Multipart 發包',
addMassData: '增加垃圾數據',
userandomvariable: '使用隨機英文單詞變量',
chunk: {
title: '分塊傳輸(實驗性功能)',
......
......@@ -466,6 +466,7 @@ class Form {
const opt = Object.assign({}, {
'ignore-https': 0,
'use-multipart': 0,
'add-MassData': 0,
'use-random-variable': 0,
'use-chunk': 0,
'chunk-step-byte-min': 2,
......@@ -500,12 +501,17 @@ class Form {
name: 'use-random-variable',
label: LANG['list']['otherConf']['userandomvariable'],
checked: opt['use-random-variable'] === 1
}, {
type: "checkbox",
name: 'add-MassData',
label: LANG['list']['otherConf']['addMassData'],
checked: opt['add-MassData'] === 1
}, {
type: "checkbox",
name: 'use-multipart',
label: LANG['list']['otherConf']['usemultipart'],
checked: opt['use-multipart'] === 1
}, {
},{
type: 'fieldset',
offsetLeft: 0,
label: LANG['list']['otherConf']['chunk']['title'],
......@@ -771,6 +777,10 @@ class Form {
if (state == true && form.isItemChecked('use-multipart')) {
form.uncheckItem('use-multipart');
}
// case 'add-MassData':
// if (state == true && form.isItemChecked('add-MassData')) {
// form.uncheckItem('add-MassData');
// }
if (state == true) {
layer.open({
title: LANG_T['info'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment