I have been trying to extract the Windows login password hint for Windows 7 programmatically and I came to know it can be retrieved from the following location in the registry HKLM\SAM\SAM\Domains\Account\Users\"userkey"\UserPasswordHint However, I am not able to figure out is there any way to find out userkey
for the currently logged-on user programmatically?
If you can get the current user name, it's quite easy, using the same registry tree.
Take a look in HKLM\SAM\SAM\Domains\Account\Users\Names\{username}
. The value of the entry would relate to the proper userkey
.
Of course remember the hint may not exist.
EDIT
Ha! Nailed it!
주석에서 말했듯이 적절한 값을 포함하는 노드의 값이 아니라 해당 노드의 기본 항목 유형입니다. 이 유형은 표준이 아니므로 C #으로 얻는 것은 불가능하지는 않지만 어렵습니다. 이 접근 방식에 문제가있어서 변경했습니다.
userkey
실제로 호출하는 16 진수 값 은 사용자 SID의 마지막 부분입니다 (이 부분을 RID라고 함). 내가 아는 한 모든 관리자는 RID = 500, 모든 게스트 = 501, 1000 또는 1001로 시작하는 일반 사용자는 지금 기억할 수 없습니다.
그리고 그것은 16 진수로 무엇입니까?
500 = 0x1f4
501 = 0x1f5
1000= 0x3e9
...
익숙해 보입니까?
그래서 우리가해야 할 일은 사용자의이 SID를 얻고, 흥미로운 부분을 추출하고, 그것을 패딩 된 16 진수 문자열로 변환하고 값을 검색하는 것입니다.
static void Main(string[] args)
{
SecurityIdentifier sid = System.Security.Principal.WindowsIdentity.GetCurrent().User;
var rid = sid.ToString().Split('-').Last();
var hexValue = int.Parse(rid).ToString("X").PadLeft(8, '0');
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SAM\SAM\Domains\Account\Users\"+hexValue);
try
{
var hint = key.GetValue("UserPasswordHint");
//...
}
catch (Exception)
{
Console.WriteLine("Could not access value");
}
}
조심해!
내가 아는 한 충분한 권한이 없으면 SAM 데이터베이스에 액세스 할 수 없습니다. 시스템 사용자 (예 :)로 실행하면 psexec -s yourbinary.exe
도움이되지만 현재 사용자가 변경되고 프로그램이 실패합니다. 따라서 흥미로운 사용자를 위해 실행하는 방법을 스스로 해결해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다