Credits
This blog post would not be possible without the groundwork from Ryan Butler and Carl Stalhood. Ryan created the initial script and Carl provided me with a current SSL cipher list for Q2 2023.
Updates and tests
Last year, I had a few new Citrix NetScaler Gateway VPX setups, and needed a fast way to get the SSL settings right. Most of the time I used the script by Ryan, but in the meantime it was outdated. I grabbed the script and the provided SSL cipher list by Carl and got a working copy that immediately scored an A+ at SSL Labs. Sadly, I did not take my time to create a pull request over at Ryan’s GitHub to give back. Today I took my time, to tidy up the code, thanks to the Visual Studio Code PowerShell formatter and write up the changelog.
I tested the latest version of the script against a NetScaler 13.1 VPX (NS13.1 33.47.nc) without any issues. The instance was pre-configured with the previous version of the script. The previous script provided me a B at SSL Labs.

After I let the latest version of the script optimize the VPX appliance, we are back to an A+. Example:
.\set-nsssl.ps1 -nsip "192.168.0.5" -adminpassword "secret" -enablesslprof -nolb -nocsw -ciphergroupname "custom-ssllabs-cipher-2022" -sslprofile "custom-ssllabs-profile-2022" -nosave

The script
The latest version of the script that contains my Pull Request can be found over at Ryan’s GitHub and embedded here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 |
<#PSScriptInfo .VERSION 1.4 .GUID 2a8be02b-621b-46be-9f20-c373a3882927 .AUTHOR @ryan_c_butler .AUTHOR Marco Hofmann @xenadmin (www.meinekleinefarm.net) .COMPANYNAME Techdrabble.com .COPYRIGHT 2016-2022 .TAGS Netscaler REST SSL A SSLLABS .LICENSEURI https://github.com/ryancbutler/Citrix/blob/master/License.txt .PROJECTURI https://github.com/ryancbutler/Citrix .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES 03-17-16: Added port 3008 and 3009 to managment ips 03-28-16: Rewrite to reflect PS best practice and managment IP ciphers 06-13-16: Adjusted to reflect https://www.citrix.com/blogs/2016/06/09/scoring-an-a-at-ssllabs-com-with-citrix-netscaler-2016-update/. Also removed management IPS from default. (Tested with 11.0 65.31) 06-14-16: Now supports HTTPS 07-02-16: Added "nosave" paramenter 03-11-17: Default SSL profile additions for 11.1 and greater 06-02-17: Changes for default profile and add for policy priority argument. Also added some error handling 08-27-17: Formatting for PS Gallery 01-27-18: Adjustment for default profile version https://support.citrix.com/article/CTX205291 06-15-22: Updated cipher groups for an A+ at SSLlabs.com - Q2/2023 (Marco Hofmann @xenadmin) 04-04-23: Re-worked formatting. (Marco Hofmann @xenadmin) 04-04-23: NetScaler 13.1 doesn't know SSLv2 anymore, so trying to disable it throws errors. Commented out for now. (Marco Hofmann @xenadmin) #> <# .SYNOPSIS A PowerShell script for hardening Netscaler SSL IPs based off of SSL LABS .DESCRIPTION A PowerShell script that enables TLS 1.2 and TLS 1.3, disables SSLv2, SSLv3, TLS1 and TLS 1.1, creates and binds Diffie-Hellman (DH) key, creates and binds "Strict Transport Security policy" and removes all other ciphers and binds cipher group mentioned in https://www.citrix.com/blogs/2015/05/22/scoring-an-a-at-ssllabs-com-with-citrix-netscaler-the-sequel/ .PARAMETER nsip DNS Name or IP of the Netscaler that needs to be configured. (MANDATORY) .PARAMETER adminaccount Netscaler admin account (Default: nsroot) .PARAMETER adminpassword Password for the Netscaler admin account (Default: nsroot) .PARAMETER https Use HTTPS for communication .PARAMETER ciphergroupname Cipher group name to search for (Default: "custom-ssllabs-cipher") .PARAMETER rwactname ReWrite action name (Default: "act-sts-header") .PARAMETER rwpolname ReWrite policy name (Default: "pol-sts-force") .PARAMETER rwpolpri ReWrite policy bind priority (Default: 50) .PARAMETER dhname DH Key to be used (Default: "dhkey2048.key") .PARAMETER sslprofile SSL Profile to be used (11.1 or greater)(Default: "custom-ssllabs-profile") .PARAMETER enablesslprof Enables SSL Default Profile (11.1 or greater) .PARAMETER mgmt Perform changes on Netsclaer managment IP .PARAMETER nolb Do not perform changes on Netscaler Load Balanced SSL VIPs .PARAMETER nocsw Do not perform changes on Netscaler Content Switch VIPs .PARAMETER novpn Do not perofm change on Netscaler VPN\Netscaler Gateway VIPs .PARAMETER noneg Do not adjust SSL renegotiation .PARAMETER nosave Do not save nsconfig at the end of the script .EXAMPLE Defaults .\set-nsssl -nsip 10.1.1.2 .EXAMPLE Enables Default SSL profile and configures Netscaler (11.1 or greater) with defaults using SSL profiles .\set-nsssl -nsip 10.1.1.2 -enablesslprof .EXAMPLE Uses HTTPs for NSIP communication .\set-nsssl -nsip 10.1.1.2 -https .Example Only can be used for 11.1 and greater .\set-nsssl.ps1 -nsip 192.168.50 -ciphergroupname superciphergroup -sslprofile myssllabsprofile .EXAMPLE .\set-nsssl -nsip 10.1.1.2 -adminaccount nsadmin -adminpassword "mysupersecretpassword" -ciphergroupname "mynewciphers" -rwactname "rw-actionnew" -rwpolname "rw-polnamenew" -dhname "mydhey.key" -mgmt -nocsw #> Param ( [Parameter(Mandatory = $true)]$nsip, [String]$adminaccount = "nsroot", [String]$adminpassword = "nsroot", [switch]$https, [string]$ciphergroupname = "custom-ssllabs-cipher", [string]$rwactname = "act-sts-header", [string]$rwpolname = "pol-sts-force", [string]$rwpolpri = "100", [string]$dhname = "dhkey2048.key", [string]$sslprofile = "custom-ssllabs-profile", [switch]$enablesslprof, [switch]$mgmt, [switch]$nolb, [switch]$nocsw, [switch]$novpn, [switch]$noneg, [switch]$nosave ) #Netscaler NSIP login information if ($https) { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } write-host "Connecting HTTPS" -ForegroundColor Yellow $hostname = "https://" + $nsip } else { write-host "Connecting HTTP" -ForegroundColor Yellow $hostname = "http://" + $nsip } $username = $adminaccount $password = $adminpassword ##Functions ############################### #Probably not much you have to edit below this ############################### #Many functions pulled from http://www.carlstalhood.com/netscaler-scripting/ function Login { # Login to NetScaler and save session to global variable $body = ConvertTo-JSON @{ "login" = @{ "username" = "$username"; "password" = "$password" } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/login" -body $body -SessionVariable NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.login+json" } -Method POST | Out-Null $Script:NSSession = $local:NSSession } Catch { throw $_ } } function Cipher ($Name, $Cipher) { # Support function called by CipherGroup $body = @{ "sslcipher_binding" = [ordered]@{ "ciphergroupname" = "$Name"; "ciphername" = "$Cipher"; } } $body = ConvertTo-JSON $body try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslcipher_binding/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslcipher_binding+json" } -Method PUT | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } function get-ciphers ($Name) { #Get cipher groups already on netscaler try { $ciphers = Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslcipher" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } return $ciphers.sslcipher } function CipherGroup ($Name) { $body = @{ "sslcipher" = @{ "ciphergroupname" = "$Name"; } } $body = ConvertTo-JSON $body try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslcipher?action=add" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslcipher+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } #feel free to edit these Cipher $Name TLS1.3-AES256-GCM-SHA384 Cipher $Name TLS1.3-CHACHA20-POLY1305-SHA256 Cipher $Name TLS1.3-AES128-GCM-SHA256 Cipher $Name TLS1.2-ECDHE-ECDSA-AES128-GCM-SHA256 Cipher $Name TLS1.2-ECDHE-ECDSA-AES256-GCM-SHA384 Cipher $Name TLS1.2-ECDHE-ECDSA-AES128-SHA256 Cipher $Name TLS1.2-ECDHE-ECDSA-AES256-SHA384 Cipher $Name TLS1-ECDHE-ECDSA-AES128-SHA Cipher $Name TLS1-ECDHE-ECDSA-AES256-SHA Cipher $Name TLS1.2-ECDHE-RSA-AES128-GCM-SHA256 Cipher $Name TLS1.2-ECDHE-RSA-AES256-GCM-SHA384 Cipher $Name TLS1.2-ECDHE-RSA-AES-128-SHA256 Cipher $Name TLS1.2-ECDHE-RSA-AES-256-SHA384 Cipher $Name TLS1-ECDHE-RSA-AES128-SHA Cipher $Name TLS1-ECDHE-RSA-AES256-SHA Cipher $Name TLS1.2-DHE-RSA-AES128-GCM-SHA256 Cipher $Name TLS1.2-DHE-RSA-AES256-GCM-SHA384 Cipher $Name TLS1-DHE-RSA-AES-128-CBC-SHA Cipher $Name TLS1-DHE-RSA-AES-256-CBC-SHA Cipher $Name TLS1-AES-128-CBC-SHA Cipher $Name TLS1-AES-256-CBC-SHA } function CipherGroup-vpx ($Name) { $body = @{ "sslcipher" = @{ "ciphergroupname" = "$Name"; } } $body = ConvertTo-JSON $body try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslcipher?action=add" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslcipher+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } #feel free to edit these Cipher $Name TLS1.3-AES256-GCM-SHA384 Cipher $Name TLS1.3-CHACHA20-POLY1305-SHA256 Cipher $Name TLS1.3-AES128-GCM-SHA256 Cipher $Name TLS1.2-ECDHE-ECDSA-AES128-GCM-SHA256 Cipher $Name TLS1.2-ECDHE-ECDSA-AES256-GCM-SHA384 Cipher $Name TLS1.2-ECDHE-ECDSA-AES128-SHA256 Cipher $Name TLS1.2-ECDHE-ECDSA-AES256-SHA384 Cipher $Name TLS1-ECDHE-ECDSA-AES128-SHA Cipher $Name TLS1-ECDHE-ECDSA-AES256-SHA Cipher $Name TLS1.2-ECDHE-RSA-AES128-GCM-SHA256 Cipher $Name TLS1.2-ECDHE-RSA-AES256-GCM-SHA384 Cipher $Name TLS1.2-ECDHE-RSA-AES-128-SHA256 Cipher $Name TLS1.2-ECDHE-RSA-AES-256-SHA384 Cipher $Name TLS1-ECDHE-RSA-AES128-SHA Cipher $Name TLS1-ECDHE-RSA-AES256-SHA Cipher $Name TLS1.2-DHE-RSA-AES128-GCM-SHA256 Cipher $Name TLS1.2-DHE-RSA-AES256-GCM-SHA384 Cipher $Name TLS1-DHE-RSA-AES-128-CBC-SHA Cipher $Name TLS1-DHE-RSA-AES-256-CBC-SHA Cipher $Name TLS1-AES-128-CBC-SHA Cipher $Name TLS1-AES-256-CBC-SHA } function get-vpnservers { #gets netscaler gateway VIPs try { $vips = Invoke-RestMethod -uri "$hostname/nitro/v1/config/vpnvserver" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } return $vips.vpnvserver } function get-vservers { #gets load balancers try { $vips = Invoke-RestMethod -uri "$hostname/nitro/v1/config/lbvserver" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } return $vips.lbvserver } function get-csservers { #gets content switches try { $vips = Invoke-RestMethod -uri "$hostname/nitro/v1/config/csvserver" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } return $vips.csvserver } function Logout { #logs out $body = ConvertTo-JSON @{ "logout" = @{ } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/logout" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.logout+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } function set-cipher ($Name, $cipher) { #unbinds all cipher groups $foundflag = 0 #flag if cipher already found $cgs = Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslvserver_sslciphersuite_binding/$Name" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET $cgs = $cgs.sslvserver_sslciphersuite_binding foreach ($cg in $cgs) { if ($cg.ciphername -notlike $cipher) { write-host "Unbinding" $cg.ciphername -ForegroundColor yellow try { Invoke-RestMethod -uri ("$hostname/nitro/v1/config/sslvserver_sslciphersuite_binding/$Name" + "?args=cipherName:" + $cg.ciphername ) -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslvserver_sslciphersuite_binding+json" } -Method DELETE | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } else { write-host $cipher "already present.." -ForegroundColor Green $foundflag = 1 } } #Make sure SSL profile not in use if ($useprofile -eq $false) { if ($foundflag -eq 0) { #binds new cipher group created if not already present write-host "Binding $cipher" -ForegroundColor Yellow $body = ConvertTo-JSON @{ "sslvserver_sslciphersuite_binding" = @{ "vservername" = "$Name"; "ciphername" = "$Cipher"; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslvserver_sslciphersuite_binding/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslvserver_sslciphersuite_binding+json" } -Method PUT | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } #disables sslv2, sslv3, tls1 and tls11 $body = ConvertTo-JSON @{ "sslvserver" = @{ "vservername" = "$Name"; "tls13" = "ENABLED"; "tls12" = "ENABLED"; "tls11" = "DISABLED"; "tls1" = "DISABLED"; "ssl3" = "DISABLED"; # "ssl2" = "DISABLED"; "dh" = "ENABLED"; "dhfile" = $dhname; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslvserver/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslvserver+json" } -Method PUT | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } } function set-nscipher ($Name, $cipher) { #unbinds all cipher groups $foundflag = 0 #flag if cipher already found $cgs = Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslservice_sslciphersuite_binding/$Name" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET $cgs = $cgs.sslservice_sslciphersuite_binding foreach ($cg in $cgs) { if ($cg.ciphername -notlike $cipher) { write-host "Unbinding" $cg.ciphername -ForegroundColor yellow try { Invoke-RestMethod -uri ("$hostname/nitro/v1/config/sslservice_sslciphersuite_binding/$Name" + "?args=cipherName:" + $cg.ciphername ) -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslservice_sslciphersuite_binding+json" } -Method DELETE | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } else { write-host $cipher "already present.." -ForegroundColor Green $foundflag = 1 } } if ($foundflag -eq 0) { #binds new cipher group created if not already present write-host "Binding $cipher" -ForegroundColor Yellow $body = ConvertTo-JSON @{ "sslservice_sslciphersuite_binding" = @{ "servicename" = "$Name"; "ciphername" = "$Cipher"; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslservice_sslciphersuite_binding/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslservice_sslciphersuite_binding+json" } -Method PUT | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } } function set-nsip { #Adjusts SSL setting for IPV4 and IPV6 on 443 $services = Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslservice" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET $services = $services.sslservice #only want nshttps services $nsips = $services | Where-Object { ($_.servicename -like "nshttps-*") -or ($_.servicename -like "nskrpcs-*") -or ($_.servicename -like "nsrpcs-*") } foreach ($nsip in $nsips) { $name = $nsip.servicename write-host $name if ($useprofile) { #Assigning SSL Profile and disabling SSLv3 $body = ConvertTo-JSON @{ "sslservice" = @{ "servicename" = "$Name"; "sslprofile" = $sslprofile; "tls11" = "DISABLED"; "tls1" = "DISABLED"; "ssl3" = "DISABLED"; # "ssl2" = "DISABLED"; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslservice/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method PUT | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } else { #No SSL Profile $body = ConvertTo-JSON @{ "sslservice" = @{ "servicename" = "$Name"; "tls13" = "ENABLED"; "tls12" = "ENABLED"; "tls11" = "DISABLED"; "tls1" = "DISABLED"; "ssl3" = "DISABLED"; # "ssl2" = "DISABLED"; "dh" = "ENABLED"; "dhfile" = $dhname; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslservice/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslservice+json" } -Method PUT | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } set-nscipher $name $ciphergroupname } } } function set-sslprofilebind ($name, $sslprofile) { #Sets SSL Profile and disables SSLv3 $body = ConvertTo-JSON @{ "sslvserver" = @{ "vservername" = "$Name"; "sslprofile" = $sslprofile; "tls11" = "DISABLED"; "tls1" = "DISABLED"; "ssl3" = "DISABLED"; # "ssl2" = "DISABLED"; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslvserver/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method PUT | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } function SaveConfig { #Saves NS config $body = ConvertTo-JSON @{ "nsconfig" = @{ } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/nsconfig?action=save" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.nsconfig+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } function get-rewritepol { #gets rewrite policies try { $pols = Invoke-RestMethod -uri "$hostname/nitro/v1/config/rewritepolicy" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } return $pols.rewritepolicy } function EnableFeature ($feature) { #enables NS feature $body = @{ "nsfeature" = @{ "feature" = $feature; } } $body = ConvertTo-JSON $body try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/nsfeature?action=enable" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.nsfeature+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } Function SetupSTS ($rwactname, $rwpolname) { # Strict Transport Security Policy creation EnableFeature Rewrite $body = ConvertTo-JSON @{ "rewriteaction" = @{ "name" = $rwactname; "type" = "insert_http_header"; "target" = "Strict-Transport-Security"; "stringbuilderexpr" = '"max-age=157680000"'; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/rewriteaction?action=add" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.rewriteaction+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } $body = ConvertTo-JSON @{ "rewritepolicy" = @{ "name" = $rwpolname; "action" = $rwactname; "rule" = 'true'; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/rewritepolicy?action=add" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.rewritepolicy+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } Function set-lbpols ($vip, $rwpolname, $rwpolpri) { #binds LB policy $name = $vip.name $body = ConvertTo-JSON @{ "lbvserver_rewritepolicy_binding" = @{ "name" = $Name; "policyname" = $rwpolname; "priority" = $rwpolpri; "bindpoint" = "RESPONSE"; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/lbvserver_rewritepolicy_binding/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.lbvserver_rewritepolicy_binding+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } Function set-cspols ($vip, $rwpolname, $rwpolpri) { #binds CS policy $name = $vip.name $body = ConvertTo-JSON @{ "csvserver_rewritepolicy_binding" = @{ "name" = $Name; "policyname" = $rwpolname; "priority" = $rwpolpri; "bindpoint" = "RESPONSE"; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/csvserver_rewritepolicy_binding/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.csvserver_rewritepolicy_binding+json" } -Method PUT | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } Function set-vpnpols ($vip, $rwpolname, $rwpolpri) { #binds NG policy $name = $vip.name $body = ConvertTo-JSON @{ "vpnvserver_rewritepolicy_binding" = @{ "name" = $Name; "policy" = $rwpolname; "priority" = $rwpolpri; "gotopriorityexpression" = "END"; "bindpoint" = "RESPONSE"; } } try { Invoke-RestMethod -uri "$hostname/nitro/v1/config/vpnvserver_rewritepolicy_binding/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.vpnvserver_rewritepolicy_binding+json" } -Method POST | Out-Null } catch { Write-Warning ($_.ErrorDetails | convertfrom-json).message } } function checkvpx { #Checks if NS is a VPX or not $info = Invoke-RestMethod -uri "$hostname/nitro/v1/config/nshardware" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET $info = $info.nshardware if ($info.hwdescription -like "NetScaler Virtual Appliance") { write-host "VPX FOUND..." -ForegroundColor Gray $found = $true } else { $found = $false } Return $found } function new-dhkey ($name) { #Creates new DH Key $body = @{ "ssldhparam" = @{ "dhfile" = $name; "bits" = "2048"; "gen" = "2"; } } $body = ConvertTo-JSON $body Invoke-RestMethod -uri "$hostname/nitro/v1/config/ssldhparam?action=create" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method POST -TimeoutSec 600 } function checkfordhkey ($dhname) { #Checks if DHKEY is present $urlstring = "$hostname" + "/nitro/v1/config/systemfile/" + $dhname + "?args=filelocation:%2Fnsconfig%2Fssl" try { $info = Invoke-RestMethod -uri $urlstring -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET $msg = $info.message } Catch { $ErrorMessage = $_.Exception.Response $FailedItem = $_.Exception.ItemName } if ($msg -like "Done") { write-host "DHKEY alredy present..." -ForegroundColor Green $found = $true } else { write-host "DHKEY NOT present..." -ForegroundColor Yellow $found = $false } Return $found } Function set-sslparams { #Allow secure renegotiation $body = ConvertTo-JSON @{ "sslparameter" = @{ "denysslreneg" = "FRONTEND_CLIENT"; } } Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslparameter/" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method PUT | Out-Null } Function enable-sslprof { #Enables default SSL profile https://docs.citrix.com/en-us/netscaler/11-1/ssl/ssl-profiles1/ssl-enabling-the-default-profile.html $body = ConvertTo-JSON @{ "sslparameter" = @{ "defaultprofile" = "ENABLED"; } } Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslparameter/" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method PUT | Out-Null } function check-nsversion { #Checks for supported NS version $info = Invoke-RestMethod -uri "$hostname/nitro/v1/config/nsversion" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET $version = $info.nsversion.version [regex]$majorreg = "(?<=NS).*?(?=:)" [regex]$minorreg = "(?<=Build ).*?(?=.n)" [version]$version = ($majorreg.match($version)).value + "." + ($minorreg.match($version)).value return $version } function check-defaultprofile { #Checks for SSL default profile $info = Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslparameter" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET return $info.sslparameter.defaultprofile } function check-sslprofile ($sslprofile) { try { #Checks for SSL default profile $info = Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslprofile/$sslprofile" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET } catch { $ErrorMessage = $_.Exception.Response $FailedItem = $_.Exception.ItemName } if ($info.sslprofile) { write-host "Found SSL PROFILE $sslprofile" -ForegroundColor Green $found = $true } else { write-host "SSL PROFILE NOT present..." -ForegroundColor Yellow $found = $false } Return $found } function new-sslprofile ($sslprofile, $dhname) { $body = ConvertTo-JSON @{ "sslprofile" = @{ "name" = $sslprofile; "sslprofiletype" = "FrontEnd"; "dh" = "ENABLED"; "dhcount" = "0"; "dhfile" = $dhname; "ersa" = "ENABLED"; "ersacount" = "0"; "sessreuse" = "ENABLED"; "sesstimeout" = "120"; "cipherredirect" = "DISABLED"; "clientauth" = "DISABLED"; "sslredirect" = "DISABLED"; "redirectportrewrite" = "DISABLED"; "nonfipsciphers" = "DISABLED"; # "ssl2" = "DISABLED"; "ssl3" = "DISABLED"; "tls1" = "DISABLED"; "tls11" = "DISABLED"; "tls12" = "ENABLED"; "tls13" = "ENABLED"; "snienable" = "DISABLED"; "ocspstapling" = "DISABLED"; "serverauth" = "DISABLED"; "pushenctrigger" = "Always"; "sendclosenotify" = "YES"; "insertionencoding" = "Unicode"; "denysslreneg" = "FRONTEND_CLIENT"; "quantumsize" = "8192"; "strictcachecks" = "NO"; "encrypttriggerpktcount" = "45"; "pushflag" = "0"; "dropreqwithnohostheader" = "NO"; "pushenctriggertimeout" = "1"; "ssltriggertimeout" = "100"; "clientauthuseboundcachain" = "DISABLED"; "sessionticket" = "DISABLED"; "sessionticketlifetime" = "300"; } } Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslprofile" -body $body -WebSession $NSSession -Headers @{"Content-Type" = "application/json" } -Method POST | Out-Null } function set-profilecipherbinding ($name, $cipher) { write-host "Binding $cipher" -ForegroundColor Yellow $body = ConvertTo-JSON @{ "sslprofile_sslcipher_binding" = @{ "name" = "$Name"; "ciphername" = "$Cipher"; } } Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslprofile_sslcipher_binding/$Name" -body $body -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method PUT | Out-Null } function set-profilecipher ($name, $cipher) { #unbinds all cipher groups $foundflag = 0 #flag if cipher already found $cgs = Invoke-RestMethod -uri "$hostname/nitro/v1/config/sslprofile_sslcipher_binding/$name" -WebSession $NSSession ` -Headers @{"Content-Type" = "application/json" } -Method GET $cgs = $cgs.sslprofile_sslcipher_binding #Check for cipher $found = 0 foreach ($cg in $cgs) { if ($cg.cipheraliasname -like $cipher) { Write-Host "Cipher Present" $found = 1 } } if ($found -eq 0) { #binds new cipher group created if not already present set-profilecipherbinding -name $name -cipher $cipher } #Remove other ciphers foreach ($cg in $cgs) { if ($cg.cipheraliasname -notlike $cipher) { write-host "Unbinding" $cg.cipheraliasname -ForegroundColor yellow Invoke-RestMethod -uri ("$hostname/nitro/v1/config/sslprofile_sslcipher_binding/$Name" + "?args=cipherName:" + $cg.cipheraliasname ) -WebSession $NSSession ` -Headers @{"Content-Type" = "application/vnd.com.citrix.netscaler.sslservice_sslciphersuite_binding+json" } -Method DELETE | Out-Null } } } ###Script starts here #Logs into netscaler write-host "Logging in..." Login #Checks for supported NS firmware version (10.5) $version = check-nsversion switch ($version) { { $_ -lt 10.5 } { throw "Netscaler firmware version MUST be greater than 10.5" exit } { $_ -lt "11.0.64.34" } { write-host "$($version.ToString()) has been detected. Default SSL profile not supported." $useprofile = $false if ($sslprofile -notlike "custom-ssllabs-profile" -or $enablesslprof) { Write-Host "SSL PROFILE IGNORED DUE TO FIRMARE VERSION" -ForegroundColor Yellow } } { $_ -ge "11.0.64.34" } { write-host "$($version.ToString()) has been detected. Default SSL profile supported." #Check for SSL default profile. Might do something around legacy in the future $testprof = check-defaultprofile if ($testprof -like "ENABLED") { write-host "DEFAULT SSL PROFILE IS ENABLED." -ForegroundColor GREEN $useprofile = $true } elseif ($testprof -like "DISABLED" -and $enablesslprof) { write-host "Enabling Default Profile Feature" -ForegroundColor Gray $useprofile = $true enable-sslprof } else { Clear-Host write-host '"Default SSL Profile" is recommended for 11.0.64.34 or greater. Running in LEGACY mode for this run.' -ForegroundColor Yellow write-host 'See https://docs.citrix.com/en-us/netscaler/11-1/ssl/ssl-profiles1/ssl-enabling-the-default-profile.html' -ForegroundColor yellow write-host 'Can enable with the -enablesslprof switch OR manually' -ForegroundColor Yellow write-host 'CLI: set ssl parameter -defaultProfile ENABLED' -ForegroundColor Yellow write-host 'GUI: Traffic Management > SSL > Change advanced SSL settings, scroll down, and select Enable Default Profile.' -ForegroundColor Yellow Start-Sleep -Seconds 5 $useprofile = $false } } } write-host "Checking for DHKEY: " $dhname -ForegroundColor White #Checks for and creates DH key if ((checkfordhkey $dhname) -eq $false) { write-host "DHKEY creation in process. Can take a couple of minutes..." -ForegroundColor yellow new-dhkey $dhname } write-host "Checking for cipher group..." -ForegroundColor White #Checks for cipher group we will be creating if (((get-ciphers).ciphergroupname) -notcontains $ciphergroupname) { write-host "Creating" $ciphergroupname -ForegroundColor Gray if (checkvpx) { write-host "Creating cipher group for VPX..." CipherGroup-vpx $ciphergroupname } else { write-host "Creating cipher group for NON-VPX..." ciphergroup $ciphergroupname } } else { write-host $ciphergroupname "already present" -ForegroundColor Green } write-host "Checking for rewrite policy..." -ForegroundColor White #Checks for rewrite policy if (((get-rewritepol).name) -notcontains $rwpolname) { write-host "Creating " $rwpolname -ForegroundColor Gray SetupSTS $rwactname $rwpolname } else { write-host $rwpolname "already present" -ForegroundColor Green } #Checking for SSL profile and creating if needed if ($useprofile) { write-host "Checking for SSL Profile..." -ForegroundColor White if ((check-sslprofile -sslprofile $sslprofile) -eq $false) { write-host "Creating SSL Profile $sslprofile" -ForegroundColor Gray new-sslprofile $sslprofile $dhname write-host "Binding Cipher Group" -ForegroundColor Gray set-profilecipher $sslprofile $ciphergroupname } } if ($mgmt) { write-host "Adjusting SSL managment IPs..." -ForegroundColor White #adjusts all managment IPs. Does not adjust ciphers set-nsip } else { write-host "Skipping SSL managment IPs..." } if ($nolb) { write-host "Skipping LB VIPs..." -ForegroundColor White } else { write-host "Checking LB VIPs..." -ForegroundColor White #Gets all LB servers that are SSL and makes changes $lbservers = (get-vservers) $ssls = $lbservers | Where-Object { $_.servicetype -like "SSL" } foreach ($ssl in $ssls) { write-host $ssl.name (set-cipher $ssl.name $ciphergroupname) if ($useprofile) { set-sslprofilebind $ssl.name $sslprofile } write-host "Binding STS policy" set-lbpols $ssl $rwpolname $rwpolpri } } if ($novpn) { write-host "Skiping VPN VIPS..." } else { write-host "Checking VPN VIPs..." -ForegroundColor White #Gets all Netscaler Gateways and makes changes $vpnservers = get-vpnservers foreach ($ssl in $vpnservers) { write-host $ssl.name if ($useprofile) { set-sslprofilebind $ssl.name $sslprofile } (set-cipher $ssl.name $ciphergroupname) write-host "Binding STS policy" set-vpnpols $ssl $rwpolname $rwpolpri } } if ($nocsw) { write-host "Skipping CSW IPs..." -ForegroundColor White } else { write-host "Checking CS VIPs..." -ForegroundColor White #Gets all Content Switches and makes changes $csservers = get-csservers #Filters for only SSL $csssls = $csservers | Where-Object { $_.servicetype -like "SSL" } foreach ($sslcs in $csssls) { write-host $sslcs.name if ($useprofile) { set-sslprofilebind $sslcs.name $sslprofile } (set-cipher $sslcs.name $ciphergroupname) write-host "Binding STS policy" set-cspols $sslcs $rwpolname $rwpolpri } } #SSL Global Params if ($noneg -or $useprofile -eq $true) { write-host "Skipping SSL global renegotiation..." -ForegroundColor White } else { write-host "Setting SSL global renegotiation..." -ForegroundColor White set-sslparams } #Save config if ($nosave) { write-host "NOT saving NS config.." -ForegroundColor White } else { write-host "Saving NS config.." -ForegroundColor White #Save NS Config SaveConfig } write-host "Logging out..." -ForegroundColor White #Logout Logout |