-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
56 lines (43 loc) · 1.23 KB
/
Copy pathindex.mjs
File metadata and controls
56 lines (43 loc) · 1.23 KB
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
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
import axios from "axios";
import { createHash } from "crypto";
const config = {
username: "admin",
password: "", // PASSWORD
};
const sha256 = (str) => createHash("sha256").update(str).digest("hex");
const axiosInstance = axios.create({
baseURL: "https://192.168.1.1",
insecureHTTPParser: true,
});
async function getEcntToken() {
const { data: loginPage } = await axiosInstance.get("/cgi-bin/login.asp");
const post_par = loginPage.match(/post_par="([^"]*)"/)[1];
const credentials = new URLSearchParams({
username: sha256(config.username + post_par),
password: sha256(config.password + post_par),
});
const { data } = await axiosInstance.post(
`/cgi-bin/check_auth.json?post_par=${post_par}`,
credentials,
{
headers: {
Cookie: "loginTimes=0",
},
}
);
return { ecntToken: data.ecntToken, post_par };
}
async function logout(token) {
await axiosInstance.get("/cgi-bin/logout.cgi", {
headers: {
Cookie: `ecntToken=${token}`,
},
});
}
async function main() {
const { ecntToken, post_par } = await getEcntToken();
console.log({ ecntToken, post_par });
await logout(ecntToken);
}
main().catch(console.error);