class GameCommunicationPacket(PacketType): DEFINITION_IDENTIFIER = 'gamecommunication' DEFINITION_VERSION = '1.0' #zenith_nadir=0---command;zenith_nadir=1---response; FIELDS = [('zenith_nadir', INT32), ("commandd", STRING({Optional: True})), ('gameresponse', STRING({Optional: True})), ('statusgame', STRING({Optional: True}))]
class SPMPPacket(PacketType): DEFINITION_IDENTIFIER = "devices.management.SPMPPacket" DEFINITION_VERSION = "1.0" MAX_ID = (2**16) - 1 FIELDS = [ ("requestId", UINT16), ("request", STRING), ("args", LIST(STRING)), ("result", STRING), ("error", STRING({Optional: True})), # The security fields are generic on purpose. Different # security mechanisms have an arbitrary number of fields # For example, a security buffer could be a signature, # encrypted data, password data, etc. ("securityType", STRING({Optional: True})), ("security", LIST(BUFFER, {Optional: True})) ] def generateRequestId(self): self.requestId = random.randint(0, self.MAX_ID) def failed(self): return self.error != FIELD_NOT_SET
class CurAccessRequest(PacketType): DEFINITION_IDENTIFIER = "apps.bank.CurAccessRequest" DEFINITION_VERSION = "1.0" FIELDS = [ ("ClientNonce", UINT64), ("ServerNonce", UINT64), ("RequestId", UINT64), ("UserName", STRING({Optional: True})), ("AccountName", STRING({Optional: True})), ]
class PlsClose(PacketType): DEFINITION_IDENTIFIER = "netsecfall2017.pls.close" DEFINITION_VERSION = "1.0" FIELDS = [("Error", STRING({Optional: True}))] def __init__(self, err): super().__init__() self.Error = err
class HandshakePacket(PacketType): DEFINITION_IDENTIFIER = "handshakepacket" DEFINITION_VERSION = "1.0" NOT_STARTED = 0 SUCCESS = 1 ERROR = 2 FIELDS = [("SYN", UINT8({Optional: True})), ("ACK", UINT8({Optional: True})), ("status", UINT8), ("error", STRING({Optional: True}))]
class SITHPacket(PacketType): DEFINITION_IDENTIFIER = "SITH.kandarp.packet.Base" DEFINITION_VERSION = "1.0" TYPE_HELLO = "HELLO" TYPE_FINISH = "FINISH" TYPE_DATA = "DATA" TYPE_CLOSE = "CLOSE" FIELDS = [ ("Random", BUFFER({Optional: True})), #older version ("Type", STRING({Optional: True})), # HELLO, FINISH, DATA, CLOSE ("PublicValue", BUFFER({Optional: True})), #to store public key ("Certificate", LIST(BUFFER)({Optional: True})), #inherit older version 'Certs' ("Signature", BUFFER({Optional: True})), ("Ciphertext", BUFFER({Optional: True})) #inherit older version 'Ciphertext' ] @classmethod def makeHelloPacket(cls, random, certs, public_key): pkt = cls() pkt.Random = random pkt.Certificate = certs pkt.Type = cls.TYPE_HELLO pkt.PublicValue = public_key.public_bytes() #change the format of 'public_key' to bytes, in order to be stored in 'Buffer' field return pkt @classmethod def makeFinishPacket(cls, m1, m2, private_key): pkt = cls() hasher = hashes.Hash(hashes.SHA256(), backend = default_backend()) hasher.update(m1 + m2) #input message needed to hash hash_msg = hasher.finalize() # get the hash result signed_msg = private_key.sign( #generate the signature of messages by signing its hash hash_msg, ec.ECDSA(hashes.SHA256()) ) pkt.Type = cls.TYPE_FINISH pkt.Signature = signed_msg return pkt @classmethod def makeDataPacket(cls, ciphertext): pkt = cls() pkt.Ciphertext = ciphertext pkt.Type = cls.TYPE_DATA return pkt @classmethod def makeClosePacket(cls, error): pkt = cls() pkt.Ciphertext = bytes(error) pkt.Type = cls.TYPE_CLOSE return pkt
class VNICSocketOpenResponsePacket(VNICSocketControlPacket): DEFINITION_IDENTIFIER = "vsockets.VNICSocketOpenResponsePacket" DEFINITION_VERSION = "1.0" FIELDS = [("port", UINT16), ("errorCode", UINT8({Optional: True})), ("errorMessage", STRING({Optional: True}))] def isFailure(self): return (self.errorCode != FIELD_NOT_SET or self.errorMessage != FIELD_NOT_SET)
class AutogradeTestStatus(PacketType): DEFINITION_IDENTIFIER = "20194.exercise6.autogradesubmitresponse" DEFINITION_VERSION = "1.0" NOT_STARTED = 0 PASSED = 1 FAILED = 2 FIELDS = [("test_id", STRING), ("submit_status", UINT8), ("client_status", UINT8), ("server_status", UINT8), ("error", STRING({Optional: True}))]
class PlsClose(PacketBaseType): DEFINITION_IDENTIFIER = "netsecfall2017.pls.close" DEFINITION_VERSION = "1.0" FIELDS = [("Error", STRING({Optional: True}))] @staticmethod def create(Error=None): newPacket = PlsClose() if Error != None: newPacket.Error = Error return newPacket
class PassthroughPacket(PacketType): DEFINITION_IDENTIFIER = "passthroughpacket" DEFINITION_VERSION = "1.0" FIELDS = [ ("syn", BOOL({Optional: True})), ("ack", BOOL({Optional: True})), ("certificate", BUFFER({Optional: True})), ("public_key", BUFFER({Optional: True})), ("challenge", STRING({Optional: True})), ("signature", BUFFER({Optional: True})), ("seq_num", UINT16({Optional: True})), ]
class PlsClose(PlsBasicType): DEFINITION_IDENTIFIER = "netsecfall2017.pls.close" DEFINITION_VERSION = "1.0" FIELDS = [ ("Error", STRING({Optional:True})) ] @classmethod def makePlsClose(cls, error): pkt = cls() pkt.Error = error return pkt
class HandshakePacket(PoopPacketType ): #这个地方就不需要start那个packet了,因为这个packet的内容就包括了start中需要的内容 DEFINITION_IDENTIFIER = "poop.handshakepacket" DEFINITION_VERSION = "1.0" NOT_STARTED = 0 SUCCESS = 1 ERROR = 2 FIELDS = [ ("status", UINT8), ("SYN", UINT32({Optional: True})), ("ACK", UINT32({Optional: True})), ("error", STRING({Optional: True})), ("hash", UINT32), ]
class GameResponsePacket(PacketType): DEFINITION_IDENTIFIER = "exercise7.gameresponse" DEFINITION_VERSION = "1.0" FIELDS = [("response_string", STRING({Optional: True})), ("status_string", STRING)] @classmethod def create_game_response_packet(cls, response, status): return cls(response_string=response, status_string=status) def game_over(self): # MUST RETURN A BOOL return self.status_string in ("dead", "escaped") def status(self): # MUST RETURN game.status (as a string) return self.status_string def response(self): # MUST return game response as a string return self.response_string
class PlsClose(PLSPacket): DEFINITION_IDENTIFIER = 'netsecfall2017.pls.close' DEFINITION_VERSION = '1.0' FIELDS = [("Error", STRING({Optional: True}))]
class PlsClose(BasePacketType): DEFINITION_IDENTIFIER = "netsecfall2017.pls.close" DEFINITION_VERSION = "1.0" FIELDS = [("Error", STRING(Optional))]
class PlsClose(PlsBasePacket): DEFINITION_IDENTIFIER = "netsecfall2017.pls.close" DEFINITION_VERSION = "1.0" FIELDS = [("Error", STRING({Optional: True}))]
class ListUsers(PacketType): DEFINITION_IDENTIFIER = "apps.bank.ListUsers" DEFINITION_VERSION = "1.0" FIELDS = [("ClientNonce", UINT64), ("ServerNonce", UINT64), ("RequestId", UINT64), ("Account", STRING({Optional: True}))]