Advertisement
Guest User

Untitled

a guest
May 15th, 2018
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. param(
  2. [Parameter(Mandatory=$true)][string]$user,
  3. [Parameter(Mandatory=$false)][string]$email
  4. )
  5.  
  6. function generate_password{
  7. #foreach ($line in $word) {if ($line.length -gt 8) {$line | out-file sorting.txt -append}}
  8. #foreach ($line in $word) {(Get-Culture).TextInfo.ToTitleCase($line) | out-file ordlista.txt -append}
  9. #get-content ordlista.txt | foreach { $_ + '123!' } | set-content ordlista.txt
  10. $wordlist = Get-Content .\ordlista.txt
  11. $password = Get-Random -InputObject $wordlist
  12. return $password
  13. }
  14.  
  15. Function Test-UserCredential {
  16. #creds > https://serverfault.com/questions/67706/tool-to-test-a-user-account-and-password-test-login
  17. Param($username, $password)
  18. Add-Type -AssemblyName System.DirectoryServices.AccountManagement
  19. $ct = [System.DirectoryServices.AccountManagement.ContextType]::Machine, $env:computername
  20. $opt = [System.DirectoryServices.AccountManagement.ContextOptions]::SimpleBind
  21. $pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ct
  22. $Result = $pc.ValidateCredentials($username, $password).ToString()
  23. return $Result
  24. }
  25.  
  26. function test_email($pass){
  27. $From = "awefawefabre@gmail.com"
  28. $To = $email
  29. $Cc = ""
  30. $Subject = "Password reset"
  31. $Body = "Your new password is: $pass "
  32. $SMTPServer = "smtp.gmail.com"
  33. $SMTPPort = "587"
  34. Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential)
  35. }
  36.  
  37. function google_email($pass){
  38. $EmailTo = $email
  39. $EmailFrom = "awefawefabre@gmail.com"
  40. $Subject = "password reset"
  41. $Body = "Your new password is:$password"
  42. $SMTPServer = "smtp.gmail.com"
  43. $SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
  44. $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
  45. $SMTPClient.EnableSsl = $true
  46. $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("awefawefabre@gmail.com", "Tesla123")
  47. $SMTPClient.Send($SMTPMessage)
  48. }
  49.  
  50. function main{
  51. $password = generate_password
  52. $securestring = ConvertTo-SecureString $password –asplaintext –force
  53. try{
  54. Set-ADAccountPassword $user -NewPassword $securestring -Reset -PassThru | Set-ADuser -PasswordNeverExpires $false | Set-ADuser -ChangePasswordAtLogon $True
  55. write-host '[*]Password changed....'
  56. }
  57. catch{
  58. write-host '[-]Cant find that user'
  59. return
  60. }
  61. $domain = ((gwmi Win32_ComputerSystem).Domain).Split(".")[0]
  62. write-host '[*]Validating new password...'
  63. $test = Test-UserCredential -username $domain\$user -password $password
  64. if($test){
  65. write-host "[+]Successful, new password is:$password"
  66. }
  67. else{
  68. write-host '[-]Error, password not changed'
  69. return
  70. }
  71.  
  72. if ($email){
  73. write-host '[*]Sending email..'
  74. try {
  75. google_email($password)
  76. write-host '[+]Email sent!'
  77. }
  78. catch{
  79. write-host '[-]Error sending mail'
  80. }
  81. }
  82.  
  83. }
  84.  
  85. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement