PDA

View Full Version : Develop on device android console(shell) app



"vinnu"
08-08-2012, 08:49 PM
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



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("");
}
}

"vinnu"
08-08-2012, 08:56 PM
Save the file and now in ....../projectname/res/layout/main.xml file type in the folowing xml 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>

"vinnu"
08-08-2012, 09:00 PM
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"

Anant Shrivastava
08-08-2012, 10:50 PM
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.

"vinnu"
08-09-2012, 10:24 AM
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"

PR4NK1
02-05-2014, 10:19 PM
Will this get me root access too? using 'su' command???