Ejemplo n.º 1
0
def ms_build_set_logon(ptype, serv_info):
    if ptype == 'diag':
        logon_type = 'MS_LOGON_DIAG'
        port = serv_info['diag_port']
    elif ptype == 'rfc':
        logon_type = 'MS_LOGON_RFC'
        port = serv_info['rfc_port']
    address = serv_info['ip']
    host = serv_info['fqdn']

    p = SAPMS(fromname=my_name,
              toname=msg_server_name,
              flag='MS_REQUEST',
              iflag='MS_SEND_NAME',
              opcode='MS_SET_LOGON',
              logon=SAPMSLogon(type=logon_type,
                               port=port,
                               address=address,
                               logonname_length=0,
                               prot_length=0,
                               host_length=len(host),
                               host=host,
                               misc_length=4,
                               misc='LB=9')) / Raw(load="\xff\xff")
    return p
Ejemplo n.º 2
0
def test_pcgen_functions(pcgen_obj):
    expected_byte_stream = '00000000800100000000400108004500002E000100004011EEA95000000A3C00000B08880889001A1A43' \
                           '000102030405060708090A0B0C0D0E0F1011'
    scapy_headers_tuple = (
        Ether(src='00:00:00:00:40:01', dst='00:00:00:00:80:01',
              type=0x0800), IP(src='80.0.0.10', dst='60.0.0.11',
                               ttl=0x40), UDP(dport=0x889, sport=0x888),
        Raw('000102030405060708090A0B0C0D0E0F1011'.decode('hex')))
    expected_crc = (366757237, 1967512597)

    pcgen_obj.build_scapy_packet(scapy_headers_tuple)
    print("test:\t\t\t\tbuild_scapy_packet\t\t\t\t\t{}".format(
        Pcgen.scapy_pkt_2_byte_stream(pcgen_obj.scapy_packet) ==
        expected_byte_stream))

    pkt = Pcgen.byte_stream_2_scapy_pkt(expected_byte_stream)
    print("test:\t\t\t\tbyte_stream_2_scapy_pkt\t\t\t\t{}".format(
        pkt.show2(dump=True) == pcgen_obj.scapy_packet.show2(dump=True)))

    stream = Pcgen.scapy_pkt_2_byte_stream(pcgen_obj.scapy_packet)
    print("test:\t\t\t\tscapy_pkt_2_byte_stream\t\t\t\t{}".format(
        expected_byte_stream == stream))

    crc = Pcgen.get_byte_stream_crc32(expected_byte_stream)
    print("test:\t\t\t\tget_byte_stream_crc32\t\t\t\t{}".format(
        expected_crc == crc))
Ejemplo n.º 3
0
    def _raise_alarm(alarm_event, olt, egress):
        try:
            frame = Ether() / Dot1Q(vlan=4000) / IP() / TCP() / Raw(load=json.dumps(alarm_event))
            egress(0, frame)

        except Exception as e:
            log.exception('failed-to-raise-alarm', e=e)
Ejemplo n.º 4
0
def callback(data):
    #print data.summary()
    ip = IP(src="10.0.0.13", dst="10.0.0.11")
    pkt = Ether() / ip / UDP(sport=1234, dport=5000) / Raw(load="CIAO")
    #print pkt.summary()
    sleep(0.1)
    sendp(pkt, realtime=True)
Ejemplo n.º 5
0
    def _clear_alarm(alarm_event, olt, egress):
        try:
            alarm_event['state'] = AlarmEventState.CLEARED
            frame = Ether() / Dot1Q(vlan=4000) / IP() / TCP() / Raw(load=json.dumps(alarm_event))
            egress(0, frame)

        except Exception as e:
            log.exception('failed-to-clear-alarm', e=e)
Ejemplo n.º 6
0
def main():
    """Open a TCP listener socket on the default BGP port. Accept an incoming
    connection, receive data and verify if data is a valid BGP Open message."""
    args = TrafficScriptArg(
        ['rx_ip', 'src_ip', 'rx_port', 'as_number', 'holdtime'])

    rx_ip = args.get_arg('rx_ip')
    src_ip = args.get_arg('src_ip')
    rx_port = int(args.get_arg('rx_port'))
    as_number = int(args.get_arg('as_number'))
    holdtime = int(args.get_arg('holdtime'))

    load_contrib("bgp")

    soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    soc.bind((rx_ip, rx_port))
    soc.listen(1)

    print "Listener active, awaiting connection..."
    soc.settimeout(8)
    conn, addr = soc.accept()
    print 'Connection established with peer:', addr

    data = conn.recv(256)
    conn.close()
    soc.close()

    bgp_layer = (BGPHeader(Raw(data).load))
    bgp_layer.show()

    if not bgp_layer.haslayer(BGPOpen):
        raise RuntimeError("Received data is not a BGP OPEN message.")
    bgp_open = bgp_layer.getlayer(BGPOpen)
    if bgp_open.bgp_id != src_ip:
        raise RuntimeError(
            "BGP ID mismatch. Received {0} but should be {1}".format(
                bgp_open.bgp_id, src_ip))
    else:
        print "BGP ID matched."

    if bgp_open.AS != as_number:
        raise RuntimeError(
            "BGP AS number mismatch. Received {0} but should be {1}".format(
                bgp_open.AS, as_number))
    else:
        print "BGP AS number matched."

    if bgp_open.hold_time != holdtime:
        raise RuntimeError(
            "Hold Time parameter mismatch. Received {0} but should be {1}.".
            format(bgp_layer.getlayer(BGPOpen).holdtime, holdtime))
    else:
        print "BGP Hold Time parameter matched."

    sys.exit(0)
Ejemplo n.º 7
0
def send_magic_packet():
    # マジックパケットの仕様に従い、文字列でペイロードを準備
    # https://ja.wikipedia.org/wiki/Wake-on-LAN
    str_payload = PREFIX_PAYLOAD + (TARGET_MAC_ADDRESS.replace(':', '') * 16)
    # Python2でしか動作させないので、decode('hex')を使う
    # https://stackoverflow.com/questions/443967/how-to-create-python-bytes-object-from-long-hex-string
    hex_payload = str_payload.decode('hex')

    ether_layer = Ether(dst=BROADCAST_MAC_ADDRESS)
    ip_layer = IP(dst=LIMITED_BROADCAST_IP_ADDRESS)
    udp_layer = UDP()
    raw_layer = Raw(load=hex_payload)
    magic_packet = ether_layer / ip_layer / udp_layer / raw_layer
    sendp(magic_packet)
Ejemplo n.º 8
0
 def __init__(self, recv_mac, src_mac, dst_mac, ds=0x01):
     self.rt = RadioTap(len=18,
                        present='Flags+Rate+Channel+dBm_AntSignal+Antenna',
                        notdecoded='\x00\x6c' + get_frequency(CHANNEL) +
                        '\xc0\x00\xc0\x01\x00\x00')
     self.dot11hdr = Dot11(type="Data",
                           subtype=DOT11_SUBTYPE_QOS_DATA,
                           addr1=recv_mac,
                           addr2=src_mac,
                           addr3=dst_mac,
                           SC=0x3060,
                           FCfield=ds) / Raw("\x80\x00")
     self.data = self.rt / self.dot11hdr
     self.num_subframes = 0
     self.recv_mac = recv_mac
     self.src_mac = src_mac
     self.dst_mac = dst_mac
Ejemplo n.º 9
0
 def __init__(self,
              recv_mac,
              src_mac,
              dst_mac,
              ds=0x01):  # 'ds' means from/to distribution system, etc
     # the next line is the original version
     self.rt = RadioTap(len=18,
                        present='Flags+Rate+Channel+dBm_AntSignal+Antenna',
                        notdecoded='\x00\x6c' + get_frequency(CHANNEL) +
                        '\xc0\x00\xc0\x01\x00\x00')
     #self.rt = RadioTap(len=18, present='Flags+Rate+Channel+dBm_AntSignal+Antenna+MCS', notdecoded='\x00\x6c' + get_frequency(CHANNEL) + '\xc0\x00\xc0\x01\x00\x00')
     self.dot11hdr = Dot11(type="Data",
                           subtype=DOT11_SUBTYPE_QOS_DATA,
                           addr1=recv_mac,
                           addr2=src_mac,
                           addr3=dst_mac,
                           SC=0x3060,
                           FCfield=ds) / Raw("\x00\x00")
     self.data = self.rt  # initially I only add the Radiotap header. I will add the rest of the headers later
     self.num_subframes = 0
     self.recv_mac = recv_mac
     self.src_mac = src_mac
     self.dst_mac = dst_mac
Ejemplo n.º 10
0
def test_scapy_ipsec_functions(scapy_ipsec_obj):
    pkt = Pcgen()
    scapy_headers_tuple = (Ether(src='00:00:00:00:40:01', dst='00:00:00:00:80:01', type=0x0800),
                           IP(src='80.0.0.10', dst='60.0.0.11', ttl=0x40),
                           UDP(dport=0x889, sport=0x888),
                           Raw('000102030405060708090A0B0C0D0E0F1011'.decode('hex')))
    pkt.build_scapy_packet(scapy_headers_tuple)

    expected_enc = '4500004C000100004032EE6A5000000A3C00000B00000201000000055EB66511D938DC08E3C51C46E3F8154D36405' \
                   '8D1BCC2ECC6BD3D36F7F2CA43FAEF51128FB6DD741EE6B8276B1EEF4292'
    expected_dec = '4500002E000100004011EEA95000000A3C00000B08880889001A1A43000102030405060708090A0B0C0D0E0F1011'

    ip_pkt = pkt.scapy_packet[IP]
    encrypted_packet = scapy_ipsec_obj.get_encrypted_packet(ip_pkt=ip_pkt)
    print("test:\t\t\t\tget_encrypted_packet\t\t\t\t{}".format(
        Pcgen.scapy_pkt_2_byte_stream(encrypted_packet) == expected_enc))

    decrypted_packet = scapy_ipsec_obj.get_decrypted_packet(encrypted_packet)
    print("test:\t\t\t\tget_decrypted_packet\t\t\t\t{}".format(
        Pcgen.scapy_pkt_2_byte_stream(decrypted_packet) == expected_dec))

    full_pkt = Pcgen()
    full_pkt.build_scapy_packet((scapy_headers_tuple[0], decrypted_packet[IP]))
    print full_pkt.packet_byte_stream_with_crc
Ejemplo n.º 11
0
                           opcode_charset=0,
                           property=SAPMSProperty(id='Release information',
                                                  release='745',
                                                  patchno=15,
                                                  platform=390))

p_prop_set_service = SAPMS(
    fromname=my_name,
    toname=msg_server_name,
    flag='MS_REQUEST',
    iflag='MS_SEND_NAME',
    opcode='MS_SET_PROPERTY',
    opcode_version=1,
    opcode_charset=0,
    property=SAPMSProperty(client='', id='MS_PROPERTY_SERVICE',
                           service=1)) / Raw(load='\x07')

p_get_server_list_l = [
    SAPMS(fromname=anon_name,
          toname=msg_server_name,
          flag='MS_ONE_WAY',
          iflag='MS_SEND_NAME',
          opcode='MS_SERVER_LONG_LIST',
          opcode_version=1,
          opcode_charset=0),
    SAPMS(fromname=anon_name,
          toname=msg_server_name,
          flag='MS_ONE_WAY',
          iflag='MS_SEND_NAME',
          opcode='MS_SERVER_LONG_LIST',
          opcode_version=1,
Ejemplo n.º 12
0
def build_raw_probe(data):
    return Raw(load=data)
def main():
    """Send IP ICMPv4/ICMPv6 packet from one traffic generator interface to
    the other one. Dot1q or Dot1ad tagging of the ethernet frame can be set.
    """
    args = TrafficScriptArg(['tx_src_mac', 'tx_dst_mac', 'tx_src_ip',
                             'tx_dst_ip', 'tx_vni', 'rx_src_ip', 'rx_dst_ip',
                             'rx_vni'])

    tx_if = args.get_arg('tx_if')
    rx_if = args.get_arg('rx_if')
    tx_src_mac = args.get_arg('tx_src_mac')
    tx_dst_mac = args.get_arg('tx_dst_mac')
    tx_src_ip = args.get_arg('tx_src_ip')
    tx_dst_ip = args.get_arg('tx_dst_ip')
    tx_vni = args.get_arg('tx_vni')
    rx_src_ip = args.get_arg('rx_src_ip')
    rx_dst_ip = args.get_arg('rx_dst_ip')
    rx_vni = args.get_arg('rx_vni')

    rxq = RxQueue(rx_if)
    txq = TxQueue(tx_if)

    sent_packets = []

    tx_pkt_p = (Ether(src='02:00:00:00:00:01', dst='02:00:00:00:00:02') /
                IP(src='192.168.1.1', dst='192.168.1.2') /
                UDP(sport=12345, dport=1234) /
                Raw('rew data'))

    pkt_raw = (Ether(src=tx_src_mac, dst=tx_dst_mac) /
               IP(src=tx_src_ip, dst=tx_dst_ip) /
               UDP(sport=23456) /
               vxlan.VXLAN(vni=int(tx_vni)) /
               tx_pkt_p)

    # Send created packet on one interface and receive on the other
    sent_packets.append(pkt_raw)
    txq.send(pkt_raw)

    ether = rxq.recv(2, ignore=sent_packets)

    # Check whether received packet contains layers Ether, IP and VXLAN
    if ether is None:
        raise RuntimeError('Packet Rx timeout')
    ip = ether.payload

    if ip.src != rx_src_ip:
        raise RuntimeError('IP src mismatch {} != {}'.format(ip.src, rx_src_ip))
    if ip.dst != rx_dst_ip:
        raise RuntimeError('IP dst mismatch {} != {}'.format(ip.dst, rx_dst_ip))
    if ip.payload.dport != 4789:
        raise RuntimeError('VXLAN UDP port mismatch {} != {}'.
                           format(ip.payload.dport, 4789))
    vxlan_pkt = ip.payload.payload

    if int(vxlan_pkt.vni) != int(rx_vni):
        raise RuntimeError('vxlan mismatch')
    rx_pkt_p = vxlan_pkt.payload

    if rx_pkt_p.src != tx_pkt_p.src:
        raise RuntimeError('RX encapsulated MAC src mismatch {} != {}'.
                           format(rx_pkt_p.src, tx_pkt_p.src))
    if rx_pkt_p.dst != tx_pkt_p.dst:
        raise RuntimeError('RX encapsulated MAC dst mismatch {} != {}'.
                           format(rx_pkt_p.dst, tx_pkt_p.dst))
    if rx_pkt_p['IP'].src != tx_pkt_p['IP'].src:
        raise RuntimeError('RX encapsulated IP src mismatch {} != {}'.
                           format(rx_pkt_p['IP'].src, tx_pkt_p['IP'].src))
    if rx_pkt_p['IP'].dst != tx_pkt_p['IP'].dst:
        raise RuntimeError('RX encapsulated IP dst mismatch {} != {}'.
                           format(rx_pkt_p['IP'].dst, tx_pkt_p['IP'].dst))

    # TODO: verify inner Ether()

    sys.exit(0)