-
Notifications
You must be signed in to change notification settings - Fork 35
/
test.mjs
167 lines (158 loc) · 6.58 KB
/
test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import child_process from 'child_process';
import Socratex from './index.mjs';
import util from 'util';
const test1 = async () => {
console.log('\nStarting TEST1 - Normal socratex!');
const server = new Socratex({});
const toTest = ['https://ifconfig.me', 'http://icanhazip.com', 'https://ifconfig.io/ua', 'http://asdahke.e'];
const PORT = 10001;
return new Promise(function(res, rej) {
server.listen(PORT, '0.0.0.0', async function() {
console.log('socratex was started!', server.address());
for (const singlePath of toTest) {
const cmd = 'curl' + ' -x 127.0.0.1:' + PORT + ' ' + singlePath;
console.log(cmd);
const { stdout, stderr } = await exec(cmd);
console.log('Response =>', stdout);
}
console.log('Closing socratex Server - TEST1\n');
server.close();
res(true);
});
});
};
// @todo: fix this test!
// by @Leask
// disabled some test due to LibreSSL compatibility issues
// const test2 = async () => {
// console.log('\nStarting TEST2 - Spoof Response!');
// let ownIp = '';
// const switchWith = '6.6.6.6';
// const IP_REGEXP = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
// const toTest = ['https://ifconfig.me', 'http://ifconfig.me'];
// const PORT = 10002; //starting server on port 10001
// const cmdOwnIp = 'curl ' + toTest[0];
// console.log('Getting Own ip with', cmdOwnIp);
// const { stdout, stderr } = await exec(cmdOwnIp);
// ownIp = stdout.match(IP_REGEXP)[0].trim();
// console.log('Your IP is:', ownIp);
// console.log('Starting Proxy Server with spoof-behaviors');
// const server = new Socratex({
// intercept: true,
// injectResponse: (data, session) => { // SPOOFING RETURNED RESPONSE
// if (data.toString().match(ownIp)) {
// const newData = Buffer.from(data.toString()
// .replace(new RegExp('Content-Length: ' + ownIp.length, 'gmi'),
// 'Content-Length: ' + (switchWith.length))
// .replace(ownIp, switchWith));
// return newData;
// }
// return data;
// }
// });
// return new Promise(function(res, rej) {
// server.listen(PORT, '0.0.0.0', async function() {
// console.log('socratex was started!', server.address());
// for (const singlePath of toTest) {
// const cmd = 'curl' + ' -x 127.0.0.1:' + PORT + ' -k ' + singlePath;
// console.log(cmd);
// const { stdout, stderr } = await exec(cmd);
// console.log('Response =>', stdout);
// }
// console.log('Closing socratex Server - TEST2\n');
// server.close();
// res(true);
// });
// });
// };
// const test3 = async () => {
// console.log('\nStarting TEST3 - Spoof Request!');
// const toTest = ['http://ifconfig.io/ua', 'https://ifconfig.me/ua'];
// const PORT = 10003; //starting server on port 10001
// console.log('Starting Proxy Server with spoof-behaviors');
// const server = new Socratex({
// intercept: true,
// injectData: (data, session) => {
// return Buffer.from(data.toString().replace('curl/7.55.1', 'Spoofed UA!!'));
// }
// });
// return new Promise(function(res, rej) {
// server.listen(PORT, '0.0.0.0', async function() {
// console.log('socratex was started!', server.address());
// for (const singlePath of toTest) {
// const cmd = 'curl' + ' -x 127.0.0.1:' + PORT + ' -k ' + singlePath;
// console.log(cmd);
// const { stdout, stderr } = await exec(cmd);
// console.log('Response =>', stdout);
// }
// console.log('Closing socratex Server - TEST3\n');
// server.close();
// res(true);
// });
// })
// };
// const test4 = async () => {
// console.log('\nStarting TEST4 - Change Some Keys on runtime!');
// const toTest = ['https://ifconfig.me/', 'https://ifconfig.me/ua'];
// const PORT = 10004; //starting server on port 10001
// const server = new Socratex({
// intercept: true,
// keys: (session) => {
// const tunnel = session.getTunnelStats();
// console.log('\t\t=> Could change keys for', tunnel);
// return false;
// }
// });
// return new Promise(function(res, rej) {
// server.listen(PORT, '0.0.0.0', async function() {
// console.log('socratex was started!', server.address());
// for (const singlePath of toTest) {
// const cmd = 'curl' + ' -x 127.0.0.1:' + PORT + ' -k ' + singlePath;
// console.log(cmd);
// const { stdout, stderr } = await exec(cmd);
// console.log('Response =>', stdout);
// }
// console.log('Closing socratex Server - TEST4\n');
// server.close();
// res(true);
// });
// });
// };
// const test5 = async () => {
// console.log('\nStarting TEST5 - Proxy With Authentication!');
// const singlePath = 'https://ifconfig.me/';
// const pwdToTest = ['bar:foo', 'wronguser:wrongpassword'];
// const PORT = 10005; //starting server on port 10001
// const server = new Socratex({
// auth: (username, password, session) => {
// return username === 'bar' && password === 'foo';
// }
// });
// return new Promise(function(res, rej) {
// server.listen(PORT, '0.0.0.0', async function() {
// console.log('socratex was started!', server.address());
// for (const pwd of pwdToTest) {
// const cmd = 'curl' + ' -x ' + pwd + '@127.0.0.1:' + PORT + ' ' + singlePath;
// console.log(cmd);
// const { stdout, stderr } = await exec(cmd)
// .catch((err) => {
// if (err.message.indexOf('HTTP code 407')) return { stdout: 'HTTP CODE 407' };
// throw err;
// });
// console.log('Response =>', stdout);
// }
// console.log('Closing socratex Server - TEST5\n');
// server.close();
// res(true);
// });
// });
// };
const exec = util.promisify(child_process.exec);
const main = async () => {
await test1();
// await test2();
// await test3();
// await test4();
// await test5();
};
await main();