netdiscover example

USAGE EXAMPLES


       Scan common LAN addresses on eth0:

           # netdiscover -i eth0

       Fast scan common LAN addresses on eth0 (search only for gateways):

           # netdiscover -i eth0 -f

       Scan some fixed ranges:

           # netdiscover -i eth0 -r 172.26.0.0/24
           # netdiscover -r 192.168.0.0/16
           # netdiscover -r 10.0.0.0/8

Bufferoverflow example

#buff.c #include #include int main(int argc, char* argv[]) { char buf[64]; if(argc<2){ printf("supply atleast one argumnets"); return 1; }else{ strcpy(buf,argv[1]); return 0; } }

Kali Live USB Persistence


fdisk -l
 /dev/sdb # usb drive must be there

#now create a new partition
fdisk /dev/sdb


command 1) n
    2)p
    3)w  # the partition table has been altered



#Lets check
fdisk -l
    /dev/sdb3 "Type" Linux must be created now


now Lets create a file system in new partiion
root@kali:~#mkfs.ext4 -L persistence /dev/sdb3

now make label
    e2label /dev/sdb3 persistence

mkdir -p /mnt/MyDrive
mount /dev/sdb3/mnt/MyDrive

echo "/ union" >  /mnt/MyDrive/persistence.conf

unmount /dev/sdb3
exit

Saving data globally Shared preferences | session management | android

 If we are Storing data in shared preferences will be persistent to all application even after user closes the application. You can save key, value pair data in Shared preferences.


This class contain all user session related functions.
In this class file creating SharedPreferences and inserting / updating / deleting user session data from SharedPreferences.
further explanation given as comment in class code.




Total Files 6 :. 1. Manifest File 2. SessionLoginActivity.java 3. SessionLogoutActivity 4.   5.


1/6. manifest file

<activity android:name=".SessionLoginActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
 
<activity android:name=".SessionLogoutActivity" /> 


2. SessionLoginActivity.java


package com.example.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SessionLoginActivity extends Activity {

    Button btnLogin;

    EditText txtUsername, txtPassword;

    // User Session Manager Class    SessionManager session;

    @Override    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.session_login);

        // User Session Manager        session = new SessionManager(getApplicationContext());

        // get Email, Password input text        txtUsername = (EditText) findViewById(R.id.txtUsername);
        txtPassword = (EditText) findViewById(R.id.txtPassword);

        Toast.makeText(getApplicationContext(),
                "User Login Status: " + session.isUserLoggedIn(),
                Toast.LENGTH_LONG).show();


        // User Login button        btnLogin = (Button) findViewById(R.id.btnLogin);


        // Login button click event        btnLogin.setOnClickListener(new View.OnClickListener() {

            @Override            public void onClick(View arg0) {

                // Get username, password from EditText                String username = txtUsername.getText().toString();
                String password = txtPassword.getText().toString();

                // Validate if username, password is filled                if(username.trim().length() > 0 && password.trim().length() > 0){

                    // For testing puspose username, password is checked with static data                    // username = admin                    // password = admin
                    if(username.equals("admin") && password.equals("learnskill.today")){

                        // Creating user login session                        // Statically storing name="Session Example"                        // and email="aashish.learnskill@gmail.com"                        session.createUserLoginSession("Session Example",
                                "aashish.learnskill@gmail.com");

                        // Starting MainActivity                        Intent i = new Intent(getApplicationContext(), SessionLogoutActivity.class);
                        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                        // Add new Flag to start new Activity                        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(i);

                        finish();

                    }else{

                        // username / password doesn't match&                        Toast.makeText(getApplicationContext(),
                                "Username/Password is incorrect",
                                Toast.LENGTH_LONG).show();

                    }
                }else{

                    // user didn't entered username or password                    Toast.makeText(getApplicationContext(),
                            "Please enter username and password",
                            Toast.LENGTH_LONG).show();

                }

            }
        });
    }
}

 
 
 
3. SessionLogoutActivity
 
package com.example.myapplication;

import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class SessionLogoutActivity extends Activity {


    // User Session Manager Class    SessionManager session;

    // Button Logout    Button btnLogout;

    @Override    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.session_logout);

        // Session class instance        session = new SessionManager(getApplicationContext());

        TextView lblName = (TextView) findViewById(R.id.lblName);
        TextView lblEmail = (TextView) findViewById(R.id.lblEmail);

        // Button logout        btnLogout = (Button) findViewById(R.id.btnLogout);

        Toast.makeText(getApplicationContext(),
                "User Login Status: " + session.isUserLoggedIn(),
                Toast.LENGTH_LONG).show();



        // Check user login (this is the important point)        // If User is not logged in , This will redirect user to LoginActivity        // and finish current activity from activity stack.        if(session.checkLogin())
            finish();

        // get user data from session        HashMap user = session.getUserDetails();

        // get name        String name = user.get(SessionManager.KEY_NAME);

        // get email        String email = user.get(SessionManager.KEY_EMAIL);

        // Show user data on activity        lblName.setText(Html.fromHtml("Name: " + name + ""));
lblEmail.setText(Html.fromHtml("Email: " + email + ""));
btnLogout.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View arg0) {
// Clear the User session data // and redirect user to LoginActivity session.logoutUser();
}
});
}
}






4. UserSessionManager.java



 package com.example.myapplication;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import java.util.HashMap;

public class SessionManager {

        // Shared Preferences reference        SharedPreferences pref;

        // Editor reference for Shared preferences        Editor editor;

        // Context        Context _context;

        // Shared pref mode        int PRIVATE_MODE = 0;

        // Sharedpref file name        private static final String PREFER_NAME = "AndroidExamplePref";

        // All Shared Preferences Keys        private static final String IS_USER_LOGIN = "IsUserLoggedIn";

        // User name (make variable public to access from outside)        public static final String KEY_NAME = "name";

        // Email address (make variable public to access from outside)        public static final String KEY_EMAIL = "email";

        // Constructor        public SessionManager(Context context){
            this._context = context;
            pref = _context.getSharedPreferences(PREFER_NAME, PRIVATE_MODE);
            editor = pref.edit();
        }

        //Create login session        public void createUserLoginSession(String name, String email){
            // Storing login value as TRUE            editor.putBoolean(IS_USER_LOGIN, true);

            // Storing name in pref            editor.putString(KEY_NAME, name);

            // Storing email in pref            editor.putString(KEY_EMAIL, email);

            // commit changes            editor.commit();
        }

        /**         * Check login method will check user login status         * If false it will redirect user to login page         * Else do anything         * */        public boolean checkLogin(){
            // Check login status            if(!this.isUserLoggedIn()){

                // user is not logged in redirect him to Login Activity                Intent i = new Intent(_context, SessionLoginActivity.class);

                // Closing all the Activities from stack                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                // Add new Flag to start new Activity                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                // Staring Login Activity                _context.startActivity(i);

                return true;
            }
            return false;
        }



        /**         * Get stored session data         * */        public HashMap getUserDetails(){

            //Use hashmap to store user credentials            HashMap user = new HashMap();

            // user name            user.put(KEY_NAME, pref.getString(KEY_NAME, null));

            // user email id            user.put(KEY_EMAIL, pref.getString(KEY_EMAIL, null));

            // return user            return user;
        }

        /**         * Clear session details         * */        public void logoutUser(){

            // Clearing all user data from Shared Preferences            editor.clear();
            editor.commit();

            // After logout redirect user to Login Activity            Intent i = new Intent(_context, SessionLoginActivity.class);

            // Closing all the Activities            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            // Add new Flag to start new Activity            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            // Staring Login Activity            _context.startActivity(i);
        }


        // Check for login        public boolean isUserLoggedIn(){
            return pref.getBoolean(IS_USER_LOGIN, false);
        }
    }
 
 
 
 
 
 
session_login.xml
 
 
 
 
 
 


 
sessionlogout.xml
 
 
 
 
 
 
 
 5.session_login.xml
 
xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:padding="10dip">

    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="Username (Enter 'admin')"        android:singleLine="true"        android:layout_marginBottom="5dip"/>

    <EditText android:id="@+id/txtUsername"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginBottom="10dip"/>

    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="Password (Enter 'learnskill.today')"        android:layout_marginBottom="5dip"/>

    <EditText android:id="@+id/txtPassword"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginBottom="20dip"        android:password="true"        android:singleLine="true"/>

    <Button android:id="@+id/btnLogin"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="Login"/>

</LinearLayout>
 

6. session_logout.xml

 

xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:padding="10dip">


    <TextView        android:id="@+id/lblName"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:singleLine="true"        android:layout_marginTop="40dip"        android:layout_marginBottom="10dip"/>


    <TextView        android:id="@+id/lblEmail"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:singleLine="true"        android:layout_marginBottom="40dip"/>


    <Button android:id="@+id/btnLogout"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="Logout"/>

</LinearLayout>
 
 

tabs | Android

Tabs.java

package com.example.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class Tabs extends Activity implements OnClickListener{
    Button bStart, bStop, addTab;
    TextView showResults;
    long  start,stop;

    TabHost th;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabs);

        bStart=(Button) findViewById(R.id.bStartWatch);
        bStop=(Button) findViewById(R.id.bStopWatch);
        addTab=(Button) findViewById(R.id.bAddTab);
        showResults=(TextView)findViewById(R.id.tvShowResults);

        addTab.setOnClickListener(this);
        bStart.setOnClickListener(this);
        bStop.setOnClickListener(this);


        th= (TabHost)findViewById(R.id.tabhost);
        th.setup();

        TabSpec specs=th.newTabSpec("tag1");

        specs.setContent(R.id.tab1);
        specs.setIndicator("StopWatch");//Frist Tab
        th.addTab(specs);

        //Second Tab        specs=th.newTabSpec("tag2");

        specs.setContent(R.id.tab2);
        specs.setIndicator("Tab 2");//second Tab
        th.addTab(specs);

        //Adda tab        specs=th.newTabSpec("tag3");

        specs.setContent(R.id.bAddTab);
        specs.setIndicator("Button Add Tab");//Frist Tab
        th.addTab(specs);
        start=0;




    }

    @Override    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch(arg0.getId()){
            case R.id.bAddTab:
                TabSpec ourSpec= th.newTabSpec("tag1");
                ourSpec.setContent(new TabHost.TabContentFactory() {

                    @Override                    public View createTabContent(String arg0) {
                        // TODO Auto-generated method stub                        TextView text=new TextView(Tabs.this);
                        text.setText("You have created new tab!!");



                        return (text);

                    }

                });
                ourSpec.setIndicator("New ");
                th.addTab(ourSpec);


                break;
            case R.id.bStartWatch:

                start= System.currentTimeMillis();
                break;
            case R.id.bStopWatch:
                stop=System.currentTimeMillis();

                if(start!=0){
                    long result=stop-start;
                    int millis=(int) result;
                    int seconds=(int) result/1000;
                    int minutes=(int) seconds/60;

                    millis%=100;
                    seconds%=60;

                    showResults.setText(String.format("%d:%02d:%02d",minutes,seconds,millis));
                }

                break;

        }


    }


}



2.tabs.xml

xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width= "match_parent"    android:layout_height= "match_parent"    android:orientation= "vertical" >

    <TabHost        android:id="@+id/tabhost"        android:layout_width="match_parent"        android:layout_height="match_parent" >

        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical" >

            <TabWidget                android:id="@android:id/tabs"                android:layout_width="423dp"                android:layout_height="79dp"></TabWidget>

            <FrameLayout                android:id="@android:id/tabcontent"                android:layout_width="match_parent"                android:layout_height="match_parent"                >

                <LinearLayout                    android:id="@+id/tab1"                    android:layout_width="match_parent"                    android:layout_height="match_parent"                    android:orientation="horizontal"
                    >

                    <Button                        android:id="@+id/bStartWatch"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:text="RESET" />

                    <Button                        android:id="@+id/bStopWatch"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:text="Stop" />

                    <TextView                        android:id="@+id/tvShowResults"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:text="TextView" />

                </LinearLayout>

                <LinearLayout                    android:id="@+id/tab2"                    android:layout_width="match_parent"                    android:layout_height="match_parent"                    android:orientation="horizontal" >
                    <TextView                        android:id="@+id/textView1"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:text="TextView 2" />
                </LinearLayout>

                <LinearLayout                    android:id="@+id/tab3"                    android:layout_width="match_parent"                    android:layout_height="match_parent"                    android:orientation="horizontal" >
                    <Button                        android:id="@+id/bAddTab"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:text=" B Add Tab" />
                </LinearLayout>

            </FrameLayout>
        </LinearLayout>
    </TabHost >

</LinearLayout>