Polymorphic code: Difference between revisions

Content deleted Content added
No edit summary
Tags: Reverted Visual edit
Restored revision 1219374385 by A Shortfall Of Gravitas (talk): Unsourced sample
Line 17:
 
The first known polymorphic virus was written by Mark Washburn. The virus, called [[1260 (computer virus)|1260]], was written in 1990. A better-known polymorphic virus was created in 1992 by the hacker [[Dark Avenger]] as a means of avoiding pattern recognition from antivirus software. A common and very virulent polymorphic virus is the file infecter [[Virut]].
 
== Example of polymorphic code ==
<syntaxhighlight lang="python">
import os
from random import *
import hashlib
 
# Récupérer le contenu du script actuel
with open(__file__, 'r') as f:
code_source = f.read()
 
# Ouvrir le fichier en mode lecture binaire
with open(__file__, 'rb') as f:
# Lire le contenu du fichier
file_data = f.read()
 
# Calculer le hash SHA-256 du contenu du fichier
sha256_hash = hashlib.sha256(file_data).hexdigest()
 
# Afficher le hash calculé
print(f"Hash SHA-256 du fichier {__file__}: {sha256_hash}")
 
 
 
 
 
 
code_source = code_source.split('\n')
code_source = [ligne if not ligne.startswith('#') else f"#{choice(list(sha256_hash))}" for ligne in code_source]
code_source = '\n'.join(code_source)
print(code_source)
 
# Écrire le code source dans un fichier
with open(f"{sha256_hash}.py", 'w') as f:
f.write(code_source)
 
print(f"Le code source a été écrit dans le fichier '{sha256_hash}.py'.")
while True: input()
</syntaxhighlight>
 
== See also ==