Pages

Thursday, May 10, 2012

Smurf Attack

From Wikipedia:
The Smurf attack is a way of generating significant computer network traffic on a victim network. This is a type of denial-of-service attack that floods a system via spoofed broadcast ping messages.
This attack relies on a perpetrator sending a large amount of ICMP echo request (ping) traffic to IP broadcast addresses, all of which have a spoofed source IP address of the intended victim. If the routing device delivering traffic to those broadcast addresses delivers the IP broadcast to all hosts (for example via a layer 2 broadcast), most hosts on that IP network will take the ICMP echo request and reply to it with an echo reply, multiplying the traffic by the number of hosts responding.


Use -b option:

ping -b 255.255.255.255


There are some special multicast groups:

224.0.0.1 is the all-hosts group. If you ping that group, all multicast capable hosts on the network should answer, as every multicast capable host must join that group at start-up on all it's multicast capable interfaces.
224.0.0.2 is the all-routers group. All multicast routers must join that group on all it's multicast capable interfaces.
224.0.0.4 is the all DVMRP routers, 224.0.0.5 the all OSPF routers, 224.0.013 the all PIM routers, etc.
All this special multicast groups are regularly published in the "Assigned Numbers" RFC.


If you don't receive a reply it may be because the machines are ignoring the broadcast pings. You can change this setting in Linux by typing

echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts


Tuesday, May 8, 2012

Send mail from Gmail using command line

I tested it on Windows.

What you need:
stunnel 
telnet

Install stunnel. Run it.

Right click on icon in System Tray. Click on Edit stunnel.conf. Uncomment the lines corresponding to [gmail-smtp] and make these changes:


[gmail-smtp]
client = yes
accept = 127.0.0.1:2301
connect = smtp.gmail.com:465

Right click on icon in System Tray. Click on Reload stunnel.conf.

Now from command prompt type: telnet localhost 2301
If telnet is not available see the next post on how to enable it.

If all goes well you should see the following in the telnet window:

220 mx.google.com ESMTP

Type:
HELO google
250 mx.google.com at your service

Type:
AUTH LOGIN
334 VXNlcm5hbWU6
This is Base64 for:
334 Username:

Type your username in Base64. Use this website for performing the conversion.

You'll now see
334 UGFzc3dvcmQ6
which is Base64 for (you guessed it!) Password:

If the u/n pwd is accepted you'll see:
xxxxxx 2.7.0 Accepted

You're in!!

Type
MAIL FROM:<username@gmail.com>
250 2.1.0 OK 

The angular brackets are important.

RCPT TO:<friend@school.edu>
250 2.1.5 OK

DATA
354  Go ahead
From: User <username@gmail.com>
To: Friend <friend@school.edu>
Subject: Hello!
Body
.
250 2.0.0 OK

End body with a . in a new line

QUIT
221 2.0.0 closing connection


Pretty cool right?

EDIT:
For doing  AUTH PLAIN use:
Python code:
from base64 import b64encode
b64encode('authorization-id' + '\0' + 'authentication-id' + '\0' + 'passwd')

The client may leave the authorization-id empty to indicate that it is the same as the authentication identity

For doing AUTH CRAM-MD5 use the following code:
http://www.net-track.ch/opensource/cmd5/

How to enable telnet on Windows 7?

If you get the following error on running telnet from command prompt:

C:\Users\xxxx>telnet
'telnet' is not recognized as an internal or external command,
operable program or batch file.

You need to enable the telnet client by following these steps:



Have you downloaded something illegal using torrents recently?

They know about it!

http://www.youhavedownloaded.com/

Monday, May 7, 2012

Simple multicast client and server

Multicast Server/Listener

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> /* close */

#define SERVER_PORT 1500
#define MAX_MSG 100

int main(int argc, char *argv[]) {

  int sd, rc, n, cliLen;
  struct ip_mreq mreq;
  struct sockaddr_in cliAddr, servAddr;
  struct in_addr mcastAddr;
  struct hostent *h;
  char msg[MAX_MSG];

  if(argc!=2) {
    printf("usage : %s <mcast address>\n",argv[0]);
    exit(0);
  }

  /* get mcast address to listen to */
  h=gethostbyname(argv[1]);
  if(h==NULL) {
    printf("%s : unknown group '%s'\n",argv[0],argv[1]);
    exit(1);
  }

  memcpy(&mcastAddr, h->h_addr_list[0],h->h_length);

  /* check given address is multicast */
  if(!IN_MULTICAST(ntohl(mcastAddr.s_addr))) {
    printf("%s : given address '%s' is not multicast\n",argv[0],
           inet_ntoa(mcastAddr));
    exit(1);
  }

  /* create UDP socket */
  sd = socket(AF_INET,SOCK_DGRAM,0);
  if(sd<0) {
    printf("%s : cannot create socket\n",argv[0]);
    exit(1);
  }

  /* bind port */
  servAddr.sin_family=AF_INET;
  servAddr.sin_addr.s_addr=htonl(INADDR_ANY);
  servAddr.sin_port=htons(SERVER_PORT);
  if(bind(sd,(struct sockaddr *) &servAddr,sizeof(servAddr))<0)  
  {
    printf("%s : cannot bind port %d \n",argv[0],SERVER_PORT);
    exit(1);
  }

  /* join multicast group */
  mreq.imr_multiaddr.s_addr=mcastAddr.s_addr;
  mreq.imr_interface.s_addr=htonl(INADDR_ANY);

  rc = setsockopt(sd,IPPROTO_IP,IP_ADD_MEMBERSHIP,
                  (void *) &mreq, sizeof(mreq));
  if(rc<0) {
    printf("%s : cannot join multicast group '%s'",argv[0],
           inet_ntoa(mcastAddr));
    exit(1);
  }
  else {
    printf("%s : listening to mgroup %s:%d\n",
           argv[0],inet_ntoa(mcastAddr), SERVER_PORT);


    /* infinite server loop */
    while(1) {
      cliLen=sizeof(cliAddr);
      n = recvfrom(sd,msg,MAX_MSG,0,(struct sockaddr *) &cliAddr,&cliLen);
      if(n<n) {
        printf("%s : cannot receive data\n",argv[0]);
        continue;
      }

      printf("%s : from %s:%d on %s : %s\n",argv[0],
             inet_ntoa(cliAddr.sin_addr),ntohs(cliAddr.sin_port),
             argv[1],
             msg);
    }/* end of infinite server loop */

  }

return 0;

}


Multicast Client/Sender

#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> /* close */

#define SERVER_PORT 1500
#define MAX_MSG 100

int main(int argc, char *argv[]) {

  int sd, rc, i;
  unsigned char ttl = 1;
  struct sockaddr_in cliAddr, servAddr;
  struct hostent *h;

  if(argc<3) {
    printf("usage %s <mgroup> <data1> <data2> ... <dataN>\n",argv[0]);
    exit(1);
  }

  h = gethostbyname(argv[1]);
  if(h==NULL) {
    printf("%s : unknown host '%s'\n",argv[0],argv[2]);
    exit(1);
  }

  servAddr.sin_family = h->h_addrtype;
  memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0],h->h_length);
  servAddr.sin_port = htons(SERVER_PORT);

  /* check if dest address is multicast */
  if(!IN_MULTICAST(ntohl(servAddr.sin_addr.s_addr))) {
    printf("%s : given address '%s' is not multicast \n",argv[0],
           inet_ntoa(servAddr.sin_addr));
    exit(1);
  }

  /* create socket */
  sd = socket(AF_INET,SOCK_DGRAM,0);
  if (sd<0) {
    printf("%s : cannot open socket\n",argv[0]);
    exit(1);
  }
  /* bind any port number */
  cliAddr.sin_family = AF_INET;
  cliAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  cliAddr.sin_port = htons(0);
  if(bind(sd,(struct sockaddr *) &cliAddr,sizeof(cliAddr))<0) {
    perror("bind");
    exit(1);
  }

  if(setsockopt(sd,IPPROTO_IP,IP_MULTICAST_TTL, &ttl,sizeof(ttl))<0) {
    printf("%s : cannot set ttl = %d \n",argv[0],ttl);
    exit(1);
  }

  printf("%s : sending data on multicast group '%s' (%s)\n",argv[0],
         h->h_name,inet_ntoa(*(struct in_addr *) h->h_addr_list[0]));


  /* send data */
  for(i=2;i<argc;i++) {
    rc = sendto(sd,argv[i],strlen(argv[i])+1,0,
                (struct sockaddr *) &servAddr, sizeof(servAddr));

    if (rc<0) {
      printf("%s : cannot send data %d\n",argv[0],i-1);
      close(sd);
      exit(1);
    }

  }/* end for */

  /* close socket and exit */
  close(sd);
  exit(0);
}
 


$ ./mcastserver 224.0.0.200
./mcastserver : listening to mgroup 224.0.0.200:1500
./mcastserver : from 192.168.10.52:51654 on 224.0.0.200 : hello
./mcastserver : from 192.168.10.52:51654 on 224.0.0.200 : bye

$ ./mcastclient 224.0.0.200 hello bye
./mcastclient : sending data on multicast group '224.0.0.200' (224.0.0.200)



The switch periodically sends Query (Type 0x11) messages to broadcast address 224.0.0.1
When a server joins a new multicast group it sends a Membership report (Type 0x16) to all the hosts.
When a server leaves the group it sends a Leave Group (0x17) message to broadcast address 224.0.0.2

Also read:
http://ntrg.cs.tcd.ie/undergrad/4ba2/multicast/antony/
http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Multicast-HOWTO.html


Why a loglog plot is any day better than a linear plot?