Пример #1
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)
from scapy.sendrecv import sniff
from scapy.main import load_contrib
from scapy.layers.can import *
import json, base64, sys

conf.contribs['ISOTP'] = {'use-can-isotp-kernel-module': True}
conf.contribs['CANSocket'] = {'use-python-can': False}

load_contrib('cansocket')
load_contrib('isotp')
load_contrib('automotive.uds')
load_contrib('automotive.ecu')

if len(sys.argv) < 2:
    iface = "vcan0"
else:
    iface = sys.argv[1]

sock = ISOTPSocket(iface, sid=0x601, did=0x701, basecls=UDS)

with open("malware.sh", "rb") as fw:
    data = fw.read()

payload = {'sign': ''}
payload['data'] = base64.b64encode(data).decode('utf-8')
payload = json.dumps(payload)

requests = [ \
    UDS()/UDS_DSC(diagnosticSessionType=0x2), \
    UDS()/UDS_RU(memorySizeLen=0x1, memoryAddressLen=0x4, memoryAddress4=0xaaaaaaaa, memorySize1=0x64), \
    UDS()/UDS_TD(blockSequenceCounter=0x0, transferRequestParameterRecord=payload), \
Пример #3
0
from scapy.contrib.pnio import ProfinetIO
from scapy.contrib.pnio_dcp import ProfinetDCP, DCPDeviceRoleBlock, DCPDeviceIDBlock
from scapy.contrib.pnio_rpc import RPC_INTERFACE_UUID
from scapy.layers.inet import UDP
from scapy.layers.l2 import Ether, Dot1Q
from scapy.main import load_contrib
from scapy.packet import Raw
from scapy.sendrecv import sniff, AsyncSniffer
from scapy.utils import hexdump
from scapy2dict import to_dict

from Device import Device, listContainsDevice, getPositionOfDeviceInList, getPositionOfDeviceInListbyMacAdress
from constants import managementServerMAC, allDevices

load_contrib("pnio_rcp")


def receiveEthernetFrame(interface):
    # sniff(iface=interface, prn=lambda x: x.show(), filter="ether src 00:0c:29:e2:35:30")
    sniff(iface=interface,
          prn=lambda x: print('Da ist was reingekommen und zwar:' + str(x.show(
          ))))
    # sniff(iface = interface, prn=lambda x: x.show())


def asyncReceiveEthernetFrame(interface):
    # return AsyncSniffer(iface=interface, prn=lambda x: print('Da ist was reingekommen und zwar:' + str(x.show())))
    return AsyncSniffer(iface=interface, prn=lambda x: incomingFrameHandler(x))

Пример #4
0
    p1.stdout.close()
    if p1.wait() == 0 and p2.wait() == 0 and b"can_isotp" in p2.stdout.read():
        p = subprocess.Popen(["isotpsend", "-s1", "-d0", iface0],
                             stdin=subprocess.PIPE)
        p.communicate(b"01")
        if p.returncode == 0:
            ISOTP_KERNEL_MODULE_AVAILABLE = True

# ############################################################################
# """ Save configuration """
# ############################################################################
conf.contribs['ISOTP'] = \
    {'use-can-isotp-kernel-module': ISOTP_KERNEL_MODULE_AVAILABLE}

# ############################################################################
# """ reload ISOTP kernel module in case configuration changed """
# ############################################################################
if six.PY3:
    import importlib
    if "scapy.contrib.isotp" in sys.modules:
        importlib.reload(scapy.contrib.isotp)  # type: ignore  # noqa: F405

load_contrib("isotp", globals_dict=globals())

if six.PY3 and ISOTP_KERNEL_MODULE_AVAILABLE:
    if ISOTPSocket is not ISOTPNativeSocket:  # type: ignore
        raise Scapy_Exception("Error in ISOTPSocket import!")
else:
    if ISOTPSocket is not ISOTPSoftSocket:  # type: ignore
        raise Scapy_Exception("Error in ISOTPSocket import!")
Пример #5
0
from scapy.main import load_contrib

load_contrib("pnio_rpc")


class ProfinetIORPCFrame:
    def __init__(self):
        pass

    def getScapyProfinetIORPCFrame(self):
        # Frame =
        pass


def readIandM0():
    pass


def writeIandM0():
    pass


def readIandM1():
    pass


def writeIandM1():
    pass


class IOConnectionRequest():
Пример #6
0
from scapy.main import load_contrib

load_contrib("pnio_dcp")


class DCPBlock:
    def __init__(self, option, sub_option):
        pass
Пример #7
0
from scapy.contrib.pnio import ProfinetIO
from scapy.main import load_contrib

load_contrib("pnio")


class ProfinetIOFrame:
    def __init__(self, frameID):
        self.frameID = frameID

    def getScapyProfinetIOFrame(self):
        scapyProfinetIOFrame = ProfinetIO(frameID=self.frameID)
        scapyProfinetIOFrame.show()
        return scapyProfinetIOFrame