github.com/zartbot/goflow@v0.0.0-20221001080520-456f7dfad288/iedb/ciscoAVC.go (about)

     1  package iedb
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/binary"
     6  )
     7  
     8  // RFC 6313 BasicList
     9  
    10  // CiscoAppVarStringElement : Handle Cisco App
    11  //       This type is used to handle IE: 9:12235
    12  //		 based on different config,this IE could be observed
    13  //		 multiple times in single record:
    14  //
    15  //		 Multiple collect type share this IE with different SubAppID
    16  //
    17  //		 http: url,useragent,refer
    18  //		 dns:  domain name
    19  //		 ssl:  common name
    20  type CiscoAppVarStringKey struct {
    21  	AppID     uint32
    22  	SubAppTag uint32
    23  }
    24  
    25  // ParseCiscoAppVarString : Parse 9:12235 Field, return structure
    26  func ParseCiscoAppVarString(b []byte) map[CiscoAppVarStringKey]string {
    27  	result := make(map[CiscoAppVarStringKey]string)
    28  	var k CiscoAppVarStringKey
    29  	k.AppID = binary.BigEndian.Uint32(b[0:4])
    30  	k.SubAppTag = uint32(binary.BigEndian.Uint16(b[4:6]))
    31  	result[k] = string(bytes.TrimRight(b[6:], "\x00"))
    32  	return result
    33  }
    34  
    35  // CiscoURLHitElement :  URL Hit Field
    36  //This field use '/0' as delimeter
    37  type CiscoURLHitItem struct {
    38  	Name   string
    39  	Number uint16
    40  }
    41  
    42  func ParseCiscoURLHitString(b []byte) []CiscoURLHitItem {
    43  	var result []CiscoURLHitItem
    44  	t := bytes.Split(b, make([]byte, 1, 1))
    45  	//fmt.Println("DEBUG:---->", len(t))
    46  	//fmt.Printf("DEBUG:::%+v\n", t)
    47  	length := len(t)
    48  	for idx := 0; idx < length-1; idx = idx + 2 {
    49  		var uh CiscoURLHitItem
    50  		uh.Name = string(t[idx])
    51  		//fmt.Println("DEBUG::::%s\t\tLen:", uh.Name, len(t[idx+1]))
    52  		if len(t[idx+1]) == 0 {
    53  			tmp := make([]byte, 2)
    54  			tmp[1] = t[idx+2][0]
    55  			uh.Number = binary.BigEndian.Uint16(tmp)
    56  			idx = idx + 1
    57  		} else {
    58  			uh.Number = binary.BigEndian.Uint16(t[idx+1])
    59  		}
    60  		result = append(result, uh)
    61  		//fmt.Printf("DEBUG::::%s\t%d\n", uh.Name, uh.Number)
    62  	}
    63  
    64  	return result
    65  }