27.06.2013 Views

Untitled

Untitled

Untitled

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

my Step_fin_bit = 0; # FIN FLAG BIT<br />

# here we put together 2 reserved fields and the 6 flags to pack as binary.<br />

my Stcp_codebi. ts '" Szero . hero . StcP_ur9_bi. t . Stcp_ocLbi t . Stcp_psh_bi t<br />

Stcp_,·sLbi.t . Stcp_syn_bit . Step_fin_bit;<br />

my Stcp_windowsize "" 124; I/. default window size<br />

my Stcp_urgent_pointer z 0; # urgent poi.nter<br />

# the followi.ng i.s not a tcp header per se. but a pseudo header<br />

# used to calculate the tcp checksum. yes, its a pain in the ass.<br />

my (Spseudo_tcp) = pack Co4 04 ( (<br />

n n n<br />

N N<br />

H2 B8<br />

n v n'.<br />

Ssrc_host. Sdest_host, $zero, Sproto_ tcP.<br />

Stcplength. Ssrc_port, Sdest_port.<br />

Ssyn, Sack,<br />

Shdr _"_reserved, Stcp_codebi. ts.<br />

Stcp_windowsize, Szero. Stcp_urgent_pointer) j<br />

my (Stcp_chksum) = &checkfro(Spseudo_tcp);<br />

# PLAY WITH THE INNARDS OF THE IP PIECE HERE! !!<br />

my Sip_version ::: "4" i # (nybble) tcp/ip version number (current is 4)<br />

my Sip_hedlen = "5"; # (nybble) number of 32-bit words i.n ip header<br />

my $ver _"_hlen ::: Sip_versi.on . Sip_hedlen; # we pack 2 nybbles together<br />

my $i.p_tos = "00"; # (byte) ip type-of-servi.ce<br />

my (Stotlength) = $teplength + 20; #tep + 20 byte ip hdr ##<br />

## we'll pack totlength i.nto 2 bytes i.n the packet<br />

my Si.p_fragment_id ::: 31337; # 2 bytes as well.<br />

my Sip_3blt_flags = "010"; # ip fragmentation flags (3 bi.ts) (frag, do not frag)<br />

my $ip_13bi. t_fragoffset = "0000000000000"; #fragment offset<br />

my Sip_flags_n_frags ::: Sip_3bit_flags . Si.p_13biCfragoffsetj<br />

my $ip_ tt 1 = 64 j # 64 seconds / hops<br />

# we have proto_tcp from above.. my $proto_tcp = 6;<br />

# we have hdr _checksum from above ...<br />

# all source and destination infoz i.s passed to us (i. t<br />

# gets set in parent routine)<br />

# change Ssyn and Sack above in tcp section<br />

# in fact, everything else i.n the packet is set above.<br />

my (Shdr) = paek ('HZ H2 n n<br />

B16 C2<br />

n a4 a4<br />

n n<br />

N N<br />

H2 B8<br />

n v n' ,<br />

$over _"_hlen, Sip_tos, $totlength, Sip_fragment_i.d,<br />

Si.p_ flags_n_frags, $i.p_ ttl, $oproto_ tcp,<br />

Shdr _cksum, $srchost, Sdest_host,<br />

# end of i.p header, begi.n tcp header<br />

$src_port, Sdest_port,<br />

Ssyn, Sack,<br />

Shdr _n_reserved,Step_eodebi ts,<br />

Step_wi.ndows ize, $tcp_chksum, Stcp_urgent_pointer) i<br />

return Shdr;<br />

sub checkfro {<br />

#dis sekzhun robbed from someplace else ... .<br />

my (<br />

Smsg # The message to checkfro<br />

) = @-;<br />

my CSlen_msg I<br />

# length of the message<br />

Snum_short, # The number of short words in the message<br />

Sshort, # One short word<br />

$chk # The checkfro<br />

) ;<br />

Slen_msg = length($msg);<br />

Snum_short ::: S 1 en_ms9 I 2;<br />

Sehk = 0;<br />

foreach $short (unpack("SSnum_short", Smsg))<br />

{<br />

}<br />

Schk += $short;<br />

# Add some 1 ead<br />

Schk += unpackC"C", substrC$ms9, Slen_msg 1, 1)) if Slen_msg % 2;<br />

Schk = (Sehk » 16) + (Sehk & 0xffff); # bust out mah fro pie<br />

return(-(($ehk » 16) + Sehk) & 0xffff); # spray some jheri<br />

Fall 1998 2600 Magazine Page 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!