banner
  Socket Programming

Coming Soon:
 

Total Page Views
Since 05/22/2007


We Support:

cry logo

Socket Programming Basics
 

Socket Programming is one of the most important topics which a budding security enthusiast has to be familiar with. Most of the important topics in security such as port scanning, host and network fingerprinting, worms etc will be using sockets to do most of their job.

Also any network security software such as a vulnerability assessment toolkits, networking monitoring software etc will be using socket programming in some form or the other.

In this socket programming basics tutorial my aim is to help you as a beginner to understand all the concepts Lets first begin by looking at a "socket programming basics" presentation.

The presentation can be downloaded here for viewing.

 

It would be a good idea to go through the presentation and the video at least twice to get a hang of things. Some of the structures such as sockaddr_in and the byte orderings etc are quite confusing in the beginning. I have myself spent long hours understanding and digesting them and i feel after a couple of example codes they would on the contrary be quite simple to use and understand.

In the next video we will do a step by step "type with me" programming exercise. We will make a simple TCP Server which sends a simple string to the Client and closes the socket. The best way to use this video is to open a terminal and type along with it. Please download this code and follow the video.

 

Hope things we simple and clear ! Let us now move to a more interesting example.

We will make an Echo Server in this video . An Echo Server listens on a port and waits for clients. A client after connecting to the server sends a string. The Echo Server echoes the same string back to the client. As an example if the Client sends a "Hi" the Server echoes back a "Hi". This is all there is to an Echo Client-Server pair - a simple yet powerful example to start socket programming with.

Please download the sample code from the link in the block below and try to follow the video.

Hope the above example was clear. If not i'd advice you to go through it a couple of times and correlating things with the code. The best way is to try and modify the code and see if you can get things to work.

Now we will discuss how to code a custom client for the Echo Server. In the above example we used the telnet utility to connect to our Echo Server and send the strings of text. Now we will code our own little Echo Client which will connect to our Echo Server and do what we achieved with the telnet utility.

Please download the code and follow the video.

 

Hope the client example was simple to follow. I would advise you to go through the video and sample code again if there is any confusion. Also with this video i conclude this introductory section on socket programming. In later sections we will be using these concepts to build more complex programmers like port scanners and sniffers.

The easiest way to pick up socket programming (i guess this applies to everything in life :) ) is to practice and practice. Use the above code and first try modifying them to build more complex client-server interactions. Once you are confident enough, start writing a small ftp client-server from scratch.

I would also suggest the following links for further reading:

1. Beej Guide to Network Programming

2. Windows Socket programming

I hope this tutorial has been fun. It would be great to know your feedback here.

 
 


Advertisements
 
 
 
©2007 Freak Labs