Need Help with Using the Discovery Tool for SSL Certificate Inventory and CI Upkeep.

humblecommitted
Kilo Guru

A call to arms fellow ServiceNow patrons,

right now i am currently using digicert scanner to extract what ports and servers that have ssl certs and exporting it to an excel spread sheet.

I am currently researching methods of determining how to run internal cmds on the servers via the discovery tool.

most cmds i have come across checks the servers externally.

i am trying to do the following:

  • find internal cmds such as:
    • port scan with finger print of services running on port
    • common file types, paths, etc. associated with ssl cert installation on the servers i.e. locate/find/which *.crt, *.key, *.cer, *.pem, etc.
    • expiration dates
    • (and any others that i have not thought of please feel free to include)
  • both powershell and bash scripts/cmd equivalents of the each other to run on both windows and linux environments.
  • then trying to configure a sensor script to interpret the output of those commands.
  • populate output to respective ci's (especially expiration dates to have a notification rule setup for that)

i would hate to reinvent the wheel, if anyone has already stumbled upon this please let me know.

any help you provide will help the greater community and i will do my best to reciprocate and share the information openly.

1 ACCEPTED SOLUTION

Hello Community,



I was able to build this out.



This solution is dependent on how you want to capture the SSL Cert information for your server.



  1. You can either run a command internally on the server to see the certs installed and capture that information, or
  2. You can run an external command that will capture the SSL cert information via externally connecting to the ssl port to request the header/thumbprint/output of the ssl cert. (This method will prove tricky because you would have to manually change the script on the probe to execute on every server, unless there is a script that can loop through all the known IPs/URLs to extract the Certs and associate them to the targeted CI)


For now I will use use case # 1 as an example:


  1. to check for certs installed locally/internally on the server we would have to know where the certs install files are located, we can do this by creating a probe to capture all locations of where .crt files are located (if needed, we can create a sensor to parse through the output to capture all the installed locations of the .crt file to populate the CI but I did not complete this step but when you read through this write up, you can tweak the script i have to collect cert expiration date to meet this need):

    locate *.crt


    find_real_file.png
  2. Once you get the output locations of where local certs are installed on the server, run this command while swapping out the files location with your own:

    openssl x509 -text -noout -in /etc/pki/tls/certs/localhost.crt


    find_real_file.png

    You can use these commands that are referenced/explained in the following URLs
    Windows based servers:
    How can I get a list of installed certificates on Windows? - Super User
    Linux based servers:
    The Most Common OpenSSL Commands

  3. After I created my probe, I then created the corresponding sensor to parse the output and relate them to the CI.
    find_real_file.png
  4. I then created this java script for the sensor to parse through the output and grab the "End date" of the ssl cmd.
    find_real_file.png
    find_real_file.png
    find_real_file.png
    find_real_file.png


/*


new DiscoverySensor({


process: function(result) {


var ssloutput = result."Not After : ";


var ssldate = new setDisplayValue();


ssldate.addSeconds(-ssloutput);


current.u_ssl_exp = ssldate;


},


type: "DiscoverySensor"


});


*/




new DiscoverySensor({


      process: function(result) {


              if (gs.nil(result.output))


                      return;




              this.parseOutput(result.output);


      },




      parseOutput: function(output) {


  var updated = false;


              var lines = output.split(/\n/);


  gs.log("This is the output for lines: "+lines);


  gs.log("Not After Index check >>>> "+output.indexOf("Not After"));


              var na = output.indexOf("Not After");


  gs.log(output.substring(na + 12, na + 32)); //to grab full date output


  gs.log(output.substring(na + 28, na + 32)); //to grab year


  gs.log(output.substring(na + 12, na + 15)); //to grab month


  gs.log(output.substring(na + 16, na + 18)); //to grab day


  gs.log(output.substring(na + 19, na + 27)); //to grab time


  var yyyy = output.substring(na + 28, na + 32);


  var mmm = output.substring(na + 12, na + 15);


  var dd = output.substring(na + 16, na + 18);


  var time = output.substring(na + 19, na + 27);


//convert cert output date to match servicenow date format.


  var mn;


  if (mmm == "Jan"){


  mn = "01";


  } else if(mmm == "Feb"){


  mn = "02";


  }else if(mmm == "Mar"){


  mn = "03";


  }else if(mmm == "Apr"){


  mn = "04";


  }else if(mmm == "May"){


  mn = "05";


  }else if(mmm == "Jun"){


  mn = "06";


  }else if(mmm == "Jul"){


  mn = "07";


  }else if(mmm == "Aug"){


  mn = "08";


  }else if(mmm == "Sep"){


  mn = "09";


  }else if(mmm == "Oct"){


  mn = "10";


  }else if(mmm == "Nov"){


  mn = "11";


  }else if(mmm == "Dec"){


  mn = "12";


  }


   




  gs.log("This is the output for mn: "+mn);


  //gs.log(yyyy+"-"+mn+"-"+dd+" "+time);


  var sslexpdate = yyyy+"-"+mn+"-"+dd+" "+time;


  gs.log(sslexpdate);


  updated = true;


  if (updated) //Only update it if the output has good value


  current.u_ssl_exp = sslexpdate;



  //gs.log("The month number is "+mn);



  //for (var i = 0; i < lines.length; i++) {


                      //var line = lines[i];


  //gs.log("This is the output for line: "+line);



                     


                      //var parts = line.split(":");


                      //var name = parts[0].trim();


                      //var value = parts[1].trim();


      //gs.log("Not After Index check >>>> "+output.indexOf("Not After"));


  //if (name == "Not After")


  //current.u_ssl_exp = value;


  //gs.log("The name is "+name+" and value is "+ value);


  //gs.log("Not After Index check >>>> "+output.indexOf("Not After"));



  //gs.log("The name is "+name+" and length is "+ name.length);


  //}


          },


             


      type: "DiscoverySensor"


});




5. Take notice that I also had to convert the output of the SSL cert date to match servicenow's date format i.e. variables "mmm", "mn" (for month number), and rearranging the date.


6. Attach the sensor to the probe.


find_real_file.png


find_real_file.png



7. Test the probe to see if there are any errors to re-mediate.


find_real_file.png


i.e. of error


find_real_file.png


find_real_file.png


find_real_file.png


i.e. of working probe:


find_real_file.png


find_real_file.png


8.   For trouble shooting of the script you can make your way to   Script Log Statements to see how your sensor code is parsing through the output.


find_real_file.png



9. I then created the corresponding variable on the CI called "u_ssl_exp" that is referenced on line 75 of my sensor code.


find_real_file.png


9. create a discovery schedule.


find_real_file.png


find_real_file.png


10. Scan will run, check with Discovery status, event logs, all (logs), script log statements, etc. to see status


find_real_file.pngfind_real_file.pngfind_real_file.png


find_real_file.png


11. Verify the CI field has been updated with the SSL expiration date:


find_real_file.png


12. Now that we have a servicenow format for a tangible date for the ssl cert, we can now have servicenow automate notifications based on cert expiration etc.



Note:   The commented out portions of my code also has portions that increment, or loop, through the ssl cert output to grab any other information if needed (it is separated by ":").   Please feel free to update the code and post here to share with the rest of the community any updated codes, practices, or methods, etc.



I hope this helps you all as much as it has helped me.



Thank you.


View solution in original post

6 REPLIES 6

chandugirish
Kilo Explorer

Hey Buddy, U have done a good job, but you were able to get the values in the Discovery? pls let me know

hondaxxx
ServiceNow Employee
ServiceNow Employee

ServiceNow has official support for this solution with Orlando release

For more details please check below link

https://community.servicenow.com/community?id=community_blog&sys_id=9733b4481b0acc10a59033f2cd4bcb05