# Remote Dynamic Blackbox Java App Analysis

> Run whatever code you want inside of a blackbox java jar

## Server side setup

### Find supported JVM

On the device running the jar file, you will need to make sure that your local JVM supports debugging.

You can check by running the application with either of the two commands below:

```bash
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1234 <Application.jar>
java -agentlib:jdwp=transport=dt_socket,server=y,address=1234,suspend=y <Application.jar>
```

If your JVM does not support debugging, you will see an error message similar to below:

```bash
$ java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1234 <Application.jar>
Unrecognized option: -xDebug
```

{% hint style="info" %}
JVMs like [JAMVM ](https://stackoverflow.com/questions/21399355/how-to-do-remote-debugging-in-jamvm)do not support the -xDebug flag
{% endhint %}

### Identify supported JVM

The default JVM may not support the xDebug flag, however there may be multiple JVMs installed on the device. Reading the jvm.cfg file located at the java install will show which JVMs are available.

```bash
$ cat /usr/lib/jvm/default-java/jre/lib/amd64/jvm.cfg
# Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
...
# and may not be available in a future release.
#
-server KNOWN
-client IGNORE
-zero KNOWN
-dcevm KNOWN
```

```
#Adding the server JVM flag will force java to call the server JVM
java -server -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1234 <Application.jar>
```

Further, if there are folders in your JRE lib folder with other JVMs, you can safely add those JVMs to the JVM.cfg

```bash
#client and server are folders that can be added as known JVMs to the jvm.cfg file
ls /home/user/test/jdk1.8.0_181/jre/lib/arm/
client              libhprof.so          libjpeg.so        libnpt.so
jli                 libinstrument.so     libjsdt.so        libresource.so
jvm.cfg             libj2gss.so          libjsig.so        libsaproc.so
libattach.so        libj2pcsc.so         libjsoundalsa.so  libsctp.so
libawt_headless.so  libj2pkcs11.so       libjsound.so      libsplashscreen.so
libawt.so           libjaas_unix.so      libkcms.so        libsunec.so
libawt_xawt.so      libjava_crw_demo.so  liblcms.so        libt2k.so
libbci.so           libjava.so           libmanagement.so  libunpack.so
libdcpr.so          libjawt.so           libmlib_image.so  libverify.so
libdt_socket.so     libjdwp.so           libnet.so         libzip.so
libfontmanager.so   libjfr.so            libnio.so         server
```

## Client Side Setup

### Installation

[Eclipse 4.3](https://www.eclipse.org/downloads/packages/release/kepler/r/eclipse-standard-43) is required for the [bytecode visualizer](https://marketplace.eclipse.org/content/bytecode-visualizer) plugin required to debug these applications.

Install [Eclipse Kepler ](https://www.eclipse.org/downloads/packages/release/kepler/r/eclipse-standard-43)and the [Bytecode Visualizer ](https://marketplace.eclipse.org/content/bytecode-visualizer)plugin.

Navigate to: Help -> Eclipse Marketplace

Search for "bytecode visualizer" and install Dr. Garbage's Bytecode Visualizer

![](https://30521890-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWRAm7V9PvgumFt5f6A%2F-LYxcReBwvm-FiuO1GS0%2F-LYxcSX9p1BDnlOny1kp%2Fimage.png?alt=media\&token=77af4a4c-beb6-4d41-8810-59b01e874403)

### Project Creation

{% hint style="info" %}
This portion taken directly from [crowdstrike](https://www.crowdstrike.com/blog/native-java-bytecode-debugging-without-source-code/)
{% endhint %}

Once Eclipse restarts, close the Welcome tab, and in the menu bar go to File → New → Java Project. Specify any project name you like and press the Next button:

![](https://30521890-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWRAm7V9PvgumFt5f6A%2F-LZ0w-Ucp9IKL2p0jwP3%2F-LZ0wZJK-tKlapYIrot-%2Fpngbase64a420fad25441eff5_0.png?alt=media\&token=47285d11-86e1-43dd-b202-9b75424d7277)

In the Java Settings window, click the Libraries tab. In the Libraries tab, press the Add External JARs button and select the JAR file you want to debug, thereby adding it to the Java project’s build path:

![](https://30521890-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWRAm7V9PvgumFt5f6A%2F-LZ0w-Ucp9IKL2p0jwP3%2F-LZ0wdMF4YdD2ZjP2dli%2Fpngbase64b0d0d1625a7f33f2.png?alt=media\&token=b5776c2d-7608-4cb5-84e6-2216ac86613c)

In the Package Explorer tab, expand your project’s Referenced Libraries to find your JAR file. Right-click on the class you want to debug and select Open with Bytecode Visualizer:

![](https://30521890-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWRAm7V9PvgumFt5f6A%2F-LZ0w-Ucp9IKL2p0jwP3%2F-LZ0wwCskQ6IBxpZ85tB%2Fpngbase645d60aef8c7557e95-1024x753.png?alt=media\&token=0e46e2e8-37a9-44bf-b012-198cae564bc9)

Set breakpoints

With the JAR’s code now visible in Bytecode Visualizer, you can set breakpoints by double-clicking on the vertical gray bar to the left of the disassembled Java code:

![](https://30521890-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWRAm7V9PvgumFt5f6A%2F-LZ0w-Ucp9IKL2p0jwP3%2F-LZ0wiJAvvccnmzLI81R%2Fpngbase64d6ea17c17e000ade-1024x753.png?alt=media\&token=45739234-6a17-47bb-a8a1-6022c5676b16)

### Debug Setup

Create a debug configuration and put in the server's IP and port information.&#x20;

![](https://30521890-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWRAm7V9PvgumFt5f6A%2F-LYxopRfiqxxmjXaCk1q%2F-LYxp6PQ8oXSVfk303aI%2Fimage.png?alt=media\&token=22269b7c-a4d5-4f0d-8dcb-5bc6e563cf06)

### Running code

Open the "Display" view in eclipse. Window -> Show View

![](https://30521890-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWRAm7V9PvgumFt5f6A%2F-LZ0w-Ucp9IKL2p0jwP3%2F-LZ0xOgRtNhzTwnDEen2%2Fimage.png?alt=media\&token=4b06256e-f3f8-4e5e-9102-386b0f2e7d88)

Once a breakpoint has been triggered or a thread has been suspended, code can be written into the Display frame and selected to run inside the suspended thread given the current context of the thread.

![](https://30521890-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWRAm7V9PvgumFt5f6A%2F-LZ0w-Ucp9IKL2p0jwP3%2F-LZ0xbewbUu8ZsjEoigG%2Fimage.png?alt=media\&token=199a66e6-004a-4def-b814-030384fe9950)

{% hint style="info" %}
References

<https://www.crowdstrike.com/blog/native-java-bytecode-debugging-without-source-code/>
{% endhint %}
