icmp篇 突破TCP-IP过滤/防火墙进入内网( 三 )


QQicmp之源代码如下:#include
#include
#include
#include #pragma comment (lib,"ws2_32")
#define maxsize 64*1024typedef struct ipheader
{
unsigned char h_lenver;
unsigned char tos;
unsigned short total_len;
unsigned short ident;
unsigned short frag_and_flags;
unsigned char ttl;
unsigned char proto;
unsigned short checksum;
unsigned int sourceip;
unsigned int destip;
}ipheader;typedef struct icmpheader
{
unsigned char type;
unsigned char code;
unsigned short checksum;
unsigned short seq;
unsigned short id;
}icmpheader;unsigned short checksum(unsigned short *buffer,int size)
{
unsigned long cksum=0;
while(size>0)
{
cksum =*buffer;
size-=sizeof(unsigned short);
}
if(size)
cksum =*(unsigned char *)buffer;
cksum=(cksum>>16) (cksum & 0xffff);
cksum =(cksum>>16);
return (unsigned short)(~cksum);
}void start()
{
cout<<" ---------------------------------------------------n";
cout<<" || || n";
cout<<" || QQicmp (ICMP转发) || n";
cout<<" || || n";
cout<<" || Author:TOo2y SafeChina || n";
cout<<" || || n";
cout<<" ---------------------------------------------------"<}void usage()
{
cout<<"nUsage:rntQQicmp -l[-g] ip port"<cout<<"tQQicmp -h"<cout<<"Example:rn";
cout<<"tQQicmp -l 192.168.0.1 8000"<cout<<"tQQicmp -g 61.144.238.156 11282"<cout<<"Attention:"<cout<<"t选项 -l : 运行于本机上 , ip填网关地址 , port为本地监听客户端端口;"<cout<<"t选项 -g : 运行于网关上 , ip填腾讯服务器地址 , port为自定义端口;"<cout<<"t选项 -h : 查看相关帮助文件 。"<}int addrlen=sizeof(struct sockaddr_in);
SOCKET sock[2][2];
struct sockaddr_in sin[2][4],sag,sal,tempr,temps;DWORD WINAPI u2i(LPVOID num)
{
UNREFERENCED_PARAMETER(num);
char msgrecv[maxsize]={0},msgsend[maxsize]={0};
fd_set fdread,fdwrite;
int iret,ret,istbcs=0;
struct icmpheader icmphdr;memset(&icmphdr,0,sizeof(icmphdr));
icmphdr.code=0;
icmphdr.id=htons(65456);
icmphdr.seq=htons(65456);
icmphdr.type=0;
icmphdr.checksum=checksum((unsigned short *)&icmphdr,sizeof(icmphdr));if((sock[0][1]=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP))==INVALID_SOCKET)
{
cout<<"Socket sock[0][1] Error: "<return -1;
}
if(bind(sock[0][1],(struct sockaddr *)&sin[0][2],addrlen)==SOCKET_ERROR)
{
cout<<"Bind sock[0][1] Error: "<return -1;
}while(1)
{
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_SET(sock[0][0],&fdread);
FD_SET(sock[0][1],&fdwrite);if((ret=select(0,&fdread,&fdwrite,NULL,NULL))==SOCKET_ERROR)
{
cout<<"Select in thread 0 Error: "<break;
}
if(ret>0)
{
if(FD_ISSET(sock[0][0],&fdread))
{
iret=recvfrom(sock[0][0],msgrecv,sizeof(msgrecv),0,(struct sockaddr *)&tempr,&addrlen);
if(iret==SOCKET_ERROR)
{
cout<<"nRecvfrom sock[0][0] Error: "<break;
}
else if(iret==0)
{
cout<<"Iret==0"<break;
}
cout<<"nThread 0 Recv "<if(istbcs==0)
{
memset(msgsend,0,sizeof(msgsend));
memcpy(msgsend,&icmphdr,sizeof(icmphdr));
istbcs =sizeof(icmphdr);
}
memcpy(msgsend istbcs,msgrecv,iret);
istbcs =iret;
memset(msgrecv,0,sizeof(msgrecv));
}
else if(FD_ISSET(sock[0][1],&fdwrite))
{while(istbcs>0)
{if(sin[0][3].sin_addr.s_addr==htonl(0))
{
cout<<"sin[0][3].sin_addr.s_addr==htonl(0)"<istbcs=0;
memset(msgsend,0,sizeof(msgsend));
break;
}iret=sendto(sock[0][1],msgsend,istbcs,0,(struct sockaddr *)&sin[0][3],addrlen);
if(iret==SOCKET_ERROR)
{
cout<<"Sendto sock[0][1] Error: "<break;
}
cout<<"Thread 0 send "

推荐阅读