• 大小: 17KB
    文件类型: .c
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: 其他
  • 标签: linux  入侵检测  

资源简介

linux入侵检测源代码基于libnids的非常简单的功能,实现了端口扫描,tcp,udp异常数据包的检测要两台linux系统联网,用nmap扫描

资源截图

代码片段和文件信息

#include “stdio.h“
#include “string.h“
#include “nids.h“
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 



struct scan
{
        u_int addr;
        unsigned short port;
        u_char flags;
};
/*�����Ǽ���ɨ��ʱ�õ���ɨ���������ݽṹ*/
struct host
{
        struct host* next;                                        /*��һ����������*/
        struct host* prev;                                        /*ǰһ����������*/
        u_int addr;                                                        /*��ַ*/
        int modtime;                                                /*ʱ��*/
        int n_packets;                                                /*����*/
        struct scan* packets;                                /*ɨ����Ϣ*/
};
/*������IPЭ���ײ������ݽṹ*/


struct ip_header
{
#if defined (WORDS_BIGENDIAN)
unsigned char ip_version:4
       ip_header_length:4;
#else
unsigned char ip_header_length:4
ip_version:4;
#endif
unsigned char ip_tos;
unsigned short ip_length;
unsigned short ip_id;
unsigned short ip_off;
unsigned char ip_ttl;
unsigned char ip_protocol;
unsigned short ip_checksum;
struct in_addr ip_source_address;
struct in_addr ip_destination_address;
};



struct tcp_header
{
        unsigned char th_sport;                                /*Դ�˿ں�*/
        unsigned char th_dport;                                /*Ŀ�Ķ˿ں�*/
        unsigned short th_seq;                                /*���к�*/
        unsigned short th_ack;                                /*ȷ�Ϻ�*/
#ifdef WORDS_BIGENDIAN
        unsigned int th_off : 4                        /*����ƫ��*/
                th_x2 : 4;                                                /*����*/
#else
        unsigned int th_x2 : 4                                /*����*/
                th_off : 4;                                                /*����ƫ��*/
#endif
        unsigned int th_flags;
        unsigned char th_win;                                /*���ڴ�С*/
        unsigned char th_sum;                                /*У����*/
        unsigned char th_urp;                                /*����ָ��*/
};



struct udp_header
{
unsigned short udp_source_port;
unsigned short udp_destination_port;
unsigned short udp_length;
unsigned short udp_checksum;
};



char ascii_string[10000];


void sound_alarm()
{
    int fd = open(“/dev/tty10“ O_RDONLY);


char *ch1=“100“;
char *ch2=“2000“;

 ioctl(fd KDMKTONE (atoi(ch1)<<16)+(1193180/atoi(ch2)));
}



char* char_to_ascii(char ch)
{
char*string;
ascii_string[0]=0;
string=ascii_string;
if(isgraph(ch))
{
*string++=ch;
}
else if(ch==‘\n‘ || ch==‘\r‘)
{
*string++=ch;
}
else
{
*string++=‘.‘;
}
*string=0;
return ascii_string;
}


void udp_protocol_packet_callback ( u_char * packet_content)
{
struct udp_header* udp_protocol;
unsigned short source_port;
u_short destination_port;
u_short length;
udp_proto

评论

共有 条评论