index.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/bash -E
  2. URL="/apt-sec"
  3. sURL="\/apt-sec"
  4. WD="/srv/http/htdocs/apt-sec/html"
  5. . pieces.sh
  6. . libcgi2.sh
  7. ##
  8. ## do the work
  9. ##
  10. cgi_getvars GET action
  11. cgi_getvars GET object
  12. #cgi_getvars BOTH file
  13. ## debugging
  14. # echo '<pre>'
  15. # set |sed 's/</\&lt\;/';
  16. # env |sed 's/</\&lt\;/';
  17. # echo '</pre>'
  18. ## input variable cavity search
  19. object=$(echo "$object"|tr -d "<>;|#\"'")
  20. action=$(echo "$action"|tr -d "<>;|#\"'")
  21. # disable during aptsec mirroring..
  22. if lockfile-check /var/lock/aptsec-update; then
  23. output="$UPDATE_MSG"
  24. else
  25. case $action in
  26. "sys")
  27. if [ "$REQUEST_METHOD" != "POST" ]; then
  28. output="<h2>System Assessment</h2><p>$FILE_FORM</p>"
  29. else
  30. tmp="$(tempfile)";
  31. # crude hack: delete last 2 and first 4 lines to extract binary file
  32. #echo -n "$QUERY_STRING_POST"|tac|tail -n +3|tac|tail -n +5 > $tmp
  33. cat - |tac|tail -n +3|tac|tail -n +5 > $tmp
  34. if grep -q 'boot_aggregate' "$tmp"; then
  35. output="$(../apt-sec attest $tmp)"
  36. else
  37. output="$(../apt-sec status $tmp)"
  38. fi
  39. rm $tmpfile
  40. sum=$(echo "$output"|grep -A99 ^Packages\ with)
  41. lines=$(($(echo "$output"|wc -l|awk '{print $1}')-$(echo "$sum"|wc -l|awk '{print $1}')))
  42. log=$(echo -e "\n\nAssessment details:"; echo "$output"|head -$lines)
  43. output="$(echo "$sum$log"|sed "s/MTTFl/MTTF<sub>\&#955;<\/sub>/")"
  44. output="<h2>System Assessment (&#955=36)</h2><p>$output</p>"
  45. fi
  46. ;;
  47. "jmp")
  48. echo "$HTTP_HEADER"
  49. echo '<html><head><meta http-equiv="refresh" content="0;url='
  50. case $object in
  51. "DSA-"*)
  52. echo -n 'http://security-tracker.debian.org/tracker/redirect/'
  53. echo -n "$object"
  54. ;;
  55. "CVE-"*)
  56. echo -n 'http://security-tracker.debian.org/tracker/redirect/'
  57. echo -n "$object"
  58. ;;
  59. *)
  60. ## assume its a debian packet
  61. echo -n 'http://packages.debian.org/'
  62. echo -n "$object"
  63. ;;
  64. esac
  65. echo '"></head><body></body></html>'
  66. exit
  67. ;;
  68. "pkg")
  69. case $object in
  70. "")
  71. output="<h2>Manual Database Query</h2><p>$OBJECT_FORM</p>"
  72. ;;
  73. *)
  74. #echo "AA${object}AA"
  75. #echo -n "$object"|wc -c
  76. #[[ "$object" =~ [a-z,A-Z,0-9] ]] && echo true;
  77. if [ $(echo -n "$object"|wc -c) -eq 40 ] && [[ "$object" =~ [a-z,A-Z,0-9] ]]; then
  78. output="$(../apt-sec sha1 $object)"
  79. output="<h2>Records on SHA1 digest $object</h2>$output"
  80. else
  81. output="$(../apt-sec show $object)"
  82. alt="$(../apt-sec alt $object)"
  83. msg="$(echo "$output"|grep ^Resolving)" && msg="$(echo -e "$msg\r\r")"
  84. output=$(echo "$output"|grep -v ^Resolving)
  85. pkgh="$(echo "$output"|awk -F'\n' '{ RS=""; if (NR == 2) {print "<h3>"$0"</h3>"}}')"
  86. pkg="$(echo "$output"|awk -F'\n' '{ RS=""; if (NR == 3) {print }}')"
  87. logh="$(echo "$output"|awk -F'\n' '{ RS=""; if (NR == 4) {print "\r\r<h3>",$0,"</h3>"}}')"
  88. log="$(echo "$output"|awk -F'\n' '{ RS=""; if (NR == 5) {print }}')"
  89. sumh="$(echo "$output"|awk -F'\n' '{ RS=""; if (NR == 6) {print "\r<h3>",$0,"</h3>"}}')"
  90. sum="$(echo "$output"|awk -F'\n' '{ RS=""; if (NR == 7) {print }}')"
  91. sum="$(echo "$sum"|grep -v "MTTFl\|STPl" \
  92. |sed -e "s/MTTF: /<i>Mean Time To Failure:<\/i>/" \
  93. -e "s/STP(12): /<i>Failure prediction:<\/i>/")"
  94. #sum="$(echo "$sum"|sed -e "s/MTTFl/MTTF<sub>\&#955;<\/sub>/" -e "s/STPl/STP<sub>\&#955;<\/sub>/")"
  95. log="$(echo "$log"|sed 's/^DSA-[0-9]\+/<br><a href="\/apt-sec\/jmp\/&">&<\/a>/')"
  96. log="$(echo "$log"|sed 's/^CVE-[0-9]\+-[0-9]\+/<a href="\/apt-sec\/jmp\/&">&<\/a>/')"
  97. pkg="$(echo "$pkg"|sed 's/.*/<a href="\/apt-sec\/jmp\/&">&<\/a>/')"
  98. alth="$(echo "$alt"|grep ^Similar |sed -e 's/^/<br><h3>/' -e 's/$/<\/h3>/')"
  99. alts="$(echo "$alt"|tail -2|sed -e "s/\([a-z,A-Z,0-9,\._-]*\)\ /<a href=\"$sURL\/pkg\/\1\">\1<\/a><br>/g")"
  100. graph="$WD/graphs/$(echo $object|md5sum|cut -b -16)"
  101. if [ ! -f $graph.png ]; then
  102. echo "$log"|grep CVE |sed s/,//g | awk '{print $5"."$6}' \
  103. |awk 'FS="." {print $5"-"$4"-"$3,$1"."$2}' |sort |grep -v -- '^--'> $graph.dat
  104. gnuplot cvegraph.plot -e "plot '$graph.dat' using 1:2 with impulses smooth frequency" > $graph.png
  105. fi
  106. img="<p><img src=\"$URL/html/graphs/$(basename $graph).png\"></img>"
  107. output="<h2>Records on package $object</h2>$img$msg$sumh$sum$alth$alts$logh$log$pkgh$pkg"
  108. fi
  109. ;;
  110. esac
  111. ;;
  112. "hits")
  113. output="$(../apt-sec hits|sed \
  114. -e "s/MTTFl/MTTF<sub>\&#955;<\/sub>/" \
  115. -e "s/STPl/STP<sub>\&#955;<\/sub>/" \
  116. -e "s/Pkg: \(.*\)/<a href=\"$sURL\/pkg\/\1\">\1<\/a>/" \
  117. |sort -n|head -100)"
  118. output="<h2>Worst 100 Packages (sorted by MTTF, &#955=36)</h2><p>$output</p>"
  119. ;;
  120. "about")
  121. output="$(../apt-sec about)"
  122. output="<h2>About TrustMiner</h2>$ABOUT_MSG$output$ABOUT_REF"
  123. ;;
  124. *)
  125. #"intro")
  126. output="<h2>Introduction</h2>$INTRO_MSG"
  127. ;;
  128. esac
  129. fi # disable on aptsec mirroring..
  130. ##
  131. ## format HTML output
  132. ##
  133. echo "$HTTP_HEADER"
  134. echo "$HTML_HEADER"
  135. echo "$MAIN_NAVI"
  136. echo '<div class="output">'
  137. echo "$output"
  138. echo '</div>'
  139. echo '<div class="padding">&nbsp;</div>'
  140. echo "$HTML_FOOTER"