android下的抓包+输入密码提醒

来源:互联网 发布:centos selinux 开启 编辑:程序博客网 时间:2024/05/21 13:55
package com.example.hackthon;import java.io.BufferedReader;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStream;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.Menu;import android.view.MenuItem;import android.widget.Toast;public class MainActivity extends Activity { @Override       public void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.activity_main);        Log.i("run","success!");         //if (haveRoot())        //Log.i("run", "have root");                 try {           Log.i("run","success!!"); //Runtime.getRuntime().exec("su");   //Runtime.getRuntime().exec("echo 'ssss'");//Runtime.getRuntime().exec("dd if=/sdcard/tcpdump of=/data/local/tcpdump");               //Runtime.getRuntime().exec("chmod 6755 /data/local/tcpdump");   String output;            Process proc = Runtime.getRuntime().exec("su");                DataOutputStream dataOutputStream = new DataOutputStream(proc.getOutputStream());                dataOutputStream.writeBytes("tcpdump -s 0 -X -tt tcp port 80" + "\n");                dataOutputStream.flush();                //dataOutputStream.writeBytes("exit" + "\n");                //dataOutputStream.flush();                //proc.waitFor();        //Log.i("run",getString(proc.exitValue()));                 //dataOutputStream.close();            BufferedReader bufferedReader1 = new BufferedReader(new InputStreamReader(proc.getInputStream()));            String out = "";            //String test=bufferedReader1.readLine();            //Log.i("run",test);        Log.i("run","success!!!");             while (((output = bufferedReader1.readLine()) != null)) {        //Log.i("run",out);                 if ((out.indexOf("password") != -1) || (out.indexOf("pwd") != -1) || (out.indexOf("PASSWORD") != -1) || (out.indexOf("Password") != -1) || (out.indexOf("PWD") != -1)){                System.out.println("warning!");            Log.i("run","success!!!!");                 Toast.makeText(this, "warning!", Toast.LENGTH_SHORT).show();                }                      if (output.startsWith("\t0x0000")) {                    out = output.substring(51);                }                else if (output.startsWith("\t"))                    out = out + output.substring(51);            }            Log.i("run","success!!!!!!!!!");              Toast.makeText(this, "success!!!!!!!!!", Toast.LENGTH_SHORT).show();        } catch (IOException e) {               // TODO Auto-generated catch block               e.printStackTrace();              Log.i("run",e.toString());                     }       }    private static boolean mHaveRoot = false;    public static boolean haveRoot() {        if (!mHaveRoot) {            int ret = execRootCmdSilent("echo test");            if (ret != 1) {            Log.i("run","have root!");                mHaveRoot = true;            } else {            Log.i("run","not root!");            }        } else {        Log.i("run","mHaveRoot = true, have root!");        }        return mHaveRoot;    }    @SuppressWarnings("deprecation")    public static String execRootCmd(String cmd) {        String result = "";        DataOutputStream dos = null;        DataInputStream dis = null;        try {            Process p = Runtime.getRuntime().exec("su");            dos = new DataOutputStream(p.getOutputStream());            dis = new DataInputStream(p.getInputStream());            Log.i("run",cmd);            dos.writeBytes(cmd + "\n");            dos.flush();            dos.writeBytes("exit\n");            dos.flush();            String line = null;            while ((line = dis.readLine()) != null) {                result += line;            }            p.waitFor();        } catch (Exception e) {            e.printStackTrace();        } finally {            if (dos != null) {                try {                    dos.close();                } catch (IOException e) {                    e.printStackTrace();                }            }            if (dis != null) {                try {                    dis.close();                } catch (IOException e) {                    e.printStackTrace();                }            }        }        return result;    }    public static int execRootCmdSilent(String cmd) {        int result = -1;        DataOutputStream dos = null;        try {            Process p = Runtime.getRuntime().exec("su");            Log.i("run", "root!!!!!!");            dos = new DataOutputStream(p.getOutputStream());            Log.i("run",cmd);            dos.writeBytes(cmd + "\n");            dos.flush();            dos.writeBytes("exit\n");            dos.flush();            p.waitFor();            result = p.exitValue();        } catch (Exception e) {            e.printStackTrace();        } finally {            if (dos != null) {                try {                    dos.close();                } catch (IOException e) {                    e.printStackTrace();                }            }        }        return result;    }}

0 0
原创粉丝点击