candyapplecorn

NIST Vulnerability Extractor

Mar 18th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ===================================================================
  4. #   Vulnerability extractor script
  5. #   by Joseph Burger
  6. #   2015 - 3 - 17
  7.  
  8. #   This shell script takes the url to the vulnerabilities XML file,
  9. #   packaged as a .gz file, from http://static.vbd.nist.gov/downloads.cfm
  10. #   and then downloads it, unzips it, extracts the vulnerability id and score
  11. #   using an awk script, and then further refines the output of that awk script
  12. #   using a sed script. The finished product is a text file with two columns, the
  13. #   first column being the vulnerability id, and the second column having the
  14. #   vulnerability's severity score, or in the case that there's no severity score,
  15. #   "TBD". This output file is saved as "condensedVulns.txt"
  16. # ===================================================================
  17.  
  18.  
  19. # ===================================================================
  20. #   Get the xml file.
  21. #   User input method is commented out, in favor of
  22. #   automatically getting it using curl with some egrep
  23. # ===================================================================
  24.  
  25. echo Please enter the download URL of the vulnerability.xml.gz file
  26. read xmlURL
  27.  
  28. #xmlURL=`curl https://nvd.nist.gov/download.cfm | \
  29. #egrep feeds/xml.*.gz | tail -n 1 | sed -r "s/.*a href='(.*?)' .*$/\1/"`;
  30.  
  31. # ===================================================================
  32. #   This command extracts the awk script from this shell script and
  33. #   stores it inside the file "awkScript"
  34. # ===================================================================
  35. tail -n 22 getVulns.sh | tr '\#' ' ' > awkScript
  36.  
  37. wget $xmlURL && \
  38. gzip -d *.xml.gz && \
  39. awk -f awkScript *.xml | sed -rn '/<entry id/N; s/^.*<entry id*."(.*)".*cvss:score>(.*)<.*$/\1\t\2/w condensedVulns.txt' && \
  40. rm *.xml awkScript
  41. echo $myURL
  42. echo The vulnerabilities are listed in "condensedVulns.txt"
  43.  
  44. # ===================================================================
  45. #   Store the awk script inside this shell script to save space
  46. # ===================================================================
  47.  
  48. # This script goes through an xml file containing vulnerabilities
  49. # and extracts the id, as well as the score. If there is no score
  50. # it substitutes "TBD".
  51. #BEGIN{
  52. #   num=0;
  53. #   }
  54. #{
  55. #   if( /entry id/ ) {
  56. #       print $0;
  57. #       arr[num++] = $0
  58. #       while ( ! /cvss:score/ && ! /entry>/ ){
  59. #           getline < FILENAME
  60. #       }
  61. #       if ( /cvss:score/ ) {
  62. #           arr[num] = arr[num] $0
  63. #       } else {
  64. #           arr[num] = arr[num] "\t<cvss:score>TBD</cvss:score>"
  65. #       }
  66. #       while ( ! /entry>/ ) {
  67. #           getline < FILENAME
  68. #       }
  69. #       print arr[num]
  70. #   }
  71. #}
  72. #END{}
Advertisement
Add Comment
Please, Sign In to add comment