Skip to content

Commit 835ffe2

Browse files
committed
Merge branch 'develop' into fragment
2 parents a5e51d3 + 1b4a0f0 commit 835ffe2

9 files changed

Lines changed: 182 additions & 105 deletions

File tree

cSploit/src/main/java/org/csploit/android/core/System.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -954,15 +954,22 @@ public static void reset() {
954954
synchronized (mTargets) {
955955
mTargets.clear();
956956

957-
Target network = new Target(mNetwork),
958-
gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()),
959-
device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware());
957+
Target network, gateway, device;
958+
959+
network = new Target(mNetwork);
960+
device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware());
961+
960962

961-
gateway.setAlias(mNetwork.getSSID());
962963
device.setAlias(android.os.Build.MODEL);
963964

964965
mTargets.add(network);
965-
mTargets.add(gateway);
966+
967+
if(mNetwork.haveGateway()) {
968+
gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware());
969+
gateway.setAlias(mNetwork.getSSID());
970+
mTargets.add(gateway);
971+
}
972+
966973
mTargets.add(device);
967974

968975
scanThemAll();
@@ -1004,7 +1011,9 @@ public static void markNetworkAsDisconnected() {
10041011

10051012
public static void markInitialNetworkTargetsAsConnected() {
10061013
InetAddress localAddress = mNetwork.getLocalAddress();
1014+
boolean haveGateway = mNetwork.haveGateway();
10071015
InetAddress gatewayAddress = mNetwork.getGatewayAddress();
1016+
10081017
synchronized (mTargets) {
10091018
for (Target t : mTargets) {
10101019
switch (t.getType()) {
@@ -1014,7 +1023,7 @@ public static void markInitialNetworkTargetsAsConnected() {
10141023
}
10151024
default:
10161025
if (localAddress.equals(t.getAddress()) ||
1017-
gatewayAddress.equals(t.getAddress())) {
1026+
(haveGateway && gatewayAddress.equals(t.getAddress()))) {
10181027
t.setConneced(true);
10191028
}
10201029
break;
@@ -1221,10 +1230,6 @@ public static Collection<Exploit> getCurrentExploits() {
12211230
return getCurrentTarget().getExploits();
12221231
}
12231232

1224-
public static String getGatewayAddress() {
1225-
return mNetwork.getGatewayAddress().getHostAddress();
1226-
}
1227-
12281233
public static boolean isForwardingEnabled() {
12291234
boolean forwarding = false;
12301235
BufferedReader reader;

cSploit/src/main/java/org/csploit/android/net/Network.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.FileInputStream;
3535
import java.io.IOException;
3636
import java.io.InputStreamReader;
37+
import java.lang.reflect.Method;
3738
import java.net.InetAddress;
3839
import java.net.InterfaceAddress;
3940
import java.net.NetworkInterface;
@@ -101,6 +102,7 @@ public String toString() {
101102
private IP4Address mNetmask = null;
102103
private IP4Address mLocal = null;
103104
private IP4Address mBase = null;
105+
private Method mTetheredIfacesMethod = null;
104106

105107
/**
106108
* see http://en.wikipedia.org/wiki/Reserved_IP_addresses
@@ -121,6 +123,7 @@ public Network(Context context, String iface) throws SocketException, UnknownHos
121123
mGateway = new IP4Address(mInfo.gateway);
122124
mNetmask = getNetmask();
123125
mBase = new IP4Address(mInfo.netmask & mInfo.gateway);
126+
mTetheredIfacesMethod = getTetheredIfacesMethod(mConnectivityManager);
124127

125128
if (iface != null) {
126129
if (initNetworkInterface(iface))
@@ -136,6 +139,15 @@ public Network(Context context, String iface) throws SocketException, UnknownHos
136139
throw new NoRouteToHostException("Not connected to any network.");
137140
}
138141

142+
private static Method getTetheredIfacesMethod(ConnectivityManager connectivityManager) {
143+
try {
144+
return connectivityManager.getClass().getDeclaredMethod("getTetheredIfaces");
145+
} catch (NoSuchMethodException e) {
146+
Logger.warning("unable to get 'ConnectivityManager#getTetheredIfaces()': " + e.getMessage());
147+
return null;
148+
}
149+
}
150+
139151
public boolean initNetworkInterface(String iface) {
140152

141153
try {
@@ -158,10 +170,17 @@ public boolean initNetworkInterface(String iface) {
158170
Short.toString(ifaceAddress.getNetworkPrefixLength()));
159171

160172
mLocal = new IP4Address(su.getInfo().getAddress());
161-
mGateway = new IP4Address(getSystemGateway(mInterface.getDisplayName()));
162173
mNetmask = new IP4Address(su.getInfo().getNetmask());
163174
mBase = new IP4Address(su.getInfo().getNetworkAddress());
164175

176+
String gateway = getSystemGateway(mInterface.getDisplayName());
177+
178+
if(gateway == null) {
179+
mGateway = null;
180+
} else {
181+
mGateway = new IP4Address(gateway);
182+
}
183+
165184
return true;
166185
} catch (Exception e) {
167186
Logger.error("Error: " + e.getLocalizedMessage());
@@ -194,11 +213,11 @@ public boolean equals(Network network) {
194213
}
195214

196215
public boolean isInternal(byte[] address) {
197-
byte[] gateway = mGateway.toByteArray();
216+
byte[] local = mLocal.toByteArray();
198217
byte[] mask = mNetmask.toByteArray();
199218

200-
for (int i = 0; i < gateway.length; i++)
201-
if ((gateway[i] & mask[i]) != (address[i] & mask[i]))
219+
for (int i = 0; i < local.length; i++)
220+
if ((local[i] & mask[i]) != (address[i] & mask[i]))
202221
return false;
203222

204223
return true;
@@ -265,8 +284,25 @@ public InetAddress getNetmaskAddress() {
265284
return mNetmask.toInetAddress();
266285
}
267286

287+
public boolean haveGateway() {
288+
return mGateway != null;
289+
}
290+
291+
public boolean isTetheringEnabled() {
292+
if(mTetheredIfacesMethod == null) {
293+
return false;
294+
}
295+
try {
296+
String[] ifaces = (String[]) mTetheredIfacesMethod.invoke(mConnectivityManager);
297+
return ifaces.length > 0;
298+
} catch (Exception e) {
299+
Logger.error("unable to retrieve tethered ifaces: " + e.getMessage());
300+
return false;
301+
}
302+
}
303+
268304
public InetAddress getGatewayAddress() {
269-
return mGateway.toInetAddress();
305+
return mGateway == null ? null : mGateway.toInetAddress();
270306
}
271307

272308
public byte[] getGatewayHardware() {

cSploit/src/main/java/org/csploit/android/plugins/ExploitFinder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ private void setStartedState() {
266266
mSearchProgress.setVisibility(View.VISIBLE);
267267

268268
final Target target = System.getCurrentTarget();
269+
mSearchFloatingActionButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_stop_24dp));
270+
buttonPlayed = true;
269271

270272
job = Search.searchExploitForServices(target,
271273
new Search.Receiver<Exploit>() {
@@ -299,8 +301,8 @@ public void onEnd() {
299301
@Override
300302
public void run() {
301303
mSearchProgress.setVisibility(View.GONE);
302-
mSearchFloatingActionButton.setImageDrawable(ContextCompat.getDrawable(getBaseContext(), R.drawable.ic_stop_24dp));
303-
buttonPlayed = true;
304+
mSearchFloatingActionButton.setImageDrawable(ContextCompat.getDrawable(getBaseContext(), R.drawable.ic_play_arrow_24dp));
305+
buttonPlayed = false;
304306
if (System.getCurrentExploits().size() == 0) {
305307
new FinishDialog(getString(R.string.warning), getString(R.string.no_exploits_found), ExploitFinder.this).show();
306308
} else if (!somethingFound) {

0 commit comments

Comments
 (0)