Ejemplo n.º 1
0
  private static void preloadVendors() {
    if (mVendors == null) {
      try {
        mVendors = new HashMap<String, String>();
        @SuppressWarnings("ConstantConditions")
        FileInputStream fstream =
            new FileInputStream(
                mContext.getFilesDir().getAbsolutePath() + "/tools/nmap/nmap-mac-prefixes");

        DataInputStream in = new DataInputStream(fstream);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;

        while ((line = reader.readLine()) != null) {
          line = line.trim();
          if (!line.startsWith("#") && !line.isEmpty()) {
            String[] tokens = line.split(" ", 2);

            if (tokens.length == 2) mVendors.put(tokens[0], tokens[1]);
          }
        }

        in.close();
      } catch (Exception e) {
        errorLogging(e);
      }
    }
  }
Ejemplo n.º 2
0
  private static void preloadServices() {
    if (mServices == null || mPorts == null) {
      try {
        // preload network service map and mac vendors
        mServices = new HashMap<String, String>();
        mPorts = new HashMap<String, String>();

        @SuppressWarnings("ConstantConditions")
        FileInputStream fstream =
            new FileInputStream(
                mContext.getFilesDir().getAbsolutePath() + "/tools/nmap/nmap-services");

        DataInputStream in = new DataInputStream(fstream);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        Matcher matcher;

        while ((line = reader.readLine()) != null) {
          line = line.trim();

          if ((matcher = SERVICE_PARSER.matcher(line)) != null && matcher.find()) {
            String proto = matcher.group(1), port = matcher.group(2);

            mServices.put(proto, port);
            mPorts.put(port, proto);
          }
        }

        in.close();
      } catch (Exception e) {
        errorLogging(e);
      }
    }
  }
Ejemplo n.º 3
0
  public static Server getServer() {
    try {
      if (mServer == null) mServer = new Server(getNetwork().getLocalAddress(), HTTP_SERVER_PORT);
    } catch (Exception e) {
      errorLogging(e);
    }

    return mServer;
  }
Ejemplo n.º 4
0
  public static Proxy getProxy() {
    try {
      if (mProxy == null) mProxy = new Proxy(getNetwork().getLocalAddress(), HTTP_PROXY_PORT);
    } catch (Exception e) {
      errorLogging(e);
    }

    return mProxy;
  }
Ejemplo n.º 5
0
  public static HTTPSRedirector getHttpsRedirector() {
    try {
      if (mRedirector == null)
        mRedirector =
            new HTTPSRedirector(mContext, getNetwork().getLocalAddress(), HTTPS_REDIR_PORT);
    } catch (Exception e) {
      errorLogging(e);
    }

    return mRedirector;
  }
Ejemplo n.º 6
0
  private void setStoppedState() {
    mSpoofSession.stop();

    try {
      if (mBufferedWriter != null) mBufferedWriter.close();
    } catch (IOException e) {
      System.errorLogging(e);
    }

    mSniffProgress.setVisibility(View.INVISIBLE);
    mRunning = false;
    mSniffToggleButton.setChecked(false);
  }
Ejemplo n.º 7
0
  public static String getAppVersionName() {
    if (mApkVersion != null) return mApkVersion;
    try {
      PackageManager manager = mContext.getPackageManager();
      PackageInfo info =
          manager != null ? manager.getPackageInfo(mContext.getPackageName(), 0) : null;

      if (info != null) return (mApkVersion = info.versionName);
    } catch (NameNotFoundException e) {
      errorLogging(e);
    }

    return "0.0.1";
  }
Ejemplo n.º 8
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);
    }
  }
Ejemplo n.º 9
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);
    }
  }
Ejemplo n.º 10
0
  private void setStartedState() {

    try {
      mSpoofSession.start(
          new Ettercap.OnDNSSpoofedReceiver() {
            @Override
            public void onSpoofed(String line) {
              Logger.info("DNSSpoofing.onevent() line: " + line);

              if (line.contains("spoofed to"))
                Toast.makeText(DNSSpoofing.this, line, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onStderr(String line) {
              if (line.contains("spoofed to"))
                Toast.makeText(DNSSpoofing.this, line, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onReady() {}

            @Override
            public void onEnd(final int exitValue) {
              DNSSpoofing.this.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      if (exitValue != 0) {
                        Toast.makeText(
                                DNSSpoofing.this,
                                "ettercap returned #" + exitValue,
                                Toast.LENGTH_LONG)
                            .show();
                      }
                      setStoppedState();
                    }
                  });
            }

            @Override
            public void onError(final String error) {
              DNSSpoofing.this.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      if (!DNSSpoofing.this.isFinishing()) {
                        new ErrorDialog(getString(R.string.error), error, DNSSpoofing.this).show();
                        setStoppedState();
                      }
                    }
                  });
            }

            @Override
            public void onDeath(final int signal) {
              DNSSpoofing.this.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      Toast.makeText(
                              DNSSpoofing.this,
                              "ettercap killed by signal #" + signal,
                              Toast.LENGTH_LONG)
                          .show();
                      setStoppedState();
                    }
                  });
            }
          });

      mSniffProgress.setVisibility(View.VISIBLE);
      mRunning = true;

    } catch (ChildManager.ChildNotStartedException e) {
      System.errorLogging(e);
      mSniffToggleButton.setChecked(false);
      Toast.makeText(DNSSpoofing.this, getString(R.string.child_not_started), Toast.LENGTH_LONG)
          .show();
    }
  }
Ejemplo n.º 11
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;
    }
  }