Exemple #1
0
  public static boolean isPortAvailable(int port) {
    boolean available = true;

    int available_code = mOpenPorts.get(port);

    if (available_code != 0) return available_code != 1;

    try {
      // attempt 3 times since proxy and server could be still releasing
      // their ports
      for (int i = 0; i < 3; i++) {
        Socket channel = new Socket();
        InetSocketAddress address =
            new InetSocketAddress(InetAddress.getByName(mNetwork.getLocalAddressAsString()), port);

        channel.connect(address, 200);

        available = !channel.isConnected();

        channel.close();

        if (available) break;

        Thread.sleep(200);
      }
    } catch (Exception e) {
      available = true;
    }

    mOpenPorts.put(port, available ? 2 : 1);

    return available;
  }
Exemple #2
0
  public static void reloadNetworkMapping() {
    try {
      mNetwork = new Network(mContext);

      Target network = new Target(mNetwork),
          gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()),
          device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware());

      gateway.setAlias(mNetwork.getSSID());
      device.setAlias(android.os.Build.MODEL);

      mTargets.clear();
      mTargets.add(network);
      mTargets.add(gateway);
      mTargets.add(device);

      mInitialized = true;
    } catch (NoRouteToHostException nrthe) {
      // swallow bitch
    } catch (Exception e) {
      errorLogging(e);
    }
  }
Exemple #3
0
  public static boolean checkNetworking(final Activity current) {
    if (!Network.isWifiConnected(mContext)) {

      Intent intent = new Intent();
      intent.putExtra(WifiScannerActivity.CONNECTED, false);
      current.setResult(Activity.RESULT_OK, intent);

      String title = current.getString(R.string.error);
      String message = current.getString(R.string.wifi_went_down);

      new FatalDialog(title, message, current).show();

      return false;
    }

    return true;
  }
Exemple #4
0
  public static void init(Context context) throws Exception {
    mContext = context;
    try {
      Logger.debug("initializing System...");
      mStoragePath =
          getSettings()
              .getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString());
      mSessionName = "csploit-session-" + java.lang.System.currentTimeMillis();
      mKnownIssues = new KnownIssues();
      mPlugins = new ArrayList<Plugin>();
      mOpenPorts = new SparseIntArray(3);

      // if we are here, network initialization didn't throw any error, lock wifi
      WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

      if (mWifiLock == null)
        mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock");

      if (!mWifiLock.isHeld()) mWifiLock.acquire();

      // wake lock if enabled
      if (getSettings().getBoolean("PREF_WAKE_LOCK", true)) {
        PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);

        if (mWakeLock == null)
          mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock");

        if (!mWakeLock.isHeld()) mWakeLock.acquire();
      }

      // set ports
      try {
        HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080"));
        HTTP_SERVER_PORT =
            Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081"));
        HTTPS_REDIR_PORT =
            Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082"));
        MSF_RPC_PORT = Integer.parseInt(getSettings().getString("MSF_RPC_PORT", "55553"));
      } catch (NumberFormatException e) {
        HTTP_PROXY_PORT = 8080;
        HTTP_SERVER_PORT = 8081;
        HTTPS_REDIR_PORT = 8082;
        MSF_RPC_PORT = 55553;
      }

      // initialize network data at the end
      mNetwork = new Network(mContext);

      Target network = new Target(mNetwork),
          gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()),
          device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware());

      gateway.setAlias(mNetwork.getSSID());
      device.setAlias(android.os.Build.MODEL);

      mTargets.add(network);
      mTargets.add(gateway);
      mTargets.add(device);

      mInitialized = true;
    } catch (Exception e) {
      if (!(e instanceof NoRouteToHostException)) errorLogging(e);

      throw e;
    }
  }
Exemple #5
0
 public static String getGatewayAddress() {
   return mNetwork.getGatewayAddress().getHostAddress();
 }