Advertisement
saleks28

pasoib8_protocols

Dec 15th, 2019
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.27 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "net/http"
  5.  
  6.     "github.com/google/gopacket/layers"
  7. )
  8.  
  9. //SaveTCPLayer saves data from TCP fields
  10. func SaveTCPLayer(w http.ResponseWriter, req *http.Request) layers.TCP {
  11.     var (
  12.         tcp layers.TCP
  13.     )
  14.  
  15.     tcp.SrcPort = layers.TCPPort(StringToUint16(req.FormValue("tcpsrcPort")))
  16.     tcp.DstPort = layers.TCPPort(StringToUint16(req.FormValue("tcpdstPort")))
  17.     tcp.Seq = StringToUint32(req.FormValue("tcpseq"))
  18.     tcp.Ack = StringToUint32(req.FormValue("tcpack"))
  19.     tcp.DataOffset = StringToUint8(req.FormValue("tcpoffset"))
  20.     tcp.FIN = RadioToBool(req.FormValue("finflag"))
  21.     tcp.SYN = RadioToBool(req.FormValue("synflag"))
  22.     tcp.RST = RadioToBool(req.FormValue("rstflag"))
  23.     tcp.PSH = RadioToBool(req.FormValue("pshflag"))
  24.     tcp.ACK = RadioToBool(req.FormValue("ackflag"))
  25.     tcp.URG = RadioToBool(req.FormValue("urgflag"))
  26.     tcp.ECE = RadioToBool(req.FormValue("eceflag"))
  27.     tcp.CWR = RadioToBool(req.FormValue("cwrflag"))
  28.     tcp.NS = RadioToBool(req.FormValue("nsflag"))
  29.    
  30.     tcp.Window = StringToUint16(req.FormValue("window"))
  31.     tcp.Checksum = StringToUint16(req.FormValue("checksumtcp"))
  32.     tcp.Options = append(tcp.Options, layers.TCPOption{
  33.         OptionType:   layers.TCPOptionKind(StringToUint8(req.FormValue("tcpoptionType"))),
  34.         OptionLength: StringToUint8(req.FormValue("tcpoptionLength")),
  35.         OptionData:   []byte(req.FormValue("tcpoptionData")),
  36.     })
  37.     return tcp
  38. }
  39.  
  40. //SaveUDPLayer saves data from UDP fields
  41. func SaveUDPLayer(w http.ResponseWriter, req *http.Request) layers.UDP {
  42.     var (
  43.         udp layers.UDP
  44.     )
  45.  
  46.     udp.Length = StringToUint16(req.FormValue("udplength"))
  47.     udp.Checksum = StringToUint16(req.FormValue("udpchecksum"))
  48.     udp.SrcPort = layers.UDPPort(StringToUint16(req.FormValue("udpsrcPort")))
  49.     udp.DstPort = layers.UDPPort(StringToUint16(req.FormValue("udpdstPort")))
  50.     return udp
  51. }
  52.  
  53. //SaveICMPLayer saves data fro m ICMP fields
  54. func SaveICMPLayer(w http.ResponseWriter, req *http.Request) layers.ICMPv4 {
  55.     var (
  56.         icmp layers.ICMPv4
  57.     )
  58.     icmp.TypeCode = layers.CreateICMPv4TypeCode(8, 0)
  59.     icmp.Id = StringToUint16(req.FormValue("icmpid"))
  60.     icmp.Seq = StringToUint16(req.FormValue("icmpseq"))
  61.     icmp.Checksum = StringToUint16(req.FormValue("icmpchecksum"))
  62.     //icmp.TypeCode = layers.ICMPv4TypeCode(StringToUint16(req.FormValue("typecode")))
  63.     return icmp
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement