Example #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
    Boolean isDark = themePrefs.getBoolean("isDark", false);
    if (isDark) setTheme(R.style.DarkTheme);
    else setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);

    UIThread = this;

    if (System.getMsfRpc() == null) {
      new FinishDialog(getString(R.string.error), "MSF RPC not connected", Sessions.this).show();
      return;
    }

    mResults = System.getCurrentTarget().getSessions();

    mListView = (ListView) findViewById(android.R.id.list);
    mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mResults);

    mListView.setAdapter(mAdapter);

    mListView.setOnItemClickListener(clickListener);

    mListView.setOnItemLongClickListener(longClickListener);

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                System.getMsfRpc().updateSessions();
                runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (mResults.isEmpty()) {
                          new FinishDialog(
                                  getString(R.string.warning),
                                  getString(R.string.no_opened_sessions),
                                  Sessions.this)
                              .show();
                        } else {
                          mAdapter.notifyDataSetChanged();
                        }
                      }
                    });
              }
            })
        .start();
  }
Example #2
0
  public static void reset() throws NoRouteToHostException, SocketException {
    mTargets.clear();

    // local network
    mTargets.add(new Target(System.getNetwork()));
    // network gateway
    mTargets.add(
        new Target(
            System.getNetwork().getGatewayAddress(), System.getNetwork().getGatewayHardware()));
    // device network address
    mTargets.add(
        new Target(System.getNetwork().getLocalAddress(), System.getNetwork().getLocalHardware()));

    mCurrentTarget = 0;
  }
Example #3
0
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   Session s = mAdapter.getItem(position);
   if (s.haveShell()) {
     System.setCurrentSession(s);
     startActivity(new Intent(Sessions.this, Console.class));
     overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
   } else {
     longClickListener.onItemLongClick(parent, view, position, id);
   }
 }
Example #4
0
  public void saveDNSlist() {

    try {
      Logger.info(
          "saveDNSList() saving dnss to: "
              + System.getContext().getFilesDir().getAbsolutePath()
              + "/tools/ettercap/share/etter.dns");
      File f =
          new File(
              System.getContext().getFilesDir().getAbsolutePath()
                  + "/tools/ettercap/share/etter.dns");
      FileOutputStream fos = new FileOutputStream(f);
      fos.write(mTextDnsList.getText().toString().getBytes());
      fos.close();

      Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
      Logger.error("readDNSList() error: " + e.getLocalizedMessage());
      Toast.makeText(this, "Error: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
    }
  }
Example #5
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);
  }
Example #6
0
  public void readDNSlist() {
    String _line = "";

    try {
      BufferedReader inputReader =
          new BufferedReader(
              new FileReader(
                  System.getContext().getFilesDir().getAbsolutePath()
                      + "/tools/ettercap/share/etter.dns"));
      while ((_line = inputReader.readLine()) != null) {
        mTextDnsList.append(_line + "\n");
      }

      inputReader.close();
    } catch (Exception e) {
      Logger.error("readDNSList() error: " + e.getLocalizedMessage());
    }
  }
Example #7
0
  public static void loadSession(String filename) throws Exception {
    File file = new File(mStoragePath + '/' + filename);

    if (file.exists() && file.length() > 0) {
      BufferedReader reader =
          new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file))));
      String line;

      // begin decoding procedure
      try {
        line = reader.readLine();
        if (line == null || !line.equals(SESSION_MAGIC))
          throw new Exception("Not a cSploit session file.");

        reset();

        // read targets
        int targets = Integer.parseInt(reader.readLine());
        for (int i = 0; i < targets; i++) {
          Target target = new Target(reader);

          if (!hasTarget(target)) {
            System.addOrderedTarget(target);
          } else {
            for (int j = 0; j < mTargets.size(); j++) {
              if (mTargets.get(j) != null && mTargets.get(j).equals(target)) {
                mTargets.set(j, target);
                break;
              }
            }
          }
        }

        mCurrentTarget = Integer.parseInt(reader.readLine());
        reader.close();

      } catch (Exception e) {
        reset();
        reader.close();
        throw e;
      }
    } else throw new Exception(filename + " does not exists or is empty.");
  }
Example #8
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
    Boolean isDark = themePrefs.getBoolean("isDark", false);
    if (isDark) setTheme(R.style.DarkTheme);
    else setTheme(R.style.AppTheme);

    setTitle(System.getCurrentTarget() + " > MITM > DNS spoofing");
    setContentView(R.layout.plugin_mitm_dns_spoofing);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mTextDnsList = (TextView) findViewById(R.id.textViewDNSList);
    mCmdSave = (Button) findViewById(R.id.cmd_save);
    mSniffToggleButton = (ToggleButton) findViewById(R.id.sniffToggleButton);
    mSniffProgress = (ProgressBar) findViewById(R.id.sniffActivity);
    mTextDnsList.setHorizontallyScrolling(true);

    mSpoofSession = new SpoofSession(false, false, null, null);

    readDNSlist();

    mSniffToggleButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mRunning) {
              setStoppedState();
            } else {
              setStartedState();
            }
          }
        });
    mCmdSave.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            saveDNSlist();
          }
        });
  }
Example #9
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();
    }
  }
Example #10
0
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
          final Session s = mAdapter.getItem(position);
          final ArrayList<Integer> availableChoices = new ArrayList<Integer>();
          availableChoices.add(R.string.show_full_description);
          if (s.haveShell()) availableChoices.add(R.string.open_shell);
          if (s.isMeterpreter()) {
            if (System.getCurrentTarget().getDeviceOS().toLowerCase().contains("windows"))
              availableChoices.add(R.string.clear_event_log);
          }
          availableChoices.add(R.string.delete);

          new ListChoiceDialog(
                  R.string.choose_an_option,
                  availableChoices.toArray(new Integer[availableChoices.size()]),
                  Sessions.this,
                  new ChoiceDialog.ChoiceDialogListener() {
                    @Override
                    public void onChoice(int choice) {
                      switch (availableChoices.get(choice)) {
                        case R.string.open_shell:
                          System.setCurrentSession(s);
                          startActivity(new Intent(Sessions.this, Console.class));
                          overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
                          break;
                        case R.string.show_full_description:
                          String message = s.getDescription();
                          if (s.getInfo().length() > 0) message += "\n\nInfo:\n" + s.getInfo();
                          new ErrorDialog(s.getName(), message, Sessions.this).show();
                          break;
                        case R.string.clear_event_log:
                          ((ShellSession) s)
                              .addCommand(
                                  "clearev",
                                  new ShellSession.RpcShellReceiver() {
                                    @Override
                                    public void onNewLine(String line) {}

                                    @Override
                                    public void onEnd(int exitValue) {
                                      Toast.makeText(
                                              Sessions.this,
                                              "command returned " + exitValue,
                                              Toast.LENGTH_LONG)
                                          .show();
                                    }

                                    @Override
                                    public void onRpcClosed() {
                                      Toast.makeText(
                                              Sessions.this,
                                              "RPC channel has been closed",
                                              Toast.LENGTH_LONG)
                                          .show();
                                    }

                                    @Override
                                    public void onTimedOut() {
                                      Toast.makeText(
                                              Sessions.this, "command timed out", Toast.LENGTH_LONG)
                                          .show();
                                    }
                                  });
                          break;
                        case R.string.delete:
                          s.stopSession();
                          System.getCurrentTarget().getSessions().remove(s);
                          mAdapter.notifyDataSetChanged();
                          break;
                      }
                    }
                  })
              .show();
          return true;
        }
Example #11
0
  private static void startCoreDaemon() throws SuException, DaemonException {
    boolean access_granted = false;
    DataOutputStream writer = null;
    BufferedReader reader = null;
    String line;
    int ret = -1;

    try {
      Process shell = Runtime.getRuntime().exec("su");
      writer = new DataOutputStream(shell.getOutputStream());
      String cmd;

      cmd =
          String.format(
              "{ echo 'ACCESS GRANTED' >&2; cd '%s' && exec ./start_daemon.sh ;} || exit 1\n",
              System.getCorePath());

      writer.write(cmd.getBytes());
      writer.flush();

      ret = shell.waitFor();

      if (ret != 0) {
        reader = new BufferedReader(new InputStreamReader(shell.getErrorStream()));

        while ((line = reader.readLine()) != null) {
          if (line.equals("ACCESS GRANTED")) {
            access_granted = true;
            Logger.debug("'ACCESS GRANTED' found");
          } else Logger.warning("STDERR: " + line);
        }
      } else access_granted = true;

    } catch (IOException e) {
      // command "su" not found or cannot write to it's stdin
      Logger.error(e.getMessage());
    } catch (InterruptedException e) {
      // interrupted while waiting for shell exit value
      Logger.error(e.getMessage());
    } finally {
      if (writer != null)
        try {
          writer.close();
        } catch (IOException ignored) {
        }
      if (reader != null)
        try {
          reader.close();
        } catch (IOException ignored) {
        }
    }

    mKnownIssues.fromFile(String.format("%s/issues", getCorePath()));

    if (!access_granted) throw new SuException();

    if (ret != 0) {
      File log = new File(System.getCorePath(), "cSploitd.log");
      DaemonException daemonException = new DaemonException("core daemon returned " + ret);
      if (log.exists() && log.canRead()) {
        ACRAConfiguration conf = ACRA.getConfig();
        conf.setApplicationLogFile(log.getAbsolutePath());
        ACRA.setConfig(conf);
        ACRA.getErrorReporter().handleException(daemonException, false);
      }
      throw daemonException;
    }
  }