-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
158 lines (124 loc) · 4.57 KB
/
app.js
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
const express = require('express');
const fs = require('fs');
const app = express();
const port = 3000;
app.use((req, res, next) => {
res.setHeader('X-Powered-By', 'Made by UltraLion');
next();
});
function WinSCP() {
var WSCP_CHARS = [];
var WSCP_SIMPLE_MAGIC = 0xA3;
var WSCP_SIMPLE_STRING = '0123456789ABCDEF';
var WSCP_SIMPLE_MAXLEN = 50;
var WSCP_SIMPLE_FLAG = 0xFF;
var WSCP_SIMPLE_INTERNAL = 0x00;
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function _simple_encrypt_char(char) {
char = ~char ^ WSCP_SIMPLE_MAGIC;
var a = (char & 0xF0) >> 4;
var b = (char & 0x0F) >> 0;
return [WSCP_SIMPLE_STRING[a], WSCP_SIMPLE_STRING[b]].join('');
}
function _simple_decrypt_next_char() {
if (WSCP_CHARS.length == 0) {
return WSCP_SIMPLE_INTERNAL;
}
var a = WSCP_SIMPLE_STRING.indexOf(WSCP_CHARS.shift());
var b = WSCP_SIMPLE_STRING.indexOf(WSCP_CHARS.shift());
return WSCP_SIMPLE_FLAG & ~(((a << 4) + b << 0) ^ WSCP_SIMPLE_MAGIC);
}
// Encrypt password
this.encrypt = function(username, hostname, password) {
var salt = [username, hostname, password].join(''), shift = 0;
if (salt.length < WSCP_SIMPLE_MAXLEN) {
shift = rand(0, WSCP_SIMPLE_MAXLEN - salt.length);
}
result = [];
result.push(_simple_encrypt_char(WSCP_SIMPLE_FLAG));
result.push(_simple_encrypt_char(WSCP_SIMPLE_INTERNAL));
result.push(_simple_encrypt_char(salt.length));
result.push(_simple_encrypt_char(shift));
for (var i = 0; i < shift; i++) {
result.push(_simple_encrypt_char(rand(0, 256)));
}
for (var i = 0; i < salt.length; i++) {
result.push(_simple_encrypt_char(salt[i].charCodeAt(0)));
}
while (result.length < WSCP_SIMPLE_MAXLEN * 2) {
result.push(_simple_encrypt_char(rand(0, 256)));
}
return result.join('');
}
// Descrypt password
this.decrypt = function(username, hostname, encrypted) {
if (!encrypted.match(/[A-F0-9]+/)) {
return '';
}
var result = [], key = [username, hostname].join('');
WSCP_CHARS = encrypted.split('');
var flag = _simple_decrypt_next_char(), length;
if (flag == WSCP_SIMPLE_FLAG) {
_simple_decrypt_next_char();
length = _simple_decrypt_next_char();
} else {
length = flag;
}
WSCP_CHARS = WSCP_CHARS.slice(_simple_decrypt_next_char() * 2);
for (var i = 0; i < length; i++) {
result.push(String.fromCharCode(_simple_decrypt_next_char()));
}
if (flag == WSCP_SIMPLE_FLAG) {
var valid = result.slice(0, key.length).join('');
if (valid != key) {
result = [];
} else {
result = result.slice(key.length);
}
}
WSCP_CHARS = [];
return result.join('');
}
}
const winSCP = new WinSCP();
function decodePassword(username, hostname, encodedPassword) {
const decodedPassword = winSCP.decrypt(username, hostname, encodedPassword);
return decodedPassword;
}
app.get('/decodeAll', (req, res) => {
const filePath = 'WinSCP.ini'; // Replace with the path to your WinSCP.ini file
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
return res.status(500).send('Error reading file');
}
const sessions = data.split('\n[').filter(session => session.startsWith('Sessions\\'));
const decodedSessions = sessions.map(session => {
const sessionName = decodeURIComponent(session.split(']')[0].replace('Sessions\\', ''));
const usernameLine = session.split('\n').find(line => line.startsWith('UserName='));
const hostnameLine = session.split('\n').find(line => line.startsWith('HostName='));
const passwordLine = session.split('\n').find(line => line.startsWith('Password='));
if (usernameLine && hostnameLine && passwordLine) {
const username = usernameLine.split('=')[1].trim();
const hostname = hostnameLine.split('=')[1].trim();
const encodedPassword = passwordLine.split('=')[1].trim();
const decodedPassword = decodePassword(username, hostname, encodedPassword);
return {
session: sessionName,
username,
hostname,
decodedPassword
};
}
return {
session: sessionName,
decodedPassword: 'Password not found'
};
});
res.send(decodedSessions);
});
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});