Add support for mitm Js Injector

This commit is contained in:
emanuele-f 2023-06-06 12:14:16 +02:00
parent 96032d3aef
commit 937c68ed07
9 changed files with 55 additions and 5 deletions

View File

@ -48,8 +48,8 @@ import java.io.IOException;
import java.lang.ref.WeakReference;
public class MitmAddon {
public static final long PACKAGE_VERSION_CODE = 14;
public static final String PACKAGE_VERSION_NAME = "v0.14";
public static final long PACKAGE_VERSION_CODE = 15;
public static final String PACKAGE_VERSION_NAME = "v0.15";
public static final String REPOSITORY = "https://github.com/emanuele-f/PCAPdroid-mitm";
private static final String TAG = "MitmAddon";
private final Context mContext;

View File

@ -95,6 +95,7 @@ public class MitmReceiver implements Runnable, ConnectionsListener, MitmListener
DATA_TRUNCATED,
MASTER_SECRET,
LOG,
JS_INJECTED
}
private static class PendingMessage {
@ -319,9 +320,11 @@ public class MitmReceiver implements Runnable, ConnectionsListener, MitmListener
// see ConnectionDescriptor.processUpdate
if(conn.status == ConnectionDescriptor.CONN_STATUS_CLOSED)
conn.status = ConnectionDescriptor.CONN_STATUS_CLIENT_ERROR;
} else if(type == MsgType.DATA_TRUNCATED)
} else if(type == MsgType.DATA_TRUNCATED) {
conn.setPayloadTruncatedByAddon();
else
} else if(type == MsgType.JS_INJECTED) {
conn.js_injected_scripts = new String(message, StandardCharsets.US_ASCII);
} else
conn.addPayloadChunkMitm(new PayloadChunk(message, getChunkType(type), isSent(type), tstamp));
}
@ -380,6 +383,8 @@ public class MitmReceiver implements Runnable, ConnectionsListener, MitmListener
return MsgType.MASTER_SECRET;
case "log":
return MsgType.LOG;
case "js_inject":
return MsgType.JS_INJECTED;
default:
return MsgType.UNKNOWN;
}

View File

@ -76,6 +76,7 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
public static class ViewHolder extends RecyclerView.ViewHolder {
ImageView icon;
ImageView jsInjectorInd;
ImageView blacklistedInd;
ImageView blockedInd;
ImageView decryptionInd;
@ -99,6 +100,7 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
decryptionInd = itemView.findViewById(R.id.decryption_status);
appName = itemView.findViewById(R.id.app_name);
lastSeen = itemView.findViewById(R.id.last_seen);
jsInjectorInd = itemView.findViewById(R.id.js_injector);
blacklistedInd = itemView.findViewById(R.id.blacklisted);
blockedInd = itemView.findViewById(R.id.blocked);
//countryFlag = itemView.findViewById(R.id.country_flag);
@ -155,6 +157,7 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter.
countryFlag.setCountryCode(conn.country);
}*/
jsInjectorInd.setVisibility(((conn.js_injected_scripts != null) && !conn.js_injected_scripts.isEmpty()) ? View.VISIBLE : View.GONE);
blacklistedInd.setVisibility(conn.isBlacklisted() ? View.VISIBLE : View.GONE);
blockedInd.setVisibility(conn.is_blocked ? View.VISIBLE : View.GONE);

View File

@ -183,7 +183,14 @@ public class ConnectionOverview extends Fragment implements ConnectionDetailsAct
else
appLabel.setText(uid_str);
view.findViewById(R.id.decryption_status_row).setVisibility(CaptureService.isDecryptingTLS() ? View.VISIBLE : View.GONE);
view.findViewById(R.id.decryption_status_row)
.setVisibility(CaptureService.isDecryptingTLS() ? View.VISIBLE : View.GONE);
boolean has_scripts = (mConn.js_injected_scripts != null) && !mConn.js_injected_scripts.isEmpty();
view.findViewById(R.id.injected_scripts_row)
.setVisibility(has_scripts ? View.VISIBLE : View.GONE);
if(has_scripts)
((TextView)view.findViewById(R.id.injected_scripts)).setText(mConn.js_injected_scripts);
if(!mConn.url.isEmpty())
url.setText(mConn.url);

View File

@ -117,6 +117,7 @@ public class ConnectionDescriptor {
private boolean encrypted_l7; // application layer is encrypted (e.g. TLS)
public boolean encrypted_payload; // actual payload is encrypted (e.g. telegram - see Utils.hasEncryptedPayload)
public String decryption_error;
public String js_injected_scripts;
public String country;
public Geomodel.ASN asn;

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="12" android:viewportWidth="12"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M 6 8 v -1 h 1.5 v 0.5 h 2 v -1 H 7 c -0.55 0 -1 -0.45 -1 -1 V 4 c 0 -0.55 0.45 -1 1 -1 h 3 c 0.55 0 1 0.45 1 1 v 1 h -1.5 v -0.5 h -2 v 1 H 10 c 0.55 0 1 0.45 1 1 V 8 c 0 0.55 -0.45 1 -1 1 h -3 C 6.45 9 6 8.55 6 8 z M 3 3 v 4.5 H 1.5 v -1 H 0 v 1 C 0 8.33 0.67 9 1.5 9 H 3 c 0.83 0 1.5 -0.67 1.5 -1.5 V 3 C 4.5 3 3.83 3 3 3 z"/>
</vector>

View File

@ -58,6 +58,15 @@
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/js_injector"
android:layout_width="wrap_content"
android:layout_height="12sp"
android:layout_marginEnd="5dp"
app:tint="@color/colorTabText"
android:contentDescription="@string/injected"
android:src="@drawable/ic_baseline_javascript" />
<ImageView
android:id="@+id/blacklisted"
android:layout_width="wrap_content"

View File

@ -307,6 +307,25 @@
tools:text="Decrypted" />
</LinearLayout>
</TableRow>
<TableRow
android:id="@+id/injected_scripts_row"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="4dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:textStyle="bold"
android:text="@string/injected" />
<TextView
android:id="@+id/injected_scripts"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:textIsSelectable="true"
tools:text="some script" />
</TableRow>
<TableRow
android:layout_width="match_parent"

View File

@ -480,4 +480,5 @@
<string name="decrypt_action">Decrypt…</string>
<string name="dont_decrypt_action">Don\'t decrypt…</string>
<string name="status_encrypted">Encrypted</string>
<string name="injected">Injected</string>
</resources>