The invention belongs to the technical field of anti-attack of messages, and discloses an anti-attack method and system of a CAN bus message based on the block chain technology. The method comprises the following steps: improving an account book generated in a block chain, generating a password with a fixed length and updating the password in real time; performing, by each ECU, encryption processing on arbitration domain data monitored every time and a code book to obtain a new code book; before a message is sent, encrypting the data domain information via the latest code book to obtain an encrypted data domain, and finally sending the data domain; filtering, by the ECU, an identifier in the arbitration domain to obtain the necessary message, analyzing the message to obtain the encrypted data domain, and decrypting the encrypted data domain by using own code book; then judging the validity of the data obtained by decryption; and if the data are valid, executing the data, and otherwise,discarding the data. By adoption of the anti-attack method and system, the counterfeit, replay and other attacks can be defended, and the security of the vehicle is enhanced.