Example #1
0
  public static String saveSession(String sessionName) throws IOException {
    StringBuilder builder = new StringBuilder();
    String filename = mStoragePath + '/' + sessionName + ".dss", session;

    builder.append(SESSION_MAGIC + "\n");

    // skip the network target
    builder.append(mTargets.size() - 1).append("\n");
    for (Target target : mTargets) {
      if (target.getType() != Target.Type.NETWORK) target.serialize(builder);
    }
    builder.append(mCurrentTarget).append("\n");

    session = builder.toString();

    FileOutputStream ostream = new FileOutputStream(filename);
    GZIPOutputStream gzip = new GZIPOutputStream(ostream);

    gzip.write(session.getBytes());

    gzip.close();

    mSessionName = sessionName;

    return filename;
  }
Example #2
0
  public static ArrayList<Endpoint> getNetworkEndpoints() {
    ArrayList<Endpoint> filtered = new ArrayList<Endpoint>();

    for (Target target : mTargets) {
      if (target.getType() == Type.ENDPOINT) filtered.add(target.getEndpoint());
    }

    return filtered;
  }
Example #3
0
  public static ArrayList<Target> getTargetsByType(Target.Type type) {
    ArrayList<Target> filtered = new ArrayList<Target>();

    for (Target target : mTargets) {
      if (target.getType() == type) filtered.add(target);
    }

    return filtered;
  }
Example #4
0
 public static void setMsfRpc(RPCClient value) {
   if (value == mMsfRpc) return;
   mMsfRpc = value;
   // refresh all exploits
   // NOTE: this method is usually called by the RPCServer Thread, which will not block the UI
   for (Target t : getTargets()) {
     for (Exploit e : t.getExploits()) {
       if (e instanceof MsfExploit) {
         ((MsfExploit) e).refresh();
       }
     }
   }
   for (Plugin plugin : getPluginsForTarget()) {
     plugin.onRpcChange(value);
   }
 }
Example #5
0
  public static Target getTargetByAddress(InetAddress address) {
    int i, size;

    synchronized (mTargets) {
      size = mTargets.size();

      for (i = 0; i < size; i++) {
        Target t = mTargets.get(i);

        if (t != null && t.getAddress() != null && t.getAddress().equals(address)) {
          return t;
        }
      }
    }

    return null;
  }
Example #6
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);
    }
  }
Example #7
0
  public static void clean(boolean releaseLocks) {
    setForwarding(false);

    try {
      if (releaseLocks) {
        Logger.debug("Releasing locks.");

        if (mWifiLock != null && mWifiLock.isHeld()) mWifiLock.release();

        if (mWakeLock != null && mWakeLock.isHeld()) mWakeLock.release();
      }

      synchronized (mTargets) {
        for (Target t : mTargets) for (Session s : t.getSessions()) s.stopSession();

        mTargets.clear();
      }

      Client.Disconnect();
      mCoreInitialized = false;
    } catch (Exception e) {
      errorLogging(e);
    }
  }
Example #8
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;
    }
  }