コード例 #1
0
def testString(inputValue):
    # Test the serialization function itself
    try:
        print(
            "\n{}Testing direct serialization and deserialization...{}".format(
                Color.BOLD, Color.END))
        serialized = Message.serializeByteArray(inputValue)
        deserialized = Message.deserializeByteArray(serialized)
        print("\tSerialized: {0}".format(serialized))
        print("\tBefore: {0}".format(str(inputValue)))
        print("\t After: {0}".format(str(deserialized)))
    except Exception as e:
        print("Caught exception running test: {}".format(str(e)))
        deserialized = ""
    printResult("Direct Serialization Test", inputValue == deserialized)

    # Also go a step further and test the inbound/outbound etc parsing
    try:
        print(
            "\n{}Testing full serialization with inbound/outbound lines...{}".
            format(Color.BOLD, Color.END))
        message = Message()
        message.direction = Message.Direction.Outbound
        message.setMessageFrom(Message.Format.Raw, bytearray(inputValue),
                               False)
        serialized = message.getSerialized()
        message.setFromSerialized(serialized)
        deserialized = message.getOriginalMessage()
        print("\tSerialized: {0}".format(serialized))
        print("\tBefore: {0}".format(str(inputValue)))
        print("\t After: {0}".format(str(deserialized)))
    except Exception as e:
        print("Caught exception running test: {}".format(str(e)))
        deserialized = ""
    printResult("Full Serialization Test", inputValue == deserialized)
コード例 #2
0
def sendPacket(connection, addr, outPacketData):
    connection.settimeout(fuzzerData.receiveTimeout)
    if connection.type == socket.SOCK_STREAM:
        connection.send(outPacketData)
    else:
        connection.sendto(outPacketData, addr)

    print "\tSent %d byte packet" % (len(outPacketData))
    if DEBUG_MODE:
        print "\tSent: %s" % (outPacketData)
        print "\tRaw Bytes: %s" % (Message.serializeByteArray(outPacketData))
コード例 #3
0
def main():
    allchars = bytearray('datadatadata unprintable chars:')
    for i in range (0, 256):
        allchars += chr(i)
    
    print("Testing serialization and deserialization...")
    serialized = Message.serializeByteArray(allchars)
    deserialized = Message.deserializeByteArray(serialized)
    print("Serialized: {0}".format(serialized))
    print("Before: {0}".format(str(allchars)))
    print(" After: {0}".format(str(deserialized)))
    
    print("Test: {0}".format("pass" if allchars == deserialized else "fail"))
コード例 #4
0
    def sendPacket(self, connection, addr, outPacketData):
        connection.settimeout(self.fuzzerData.receiveTimeout)
        if connection.type == socket.SOCK_STREAM:
            connection.send(outPacketData)
        elif connection.type == socket.SOCK_RAW:  #for L2raw clumsden start
            connection.send(
                outPacketData
            )  # clumsden, ran into trouble with this later and needed sendto(outPacketData,addr)...what it was orginally?
        else:
            connection.sendto(outPacketData, addr)

        print "\tSent %d byte packet" % (len(outPacketData))
        if DEBUG_MODE:
            print "\tSent: %s" % (outPacketData)
            print "\tRaw Bytes: %s" % (
                Message.serializeByteArray(outPacketData))