Results 1 to 6 of 6

Thread: Develop on device android console(shell) app Share/Save - My123World.Com!

  1. #1

    Develop on device android console(shell) app

    Namaste
    An android device with development environment is a great weapon for hacking. In this thread we'll develop our own console application to execute the shell commands provided by android os
    Search for AIDE app in google app store and install it. It is an ondevice IDE/compiler for android app development

    Create a new project and into its MainActivity.java file paste the following code

    Code:
    package com.mycompany.myapp;
    
    import android.app.*;
    import android.os.*;
    import android.view.View;
    import android.widget.*;
    import android.widget.TextView;
    import android.util.Log;
    import android.widget.Button;
    import android.widget.EditText;
    import java.io.*;
    import java.lang.Process;
    import android.text.method.*;
    import java.io.BufferedReader.*;
    import java.io.BufferedWriter.*;
    
    public class MainActivity extends Activity implements View.OnClickListener
    {
    	public String ver = "Android Console v0.01\nDeveloper: \"vinnu\"\nTeam:\"Legion Of Xtremers\" & secfence\nUrl:www.secfence.com\n";
    	private TextView tvp;
    	private EditText et;
    	private TextView tvout;
    	private Process rprocc;
    	private BufferedReader br;
    	private BufferedWriter bw;
    	
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
    	{
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    		TextView tv = (TextView)findViewById(R.id.tver);
    		tv.setText(ver);
    		
    		Button bt = (Button)findViewById(R.id.hello);
    		bt.setOnClickListener(this);
    		
    		tvp = (TextView)findViewById(R.id.prompt);
    		
    		et = (EditText)findViewById(R.id.texf);
    		et.setText("");
    		tvout = (TextView)findViewById(R.id.out);
    		tvout.setMovementMethod(new ScrollingMovementMethod());
    
        }
    	public void onClick(View view)	{
    		sheller();
    	}
    
    	public void sheller()	{
    		StringBuffer output = new StringBuffer();
    		int read = 0;
    		char[] buffer = new char[4096];
    		String [] cmd = {"/system/bin/sh","-c", "\""+et.getText()+"\"\n"};
    		try{
    			rprocc = Runtime.getRuntime().exec(cmd);
    			br = new BufferedReader(new InputStreamReader(rprocc.getInputStream()));
    //			bw = new BufferedWriter(new OutputStreamWriter(rproc.getOutputStream()));
    			
    			while((read = br.read(buffer)) > 0)	{
    				Log.d("DEBUGTAG","Reading output of command.");
    				output.append(buffer, 0, read);
    			}
    			tvout.setText(tvp.getText()+""+et.getText()+"\n"+output+tvout.getText());
    		} catch(IOException e)	{
    			throw new RuntimeException();
    		}
    		et.setText("");
    	}
    }
    Last edited by "vinnu"; 08-08-2012 at 09:19 PM.

  2. #2
    Save the file and now in ....../projectname/res/layout/main.xml file type in the folowing xml code:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
    	android:stretchColumns="1"
    	android:shrinkColumns="0"
    >
    	<TableRow>
        	<TextView
    			android:id="@+id/tver"
    	        android:layout_width="wrap_content"
        	    android:layout_height="wrap_content"
    		/>
    	</TableRow>
    	<TableRow>
    		<TextView
    			android:id="@+id/prompt"
    			android:layout_width="wrap_content"
    			android:layout_height="wrap_content"
    			android:text="127.0.0.1:~$"
    		/>
    		<EditText
    			android:id="@+id/texf"
    			android:layout_width="fill_parent"
    			android:layout_height="wrap_content"
    			android:singleLine="true"
    			android:layout_span="3"
    		/>
    		<Button
            	android:id="@+id/hello"
    			android:layout_width="wrap_content"
    			android:layout_height="wrap_content"
    			android:text="Exec"
    		/>
    	</TableRow>
    	<TableRow>
    		<TextView
    			android:id="@+id/out"
    			android:layout_width="fill_parent"
    			android:layout_height="wrap_content"
    			android:scrollbars="vertical"
    			android:maxLines="30"
    			android:layout_span="4"
    		/>
    	</TableRow>
    </TableLayout>

  3. #3
    You need to select the "Install apps from unknown source" [like that] setting from ur device's settings menu before rrunning this app. Select Save and then Run from AIDE menu to install ur app and execute it.


    ..."vinnu"

  4. #4
    Security Researcher
    Join Date
    May 2011
    Location
    Pune, Maharashtra, India
    Posts
    237
    Blog Entries
    1
    Quote Originally Posted by "vinnu" View Post
    You need to select the "Install apps from unknown source" [like that] setting from ur device's settings menu before rrunning this app. Select Save and then Run from AIDE menu to install ur app and execute it.


    ..."vinnu"
    Hi Vinnu,

    good exercise but why take so much effort when terminal emulator is directly available.
    Website :
    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

    Blog :
    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  5. #5
    Namaste
    Yes, there are several, but there is always a charm of deveoping own tools, this gives us more power and control as we can do whatever we wish. And the bliss comes when our tool works, but not when other's app did stuff for us...."vinnu"

  6. #6
    Will this get me root access too? using 'su' command???

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •