473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Constructing and sending a SYN header

The following code is intended to construct a SYN header and send it
to a host (just the localhost at the moment) to form part of a port
scanner tool for network security. However, the packet that the
socket receives in response is a copy of the SYN packet sent with some
data inserted at the start. Can someone please shed some light on
what is happening?

Code:

using System;
using System.Net;
using System.Net.Sockets;

public class SynTest
{
public static void Main ()
{
IPAddress localIP = IPAddress.Parse ("127.0.0.1");
int localPort = 1025;
IPEndPoint localEndPoint = new IPEndPoint (localIP, localPort);

IPAddress remoteIP = IPAddress.Parse ("127.0.0.1"); // Use
localhost for now int remotePort = 22;
IPEndPoint remoteEndPoint = new IPEndPoint (remoteIP, remotePort);

Socket ipSocket = new Socket (AddressFamily.InterNetwork,
SocketType.Raw, ProtocolType.IP);

// Bind the socket to the local end point

ipSocket.Bind (localEndPoint);

// Code to construct the datagram
byte[] datagram = new byte[32];

// Source address

datagram[0] = 127;
datagram[1] = 0;
datagram[2] = 0;
datagram[3] = 1;

// Destimation address

datagram [4] = 127;
datagram [5] = 0;
datagram [6] = 0;
datagram [7] = 1;

// Zero bits

datagram [8] = 0;

// Protocol - TCP = 6

datagram [9] = 6;

// TCP length

datagram [10] = 0;
datagram [11] = 32;

// Source port

datagram [12] = 4; // 1025
datagram [13] = 1;
// Destination port

datagram [14] = 0;
datagram [15] = 22; // 22

// Sequence number

datagram [16] = 0;
datagram [17] = 0;
datagram [18] = 0;
datagram [19] = 0;

// Acknowledgement number

datagram [20] = 0;
datagram [21] = 0;
datagram [22] = 0;
datagram [23] = 0;

// Data Offset + reserved - the left four bytes = 5 for header
length (* four-byte words), the right four bits = 0. The whole byte =
80 in base 10.

datagram [24] = 80;

// Flags

datagram [25] = 2; // Bit 2 set - SYN flag only

// Window

datagram [26] = 0;
datagram [27] = 255;

// Checksum - initialised to 0

datagram [28] = 0;
datagram [29] = 0;

// Urgent field

datagram [30] = 0;
datagram [31] = 0;

byte[] receivedPacket = new byte[256];
Console.WriteLine ("Sending packet...");
ipSocket.SendTo (datagram, remoteEndPoint);
Console.WriteLine ("Packet sent");
ipSocket.Receive (receivedPacket);
Console.WriteLine ("Received packet");
for (int i = 0; i < 256; i++)
{
Console.WriteLine (i + " " + receivedPacket[i]);
}
}
}

Jan 27 '07 #1
0 1823

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Kubaton Lover | last post by:
I have a pdf file (syllabus.pdf) on the server. I have written the following PHP code. It correctly finds the file, but it is sending the file back as text I think because I'm seeing the binary...
3
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt....
3
by: karthick | last post by:
Hi, I am constructing a Message (Body) for sending our Emails. It is around 3000 characters long. But for whatever reason, the last line seems to be broken with a "!" exclamatory mark in it,...
4
by: Winston Nimchan | last post by:
Hi: I'm currently developing a socket application and would like to precede the data being sent with a 4 byte message length header (bin4). Can anyone help Regards Winston
4
by: Narendra | last post by:
Hi All, This is narendra from india doing my engineering. i need to develop an E-mail client in python,which connects to my MTA on port 25 and sends email from there. I was able to do that...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
3
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce...
3
by: Sells, Fred | last post by:
I'm using MSW XP Pro with Python 2.4 to develop but production will be Linux with Python 2.3. (could upgrade to 2.4 if absolutely necessary) I can also switch to Linux for development if...
3
by: FFMG | last post by:
Hi, I want to send expiry headers along with my images. This is the code in my .htaccess file Code: -------------------- ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.