View
223
Download
0
Embed Size (px)
Citation preview
7/23/2019 How to Create TCP IP Packets Code in C Programming
http://slidepdf.com/reader/full/how-to-create-tcp-ip-packets-code-in-c-programming 1/6
How to Create TCP/IP Packets Code in C Programming
Read more : http://www.ehow.com/how_1140047_create!tcp!ip!packets!code!c! programming.htm"
Creating a TCP/IP packet is important when you want your C program to make an active
connection with a remote host to send data back and forth. TCP/IP is a networking
protocol that provides reliable and ordered delivery of packets between two hosts.
The world wide web, email and file transfer applications all use the TCP/IP protocol.
Create a TCP/IP packet by collecting data about a host, making a socket out of that
data and then sending the socket to the remote host
Instructions
1.
o 1
#pen $o%r C &i"e in an editor s%ch as 'C((.
o )
*dd the +insock "i,rar$ to $o%r compi"er-s proect settings so that it wi"" "ink
proper"$. In 'C(( this is done ,$ c"icking the Proect men% c"icking
ettings... c"icking 2ink and t$ping ws)_3)."i, in the ,o tit"ed
#,ect/"i,rar$ mod%"es. #ther possi,"e names &or the +insock "i,rar$ inc"%dewinsock3)."i, and wsock3)."i,.
3
Inc"%de the winsock) and ws3tcpip headers to access the socket &%nctions ,$ adding the&o""owing code at the top o& $o%r &i"e:
inc"%de 5winsock).h6
inc"%de 5ws)tcpip.h6
4
ec"are the 8aria,"es needed to create a TCP/IP packet ,$ adding the &o""owing code in $o%r&%nction:
str%ct addrin&o hints 9res
int socket_descriptor
7/23/2019 How to Create TCP IP Packets Code in C Programming
http://slidepdf.com/reader/full/how-to-create-tcp-ip-packets-code-in-c-programming 2/6
The addrin&o str%cts wi"" store the ret%rn 8a"%e o& the getaddrin&o &%nction. The
socket_descriptor is the integer descriptor that the socket &%nction wi"" ret%rn.
;
Initia"i<e the 8aria,"es ,$ adding the &o""owing code:
memset=>hints 0 si<eo& hints?
hints.ai_&ami"$ @ *A_BPDC
hints.ai_sockt$pe @ #CE_TRD*F
The *A_BPDC 8a"%e speci&ies that the address &ami"$ &or the getaddrin&o &%nction can ,e
an$ 8a"id t$pe s%ch as IP84 or IP8. The #CE_TRD*F indicates a TCP stream socket.
Ca"" the getaddrin&o &%nction ,$ adding the &o""owing code:
getaddrin&o=www.ser8er.com 34G0 >hints >res?
Rep"ace www.ser8er.com with the ser8er $o% want to connect to. Rep"ace 34G0 with the port
$o% wi"" connect to. The getaddrin&o &%nction co""ects protoco"!independent in&ormation a,o%t
an address &rom its host name which it ret%rns in the addrin&o str%cts.
7
Create a TCP/IP socket with the socket &%nction ,$ adding the &o""owing code:
socket_descriptor @ socket=res!6ai_&ami"$ res!6ai_sockt$pe res!6ai_protoco"?
The socket &%nction %ses the in&ormation ret%rned &rom the getaddrin&o &%nction to create a
comp"ete socket.
Connect to the remote ser8er with the connect &%nction ,$ adding the &o""owing code:
connect=socket_descriptor res!6ai_addr res!6ai_addr"en?
The connect &%nction takes $o%r socket sends it to the speci&ied address and creates an acti8e
connection with the host.
G
7/23/2019 How to Create TCP IP Packets Code in C Programming
http://slidepdf.com/reader/full/how-to-create-tcp-ip-packets-code-in-c-programming 3/6
a8e the &i"e compi"e and eec%te $o%r program to create the TCP/IP packet.
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’’’’’’’’
How to change all incoming udp packets to tcp
packets on the same port using ip tables?
just for security reasons i have to write this rule using IP tables in my rule. u can
give me the answer using mangle tables or other tables.It is network administration
question. Thanks for the help and your time.
nswer!
"#P packets have a di$erent header than T%P packets. %hange the header& andbasically& you have changed the packet.
'ot only is this impractical.. but if you did succeed& then you need to arti(cially
create your syn)ack handshake.. "#P doesn*t care about handshakes+ but your
destination host needs to open a channel to receive T%P packets.
you need to create packet ack) answers..or at least a sink for them to be routed to..
"#P source doesn*t care if you got the packet.. it won*t retransmit anyhow.
If an instructor gave me this question& I*d want to clarify the reasons..
using only ip tables& I suppose I could just retransmit the packet.. but it makes no
sense.#oing this creates more latency, and
if a packet is dropped between your ip tables rule and the destination + then how
will you handle the retransmission request- The destination host is waiting +
possibly forever-
and
using IP tables ) mangle tables or any similar tool is not a complete solution.
I*d suspect this is a question designed to see if I know the protocols and perhaps
the tools/ that I am supposed to know... enough to know this is a silly proposition.
0ure& anything can be done if you try hard enough.. but this is like 1oating icebergsto the 0ahara. 2ith enough money& it could be done& but is really impractical.
7/23/2019 How to Create TCP IP Packets Code in C Programming
http://slidepdf.com/reader/full/how-to-create-tcp-ip-packets-code-in-c-programming 4/6
How to edit the network packet ?
how to edit the information in a packet which have information like tcp)ip packets
how to edit their informations -
2hat you are probably looking for is information on 3packet injection3 or 3packet
crafting3. There aren*t many legitimate reasons that someone would want to do this
so I can only guess you are interested for reasons of security or evil/.
4ou should know that this practice is highly complicated. 2hat you are suggesting is
that you want to change a packet that has all ready made it*s way onto a network in
route to it*s destination. 0o your goal is to get into the middle of that conversation.
That would mean that you would need to become that users gateway so that you
can intercept& recraft& and resend that information along on it*s way. This can be
done by using a tool such as *ettercap*.
If you are only trying to change your own packets& I suppose that this could be a
little easier. 5ut the way that you are asking this questions suggests that you might
need to study up on networking a bit more before you try something like this.
I would suggest downloading and installing wireshark. Take a look at house things
work and once you really understand matters& you can start looking into security
tools. 4ou might also want to try 3backtrack3& which is a bootable 6inu7 distribution
that comes pre+loaded with a lot of various security tools.
Source:
http!))en.wikipedia.org)wiki)Packet8inje...
http!))en.wikipedia.org)wiki)9aw8socket
http!))www.wireshark.org)
http!))www.backtrack+linu7.org)
7/23/2019 How to Create TCP IP Packets Code in C Programming
http://slidepdf.com/reader/full/how-to-create-tcp-ip-packets-code-in-c-programming 5/6
I*d like to know how one can send a T%P)IP or "#P packet& and then send it.
Preferably in %)%::& if it must be written in a programming language.
do you have a ;am radio set up-
if so you can do pakets with a T'%.
I hook up with the satalites once in a while with my <antronics packet producingtransmitter with the aid of a T'% on =;> and ";> freqs..
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’’’’’’’’’’’’’’’’’
How to construct and inject/send a new TCP
packet?
Hi I was wondering i& some,od$ co%"d he"p me with the process o& constr%cting &rom scratchm$ own IP84/TCP header and inecting it at the network send "a$er
I-8e ,een attempting the &o""owing method =tho%gh I %nderstand it ma$ ,e and in a"" "ike"ihood
I comp"ete"$ wrong?
1. *""ocate a data ,%&&er with ExAllocatePoolWithTag with eno%gh space &or a IP84 header
and a TCP header. =I don-t need to send a pa$"oad c%rrent"$? Femset this ,%&&er to 0.). *""ocate an F2 %sing NdisAllocateMdl %sing as parameters m$ dri8er hand"e the data
,%&&er and the si<e o& the data ,%&&er.
3. *""ocate a etJ%&&er and J2 %sing NdisAllocateNetBufferAndNetBufferList %sing as
parameters m$ dis Poo" Hand"e =which I acK%ired ear"ier? 0 &or the contet si<e and ,ack &i"" m$ F2 I %st a""ocated 0 &or the ata#&&set and the data ,%&&er si<e &or the
ata2ength.
4. Bse the NET_BUFFER_LIT_FIRT_NB macro and Ndis!et"ataBuffer &%nction to get a
pointer to the data ,%&&er =I think I co%"d ha8e %sed the o"d data ,%&&er pointer &or this ,%tI wanted to check that the contig%o%s space had ,een a""ocated to the str%ct%re proper"$
an$wa$? parameters %sed &or the &%nction was the etJ%&&er recei8ed &rom the macro
the data ,%&&er si<e B22 &or storage si<eo&=BIT? &or a"ignment m%"tip"e and 0 &or
a"ignment o&&set =not s%re a,o%t those "ast two parameters?.
;. Then I &i"" this ,%&&er with the data I wanted &or the IP84 and TCP header.
. Then I ca"" F#$sIn%ectNet#or&endAs'nc( %sing as parameters m$ inection hand"e
B22 &or inection contet 0 &or &"ags BPDCIAID_C#FP*RTFDT_I the
J2 m$ comp"etionAn and a data str%ct%re containing pointers so I can c"ean %pe8er$thing a&terwards.
#n the "ast step I get ,ack the TT*TB code T*TB_A+P_I'*2I_P*R*FDTDR I
7/23/2019 How to Create TCP IP Packets Code in C Programming
http://slidepdf.com/reader/full/how-to-create-tcp-ip-packets-code-in-c-programming 6/6
think there-s a "ot that co%"d ha8e gone wrong at an$ o& the steps =tho%gh the pre8io%s ones a""
seemed to s%cceed %dging ,$ the stat%s codes? so I was hoping that some,od$ here more
know"edga,"e than me might ,e a,"e to see where I-m going wrong or te"" me i& I-m %st doing
the wrong method entire"$ I ha8en-t &o%nd an$ eamp"es in the E &or doing this tho%gh I did
see some &or modi&$ing eisting packets. I ,asica""$ %st tried this process &rom reading thro%gh
the *PI and Loog"ing to tr$ to work o%t how it a"" appears to "ink together.
Thanks in ad8ance &or an$ he"pM
*nswer:
?ust to let you all know I think I*ve managed to (7 it now@
I changed my function call from NdisAllocateNetBuferAndNetBuferList to
FwpsAllocateNetBuferAndNetBuferList0 both of which take more or less the same
parameters/ and my constructed packet now seems to inject correctly& it shows in
2ireshark on both the source and destination computers. I think that was the only
change I made.
http!))jnetpcap.com)node)ABC
http!))search.yahoo.com)search-pDhow:to:make:a:tcp:packet