Information Security Management: Lab Assessment - 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Information Security Management

Lab Assessment -1

REG NO-18BCE0904

NAME-ASMIT GUPTA

Faculty: Amutha Prabakar M

QUESTION:-

Develop a software for verifying the authentication and access control

of additional hardware addition and deletion

Meta:
*Platform : Linux / Unix
*Default Password : what
*Language : Java

Code:

import java.io.*; import


java.util.*; import
java.awt.*; import
java.awt.event.*;
import javax.swing.*;
public class Test{

static String prev,next; static ArrayList<String> P =


new ArrayList<String>(); static ArrayList<String> N =
new ArrayList<String>();
public static void bind(final int in)throws Exception{
new Thread(){ public void run(){ try{
String a,b,c; for(int i=in;i>=0;i--){
if(N.get(i).substring(1,2).equals(":")){
a=N.get(i).substring(9,10);
b=N.get(i+1).substring(13,14);
c=N.get(in).substring(17,18);
System.out.println(a+"-"+b+"."+c); String
add="";

try{ int cint=Integer.parseInt(c);


add="\'"+a+"-"+b+"."+c+"\'";
}
catch(Exception e){ add="\'"+a+"-
"+b+"\'";
}
System.out.println(add);
String command="echo "+ add +"
> /sys/bus/usb/drivers/usb/unbind";
Process p1
=Runtime.getRuntime().exec(new String[]{"bash","-c",command});
command="echo "+ add +" >
/sys/bus/usb/drivers/usb/bind"; new Password(command,in); break;
}
}
}catch(Exception e){System.out.println(e.toString());}
}
}.start();
}

public static void exec()throws Exception{


String p[] = prev.split("\n");
String n[] = next.split("\n");
P.clear();
N.clear();
for(int i=0;i<p.length;i++){
P.add(p[i]); }
for(int i=0;i<n.length;i++){
N.add(n[i]); } for(int
i=0;i<N.size();i++){
if(!P.contains(N.get(i))){
bind(i);
}
}
prev=""; for(int
i=0;i<N.size();i++){
prev+=N.get(i)+"\n";
}
while(Thread.activeCount()!=1){}
}

public static void remove(){


try{
Process p0 = Runtime.getRuntime().exec("rm out.txt");
}catch(Exception e){System.out.println(e.toString());}
}

public static void check()throws


Exception{ String tmp=""; remove();
Process p1 = Runtime.getRuntime().exec(new String[]{ "bash" ,
"-c" , "lsusb -t" });
BufferedReader br1 = new BufferedReader(new
InputStreamReader(p1.getInputStream()));
next=""; tmp=""; while((tmp =
br1.readLine())!=null)
next+=tmp+"\n";

if(!prev.equals(next)){
exec();
}
}

public static void init()throws Exception{


Process p1 = Runtime.getRuntime().exec("sh out.sh");
remove(); p1 = Runtime.getRuntime().exec(new String[]{
"bash" , "-c" ,
"lsusb -t" });
BufferedReader br = new BufferedReader(new
InputStreamReader(p1.getInputStream()));
prev="";
String tmp=""; while((tmp =
br.readLine())!=null)
prev+=tmp+"\n";

while(true){ try{
check();
}catch(Exception e){System.out.println(e.toString());}
}
}

public static void main(String []args)throws


Exception{ while(true){ try{ init();
}catch(Exception e){System.out.println(e.toString());}
}
}
}

class Password extends Frame implements ActionListener{

private Panel p1,p4; private


Label lbl; private TextField pass;
private Button
submitBtn,exitBtn;

int count;
String Command;
int index;

public Password( String Command , int index){


this.Command=Command;
this.index=index;

setLayout(new BorderLayout()); lbl=new Label("Enter


The Token"); p1=new Panel(); p1.setLayout(new
FlowLayout(FlowLayout.CENTER)); p1.add(lbl);
add("North",p1);

p4=new Panel();
p4.setLayout(new FlowLayout());
pass=new TextField("",25);
pass.setEditable(true);
pass.setEchoChar('*');
p4.add(pass); submitBtn=new
Button("Submit");
p4.add(submitBtn); exitBtn=new
Button("Exit"); p4.add(exitBtn);
add("South",p4);

pass.addActionListener(this);
submitBtn.addActionListener(this);
exitBtn.addActionListener(this); setSize(600,400);
setTitle("Pen-Drive By-Pass - By Gunda Sai
Likhith");

p1.setVisible(true);
p4.setVisible(true);
setVisible(true);
}

public void submitbtn()throws Exception{


if(pass.getText().equals("what")){
Process p1 =Runtime.getRuntime().exec(new
String[]{"bash","-c",Command});
dispose();
}
else if(count<3){ lbl.setText("Wrong
Token."+ ++count);
}
else{ dispose();
Test.N.remove(index);
pass.setEditable(false);
}
}

public void actionPerformed(ActionEvent


evt){ if(evt.getSource()==submitBtn){
try{ submitbtn();
}catch(Exception e){}
}
else if(evt.getSource()==pass){
try{ submitbtn();
}catch(Exception e){}
}
else if(evt.getSource()==exitBtn){
dispose();
}
}
}

Important Lines:

1. Binding and Unbinding

2. Verifying

Output:

1. Execution:
2. Prompt:
3. Wrong Password:

4. Now after correct password: Opened

You might also like