示例#1
0
def service_craft(pkt, fp, mac, service, type_=False):
    try:
        ether = Ether()
        ether.src = mac
        ether.dst = pkt[Ether].dst
        ether.type = 0x800
    except IndexError:
        ether = None

    ip = IP()
    ip.src = pkt[IP].dst
    ip.dst = pkt[IP].src
    ip.ttl = int(fp.ttl, 16)
    ip.flags = 0x4000

    tcp = TCP()
    tcp.sport = pkt[TCP].dport
    tcp.dport = pkt[TCP].sport

    if type_:
        tcp.flags = 0x018  # PSH / ACK
        tcp.seq = pkt[TCP].seq
        tcp.ack = pkt[TCP].ack
        data = service[pkt[TCP].dport]
        fin_pkt = ip / tcp / data if ether is None else ether / ip / tcp / data
        return fin_pkt
    else:
        tcp.flags = 0x012  # SYN / ACK
        tcp.seq = pkt[TCP].seq
        tcp.ack = pkt[TCP].seq + 1
        fin_pkt = ip / tcp if ether is None else ether / ip / tcp
        return fin_pkt
示例#2
0
def Ether_layer(attributes):
    layer2 = Ether()
    layer2.dst = attributes['dst']
    layer2.src = attributes['src']
    layer2.type = attributes['type']

    return layer2
示例#3
0
def seqgen_pkt_craft(pkt, fp, mac, pno):
    try:
        ether = Ether()
        ether.src = mac
        ether.dst = pkt[Ether].dst
        ether.type = 0x800
    except IndexError:
        ether = None

    ip = IP()
    ip.src = pkt[IP].dst
    ip.dst = pkt[IP].src
    ip.ttl = int(fp.probe['T1']['TTL'], 16)
    ip.flags = fp.probe['T1']['DF']
    ip.id = fp.ip_id_gen()

    tcp = TCP()

    s_val = fp.probe['T1']['S']
    if s_val == 'Z':
        tcp.seq = 0
    elif s_val == 'A':
        tcp.seq = pkt[TCP].ack
    elif s_val == 'A+':
        tcp.seq = pkt[TCP].ack + 1
    else:
        tcp.seq = fp.tcp_seq_gen()

    a_val = fp.probe['T1']['A']
    if a_val == 'Z':
        tcp.ack = 0
    elif a_val == 'S':
        tcp.ack = pkt[TCP].seq
    elif a_val == 'S+':
        tcp.ack = pkt[TCP].seq + 1
    else:
        tcp.ack = pkt[TCP].seq + 369

    flag_val = fp.probe['T1']['F']
    tcp.flags = flag_val

    tcp.window = fp.probe['WIN']['W' + pno]

    tcp.sport = pkt[TCP].dport
    tcp.dport = pkt[TCP].sport

    tcp.options = fp.probe['OPS']['O' + pno]

    rd_val = fp.probe['T1']['RD']
    if rd_val != '0':
        crc = int(rd_val, 16)
        data = b'TCP Port is closed\x00'
        data += compensate(data, crc)
        fin_pkt = ip / tcp / data if ether is None else ether / ip / tcp / data

    else:
        fin_pkt = ip / tcp if ether is None else ether / ip / tcp
    return fin_pkt
示例#4
0
def simple_multicast_fabric_packet(header_version=0,
                                   packet_version=0,
                                   fabric_color=0,
                                   fabric_qos=0,
                                   dst_device=0,
                                   dst_port_or_group=0,
                                   routed=0,
                                   outer_routed=0,
                                   tunnel_terminate=0,
                                   ingress_tunnel_type=0,
                                   ingress_ifindex=1,
                                   ingress_bd=0,
                                   mcast_grp_A=0,
                                   mcast_grp_B=0,
                                   ingress_rid=0,
                                   l1_exclusion_id=0,
                                   inner_pkt=None):

    ether = Ether(str(inner_pkt))
    eth_type = ether.type
    ether.type = 0x9000

    fabric_header = FabricHeader(packet_type=0x2,
                                 header_version=header_version,
                                 packet_version=packet_version,
                                 pad1=0,
                                 fabric_color=fabric_color,
                                 fabric_qos=fabric_qos,
                                 dst_device=dst_device,
                                 dst_port_or_group=dst_port_or_group)

    fabric_multicast_header = FabricMulticastHeader(
        routed=routed,
        outerRouted=outer_routed,
        tunnelTerminate=tunnel_terminate,
        ingressTunnelType=ingress_tunnel_type,
        ingressIfindex=ingress_ifindex,
        ingressBd=ingress_bd,
        mcastGrpA=mcast_grp_A,
        mcastGrpB=mcast_grp_B,
        ingressRid=ingress_rid,
        l1ExclusionId=l1_exclusion_id)

    fabric_payload_header = FabricPayloadHeader(ether_type=eth_type)

    if inner_pkt:
        pkt = (
            str(ether)[:14]
        ) / fabric_header / fabric_multicast_header / fabric_payload_header / (
            str(inner_pkt)[14:])
    else:
        ip_pkt = simple_ip_only_packet()
        pkt = (
            str(ether)[:14]
        ) / fabric_header / fabric_multicast_header / fabric_payload_header / ip_pkt

    return pkt
示例#5
0
def simple_cpu_packet(header_version=0,
                      packet_version=0,
                      fabric_color=0,
                      fabric_qos=0,
                      dst_device=0,
                      dst_port_or_group=0,
                      ingress_ifindex=1,
                      ingress_bd=0,
                      mcast_grp=0,
                      egress_queue=0,
                      tx_bypass=False,
                      ingress_port=1,
                      reason_code=0,
                      sflow_sid=0,
                      sflow_egress_port=0,
                      inner_pkt=None):

    ether = Ether(str(inner_pkt))
    eth_type = ether.type
    ether.type = 0x9000

    fabric_header = FabricHeader(packet_type=0x5,
                                 header_version=header_version,
                                 packet_version=packet_version,
                                 pad1=0,
                                 fabric_color=fabric_color,
                                 fabric_qos=fabric_qos,
                                 dst_device=dst_device,
                                 dst_port_or_group=dst_port_or_group)

    fabric_cpu_header = FabricCpuHeader(egress_queue=egress_queue,
                                        tx_bypass=tx_bypass,
                                        reserved1=0,
                                        ingress_port=ingress_port,
                                        ingress_ifindex=ingress_ifindex,
                                        ingress_bd=ingress_bd,
                                        reason_code=reason_code,
                                        mcast_grp=mcast_grp)

    fabric_payload_header = FabricPayloadHeader(ether_type=eth_type)

    pkt = (str(ether)[:14]) / fabric_header / fabric_cpu_header

    if sflow_sid:
        pkt = pkt / FabricCpuSflowHeader(sflow_sid=sflow_sid,
                                         sflow_egress_port=sflow_egress_port)

    pkt = pkt / fabric_payload_header

    if inner_pkt:
        pkt = pkt / (str(inner_pkt)[14:])
    else:
        ip_pkt = simple_ip_only_packet()
        pkt = pkt / ip_pkt

    return pkt
示例#6
0
    def packet_out(self, in_port, out_port, data):
        in_port = "CONTROLLER" if in_port == ofp.OFPP_CONTROLLER else in_port
        print "PACKET OUT (%s => %s): " % (in_port, out_port)
        hexdump(data)

        if self.in_out_iface is not None:

            try:
                # disect the packet
                pkt = Ether(data)

                # remove payload from Ether frame
                payload = pkt.payload
                payload_type = pkt.type
                pkt.remove_payload()

                # insert Dot1Q shim with vlan_id = out_port

                if self.in_out_stag is None:
                    ## WARNING -- This was changed from 0x88a8 to 0x8100 when
                    ## testing with the Intel XL710 quad 10GE boards.  The
                    ## XL710 does not support the TPID for the STAG.
                    ##
                    ## Long term, it should be changed back to 0x88a8!
                    ##
                    pkt.type = 0x8100
                    new_pkt = pkt / Dot1Q(vlan=out_port,
                                          type=payload_type) / payload

                else:
                    pkt.type = 0x8100
                    new_pkt = (pkt /
                               Dot1Q(vlan=self.in_out_stag, type=0x8100) /
                               Dot1Q(vlan=out_port, type=payload_type) /
                               payload)

                # send out the packet
                sendp(new_pkt, iface=self.in_out_iface)

            except Exception, e:
                logging.exception(
                    "Could not parse packet-out data as scapy.Ether:\n")
                logging.error(hexdump(data, 'return'))
示例#7
0
文件: utils.py 项目: krambn/switch
def simple_cpu_packet(header_version = 0,
                      packet_version = 0,
                      fabric_color = 0,
                      fabric_qos = 0,
                      dst_device = 0,
                      dst_port_or_group = 0,
                      ingress_ifindex = 1,
                      ingress_bd = 0,
                      mcast_grp = 0,
                      egress_queue = 0,
                      tx_bypass = False,
                      ingress_port = 1,
                      reason_code = 0,
                      sflow_sid = 0,
                      sflow_egress_port = 0,
                      inner_pkt = None):

    ether = Ether(str(inner_pkt))
    eth_type = ether.type
    ether.type = 0x9000

    fabric_header = FabricHeader(packet_type = 0x5,
                                  header_version = header_version,
                                  packet_version = packet_version,
                                  pad1 = 0,
                                  fabric_color = fabric_color,
                                  fabric_qos = fabric_qos,
                                  dst_device = dst_device,
                                  dst_port_or_group = dst_port_or_group)

    fabric_cpu_header = FabricCpuHeader(egress_queue = egress_queue,
                                        tx_bypass = tx_bypass,
                                        reserved1 = 0,
                                        ingress_port = ingress_port,
                                        ingress_ifindex = ingress_ifindex,
                                        ingress_bd = ingress_bd,
                                        reason_code = reason_code,
                                        mcast_grp = mcast_grp)

    fabric_payload_header = FabricPayloadHeader(ether_type = eth_type)

    pkt = (str(ether)[:14]) / fabric_header / fabric_cpu_header

    if sflow_sid:
        pkt = pkt / FabricCpuSflowHeader(sflow_sid = sflow_sid, sflow_egress_port = sflow_egress_port)

    pkt = pkt / fabric_payload_header

    if inner_pkt:
        pkt = pkt / (str(inner_pkt)[14:])
    else:
        ip_pkt = simple_ip_only_packet()
        pkt = pkt / ip_pkt

    return pkt
示例#8
0
def udp_craft(pkt, mac, fp):
    try:
        ether = Ether()
        ether.src = mac
        ether.dst = pkt[Ether].dst
        ether.type = 0x800
    except IndexError:
        ether = None

    ip = IP()
    ip.src = pkt[IP].dst
    ip.dst = pkt[IP].src
    ip.ttl = int(fp.probe['U1']['TTL'], 16)
    ip.flags = fp.probe['U1']['DF']
    ip.len = 56
    ip.id = 4162

    icmp = ICMP()
    icmp.type = 3
    icmp.unused = 0
    icmp.code = 13  # code 3 for reply

    iperror = IPerror()
    iperror.proto = 'udp'
    iperror.ttl = 0x3E
    iperror.len = fp.probe['U1']['RIPL']
    iperror.id = fp.probe['U1']['RID']

    ripck_val = fp.probe['U1']['RIPCK']
    if ripck_val == 'G':
        pass
    elif ripck_val == 'Z':
        iperror.chksum = 0
    else:
        iperror.chksum = pkt[IP].chksum

    udperror = UDPerror()
    udperror.sport = pkt[UDP].sport
    udperror.dport = pkt[UDP].dport
    udperror.len = pkt[UDP].len
    if fp.probe['U1']['RUCK'] == 'G':
        udperror.chksum = pkt[UDP].chksum
    else:
        udperror.chksum = fp.probe['U1']['RUCK']

    try:
        ipl = int(fp.probe['U1']['IPL'], 16)
    except KeyError:
        ipl = None

    data = pkt[Raw].load

    fin_pkt = ip / icmp / iperror / udperror / data if ether is None else ether / ip / icmp / iperror / udperror / data

    return fin_pkt
示例#9
0
    def packet_out(self, in_port, out_port, data):
        in_port = "CONTROLLER" if in_port == ofp.OFPP_CONTROLLER else in_port
        print "PACKET OUT (%s => %s): " % (in_port, out_port)
        hexdump(data)

        if self.in_out_iface is not None:

            try:
                # disect the packet
                pkt = Ether(data)

                # remove payload from Ether frame
                payload = pkt.payload
                payload_type = pkt.type
                pkt.remove_payload()

                # insert Dot1Q shim with vlan_id = out_port

                if self.in_out_stag is None:
                    ## WARNING -- This was changed from 0x88a8 to 0x8100 when
                    ## testing with the Intel XL710 quad 10GE boards.  The
                    ## XL710 does not support the TPID for the STAG.
                    ##
                    ## Long term, it should be changed back to 0x88a8!
                    ##
                    pkt.type = 0x8100
                    new_pkt = pkt / Dot1Q(vlan=out_port, type=payload_type) / payload

                else:
                    pkt.type = 0x8100
                    new_pkt = (
                            pkt /
                            Dot1Q(vlan=self.in_out_stag, type=0x8100) /
                            Dot1Q(vlan=out_port, type=payload_type) /
                            payload)

                # send out the packet
                sendp(new_pkt, iface=self.in_out_iface)

            except Exception, e:
                logging.exception("Could not parse packet-out data as scapy.Ether:\n")
                logging.error(hexdump(data, 'return'))
示例#10
0
def simple_multicast_fabric_packet(header_version = 0,
                      packet_version = 0,
                      fabric_color = 0,
                      fabric_qos = 0,
                      dst_device = 0,
                      dst_port_or_group = 0,
                      routed = 0,
                      outer_routed = 0,
                      tunnel_terminate=0,
                      ingress_tunnel_type=0,
                      ingress_ifindex = 1,
                      ingress_bd = 0,
                      mcast_grp_A = 0,
                      mcast_grp_B = 0,
                      ingress_rid = 0,
                      l1_exclusion_id = 0,
                      inner_pkt = None):

    ether = Ether(str(inner_pkt))
    eth_type = ether.type
    ether.type = 0x9000

    fabric_header = FabricHeader(packet_type = 0x2,
                                  header_version = header_version,
                                  packet_version = packet_version,
                                  pad1 = 0,
                                  fabric_color = fabric_color,
                                  fabric_qos = fabric_qos,
                                  dst_device = dst_device,
                                  dst_port_or_group = dst_port_or_group)

    fabric_multicast_header = FabricMulticastHeader(routed = routed,
                                    outerRouted = outer_routed,
                                    tunnelTerminate = tunnel_terminate,
                                    ingressTunnelType = ingress_tunnel_type,
                                    ingressIfindex = ingress_ifindex,
                                    ingressBd = ingress_bd,
                                    mcastGrpA = mcast_grp_A,
                                    mcastGrpB = mcast_grp_B,
                                    ingressRid = ingress_rid,
                                    l1ExclusionId = l1_exclusion_id)

    fabric_payload_header = FabricPayloadHeader(ether_type = eth_type)

    if inner_pkt:
        pkt = (str(ether)[:14]) / fabric_header / fabric_multicast_header / fabric_payload_header / (str(inner_pkt)[14:])
    else:
        ip_pkt = simple_ip_only_packet()
        pkt = (str(ether)[:14]) / fabric_header / fabric_multicast_header / fabric_payload_header / ip_pkt

    return pkt
示例#11
0
def ecn_craft(pkt, mac, fp):
    try:
        ether = Ether()
        ether.src = mac
        ether.dst = pkt[Ether].dst
        ether.type = 0x800
    except IndexError:
        ether = None

    ip = IP()
    ip.src = pkt[IP].dst
    ip.dst = pkt[IP].src
    ip.ttl = int(fp.probe['ECN']['TTL'], 16)

    ip_flag = fp.probe['ECN']['DF']
    if ip_flag == 'Y':
        ip.flags = 2
    else:
        ip.flags = 0
    ip.id = fp.ip_id_gen()

    tcp = TCP()
    w_val = fp.probe['ECN']['W']
    if w_val == 'ECHOED':
        tcp.window = pkt[TCP].window
    else:
        tcp.window = w_val
    tcp.sport = pkt[TCP].dport
    tcp.dport = pkt[TCP].sport

    cc_val = fp.probe['ECN']['CC']
    if cc_val == 'Y':
        tcp.flags = 0x52
    elif cc_val == 'N':
        tcp.flags = 0x12
    elif cc_val == 'S':
        tcp.flags = 0xD2
    else:
        tcp.flags = 0x10

    o_val = fp.probe['ECN']['O']
    if o_val == 'EMPTY':
        pass
    else:
        tcp.options = o_val

    fin_pkt = ip / tcp if ether is None else ether / ip / tcp

    return fin_pkt
示例#12
0
def simple_unicast_fabric_packet(header_version=0,
                                 packet_version=0,
                                 fabric_color=0,
                                 fabric_qos=0,
                                 dst_device=0,
                                 dst_port_or_group=0,
                                 routed=0,
                                 outer_routed=0,
                                 tunnel_terminate=0,
                                 ingress_tunnel_type=0,
                                 nexthop_index=0,
                                 inner_pkt=None):

    ether = Ether(str(inner_pkt))
    eth_type = ether.type
    ether.type = 0x9000

    fabric_header = FabricHeader(packet_type=0x1,
                                 header_version=header_version,
                                 packet_version=packet_version,
                                 pad1=0,
                                 fabric_color=fabric_color,
                                 fabric_qos=fabric_qos,
                                 dst_device=dst_device,
                                 dst_port_or_group=dst_port_or_group)

    fabric_unicast_header = FabricUnicastHeader(routed=0,
                                                outerRouted=0,
                                                tunnelTerminate=0,
                                                ingressTunnelType=0,
                                                nexthopIndex=0)

    fabric_payload_header = FabricPayloadHeader(ether_type=eth_type)

    if inner_pkt:
        pkt = (
            str(ether)[:14]
        ) / fabric_header / fabric_unicast_header / fabric_payload_header / (
            str(inner_pkt)[14:])
    else:
        ip_pkt = simple_ip_only_packet()
        pkt = (
            str(ether)[:14]
        ) / fabric_header / fabric_unicast_header / fabric_payload_header / ip_pkt

    return pkt
示例#13
0
 def sendPacket(self, packet, if_out, rota):
     # Envia informação para interface de saída.
     #  Detecta o tipo do pacote para montar corretamente para ser enviado.
     #  Monta cabeçalhos ethernet de origem e destino.
     #  Verifica o MAC do endereço IP de destino
     #resp = srp1(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=packet.dst), iface=if_out, timeout=2)
     # #print "Resposta ARP destino %s : %s"  % (packet.dst, resp)
     # Monta cabeçalho ethernet
     print rota.src_mac
     print rota.dst_mac
     #eth_dst = resp.src
     #eth_src = resp.dst
     eth = Ether(src=rota.src_mac, dst=rota.dst_mac)
     eth.type = 2048
     packet.show2()
     #Envia pacote para a interface de saida delimitada.
     sendp(eth / packet, iface=if_out)
示例#14
0
 def sendPacket(self, packet, if_out, rota):
     # Envia informação para interface de saída.
     #  Detecta o tipo do pacote para montar corretamente para ser enviado.
     #  Monta cabeçalhos ethernet de origem e destino.
     #  Verifica o MAC do endereço IP de destino
     #resp = srp1(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=packet.dst), iface=if_out, timeout=2)
     # #print "Resposta ARP destino %s : %s"  % (packet.dst, resp)
     # Monta cabeçalho ethernet
     print rota.src_mac
     print rota.dst_mac
     #eth_dst = resp.src
     #eth_src = resp.dst
     eth = Ether(src=rota.src_mac, dst=rota.dst_mac)
     eth.type = 2048
     packet.show2()
     #Envia pacote para a interface de saida delimitada.
     sendp(eth/packet, iface=if_out)
示例#15
0
def simple_unicast_fabric_packet(header_version = 0,
                      packet_version = 0,
                      fabric_color = 0,
                      fabric_qos = 0,
                      dst_device = 0,
                      dst_port_or_group = 0,
                      routed = 0,
                      outer_routed = 0,
                      tunnel_terminate = 0,
                      ingress_tunnel_type = 0,
                      nexthop_index = 0,
                      inner_pkt = None):

    ether = Ether(str(inner_pkt))
    eth_type = ether.type
    ether.type = 0x9000

    fabric_header = FabricHeader(packet_type = 0x1,
                                  header_version = header_version,
                                  packet_version = packet_version,
                                  pad1 = 0,
                                  fabric_color = fabric_color,
                                  fabric_qos = fabric_qos,
                                  dst_device = dst_device,
                                  dst_port_or_group = dst_port_or_group)

    fabric_unicast_header = FabricUnicastHeader(routed = 0,
                                                outerRouted = 0,
                                                tunnelTerminate = 0,
                                                ingressTunnelType = 0,
                                                nexthopIndex = 0)

    fabric_payload_header = FabricPayloadHeader(ether_type = eth_type)

    if inner_pkt:
        pkt = (str(ether)[:14]) / fabric_header / fabric_unicast_header / fabric_payload_header / (str(inner_pkt)[14:])
    else:
        ip_pkt = simple_ip_only_packet()
        pkt = (str(ether)[:14]) / fabric_header / fabric_unicast_header / fabric_payload_header / ip_pkt

    return pkt
示例#16
0
def icmp_craft(pkt, fp, mac):
    try:
        ether = Ether()
        ether.src = mac
        ether.dst = pkt[Ether].dst
        ether.type = 0x800
    except IndexError:
        ether = None

    ip = IP()
    ip.src = pkt[IP].dst
    ip.dst = pkt[IP].src
    ip.ttl = int(fp.probe['IE']['TTL'], 16)
    dfi_flag = fp.probe['IE']['DFI']
    if dfi_flag == 'N':
        ip.flags = 0
    elif dfi_flag == 'S':
        ip.flags = pkt[IP].flags
    elif dfi_flag == 'Y':
        ip.flags = 2
    else:
        ip.flags = 0 if pkt[IP].flags == 2 else 2

    ip.id = fp.ip_id_icmp_gen()
    icmp = ICMP()
    icmp.type = 0
    icmp.id = pkt[ICMP].id

    cd_val = fp.probe['IE']['CD']
    if cd_val == 'Z':
        icmp.code = 0
    elif cd_val == 'S':
        icmp.code = pkt[ICMP].code
    else:
        icmp.code = random.randint(0, 15)

    icmp.seq = pkt[ICMP].seq
    data = pkt[ICMP].payload

    fin_pkt = ip / icmp / data if ether is None else ether / ip / icmp / data
    return fin_pkt
示例#17
0
'''
Created on Jan 19, 2012

@author: art3
'''

from scapy.all import Ether, sniff, sendp

a = Ether()
a.type = 0x8088
a.src = 'cc:52:af:0e:2c:c2'

while True:
    print("say something, and be sure to add quotation marks")

    data = 'victor says : ' + input()

    b = a / data

    sendp(b, count=2, iface='wlan0')
'''
Created on Jan 19, 2012

@author: art3
'''

from scapy.all import Ether,sniff,sendp

a=Ether()
a.type=0x8088
a.src='cc:52:af:0e:2c:c2'

while True:
    print("say something, and be sure to add quotation marks")

    data = 'victor says : ' + input()

    b=a/data

    sendp(b, count=2, iface='wlan0')
示例#19
0
def t2tot7_craft(pkt, fp, mac, tno):
    try:
        ether = Ether()
        ether.src = mac
        ether.dst = pkt[Ether].dst
        ether.type = 0x800
    except IndexError:
        ether = None

    ip = IP()
    ip.src = pkt[IP].dst
    ip.dst = pkt[IP].src
    ip.ttl = int(fp.probe[tno]['TTL'], 16)
    ip.flags = fp.probe[tno]['DF']
    ip.id = random.randint(1, 1000)

    tcp = TCP()

    s_val = fp.probe[tno]['S']
    if s_val == 'Z':
        tcp.seq = 0
    elif s_val == 'A':
        tcp.seq = pkt[TCP].ack
    elif s_val == 'A+':
        tcp.seq = pkt[TCP].ack + 1
    else:
        tcp.seq = pkt[TCP].ack + 369

    a_val = fp.probe[tno]['A']
    if a_val == 'Z':
        tcp.ack = 0
    elif a_val == 'S':
        tcp.ack = pkt[TCP].seq
    elif a_val == 'S+':
        tcp.ack = pkt[TCP].seq + 1
    else:
        tcp.ack = pkt[TCP].seq + 369

    flag_val = fp.probe[tno]['F']
    tcp.flags = flag_val

    w_val = fp.probe[tno]['W']
    if w_val == 'ECHOED':
        tcp.window = pkt[TCP].window
    else:
        tcp.window = w_val

    tcp.sport = pkt[TCP].dport
    tcp.dport = pkt[TCP].sport

    o_val = fp.probe[tno]['O']
    if o_val == 'EMPTY':
        pass
    else:
        tcp.options = o_val

    rd_val = fp.probe[tno]['RD']
    if rd_val != '0':
        crc = int(rd_val, 16)
        data = b'TCP Port is closed\x00'
        data += compensate(data, crc)
        fin_pkt = ip / tcp / data if ether is None else ether / ip / tcp / data
    else:
        fin_pkt = ip / tcp if ether is None else ether / ip / tcp

    return fin_pkt