This repository was archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
168 lines (134 loc) · 4.8 KB
/
index.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
159
160
161
162
163
164
165
166
167
168
const path = require('path');
const { readdirSync } = require('fs');
const config = require('./config.json');
const express = require('express'),
hyenas = express();
const { parse } = require('querystring'),
{ parseString } = require('xml2js');
const { ticketGen } = require('./local_modules/ticketTools.js'),
{ profileGen } = require('./local_modules/profileTools.js');
hyenas.use(express.static(config.static));
const updns = require('updns').createServer(53, '127.0.0.1')
// Updns functions, error and starting Updns as a service.
updns.on('error', error => {
console.log(error)
})
updns.on('listening', server => {
console.log('DNS service has started')
})
//TLSv1.2 Testing with a Certificate and Key.
var fs = require('fs');
var http = require('http');
var https = require('https');
//var privateKey = fs.readFileSync('certs/SCEIDNASROOT05.key', 'utf8');
//var certificate = fs.readFileSync('certs/SCEIDNASROOT05.crt', 'utf8');
//var credentials = { key: privateKey, cert: certificate };
var httpsServer = https.createServer(/*credentials,*/ hyenas);
httpsServer.listen(config.port3, () => console.log(`Hyenas has started https server on Port: ${config.port3}`));
/*
updns.on('message', (domain, send, proxy) => {
if(domain === 'playstation.com'){
console.log("Redirecting ${domain}")
send('127.0.0.1')
}else {
proxy('127.0.0.1')
}
})
*/
//MySQL Testing
/*
const sql = require('mysql');
hyenas.connection = sql.createConnection({
host: config.host,
user: config.username,
password: config.password,
database: config.database,
insecureAuth: true
});
hyenas.connection.config.queryFormat = function (query, values) {
if (!values) return query;
return query.replace(/\:(\w+)/g, function (txt, key) {
if (values.hasOwnProperty(key))
return this.escape(values[key]);
return txt;
}.bind(this));
};
hyenas.connection.connect((err) => {
if (err) throw err;
console.log(`[OK] SQL connection made to database: ${config.database}`);
});
*/ // Until proper SQL is setup, this should be commented, I suppose. //
// Weird module setup, should probably be changed at some point. //
const getModules = source => readdirSync(source, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
const modules = getModules(path.join(__dirname, config.modules));
modules.forEach((module) => {
try {
require(path.join(__dirname, config.modules, module, 'module.js'))(hyenas)
console.log(`Hyenas has initialized module: ${module}`);
} catch (error) { console.log(`Hyenas failed to initialize module: ${module}`)}
});
hyenas.post('/nav/auth/', (req, res) => {
res.writeHead(200, {
'Content-Type': 'application/x-i-5-ticket',
'X-I-5-Version': '1.0',
'X-N': 'S',
'X-I-5-Status': 'OK'
});
collectRequestData(req, result =>
res.end(ticketGen(result.loginid, result.password, result.serviceid)));
});
hyenas.get('/nav/auth/', (req, res) => {
res.writeHead(400, {
'Content-Type': 'application/x-i-5-ticket',
'Filename': 'ticket.dat',
'X-I-5-Version': "1.0",
'X-N': 'S',
'X-I-5-Status': 'NG',
'reason': '400'
}); // likely isn't what its looking for but whatever, its an http response code
res.end();
});
hyenas.post('/basic_view/sec/get_self_profile/', (req, res) => {
collectRequestData(req, result =>
res.status(200).end(profileGen(result.profile.ticket[0], result.profile.env)));
});
hyenas.get('/basic_view/sec/get_self_profile', (req, res) => res.status(400).end());
//Network Test Functions
hyenas.get('/networktest/get_2m', (req, res) => {
try {
res.end(Buffer.alloc(2097152));
} catch (err) { res.status(410).end(); }
});
hyenas.get('/gs2/networktest/get_6m', (req, res) =>
res.sendFile(path.join(__dirname, config.system, 'networktest/get_6m')));
hyenas.post('/networktest/post_128', (req, res) => res.status(200).end());
//Start Hyenas on Port 80 as port1 and Port 53 as port2
hyenas.listen(config.port1, () => console.log(`Hyenas has started on Port: ${config.port1}`));
hyenas.listen(config.port2, () => console.log(`Hyenas has started on Port: ${config.port2}`));
hyenas.listen(config.port4, () => console.log(`Hyenas has started on Port: ${config.port4}`));
// Yay, stolen functions!
function collectRequestData(request, callback) {
const FORM_URLENCODED = 'application/x-www-form-urlencoded';
const FORM_XML = 'text/xml';
let body = '';
request.on('data', chunk => {
body += chunk.toString();
});
request.on('end', () => {
switch (request.headers['content-type']) {
case FORM_URLENCODED:
callback(parse(body));
break;
case FORM_XML:
parseString(body, (err, xmlResult) => {
callback(xmlResult)
});
break;
default:
callback(null);
break;
}
});
}