📄 413.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://apue.dhs.org"><font face="黑体"><big><big>apue</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center"> ● UNIX网络编程 (BM: clown) </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="100" align="center" valign="top"><br><p align="center">[<a href="index.htm">回到开始</a>][<a href="316.htm">上一层</a>][<a href="414.htm">下一篇</a>]
<hr><p align="left"><small>发信人: AngelFalls (Happiness Forever), 信区: Security <br>
标 题: SYN/FIN扫描器的问题 <br>
发信站: 武汉白云黄鹤站 (Thu Mar 23 11:03:11 2000), 站内信件 <br>
下面是我编的一个SYN/FIN扫描器的程序,但是 <br>
我用Sniffer察看它的包(包括IP与TCP包头)发现 <br>
它的各个部分与真正的TCP的SYN包都一样, <br>
可是就是收不到对方的RST信号(我没有在程序里面 <br>
RecvFrom,使用的是自己编的Sniffer察看的). <br>
请cloudsky等各位高手看一看,这个Linux下面的程序 <br>
有什么问题,多谢了。 <br>
#include <stdio.h> <br>
#include <sys/types.h> <br>
#include <sys/socket.h> <br>
#include <netinet/in.h> <br>
#include <netinet/ip.h> <br>
#include <netinet/ip_icmp.h> <br>
#include <netinet/tcp.h> <br>
#include <sys/time.h> <br>
#include <errno.h> <br>
#include <unistd.h> <br>
#include <signal.h> <br>
#include <string.h> <br>
#define SRCPORT 3000 <br>
#define HEADER_LEN 36 //24+12 <br>
struct t_tcphdr{ <br>
struct tcphdr thdr; <br>
u_int8_t opt_name; <br>
u_int8_t opt_len; <br>
u_int16_t opt; <br>
}; <br>
struct tothdr{ <br>
struct iphdr ihdr; <br>
struct tcphdr thdr; <br>
u_int8_t opt_name; <br>
u_int8_t opt_len; <br>
u_int16_t opt; <br>
}; <br>
u_int16_t in_chksum(u_short *addr, int len) <br>
{ <br>
u_int32_t sum = 0; <br>
u_int16_t *ad = addr, result; <br>
while(len > 1) <br>
{ <br>
sum += *ad++; <br>
len -= 2; <br>
} <br>
if(len == 1) <br>
{ <br>
result = 0; <br>
*((u_char *)&result) = *(u_char *)ad; <br>
sum += result; <br>
} <br>
sum = (sum >> 16) + (sum & 0xffff); <br>
sum += (sum >> 16); <br>
result = ~sum; <br>
return(result); <br>
} <br>
int main(int argc, char *argv[]) <br>
{ <br>
struct sockaddr_in sa_to, sa_fr; <br>
struct tothdr t_hdr; <br>
int syn = 0, sock_raw, i; <br>
u_char pseudoHead[HEADER_LEN]; <br>
u_int16_t tcp_len; <br>
const int on = 1; <br>
if( argc != 3) <br>
{ <br>
{ <br>
printf("Usage : %s [-s, -f] remoteIP\n", argv[0]); <br>
exit(-1); <br>
} <br>
if( strcmp(argv[1], "-s") && strcmp(argv[1], "-f") ) <br>
{ <br>
printf("Usage : %s [-s, -f] remoteIP\n", argv[0]); <br>
exit(-1); <br>
} <br>
else if(!strcmp( argv[1], "-s" )) <br>
syn = 1; //syn = 0 means FIN scannning <br>
bzero(&sa_to, sizeof(sa_to)); <br>
sa_to.sin_family = AF_INET; <br>
if( inet_aton(argv[2], &sa_to.sin_addr) < 0 ) <br>
{ <br>
perror("Inet_aton"); <br>
exit(-1); <br>
} <br>
if( ( sock_raw = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) < 0 ) <br>
{ <br>
perror("Socket Raw"); <br>
exit(-1); <br>
} <br>
} <br>
if( setsockopt(sock_raw, IPPROTO_IP, IP_HDRINCL, &on, sizeof(int)) < <br>
<br>
0 ) <br>
{ <br>
perror("SetSockOpt IPPROTO_IP"); <br>
exit(-1); <br>
} <br>
setuid(getuid()); <br>
for(i=1; i< 1024; i++) <br>
{ <br>
if( i != 23 ) <br>
continue; <br>
bzero(&t_hdr, sizeof(t_hdr)); <br>
t_hdr.ihdr.ihl = 5; <br>
t_hdr.ihdr.version = 4; <br>
t_hdr.ihdr.tos = 0; <br>
t_hdr.ihdr.tot_len = htons(40); <br>
t_hdr.ihdr.id = 0; <br>
t_hdr.ihdr.frag_off = htons(IP_DF); <br>
t_hdr.ihdr.ttl = 64; <br>
t_hdr.ihdr.protocol = IPPROTO_TCP; <br>
t_hdr.ihdr.check = 0; <br>
t_hdr.ihdr.daddr = sa_to.sin_addr.s_addr; <br>
t_hdr.ihdr.saddr = htonl(INADDR_ANY); <br>
t_hdr.thdr.source = htons(SRCPORT); <br>
t_hdr.thdr.dest = htons(i); <br>
t_hdr.thdr.seq = htonl(getpid() | 0x40000000); <br>
t_hdr.thdr.ack_seq = 0; <br>
t_hdr.thdr.doff = 5 + syn; <br>
t_hdr.thdr.fin = 1-syn; <br>
t_hdr.thdr.syn = syn; <br>
t_hdr.thdr.rst = 0; <br>
t_hdr.thdr.psh = 0; <br>
t_hdr.thdr.ack = 1-syn; <br>
t_hdr.thdr.urg = 0; <br>
t_hdr.thdr.window = htons(8192); <br>
t_hdr.thdr.check = 0; <br>
t_hdr.thdr.urg_ptr = 0; <br>
if( !syn ) <br>
{ <br>
bzero(pseudoHead, HEADER_LEN); <br>
memcpy(pseudoHead, &(t_hdr.ihdr.saddr), 8); <br>
pseudoHead[9] = IPPROTO_TCP; <br>
tcp_len = htons( sizeof(struct tcphdr) ); <br>
memcpy(&pseudoHead[10], &tcp_len, 2); <br>
memcpy(&pseudoHead[12], &(t_hdr.thdr), sizeof(struct <br>
tcp <br>
hdr)); <br>
t_hdr.thdr.check = in_chksum((u_short *)pseudoHead, <br>
HEAD <br>
ER_LEN - 4); <br>
if( sendto(sock_raw, &t_hdr, sizeof(struct tcphdr) + <br>
siz <br>
eof(struct <br>
iphdr), 0, &sa_to, sizeof(sa_to)) < 0 ) <br>
perror("Sendto"); <br>
} <br>
else <br>
{ <br>
t_hdr.opt_name = 2; <br>
t_hdr.opt_len = 4; <br>
t_hdr.opt = htons(1460); <br>
bzero(pseudoHead, HEADER_LEN); <br>
memcpy(pseudoHead, &(t_hdr.ihdr.saddr), 8); <br>
pseudoHead[9] = IPPROTO_TCP; <br>
tcp_len = htons( sizeof(struct tcphdr) + 4); <br>
memcpy(&pseudoHead[10], &tcp_len, 2); <br>
memcpy(&pseudoHead[12], &(t_hdr.thdr), sizeof(struct <br>
tcp <br>
hdr) + 4); <br>
t_hdr.thdr.check = in_chksum((u_short *)pseudoHead, <br>
HEAD <br>
ER_LEN); <br>
if( sendto(sock_raw, &t_hdr, sizeof(t_hdr), 0, &sa_t <br>
o, s <br>
izeof(sa_to)) <br>
< 0 ) <br>
perror("Sendto"); <br>
} <br>
usleep(25); <br>
} <br>
return 0; <br>
} <br>
-- <br>
Wish your sky be sunny, <br>
Wish your heart be happy, <br>
Wish your body be healthy, <br>
Wish U never be lazy. <br>
:) :> ;) ;> :-) :-> ;-) ;-> <br>
</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="316.htm">上一层</a>][<a href="414.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -