lunes, 28 de noviembre de 2011

Nachos 3 Practical Presentation

Networking test in NachOS


In order to make a networking functionality test in nachos we must first open two separate terminals, then we enter to the network folder, after we enter we must write ./ nachos. When we finish writing ./nachos we write first -m 0 (from) -o 1(to) in one terminal and then -m 0 (from) -o 0 (to) in the other terminal simultaneously.

Now where we wrote -m 0 -o 1 we will receive this message:

Got "Hello there!" from 1, box 1
Got "Got it!" from 1, box 1
Machine halting!

Where we wrote -m 0 -o 0 we will receive this message:

Got "Hello there!" from 0, box 1
Got "Got it!" from 0, box 1
Machine halting!

Here we show you some of the code in nachos that does this
This is contained in nettest.cc


Here it sends a message to the machine with ID "farAddr", then it waits for this message to arrive. When it sends an acknowledgement for the other machine´s message it keeps waiting for the acknowledgment from the other machine to the original message.


Now we construct the packet and we specify the destination where we are going to send it, and also from where we are sending the packet.  

Finally we send the message and we wait for a confirmation message from the other machine.

The execution would be like this:









Network in Nachos

Here we are going to show you a little introduction of how networking works in NachOS.

In Nachos we have two main classes: 
The network class
The postoffice class

Network

The network class is not directly used by the user. It is the Link between nachOS and sockets TCP/IP.
It has four methods:


  • Send: Sends a packet to a NachOS machine.
  • Receive: If there is a packet, it receives it. If not, it returns with a 0.
  • CheckPktAvail: It activates regularly to verify if a packet arrives.
  • SendDone: When it receives the packet, it calls a manager  in order to organize it.


For communication, NachOS uses PacketHeader and MailHeader.

They both contain:
To (Destination of the packet)
From (Origin of the packet)
Length (Size of the packet)

Postoffice


Example of postoffice

  • Sends a packet to a given address
  • Waits for a message and prints it once received
  • Sends another packet to the same address
  • Waits for a message and prints it once received


Now we are going to explain some other important files in the network folder and we are going to show you some code

  • nettest.cc  (nachos/code/network)


Here is where we run the routines of the network test.



  • post.h, post.cc  (nachos/code/network)


They help to synchronize the data sent and received. (like a messenger)

Here we show you some code 

Post.h


       Post.cc



  • network.h, network.cc (nachos/code/machine)


They are a physical network hardware emulation. 

Network.h


        Network.cc




References:


bit.ly/vtlhRr





domingo, 27 de noviembre de 2011

Wireshark


Ok, in the last publications many people talk about encrypt, security, pings, and other, but we need to know a some tools that can help to want vulnerabilities in ours network, for example the information that we send and pass to the modem or other computer, this information is encrypt or go visible? or how many package we send and what package we send.


For this things have a many tools for example, nmap (this help to know the network, ports, information of the computer connected in the local network), aircrack (help to decrypt the key of the router or modem), kismet (help to put the network card in mode monitor "sniff"), wireshark(sniff packages).


But and talk about wireshark, is a tool using to make testing in the network


We can download putting in terminal sudo apt-get install wireshark


Then we run in mode administrator (sudo)


Then we go in Interface List and choose wlan0
Next the program open a window showing the package that was sending
Then of a little time, we stop the program.
Stop listening and you will see the information, for example where is the place to go and what your destination.

If we click on one of them we will display all your specific information,which is where you used that port, protocol, etc.
Also what can be done is that you give and give it the 2nd buttonFollo TCP Stream and teach you the information being sent.
If we try to read it, we can not, as many times this is encrypted, so you will not see, rather than the odd line.

But now we know how this works, seen with the previous, so we can implement any tool or program to unzip us the information. For this too has wireshark decryption tool, it is a matter of us to choose which is the indicaga as they deal with different protocols. To facilitate thiswe can also set filters, that is which at a certain port and ip.

Client - Server

Here is the code of client-server using a simple chat and implement encrypt text or you can download the code in this links: server.py and client.py

#!/usr/bin/python

# Server program
from socket import *

# Set the socket parameters
host = "localhost"
port = 21567
buf = 2048
addr = (host,port)

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)

#decrypt
def decrypt(a):
    length = len(a)
    for position in range (length):
        temp = ord(a[position])
        temp = temp - 1                                                        
        temp = chr(temp)
        data = a[:position] + temp + a[position + 1:]
    return data
  
print "Waiting message..."

# Receive messages
while 1:
    data,addr = UDPSock.recvfrom(buf)
    data1,addr = UDPSock.recvfrom(buf)
    if not data:
        print "Client has died!"
        break
    else:
        data, key = data.split(';')
        print "\nReceived message '", data1,"'"
        clave = raw_input('Give me the key to decrypt: ')
        if (clave == key):
            decrypt(data1)
            print "Mensaje: ",data
        else:
            break

# Close socket
UDPSock.close()

#!/usr/bin/python

# Client program
from socket import *

# Set the socket parameters
host = "localhost"
port = 21567
buf = 2048
addr = (host,port)

# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)

def_msg = "Write something ";
print "\n",def_msg

#encrypt
def encrypt(data):
    length = len(data)
    for position in range (length):
       temp = ord(data[position])
       temp = temp + 1
       temp = chr(temp)
       data = data[:position] + temp + data[position + 1:]
    return data


# Send messages
while (1):
    data = raw_input('Introduce Message: ')
    clave = raw_input('Give me the key: ')
    data = data+";"+clave
    if not data:
        break
    else:
        if(UDPSock.sendto(data,addr)):
            print "Sending message.....\n"
            data1 = encrypt(data);            
            UDPSock.sendto(data1,addr)
            
# Close socket
UDPSock.close()

Now i'm try to explain the code:
host = "localhost"
port = 21567
buf = 2048
addr = (host,port)
In this part we set the parameters, we can change, for example port to another, the size of the buffer, and the host, but if we change in server or client, we need to change too in the other code. The parameter is used to do a connection between client and server.

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)
In this part we create the socket connection and bind the address, AF_INET & SOCK_DGRAM, represents the address family INET for the internet sockets.
#decrypt
def decrypt(a):
    length = len(a)
    for position in range (length):
        temp = ord(a[position])
        temp = temp - 1                                                        
        temp = chr(temp)
        data = a[:position] + temp + a[position + 1:]
    return data
The next part, is a function of decrypt, we saw this in other publication, is the same but we use to decrypt the message.
# Receive messages
while 1:
    data,addr = UDPSock.recvfrom(buf)
    data1,addr = UDPSock.recvfrom(buf)
    if not data:
        print "Client has died!"
        break
    else:
        data, key = data.split(';')
        print "\nReceived message '", data1,"'"
        clave = raw_input('Give me the key to decrypt: ')
        if (clave == key):
            decrypt(data1)
            print "Mensaje: ",data
        else:
            break

# Close socket
UDPSock.close()

The next part take the parameters and data sending, then separate the string in data (Information) and key (key to decrypt the text), then we compare between key to clave and if this is correct show the message and in the last part close the socket.

TUDPSock.sendto(data1, addr)

Execution: 



Encryption/Decryption

This is a program we made for encrypt/decrypt some text.

In this code, first we declare the functions Encrypt() and Decrypt(), then we ask to the user to write something and we save this text in a string variable called text, then the Encrypt method is called. In this function, the variable len gets the text length and then is a for for 0 to the lenght of the text -1 this is to read each letter of the text that user write. Then we get the ASCII value of 'c', multiply this ASCII value by 2 and set the new ASCII value back into the char. Finally insert the new value back into the text. Decrypt function returns the encrypted text into the start text.


#include <iostream>
#include <cstring>
#include <cctype>


using namespace std;
void Encrypt(string&);
string Decrypt(string text);


int main() {
 

  string text;
  cout << "Write something: ";
  getline(cin,text);
  string temp(text);
  Encrypt(text);


  cout << "Encrypted: " << text << endl;
  cout << "Decrypted: " << Decrypt(text) << endl;


  return 0;
}


void Encrypt(string &text)
{
  int len = text.length();
  char c;
  string Finaltext(text);


  for (int i = 0; i <= (len-1); i++)
    {
      c = text.at(i);
      int a = (int)c;
      a += 2;
      if (a > 254) { a = 254; }
      c = (char)a;
      Finaltext.insert(i , 1, c);
    }
  string textEncrypted(Finaltext, 0, len);
  text = textEncrypted;
}


string Decrypt(string text)<
{

  int len = text.length();
  char c;
  string Finaltext(text);


  for (int i = 0; i <= (len-1); i++)
    {
      c = text.at(i);
      int a = (int)c;
      a -= 2;


      c = (char)a;
      Finaltext.insert(i, 1, c);
    }
  string textDecrypted(Finaltext, 0, len);
  return textDecrypted;
} 
Execution: