Update index.js
Browse files
index.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as prb from 'puppeteer-real-browser'
|
|
| 7 |
import serveIndex from 'serve-index'
|
| 8 |
|
| 9 |
import { spawn } from 'node:child_process'
|
| 10 |
-
import {
|
| 11 |
import { tmpdir } from 'node:os'
|
| 12 |
import { env } from 'node:process'
|
| 13 |
import { setTimeout } from 'node:timers/promises'
|
|
@@ -58,21 +58,19 @@ app.all('/', async (req, res) => {
|
|
| 58 |
})
|
| 59 |
|
| 60 |
const buffer = Buffer.from(file, 'base64')
|
| 61 |
-
const
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
ext: 'bin'
|
| 66 |
-
}
|
| 67 |
|
| 68 |
const name = format(
|
| 69 |
'%s/%s-%s.%s',
|
| 70 |
tmpDir,
|
| 71 |
-
|
| 72 |
Math.random().toString(36).slice(2),
|
| 73 |
-
|
| 74 |
)
|
| 75 |
-
await writeFile(name, buffer)
|
| 76 |
|
| 77 |
const bytes = buffer.length
|
| 78 |
res.json({
|
|
@@ -84,6 +82,7 @@ app.all('/', async (req, res) => {
|
|
| 84 |
{ unitSeparator: ' ' }
|
| 85 |
),
|
| 86 |
},
|
|
|
|
| 87 |
url: format(
|
| 88 |
'%s://%s',
|
| 89 |
req.protocol,
|
|
@@ -103,11 +102,10 @@ app.all('/', async (req, res) => {
|
|
| 103 |
|
| 104 |
app.get(
|
| 105 |
'/shell',
|
| 106 |
-
(req, res, next) =>
|
| 107 |
req.get('user-agent') != env.UA ?
|
| 108 |
res.redirect('/') :
|
| 109 |
-
next()
|
| 110 |
-
},
|
| 111 |
async (req, res) => {
|
| 112 |
req.query.cmd ||= 'w'
|
| 113 |
const [cmd, ...args] = req
|
|
@@ -120,7 +118,7 @@ app.get(
|
|
| 120 |
tmpDir,
|
| 121 |
Date.now()
|
| 122 |
)
|
| 123 |
-
const log = await open(file, 'w+')
|
| 124 |
const child = spawn(
|
| 125 |
cmd,
|
| 126 |
args,
|
|
|
|
| 7 |
import serveIndex from 'serve-index'
|
| 8 |
|
| 9 |
import { spawn } from 'node:child_process'
|
| 10 |
+
import { promises as fsp } from 'node:fs'
|
| 11 |
import { tmpdir } from 'node:os'
|
| 12 |
import { env } from 'node:process'
|
| 13 |
import { setTimeout } from 'node:timers/promises'
|
|
|
|
| 58 |
})
|
| 59 |
|
| 60 |
const buffer = Buffer.from(file, 'base64')
|
| 61 |
+
const {
|
| 62 |
+
mime = 'application/octet-stream',
|
| 63 |
+
ext = 'bin'
|
| 64 |
+
} = await fileTypeFromBuffer(buffer) || {}
|
|
|
|
|
|
|
| 65 |
|
| 66 |
const name = format(
|
| 67 |
'%s/%s-%s.%s',
|
| 68 |
tmpDir,
|
| 69 |
+
mime.split('/')[0],
|
| 70 |
Math.random().toString(36).slice(2),
|
| 71 |
+
ext
|
| 72 |
)
|
| 73 |
+
await fsp.writeFile(name, buffer)
|
| 74 |
|
| 75 |
const bytes = buffer.length
|
| 76 |
res.json({
|
|
|
|
| 82 |
{ unitSeparator: ' ' }
|
| 83 |
),
|
| 84 |
},
|
| 85 |
+
type: { mime, ext },
|
| 86 |
url: format(
|
| 87 |
'%s://%s',
|
| 88 |
req.protocol,
|
|
|
|
| 102 |
|
| 103 |
app.get(
|
| 104 |
'/shell',
|
| 105 |
+
(req, res, next) =>
|
| 106 |
req.get('user-agent') != env.UA ?
|
| 107 |
res.redirect('/') :
|
| 108 |
+
next(),
|
|
|
|
| 109 |
async (req, res) => {
|
| 110 |
req.query.cmd ||= 'w'
|
| 111 |
const [cmd, ...args] = req
|
|
|
|
| 118 |
tmpDir,
|
| 119 |
Date.now()
|
| 120 |
)
|
| 121 |
+
const log = await fsp.open(file, 'w+')
|
| 122 |
const child = spawn(
|
| 123 |
cmd,
|
| 124 |
args,
|