Commit 3555ca98 authored by Medicean's avatar Medicean

Merge branch 'feature/decoder' into v2.1.x

parents 31f0bb60 c9586e85
......@@ -156,6 +156,7 @@ class Database {
addr: ret['addr'],
encode: opts.base['encode'],
encoder: opts.base['encoder'],
decoder: opts.base['decoder'],
httpConf: opts.http,
otherConf: opts.other,
ctime: +new Date,
......@@ -198,6 +199,7 @@ class Database {
type: _new.base['type'],
encode: _new.base['encode'],
encoder: _new.base['encoder'],
decoder: _new.base['decoder'],
httpConf: _new.http,
otherConf: _new.other,
utime: +new Date
......
/**
* asp::default解码器
*/
'use strict';
module.exports = {
asoutput: () => {
return ``.replace(/\n\s+/g, '');
},
decode_str: (data) => {
return data;
},
decode_buff: (data) => {
return data;
}
}
\ No newline at end of file
......@@ -27,6 +27,10 @@ class ASP extends Base {
this.encoders.map((_) => {
this.parseEncoder(`./asp/encoder/${_}`);
});
this.decoders.map((_) => {
this.parseDecoder(`./asp/decoder/${_}`);
});
}
/**
......@@ -37,6 +41,10 @@ class ASP extends Base {
return ['insert_percent', 'xxxxdog'];
}
get decoders() {
return ['default'];
}
/**
* HTTP请求数据组合函数
* @param {Object} data 通过模板解析后的代码对象
......
/**
* aspx::default解码器
*/
'use strict';
module.exports = {
asoutput: () => {
return ``.replace(/\n\s+/g, '');
},
decode_str: (data) => {
return data;
},
decode_buff: (data) => {
return data;
}
}
\ No newline at end of file
......@@ -30,6 +30,9 @@ class ASPX extends Base {
this.encoders.map((_) => {
this.parseEncoder(`./aspx/encoder/${_}`);
});
this.decoders.map((_) => {
this.parseDecoder(`./aspx/decoder/${_}`);
});
}
/**
......@@ -40,6 +43,10 @@ class ASPX extends Base {
return ["base64","hex"];
}
get decoders() {
return ["default"];
}
/**
* HTTP请求数据组合函数
* @param {Object} data 通过模板解析后的代码对象
......
......@@ -53,6 +53,7 @@ class Base {
](pwd, data);
}
}
this['__decoder__'] = {}
// 解析自定义编码器
this.user_encoders.map((_) => {
this.parseEncoder(`${_}`);
......@@ -207,6 +208,11 @@ class Base {
this['__encoder__'][enc.indexOf(`encoder/`) > -1 ? enc.split(`encoder/`)[1] : enc.split(`encoder\\`)[1]] = require(`${enc}`);
}
parseDecoder(dec) {
delete require.cache[require.resolve(`${dec}`)];
this['__decoder__'][dec.indexOf(`decoder/`) > -1 ? dec.split(`decoder/`)[1] : dec.split(`decoder\\`)[1]] = require(`${dec}`);
}
/**
* 编码处理并返回操作
* @param {String} tag_s 前截断符
......@@ -249,13 +255,13 @@ class Base {
.once(`request-${hash}`, (event, ret) => {
return res({
'encoding': ret['encoding'] || "",
'text': ret['text'],
'buff': ret['buff']
'text': this.__decoder__[this.__opts__['decoder']||'default'].decode_str(ret['text']),
'buff': this.__decoder__[this.__opts__['decoder']||'default'].decode_buff(ret['buff'])
});
})
// HTTP请求返回字节流
.on(`request-chunk-${hash}`, (event, ret) => {
return chunkCallBack ? chunkCallBack(ret) : null;
return chunkCallBack ? chunkCallBack(this.__decoder__[this.__opts__['decoder']||'default'].decode_buff(ret)) : null;
})
// 数据请求错误
.once(`request-error-${hash}`, (event, ret) => {
......@@ -289,7 +295,7 @@ class Base {
* @return {Promise} Promise操作对象
*/
download(savePath, postCode, progressCallback) {
const opt = this.complete(postCode);
const opt = this.complete(postCode, true);
return new Promise((ret, rej) => {
// 随机ID(用于监听数据来源)
const hash = (String(+new Date) + String(Math.random())).substr(10, 10).replace('.', '_');
......
/**
* CUSTOM::default解码器
*/
'use strict';
module.exports = {
asoutput: () => {
return ``.replace(/\n\s+/g, '');
},
decode_str: (data) => {
return data;
},
decode_buff: (data) => {
return data;
}
}
\ No newline at end of file
......@@ -23,6 +23,9 @@ class CUSTOM extends Base {
this.encoders.map((_) => {
this.parseEncoder(`./custom/encoder/${_}`);
});
this.decoders.map((_) => {
this.parseDecoder(`./custom/decoder/${_}`);
});
}
/**
......@@ -33,6 +36,10 @@ class CUSTOM extends Base {
return ['base64','hex'];
}
get decoders() {
return ["default", "base64"];
}
/**
* HTTP请求数据组合函数
* @param {Object} data 通过模板解析后的代码对象
......
/**
* php::base64解码器
*/
'use strict';
module.exports = {
/**
* @returns {string} asenc 将返回数据base64编码
*/
asoutput: () => {
return `function asenc($out){
return @base64_encode($out);
}
`.replace(/\n\s+/g, '');
},
/**
* 解码字符串
* @param {string} data 要被解码的字符串
* @returns {string} 解码后的字符串
*/
decode_str: (data) => {
return Buffer.from(data, 'base64').toString();
},
/**
* 解码 Buffer
* @param {string} data 要被解码的 Buffer
* @returns {string} 解码后的 Buffer
*/
decode_buff: (data) => {
return Buffer.from(data.toString(), 'base64');
}
}
\ No newline at end of file
/**
* php::default解码器
*/
'use strict';
module.exports = {
/**
* @returns {string} asenc 加密返回数据的函数
*/
asoutput: () => {
return `function asenc($out){
return $out;
}
`.replace(/\n\s+/g, '');
},
/**
* 解码字符串
* @param {string} data 要被解码的字符串
* @returns {string} 解码后的字符串
*/
decode_str: (data) => {
return data;
},
/**
* 解码 Buffer
* @param {string} data 要被解码的 Buffer
* @returns {string} 解码后的 Buffer
*/
decode_buff: (data) => {
return data;
}
}
\ No newline at end of file
/**
* php::base64解码器
* ? 利用php的base64_decode进行解码处理
*/
'use strict';
const rot13encode = (s) => {
//use a Regular Expression to Replace only the characters that are a-z or A-Z
return s.replace(/[a-zA-Z]/g, function (c) {
//Get the character code of the current character and add 13 to it
//If it is larger than z's character code then subtract 26 to support wrap around.
return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
});
};
module.exports = {
asoutput: (tag_s, tag_e) => {
return `function asenc($out){
return str_rot13($out);
}
`.replace(/\n\s+/g, '');
},
decode_str: (data) => {
return rot13encode(data);
},
decode_buff: (data) => {
return Buffer.from(rot13encode(data.toString()));
}
}
\ No newline at end of file
......@@ -31,6 +31,9 @@ class PHP extends Base {
this.encoders.map((_) => {
this.parseEncoder(`./php/encoder/${_}`);
});
this.decoders.map((_) => {
this.parseDecoder(`./php/decoder/${_}`);
});
}
/**
......@@ -42,20 +45,29 @@ class PHP extends Base {
return ["base64", "chr", "chr16", "rot13"];
}
get decoders() {
return ["default", "base64", "rot13"];
}
/**
* HTTP请求数据组合函数
* @param {Object} data 通过模板解析后的代码对象
* @param {bool} force_default 强制使用 default 解码
* @return {Promise} 返回一个Promise操作对象
*/
complete(data) {
complete(data, force_default=false) {
// 分隔符号
let tag_s = Math.random().toString(16).substr(2, 5); // "->|";
let tag_e = Math.random().toString(16).substr(2, 5); // "|<-";
let asencCode;
if(!force_default){
asencCode = this.__decoder__[this.__opts__['decoder'] || 'default'].asoutput();
}else{
asencCode = this.__decoder__['default'].asoutput();
}
// 组合完整的代码
let tmpCode = data['_'];
data['_'] = `@ini_set("display_errors", "0");@set_time_limit(0);echo "${tag_s}";try{${tmpCode};}catch(Exception $e){echo "ERROR://".$e->getMessage();};echo "${tag_e}";die();`;
data['_'] = `@ini_set("display_errors", "0");@set_time_limit(0);${asencCode};function asoutput(){$output=ob_get_contents();ob_end_clean();echo "${tag_s}";echo @asenc($output);echo "${tag_e}";}register_shutdown_function("asoutput");ob_start();try{${tmpCode};}catch(Exception $e){echo "ERROR://".$e->getMessage();};die();`;
// 使用编码器进行处理并返回
return this.encodeComplete(tag_s, tag_e, data);
......
......@@ -121,7 +121,8 @@ module.exports = {
note: '网站备注',
encode: '编码设置',
type: '连接类型',
encoder: '编码器'
encoder: '编码器',
decoder: '解码器',
},
test_success: '连接成功!',
test_warning: '返回数据为空',
......
......@@ -50,6 +50,7 @@ class Form {
"type": opts.base['type'],
"encode": opts.base['encode'],
"encoder": opts.base['encoder'],
"decoder": opts.base['decoder'],
"httpConf": opts.http,
"otherConf": opts.other,
}
......@@ -194,7 +195,8 @@ class Form {
note: '',
type: 'php',
encode: 'utf8',
encoder: 'default'
encoder: 'default',
decoder: 'default'
}, arg);
const form = this.accordion.cells('base').attachForm([
{ type: 'settings', position: 'label-left', labelWidth: 80, inputWidth: 400 },
......@@ -213,7 +215,7 @@ class Form {
name: 'encode', readonly: true, options: this._parseEncodes(opt.encode)
}, {
type: 'combo', label: LANG['list']['add']['form']['type'],
name: 'type', readonly: true, options: this._parseTypes(opt.type, opt.encoder)
name: 'type', readonly: true, options: this._parseTypes(opt.type, opt.encoder, opt.decoder)
}
] }
], true);
......@@ -283,17 +285,20 @@ class Form {
* @param {String} _encoder 默认编码器
* @return {array} [description]
*/
_parseTypes(_default = 'php', _encoder = 'default') {
_parseTypes(_default = 'php', _encoder = 'default', _decoder = 'default') {
let ret = [];
for (let c in antSword['core']) {
// 加载默认编码器和用户自定义编码器
let encoders;
let decoders;
switch(c){
case 'php4':
encoders = antSword['core']['php4'].prototype.encoders.concat(antSword['encoders']['php']);
decoders = antSword['core'][c].prototype.decoders;
break;
default:
encoders = antSword['core'][c].prototype.encoders.concat(antSword['encoders'][c]);
decoders = antSword['core'][c].prototype.decoders;
break;
}
ret.push({
......@@ -317,6 +322,16 @@ class Form {
value: e, label: e, checked: e === _encoder
})
});
_.push({
type: 'label', label: LANG['list']['add']['form']['decoder']
});
decoders.map((e) => {
_.push({
type: 'radio', name: `decoder_${c}`,
value: e, label: e, checked: e === _decoder
})
});
return _;
})(c)
});
......@@ -340,7 +355,8 @@ class Form {
note: base['note'],
type: base['type'],
encode: base['encode'],
encoder: base[`encoder_${base['type']}`]
encoder: base[`encoder_${base['type']}`],
decoder: base[`decoder_${base['type']}`]
};
// 提取需要的http数据
let [headers, bodys] = [{}, {}];
......
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