• PUDN用户
    了解作者
  • C/C++
    开发工具
  • 17KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2020-06-22 10:22
    上传日期
综合端口扫描器,共包含12个文件。其中Scaner.h实现了ping函数以及一些共用函数的编写。Scaner.cpp文件包含了main函数,根据不同的命令调用不同的端口扫描模块。DataStructure.h定义了各扫描线程的参数以及IP数据报头的格式。TCPConnectScan.h与TCPConnectScan.cpp文件实现了TCP Connect扫描。TCPFINScan.h与TCPFINScan.cpp文件实现了TCP FIN扫描。TCPSYNScan.h与TCPSYNScan.cpp文件实现了TCP SYN扫描。UDPScan.h与UDPScan.cpp文件实现了UDP扫描。 编译:命令行模式下,切换到代码所在目录,输入make后回车即可。
8.zip
  • 8
  • Scaner.h
    4.9KB
  • Scaner.cpp
    5.1KB
  • TCPSYNScan.cpp
    6KB
  • TCPConnectScan.h
    434B
  • TCPFINScan.cpp
    7.2KB
  • TCPConnectScan.cpp
    3.5KB
  • DataStructure.h
    1.3KB
  • TCPSYNScan.h
    647B
  • makefile
    521B
  • UDPScan.h
    539B
  • UDPScan.cpp
    5.6KB
  • TCPFINScan.h
    645B
内容介绍
#include "TCPFINScan.h" //============================================================================== void* Thread_TCPFINHost(void* param) { struct TCPFINHostThrParam *p; string HostIP,SrcIP,DstIP,LocalIP; unsigned HostPort,LocalPort,SrcPort,DstPort,LocalHostIP; struct sockaddr_in FINScanHostAddr,FromAddr,FinRevAddr; struct in_addr in_LocalhostIP; int FinSock,FinRevSock; int len,FromAddrLen; char sendbuf[8192]; char recvbuf[8192]; struct timeval TpStart,TpEnd; //for time of receive tcp fin response float TimeUse; //------------------Get IP and Port------------------------------------------------- p=(struct TCPFINHostThrParam*)param; HostIP = p->HostIP; HostPort = p->HostPort; LocalPort = p->LocalPort; LocalHostIP = p->LocalHostIP; //-------------set TCP FIN Scan Host address---------------------------------------- memset(&FINScanHostAddr,0,sizeof(FINScanHostAddr)); FINScanHostAddr.sin_family = AF_INET; FINScanHostAddr.sin_addr.s_addr = inet_addr(&HostIP[0]); FINScanHostAddr.sin_port = htons(HostPort); //-------------------creat socket---------------------------------------------------- FinSock=socket(PF_INET, SOCK_RAW, IPPROTO_TCP); if ( FinSock<0 ) { pthread_mutex_lock(&TCPFinPrintlocker); cout<<"Can't creat raw socket !"<<endl; pthread_mutex_unlock(&TCPFinPrintlocker); } //-------------------Create FinRevSock----------------------------------------------- FinRevSock=socket(PF_INET, SOCK_RAW, IPPROTO_TCP); if ( FinRevSock<0 ) { pthread_mutex_lock(&TCPFinPrintlocker); cout<<"Can't creat raw socket !"<<endl; pthread_mutex_unlock(&TCPFinPrintlocker); } //--------------------fill tcp packet------------------------------------------------ struct pseudohdr *ptcph=(struct pseudohdr*)sendbuf; struct tcphdr *tcph=(struct tcphdr*)(sendbuf+sizeof(struct pseudohdr)); ptcph->saddr = LocalHostIP; ptcph->daddr = inet_addr(&HostIP[0]); ptcph->useless = 0; ptcph->protocol = IPPROTO_TCP; ptcph->length = htons(sizeof(struct tcphdr)); tcph->th_sport=htons(LocalPort); tcph->th_dport=htons(HostPort); tcph->th_seq=htonl(123456); tcph->th_ack=0; tcph->th_x2=0; tcph->th_off=5; tcph->th_flags=TH_FIN; tcph->th_win=htons(65535); tcph->th_sum=0; tcph->th_urp=0; tcph->th_sum=in_cksum((unsigned short*)ptcph, 20+12); //--------------------send tcp fin packet--------------------------------------------- len=sendto(FinSock, tcph, 20, 0, (struct sockaddr *)&FINScanHostAddr, sizeof(FINScanHostAddr)); if( len < 0) { pthread_mutex_lock(&TCPFinPrintlocker); cout<<"Send TCP FIN Packet error !"<<endl; pthread_mutex_unlock(&TCPFinPrintlocker); } //---------------set socket in non-blocked model--------------------------------------- if(fcntl(FinRevSock, F_SETFL, O_NONBLOCK) == -1) { pthread_mutex_lock(&TCPFinPrintlocker); cout<<"Set socket in non-blocked model fail !"<<endl; pthread_mutex_unlock(&TCPFinPrintlocker); } FromAddrLen = sizeof(struct sockaddr_in); //--------------------receive circle---------------------------------------------------- gettimeofday(&TpStart,NULL); //get start time do { len = recvfrom(FinRevSock,recvbuf,sizeof(recvbuf),0,(struct sockaddr*)&FromAddr,(socklen_t*)&FromAddrLen); if(len > 0) { SrcIP = inet_ntoa(FromAddr.sin_addr); if(SrcIP == HostIP) { struct ip *iph=(struct ip *)recvbuf; int i=iph->ip_hl*4; struct tcphdr *tcph=(struct tcphdr *)&recvbuf[i]; SrcIP = inet_ntoa(iph->ip_src); //source IP in TCP response packet DstIP = inet_ntoa(iph->ip_dst); //destination IP in TCP response packet in_LocalhostIP.s_addr = LocalHostIP; LocalIP = inet_ntoa(in_LocalhostIP); //LocalhostIP unsigned SrcPort = ntohs(tcph->th_sport); //source port in TCP response packet unsigned DstPort = ntohs(tcph->th_dport); //destination port in TCP response packet if(HostIP == SrcIP && LocalIP == DstIP && SrcPort == HostPort && DstPort == LocalPort) { if (tcph->th_flags == 0x14) { pthread_mutex_lock(&TCPFinPrintlocker); cout<<"Host: "<<SrcIP<<" Port: "<<ntohs(tcph->th_sport)<<" closed !"<<endl; pthread_mutex_unlock(&TCPFinPrintlocker); } } break; } } //--------------------------------------------------------------------------- gettimeofday(&TpEnd,NULL); TimeUse=(1000000*(TpEnd.tv_sec-TpStart.tv_sec)+(TpEnd.tv_usec-TpStart.tv_usec))/1000000.0; if(TimeUse<5) { continue; } else { pthread_mutex_lock(&TCPFinPrintlocker); cout<<"Host: "<<HostIP<<" Port: "<<HostPort<<" open !"<<endl; pthread_mutex_unlock(&TCPFinPrintlocker); break; } } while(true); //--------------------exit subthread--------------------------------------------- delete p; close(FinSock); close(FinRevSock); pthread_mutex_lock(&TCPFinScanlocker); TCPFinThrdNum--; pthread_mutex_unlock(&TCPFinScanlocker); } //============================================================================== void* Thread_TCPFinScan(void* param) { struct TCPFINThrParam *p; string HostIP; unsigned BeginPort,EndPort,TempPort,LocalPort,LocalHostIP; pthread_t listenThreadID,subThreadID; pthread_attr_t attr,lattr; int ret; //------------------Get IP and Port------------------------------------------------- p=(struct TCPFINThrParam*)param; HostIP = p->HostIP; BeginPort = p->BeginPort; EndPort = p->EndPort; LocalHostIP = p->LocalHostIP; //----------------TCP Fin circle from BeginPort to EndPort-------------------------- TCPFinThrdNum = 0; LocalPort = 1024; for (TempPort=BeginPort;TempPort<=EndPort;TempPort++) { //--------------Create sub thread------------------------------------- //--------------set thread param-------------------------------------- struct TCPFINHostThrParam *pTCPFINHostParam = new TCPFINHostThrParam; pTCPFINHostParam->HostIP = HostIP; pTCPFINHostParam->HostPort = TempPort; pTCPFINHostParam->LocalPort = TempPort + LocalPort; pTCPFINHostParam->LocalHostIP = LocalHostIP; //-------------set thread as detach state----------------------------- pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); //-------------Create TCP SYN thread----------------------------------- ret=pthread_create(&subThreadID,&attr,Thread_TCPFINHost,pTCPFINHostParam); if (ret==-1) { cout<<"Can't create the TCP FIN Scan Host thread !"<<endl; } //-------------destroy attribute--------------------------------------- pthread_attr_destroy(&attr); //-------------compute thread number---------------------------------- pthread_mutex_lock(&TCPFinScanlocker); TCPFinThrdNum++; pthread_mutex_unlock(&TCPFinScanlocker); while (TCPFinThrdNum>100) { sleep(3); } } //-----------------waiting for exit----------------------------------------- while (TCPFinThrdNum != 0) { sleep(1); } cout<<"TCP FIN scan thread exit !"<<endl; pthread_exit(NULL); }
评论
    相关推荐
    • Nmap端口扫描
      Nmap是一款网络扫描和主机检测的非常有用的工具。Nmap是不局限于仅仅收集信息和枚举,同时可以用来作为一个漏洞探测器或安全扫描器。它可以适用于winodws,linux,mac等操作系统
    • 端口扫描器程序
      端口扫描器程序,实现了: TCP Connect扫描 TCP SYN扫描 TCP FIN扫描 TCP ACK扫描 TCP NULL扫描 TCP XMAS扫描 UDP扫描
    • windows开放端口扫描器
      扫描器实现了:TCP Connect 扫描,TCP SYN扫描,TCP Fin扫描,TCP ACK扫描及UDP端口扫描,这些扫描能够实现扫描特定IP地址范围内端口和扫描某IP地址范围内全部主机特定端口两种模式,并且SYN扫描能够区分端口开放、...
    • 网络主机端口扫描(Connect和FIN)和报告
      一些防火墙和包过滤会对一些指定的端口进行监视,有的程序能检测到这些扫描。相反,FIN数据包可能会没有任何麻烦的通过。这种扫描方法的思想是关闭的端口会用适当的RST来回复FIN数据包。另一方面,打开的端口会...
    • nmap网络的端口扫描工具
      其次是扫描 主机端口,嗅探所提供的网络服务;还可以推断主机所用的操作系统 。Nmap可用于扫描仅有两个节点的LAN,直至500个节点以上的网络。Nmap 还允许用户定制扫描技巧。通常,一个简单的使用ICMP协议的ping操 作...
    • PortScanner:C#实现多线程端口扫描器V1.0
      ##PortScanner项目(C#实现多线程端口扫描器)说明 ###1. 概述 文件结构 ####1.1 课程设计目的 加深TCP/IP协议的理解,掌握TCP四次握手机制,同时熟悉socket编程。 ####1.2 课程设计内容 实现一个端口扫描器: 支持多...
    • Port-Scanner:用 C 语言实现的端口扫描器。支持多线程
      端口扫描器 项目介绍 本项目是端口扫描器的基本实现,帮助网络管理员确保网络中的机器正常运行。 基本上,这个端口扫描器可以扫描用户提供的IP地址的所有端口。 通过向远程主机的端口发送适当的数据包,它可以解析...
    • 端口扫描程序源码
      该源码为《计算机网络高级软件编程技术》第17章的源码,用TCP,UDP,ACK,FIN,ARP,ICMP等几种方法实现了IP扫描、端口扫描
    • 网络端口扫描器与攻击程序 源码
      网络端口扫描与攻击程序,采用VS2005 C#开发。 实现了TCP CONNECT、TCP SYN、TCP FIN三种扫描方式,实现了SYN FLOOD、PING FLOOD两种攻击方式。 降分~
    • 实验六 端口扫描攻击检测.rar
      基于Snort入侵检测工具实现端口扫描检测试验