用於證書管理git
支持環境: XP - Windows 10 全系統github
更多:https://technet.microsoft.com/zh-cn/library/cc755341(v=ws.10).aspxshell
(1) 保存在當前路徑,文件名稱同URLc#
eg:windows
certutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/version.txt
緩存
(2) 保存在當前路徑,指定保存文件名稱工具
eg:開發工具
certutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/version.txt file.txt
測試
(3) 保存在緩存目錄,名稱隨機編碼
緩存目錄位置: %USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content
eg:
certutil.exe -urlcache -f https://raw.githubusercontent.com/3gstudent/test/master/version.txt
(4) 支持保存二進制文件
eg:
certutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg.dll
注:
使用downloader默認在緩存目錄位置: %USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content
保存下載的文件副本
清除下載文件副本方法:
方法1: 直接刪除緩存目錄對應文件
以下圖
方法2: 命令行:
certutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg.dll delete
補充:
查看緩存項目:
certutil.exe -urlcache *
以下圖
實際測試:
測試系統安裝Office軟件,下載執行dll對應的powershell代碼以下:
$path="c:\test\msg1.dll" certutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg.dll $path $excel = [activator]::CreateInstance([type]::GetTypeFromProgID("Excel.Application")) $excel.RegisterXLL($path)
測試以下:
(1) SHA1
certutil.exe -hashfile msg.dll
(2) SHA256:
certutil.exe -hashfile msg.dll SHA256
(3) MD5:
certutil.exe -hashfile msg.dll MD5
(1) base64編碼:
CertUtil -encode InFile OutFile
(2) base64解碼
CertUtil -decode InFile OutFile
注:
編碼後的文件會添加兩處標識信息:
文件頭:
-----BEGIN CERTIFICATE-----
文件尾:
-----END CERTIFICATE-----
以下圖
利用certUtil簡便快捷,可是使用後須要注意清除緩存,路徑以下:
%USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content
downloader經常使用方法以下:
在編寫腳本操做二進制文件時,經常會由於不可見字符報錯,因此一般會選擇先對二進制文件做base64編碼再操做,最後經過解碼還原出二進制文件。
因此在此整理一下經常使用不一樣開發工具對應的base64編碼轉換方式
base64編碼:
$PEBytes = [System.IO.File]::ReadAllBytes("C:\windows\system32\calc.exe") $Base64Payload = [System.Convert]::ToBase64String($PEBytes) Set-Content base64.txt -Value $Base64Payload
base64解碼:
$Base64Bytes = Get-Content ("base64.txt") $PEBytes= [System.Convert]::FromBase64String($Base64Bytes) [System.IO.File]::WriteAllBytes("calc.exe",$PEBytes)
base64編碼:
using System.IO; byte[] AsBytes = File.ReadAllBytes(@"C:\windows\system32\calc.exe"); String AsBase64String = Convert.ToBase64String(AsBytes); StreamWriter sw = new StreamWriter(@"C:\test\base64.txt"); sw.Write(AsBase64String); sw.Close();
base64解碼:
using System.IO; String AsString = File.ReadAllText(@"C:\test\base64.txt"); byte[] bytes = Convert.FromBase64String(AsString); FileStream fs = new FileStream(@"C:\test\calc.exe", FileMode.Create); fs.Write(bytes, 0, bytes.Length); fs.Flush(); fs.Close();
base64解碼:
fso1=new ActiveXObject("Scripting.FileSystemObject"); f=fso1.OpenTextFile("C:\\test\\base64.txt",1); base64string=f.ReadAll(); f.Close(); enc = new ActiveXObject("System.Text.ASCIIEncoding"); length = enc.GetByteCount_2(base64string); ba = enc.GetBytes_4(base64string); transform = new ActiveXObject("System.Security.Cryptography.FromBase64Transform"); ba = transform.TransformFinalBlock(ba, 0, length); s=new ActiveXObject("ADODB.Stream"); s.Type=1; s.Open(); s.Write(ba); s.SaveToFile("C:\\test\\calc.exe",2);
base64編碼:
CertUtil -encode InFile OutFile
base64解碼:
CertUtil -decode InFile OutFile
注:
編碼後的文件會添加兩處標識信息:
文件頭:
—–BEGIN CERTIFICATE—–
文件尾:
—–END CERTIFICATE—–
查看利用certUtil下載文件的緩存記錄:
certutil.exe -urlcache *
緩存文件位置:
%USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content