├── SharpZipAES ├── packages.config ├── app.config ├── Properties │ └── AssemblyInfo.cs ├── SharpZipAES.csproj └── Program.cs ├── SharpZipAES.sln ├── README.md ├── readme_en.md └── .gitignore /SharpZipAES/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SharpZipAES/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SharpZipAES/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("SharpZipAES")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpZipAES")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("bcef7be5-837d-4eef-9dc4-35042c320702")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SharpZipAES.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30114.105 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpZipAES", "SharpZipAES\SharpZipAES.csproj", "{BCEF7BE5-837D-4EEF-9DC4-35042C320702}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {BCEF7BE5-837D-4EEF-9DC4-35042C320702}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {BCEF7BE5-837D-4EEF-9DC4-35042C320702}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {BCEF7BE5-837D-4EEF-9DC4-35042C320702}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {BCEF7BE5-837D-4EEF-9DC4-35042C320702}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {EE4770F7-A752-4066-953D-84F4FA022FB7} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SharpZipAES/SharpZipAES.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {BCEF7BE5-837D-4EEF-9DC4-35042C320702} 8 | Exe 9 | SharpZipAES 10 | SharpZipAES 11 | v4.5 12 | 512 13 | true 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | false 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SharpZipAES 2 | 3 | [English](https://github.com/yutianqaq/SharpZipAES/blob/main/readme_en.md) 简体中文 4 | 5 | 使用 csharp (.net 4.5)开发的工具,用于压缩和加密文件,以缩短传输时间。支持多文件压缩和加密、单文件压缩、目录压缩和加密。 6 | 7 | ## 特点 8 | 9 | - 仅 10 kb 10 | - 无需落地 11 | - 更安全的加密方式 12 | 13 | ``` 14 | .\SharpZipAES.exe 15 | Author: Yutian 16 | Github: https://github.com/yutianqaq/SharpZipAES 17 | [-] Usage: 18 | SharpZipAES.exe encrypt 19 | SharpZipAES.exe decrypt 20 | ``` 21 | 22 | ## 多个文件压缩并加密 23 | ```powershell 24 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe encrypt Password1 .\SharpZipAES.exe .\SharpZipAES.exe.config .\SharpZipAES.pdb 25 | Author: Yutian 26 | [+] Wrote encrypted archive 27 | [+] Packed compressed file 28 | [+] Packed compressed file to swvHxCvZ.zip succeeded 29 | [+] Wrote encrypted archive swvHxCvZ.aes.zip to disk! 30 | [+] Removed encryption key from memory 31 | [+] Deleted unecrypted archive 32 | [+] Ready for exfil 33 | [+] Program run time is: 00:00:00.3377748 34 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe decrypt Password1 .\swvHxCvZ.aes.zip 35 | Author: Yutian 36 | [+] Wrote encrypted archive 37 | [+] Decrypting .\swvHxCvZ.aes.zip 38 | [+] Decrypted swvHxCvZ.zip successfully! 39 | [+] Program run time is: 00:00:00.3165076 40 | ``` 41 | 42 | ## 单个文件压缩并加密 43 | ```powershell 44 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe encrypt Password1 .\SharpZipAES.exe 45 | Author: Yutian 46 | [+] Wrote encrypted archive 47 | [+] Packed compressed file 48 | [+] Packed compressed file to MGvmLoY2.zip succeeded 49 | [+] Wrote encrypted archive MGvmLoY2.aes.zip to disk! 50 | [+] Removed encryption key from memory 51 | [+] Deleted unecrypted archive 52 | [+] Ready for exfil 53 | [+] Program run time is: 00:00:00.3319586 54 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe decrypt Password1 .\MGvmLoY2.aes.zip 55 | Author: Yutian 56 | [+] Wrote encrypted archive 57 | [+] Decrypting .\MGvmLoY2.aes.zip 58 | [+] Decrypted MGvmLoY2.zip successfully! 59 | [+] Program run time is: 00:00:00.3204786 60 | ``` 61 | 62 | ## 目录压缩并加密 63 | 64 | ```powershell 65 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe encrypt Password1 .\Test\ 66 | Author: Yutian 67 | [+] Wrote encrypted archive 68 | [+] Packed compressed directory to tvdOAOZP.zip succeeded 69 | [+] Wrote encrypted archive tvdOAOZP.aes.zip to disk! 70 | [+] Removed encryption key from memory 71 | [+] Deleted unecrypted archive 72 | [+] Ready for exfil 73 | [+] Program run time is: 00:00:31.9781834 74 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe decrypt Password1 .\tvdOAOZP.aes.zip 75 | Author: Yutian 76 | [+] Wrote encrypted archive 77 | [+] Decrypting .\tvdOAOZP.aes.zip 78 | [+] Decrypted tvdOAOZP.zip successfully! 79 | [+] Program run time is: 00:00:11.5933884 80 | ``` 81 | 82 | 83 | 84 | # References 85 | 86 | https://github.com/uknowsec/SharpZip 87 | 88 | https://github.com/matterpreter/OffensiveCSharp 89 | -------------------------------------------------------------------------------- /readme_en.md: -------------------------------------------------------------------------------- 1 | # SharpZipAES 2 | 3 | English [简体中文](https://github.com/yutianqaq/SharpZipAES/blob/main/README.md) 4 | 5 | 6 | Tool developed using csharp (.net 4.5) for compressing and encrypting files to shorten transfer times. Supports multi-file compression and encryption, single-file compression, and directory compression. 7 | 8 | ## feature 9 | - Only 10 KB in size 10 | - No need for disk interaction 11 | - More secure encryption method 12 | 13 | ``` 14 | .\SharpZipAES.exe 15 | Author: Yutian 16 | Github: https://github.com/yutianqaq/SharpZipAES 17 | [-] Usage: 18 | SharpZipAES.exe encrypt 19 | SharpZipAES.exe decrypt 20 | ``` 21 | 22 | ## Multiple file compression and encryption 23 | ```powershell 24 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe encrypt Password1 .\SharpZipAES.exe .\SharpZipAES.exe.config .\SharpZipAES.pdb 25 | Author: Yutian 26 | [+] Wrote encrypted archive 27 | [+] Packed compressed file 28 | [+] Packed compressed file to swvHxCvZ.zip succeeded 29 | [+] Wrote encrypted archive swvHxCvZ.aes.zip to disk! 30 | [+] Removed encryption key from memory 31 | [+] Deleted unecrypted archive 32 | [+] Ready for exfil 33 | [+] Program run time is: 00:00:00.3377748 34 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe decrypt Password1 .\swvHxCvZ.aes.zip 35 | Author: Yutian 36 | [+] Wrote encrypted archive 37 | [+] Decrypting .\swvHxCvZ.aes.zip 38 | [+] Decrypted swvHxCvZ.zip successfully! 39 | [+] Program run time is: 00:00:00.3165076 40 | ``` 41 | 42 | ## Single file compression and encryption 43 | ```powershell 44 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe encrypt Password1 .\SharpZipAES.exe 45 | Author: Yutian 46 | [+] Wrote encrypted archive 47 | [+] Packed compressed file 48 | [+] Packed compressed file to MGvmLoY2.zip succeeded 49 | [+] Wrote encrypted archive MGvmLoY2.aes.zip to disk! 50 | [+] Removed encryption key from memory 51 | [+] Deleted unecrypted archive 52 | [+] Ready for exfil 53 | [+] Program run time is: 00:00:00.3319586 54 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe decrypt Password1 .\MGvmLoY2.aes.zip 55 | Author: Yutian 56 | [+] Wrote encrypted archive 57 | [+] Decrypting .\MGvmLoY2.aes.zip 58 | [+] Decrypted MGvmLoY2.zip successfully! 59 | [+] Program run time is: 00:00:00.3204786 60 | ``` 61 | 62 | ## Directory compression and encryption 63 | 64 | ```powershell 65 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe encrypt Password1 .\Test\ 66 | Author: Yutian 67 | [+] Wrote encrypted archive 68 | [+] Packed compressed directory to tvdOAOZP.zip succeeded 69 | [+] Wrote encrypted archive tvdOAOZP.aes.zip to disk! 70 | [+] Removed encryption key from memory 71 | [+] Deleted unecrypted archive 72 | [+] Ready for exfil 73 | [+] Program run time is: 00:00:31.9781834 74 | PS C:\Users\havoc\Desktop\SharpZipAES\SharpZipAES\bin\Release> .\SharpZipAES.exe decrypt Password1 .\tvdOAOZP.aes.zip 75 | Author: Yutian 76 | [+] Wrote encrypted archive 77 | [+] Decrypting .\tvdOAOZP.aes.zip 78 | [+] Decrypted tvdOAOZP.zip successfully! 79 | [+] Program run time is: 00:00:11.5933884 80 | ``` 81 | 82 | 83 | 84 | # References 85 | 86 | https://github.com/uknowsec/SharpZip 87 | 88 | https://github.com/matterpreter/OffensiveCSharp 89 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc 262 | 263 | .DS_Store 264 | bin/ 265 | -------------------------------------------------------------------------------- /SharpZipAES/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.IO.Compression; 6 | using System.Linq; 7 | using System.Runtime.InteropServices; 8 | using System.Security.Cryptography; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace SharpZipAES 13 | { 14 | class Program 15 | { 16 | [DllImport("kernel32.dll", EntryPoint = "RtlZeroMemory")] 17 | public static extern bool RtlZeroMemory(IntPtr Destination, int Length); 18 | 19 | public static byte[] GenerateSalt() 20 | { 21 | byte[] data = new byte[32]; 22 | RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); 23 | for (int i = 0; i < 10; i++) 24 | { 25 | rng.GetBytes(data); 26 | } 27 | return data; 28 | } 29 | 30 | public static void Encrypter(string inputFile, string password) 31 | { 32 | 33 | FileStream fsCrypt = new FileStream(Path.GetFileNameWithoutExtension(inputFile) + ".aes.zip", FileMode.Create); //Output.aes.zip 34 | byte[] passwordBytes = Encoding.UTF8.GetBytes(password); 35 | 36 | //Setup AES256 CFB 37 | RijndaelManaged AES = new RijndaelManaged(); 38 | AES.KeySize = 256; 39 | AES.BlockSize = 128; 40 | AES.Padding = PaddingMode.PKCS7; 41 | byte[] salt = GenerateSalt(); 42 | var key = new Rfc2898DeriveBytes(passwordBytes, salt, 50000); //PBKDF2 43 | AES.Key = key.GetBytes(AES.KeySize / 8); 44 | AES.IV = key.GetBytes(AES.BlockSize / 8); 45 | AES.Mode = CipherMode.CFB; 46 | 47 | fsCrypt.Write(salt, 0, salt.Length); 48 | CryptoStream cs = new CryptoStream(fsCrypt, AES.CreateEncryptor(), CryptoStreamMode.Write); 49 | FileStream fs = new FileStream(inputFile, FileMode.Open); 50 | 51 | byte[] buffer = new byte[1048576]; //Allocate 1MB instead of the whole target file 52 | int read; 53 | 54 | try 55 | { 56 | while ((read = fs.Read(buffer, 0, buffer.Length)) > 0) 57 | { 58 | cs.Write(buffer, 0, read); 59 | } 60 | fs.Close(); 61 | } 62 | catch (Exception e) 63 | { 64 | Console.WriteLine("Error: " + e.Message); 65 | } 66 | finally 67 | { 68 | cs.Close(); 69 | fsCrypt.Close(); 70 | } 71 | 72 | } 73 | 74 | public static void Decrypter(string inputFile, string outputFile, string password) 75 | { 76 | byte[] passwordBytes = Encoding.UTF8.GetBytes(password); 77 | byte[] salt = new byte[32]; 78 | 79 | FileStream fsCrypt = new FileStream(inputFile, FileMode.Open); 80 | fsCrypt.Read(salt, 0, salt.Length); 81 | RijndaelManaged AES = new RijndaelManaged(); 82 | AES.KeySize = 256; 83 | AES.BlockSize = 128; 84 | var key = new Rfc2898DeriveBytes(passwordBytes, salt, 50000); 85 | AES.Key = key.GetBytes(AES.KeySize / 8); 86 | AES.IV = key.GetBytes(AES.BlockSize / 8); 87 | AES.Padding = PaddingMode.PKCS7; 88 | AES.Mode = CipherMode.CFB; 89 | 90 | CryptoStream cs = new CryptoStream(fsCrypt, AES.CreateDecryptor(), CryptoStreamMode.Read); 91 | FileStream fs = new FileStream(outputFile, FileMode.Create); 92 | 93 | byte[] buffer = new byte[1048576]; 94 | int read; 95 | 96 | try 97 | { 98 | while ((read = cs.Read(buffer, 0, buffer.Length)) > 0) 99 | { 100 | fs.Write(buffer, 0, read); 101 | } 102 | } 103 | catch (CryptographicException ex_CryptographicException) 104 | { 105 | Console.WriteLine("[-] Error decrypting the archive: " + ex_CryptographicException.Message); 106 | return; //Usually due to invalid key 107 | } 108 | catch (Exception e) 109 | { 110 | Console.WriteLine("[-] Error: " + e.Message); 111 | return; 112 | } 113 | 114 | try 115 | { 116 | cs.Close(); 117 | } 118 | catch (Exception e) 119 | { 120 | Console.WriteLine("[-] Error closing the crypto stream: " + e.Message); 121 | return; 122 | } 123 | finally 124 | { 125 | fs.Close(); 126 | fsCrypt.Close(); 127 | } 128 | } 129 | 130 | public static void Zipfiles(List filepathlist, string zipnamepath, string passwordd) 131 | { 132 | try 133 | { 134 | using (var zip = ZipFile.Open(zipnamepath, ZipArchiveMode.Create)) 135 | { 136 | 137 | foreach (string filepath in filepathlist) 138 | { 139 | string filename = Path.GetFileName(filepath); 140 | zip.CreateEntryFromFile(filepath, filename); 141 | } 142 | } 143 | Encrypter(zipnamepath, passwordd); 144 | 145 | Console.WriteLine("[+] Packed compressed file to {0} succeeded", zipnamepath); 146 | Console.WriteLine("[+] Wrote encrypted archive " + Path.GetFileNameWithoutExtension(zipnamepath) + ".aes.zip to disk!"); 147 | File.Delete(zipnamepath); 148 | 149 | 150 | } 151 | catch (Exception ex) 152 | { 153 | Console.WriteLine(" [-] Failed with error info: {0}", ex.Message); 154 | } 155 | 156 | } 157 | 158 | public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, string password) 159 | { 160 | try 161 | { 162 | ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName); 163 | Console.WriteLine("[+] Packed compressed directory to {0} succeeded", destinationArchiveFileName); 164 | Encrypter(destinationArchiveFileName, password); 165 | 166 | Console.WriteLine("[+] Wrote encrypted archive " + Path.GetFileNameWithoutExtension(destinationArchiveFileName) + ".aes.zip to disk!"); 167 | File.Delete(destinationArchiveFileName); 168 | } 169 | catch (Exception ex) 170 | { 171 | Console.WriteLine(" [-] Failed with error info: {0}", ex.Message); 172 | } 173 | } 174 | 175 | static void Main(string[] args) 176 | { 177 | Stopwatch stopwatch = new Stopwatch(); 178 | stopwatch.Start(); 179 | 180 | 181 | Console.WriteLine("Author: Yutian"); 182 | Console.WriteLine("Github: https://github.com/yutianqaq/SharpZipAES"); 183 | string usage = "[-] Usage:\n" + 184 | " SharpZipAES.exe encrypt \n" + 185 | " SharpZipAES.exe decrypt "; 186 | 187 | if (args.Length < 3) 188 | { 189 | Console.WriteLine(usage); 190 | return; 191 | } 192 | 193 | if (args[0].ToLower() == "encrypt") 194 | { 195 | Console.WriteLine("[+] Wrote encrypted archive "); 196 | //Generate a random filename for the archive 197 | Random random = new Random(); 198 | string characters = "0123456789"; 199 | characters += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 200 | characters += "abcdefghijklmnopqrstuvwxyz"; 201 | StringBuilder randomName = new StringBuilder(8); 202 | for (int i = 0; i < 8; i++) 203 | { 204 | randomName.Append(characters[random.Next(characters.Length)]); 205 | } 206 | string archiveName = randomName.ToString() + ".zip"; 207 | string passwd = args[1]; 208 | GCHandle handle = GCHandle.Alloc(passwd, GCHandleType.Pinned); //Pin the password 209 | 210 | if (!Path.HasExtension(args[2])) 211 | { 212 | CreateFromDirectory(args[2], archiveName, passwd); 213 | } 214 | else 215 | { 216 | Console.WriteLine("[+] Packed compressed file"); 217 | List list = new List(); 218 | for (int i = 2; i < args.Length; i++) 219 | { 220 | list.Add(args[i]); 221 | } 222 | Zipfiles(list, archiveName, passwd); 223 | } 224 | 225 | //Cleanup 226 | RtlZeroMemory(handle.AddrOfPinnedObject(), passwd.Length * 2); //Zero out the pinned password on the heap 227 | handle.Free(); 228 | Console.WriteLine("[+] Removed encryption key from memory"); 229 | Console.WriteLine("[+] Deleted unecrypted archive"); 230 | 231 | Console.WriteLine("[+] Ready for exfil"); 232 | 233 | 234 | } 235 | else if (args[0].ToLower() == "decrypt") 236 | { 237 | Console.WriteLine("[+] Decrypting " + args[2]); 238 | string[] fileName = (Path.GetFileNameWithoutExtension(args[2])).Split('.'); 239 | string outFile = fileName[0] + ".zip"; 240 | try 241 | { 242 | Decrypter(args[2], outFile, args[1]); 243 | Console.WriteLine("[+] Decrypted {0} successfully!", outFile); 244 | } 245 | catch 246 | { 247 | Console.WriteLine("[-] Something went wrong decrypting the file."); 248 | return; 249 | } 250 | } 251 | else 252 | { 253 | Console.WriteLine(usage); 254 | return; 255 | } 256 | 257 | 258 | stopwatch.Stop(); 259 | Console.WriteLine("[+] Program run time is: " + stopwatch.Elapsed); 260 | 261 | } 262 | } 263 | } 264 | --------------------------------------------------------------------------------