Have you thought about how to ban others from accessing Web Server, POP3, FTP, etc. in the LAN. So how do you forbidden? Everyone knows that TCP is connected, three handshakes, after which it can be confirmed. Then we should be able to fake a servant's handshake after the first time, so that the TCP connection is unsuccessful and cannot be accessed. The procedure is as follows:
Void Decodeip (BUF, IBUFSIZE) / / Analyzes the IP Packets IP
{
Ipheader * piphdr;
TCPHEADER * PTCPHDR;
Piphdr = (ipheader *) buf;
// Get the starting position of TCP Header
INT iiphlen = SizeOf (piphdr-> h_lenver & 0xf);
PTCPHDR = (TCPHEADER *) (BUF iiphlen);
/ / Judgment is the first handshake IP packet, piphdr-> th_flag = 2 ("-s ----")
IF (ibufsize == 48) && (piphdr-> iprotocol == ipproto_tcp) && (piphdr-> th_flag == 2)
Sendtcp_synack (szdestip, szsourceip, ptcphdr-> destport, ptcphdr-> Srcport, PTCPHDR-> SEQ);
}
Void sendtcp_synack (char * szsrcip, char * szdestip, unsigned short srcport, unsigned short destport, unsigned int ic)
{
Int IrrorCode;
Socket S;
IP_HEADER IP_HEADER;
TCP_HEADER TCP_HEADER;
PSD_Header PSD_Header;
Struct SockAddr_in Remote;
Char * ptr = NULL;
// Create a Socket
s = socket (AF_INET, SOCK_RAW, IPPROTO_IP);
IF (Checksockerror (S, "Socket-TCP")))
Return False;
Bool BOPT = TRUE;
Irrorcode = setsockopt (s, ipproto_ip, ip_hdrincl, (char *) & bopt, sizeof (bopt));
IF (CHECKSockerror (IrrorCode, "SetsockOpt-TCP"))
{
CloseSocket (s);
Return False;
}
// --- End-
// Camouflage connection
UNSIGNED Short itotalsize = 44;
Unsigned short itcpsize = 24;
Char * sendbuf = new char [itotalsize];
IP_HEADER.H_LENVER = (4 << 4 | sizeof (ip_header) / sizeof (unsigned long);
// High four version number, low four head length
IP_HEADER.TOTAL_LEN = HTONS (ITOTALSIZE); // 16-bit total length
IP_HEADER.TOS = 0;
IP_HEADER.IDENT = HTONS (17393); // 16 ?? ± ±ê?
IP_HEADER.FRAG_AND_FLAGS = 0; //3?? ±????????offsetip_header.ttl=57; // 8 ?? éú '? ê ± ?? TTL
IP_HEADER.PROTO = ipproto_tcp; // 8 ?? d-òé (TCP, UDP? -)
IP_HEADER.CHECKSUM = 0; // 16-bit checksum
ip_header.sourceip = inet_addr (szsrcip); // 32 remote address ·
IP_HEADER.Destip = INET_ADDR (SZDestip); // 32 bit destination address ·
IP_HEADER.CHECKSUM = Checksum ((Ushort *) & ip_header, 20);
// Pack TCP header
TCP_HEADER.TH_SPORT = HTONS (srcport); // Source Port
TCP_HEADER.TH_DPORT = HTONS (DESTPORT); // destination port
TCP_HEADER.TH_SEQ = HTONL (0x581A784D); // SYN serial number
TCP_HEADER.TH_ACK = HTONL (IACK 1); // Answer Sequence Number
TCP_HEADER.TH_LENRES = (ITCPSIZE / SIZEOF (unsigned long) << 4 | 0); // TCP length and reserved bit
TCP_HEADER.TH_FLAG = 0x12; // SYN flag
TCP_HEADER.TH_WIN = HTONS (65535); // Window size
TCP_HEADER.TH_URP = 0; // Emergency pointer
TCP_HEADER.TH_SUM = 0; // Check and
// Fill the TCP pseudo header (only for generating checks)
PSD_Header.saddr = IP_HEADER.SOURCEIP;
PSD_Header.daddr = IP_Header.destip;
PSD_Header.mbz = 0;
PSD_Header.ptCl = ipproto_tcp;
PSD_Header.tcpl = htons (itcpsize);
ZeromeMory (Sendbuf, ITOTALSIZE);
/ / Calculate TCP checksum, including pseudo TCP Header
Memcpy (sendbuf, & psd_header, sizeof (psd_header));
PTR = Sendbuf SizeOf (PSD_HEADER);
Memcpy (PTR, & TCP_HEADER, SIZEOF (TCP_HEADER));
Ptr = sendbuf sizeof (psd_header) sizeof (tcp_header);
* PTR = (char) 0x02; * (PTR 1) = (char) 0x04; * (PTR 2) = (char) 0x05; * (PTR 3) = (char) 0xB4;
TCP_HEADER.TH_SUM = Checksum ((USHORT *) Sendbuf, Sizeof (PSD_Header) 24);
ZeromeMory (Sendbuf, ITOTALSIZE);
// Fill the send buffer
Memcpy (sendbuf, & ip_header, sizeof (ip_header));
Ptr = sendbuf sizeof (ip_header);
Memcpy (PTR, & TCP_HEADER, SIZEOF (TCP_HEADER));
Ptr = sendbuf sizeof (ip_header) sizeof (tcp_header);
* PTR = (char) 0x02; * (PTR 1) = (char) 0x04; * (PTR 2) = (char) 0x05; * (PTR 3) = (char) 0xB4; remote.sin_family = AF_INET;
Remote.sin_port = htons (destport);
Remote.sin_addr.s_addr = inet_addr (szdestip);
Irrorcode = Sendto (S, Sendbuf, ITOTALSIZE, 0, (SockAddr *) & Remote, SizeOf (remote));
Checksockerror (Irrorcode, "SYNACK Sendto");
// Spost closure connection
iTotalsize = 40;
ITCPSIZE = 20;
// end --------
CloseSocket (s);
delete [] sendbuf;
Return True;
}