n4tuss3c

hardenSMB.ps1

Jan 11th, 2022 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.  
  3. TITLE - hardenSMB
  4.  
  5. FILENAME - hardensmb.ps1
  6.  
  7. DESCRIPTION - Disables SMBv1 protocol on server/workstation and enables SMBv2/3
  8.  
  9. AUTHOR -
  10.  
  11. COMPANY -
  12.  
  13. #>
  14.  
  15. Write-Host "*********************************************" -ForegroundColor Yellow
  16. Write-Host "  _                _          ___ __  __ ___  "
  17. Write-Host " | |_  __ _ _ _ __| |___ _ _ / __|  \/  | _ ) "
  18. Write-Host " | ' \/ _` | '_/ _` / -_) ' \\__ \ |\/| | _ \ "
  19. Write-Host " |_||_\__,_|_| \__,_\___|_||_|___/_|  |_|___/ "
  20. Write-Host "                                h4ck7h3pl@n37 "
  21. Write-Host "**********************************************" -ForegroundColor Yellow
  22.  
  23. Write-host "+++++++++++++++" -ForegroundColor Red
  24. Write-Host "INITIALIZING..."
  25. Write-host "+++++++++++++++" -ForegroundColor Red
  26. Start-Sleep -Seconds 3
  27.  
  28. $servers = Get-Content <path to server list file>
  29. $results = @()
  30.  
  31. Write-host "+++++++++++++++++++++" -ForegroundColor Red
  32. Write-Host "EXECUTING PROGRAM... "
  33. Write-Host "hold on to your butts"
  34. Write-host "+++++++++++++++++++++" -ForegroundColor Red
  35. Start-Sleep -Seconds 3
  36.  
  37.  
  38. foreach($server in $servers){
  39.     Write-Host "Pinging " $server -ForegroundColor Red
  40.     $ping = Test-Connection -Count 1 -ComputerName $server -ErrorAction SilentlyContinue
  41.  
  42.         if ( $ping -ne $null ){
  43.             Write-Host $server 'is up. Attemptin to JACK IN...' -ForegroundColor Yellow
  44.             $testSession = New-PSSession -ComputerName $server -ErrorAction SilentlyContinue
  45.  
  46.             if ( $testSession -ne $null ) {
  47.                 Write-Host 'Successful REMCON...Modifying Configuration' -ForegroundColor Green
  48.                 Invoke-Command -ComputerName $server -FilePath '<path to list of commands.ps1>'
  49.                 Write-Host 'SMBv1 disable and SMBv2/3 enable successful on ' $server -ForegroundColor Green
  50.                 $status = 'COMPLETED'
  51.            
  52.             } else {
  53.            
  54.                 write-host 'REMCON failure to ' $server -ForegroundColor Red
  55.                 $status = 'COULD NOT ESTABLISH REMOTE SESSION'
  56.                
  57.            
  58.             }
  59.        
  60.         } else {
  61.        
  62.             Write-Host $server ' appears to be down' -ForegroundColor red
  63.             $status = 'NO PING'
  64.        
  65.         }
  66.  
  67.         Write-Host 'Writing d3375 to 0u7pu7'
  68.         $itemDetails = [PSCustomObject]@{
  69.            
  70.             ServerName = $server
  71.             Status = $status
  72.        
  73.         }
  74.        
  75.         Write-Host '+++++++++++++++++++++'
  76.         Write-Host 'Compiling d3375 4rr4y' -ForegroundColor DarkYellow
  77.         Write-Host '+++++++++++++++++++++'
  78.  
  79.         $results += $itemDetails
  80. }
  81.  
  82. Write-Host '+++++++++++++++++++++' -ForegroundColor Green
  83. Write-Host 'Dropping d3375 to CSV'
  84. Write-Host '+++++++++++++++++++++' -ForegroundColor Green
  85.  
  86. $results | export-csv <output path>
Advertisement
Add Comment
Please, Sign In to add comment