hipreport.sh 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #!/bin/sh
  2. # openconnect will call this script with the follow command-line
  3. # arguments, which are needed to populate the contents of the
  4. # HIP report:
  5. #
  6. # --cookie: a URL-encoded string, as output by openconnect
  7. # --authenticate --protocol=gp, which includes parameters
  8. # from the /ssl-vpn/login.esp response
  9. #
  10. # --client-ip{,v6}: IPv4/6 addresses allocated by the GlobalProtect
  11. # VPN for this client (included in
  12. # /ssl-vpn/getconfig.esp response)
  13. #
  14. # --md5: The md5 digest to encode into this HIP report. I'm not sure
  15. # exactly what this is the md5 digest *of*, but all that
  16. # really matters is that the value in the HIP report
  17. # submission should match the value in the HIP report check.
  18. #
  19. # --client-os: The platform name in GlobalProtect's format (known
  20. # values are 'Linux', 'Mac' or 'Windows' ). Defaults to
  21. # 'Windows'.
  22. #
  23. # This hipreport.sh does not work as-is on Android. The large here-doc
  24. # (cat <<EOF) does not appear to work with Android's /system/bin/sh,
  25. # likely due to an insufficient read buffer size.
  26. # Try hipreport-android.sh instead.
  27. # Read command line arguments into variables
  28. COOKIE=
  29. IP=
  30. IPv6=
  31. MD5=
  32. CLIENTOS=Windows
  33. while [ "$1" ]; do
  34. if [ "$1" = "--cookie" ]; then shift; COOKIE="$1"; fi
  35. if [ "$1" = "--client-ip" ]; then shift; IP="$1"; fi
  36. if [ "$1" = "--client-ipv6" ]; then shift; IPV6="$1"; fi
  37. if [ "$1" = "--md5" ]; then shift; MD5="$1"; fi
  38. if [ "$1" = "--client-os" ]; then shift; CLIENTOS="$1"; fi
  39. shift
  40. done
  41. if [ -z "$COOKIE" -o -z "$MD5" -o -z "$IP$IPV6" ]; then
  42. echo "Parameters --cookie, --md5, and --client-ip and/or --client-ipv6 are required" >&2
  43. exit 1;
  44. fi
  45. # Extract username and domain and computer from cookie
  46. USER=$(echo "$COOKIE" | sed -rn 's/(.+&|^)user=([^&]+)(&.+|$)/\2/p')
  47. DOMAIN=$(echo "$COOKIE" | sed -rn 's/(.+&|^)domain=([^&]+)(&.+|$)/\2/p')
  48. COMPUTER=$(echo "$COOKIE" | sed -rn 's/(.+&|^)computer=([^&]+)(&.+|$)/\2/p')
  49. # This value may need to be extracted from the official HIP report, if a made-up value is not accepted.
  50. HOSTID="deadbeef-dead-beef-dead-beefdeadbeef"
  51. case $CLIENTOS in
  52. Linux)
  53. CLIENT_VERSION="5.1.5-8"
  54. OS="Linux Fedora 32"
  55. OS_VENDOR="Linux"
  56. NETWORK_INTERFACE_NAME="virbr0"
  57. NETWORK_INTERFACE_DESCRIPTION="virbr0"
  58. # Not currently used for Linux
  59. ENCDRIVE='/'
  60. ;;
  61. *)
  62. CLIENT_VERSION="5.1.5-8"
  63. OS="Microsoft Windows 10 Pro , 64-bit"
  64. OS_VENDOR="Microsoft"
  65. NETWORK_INTERFACE_NAME="{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}"
  66. NETWORK_INTERFACE_DESCRIPTION="PANGP Virtual Ethernet Adapter #2"
  67. # Many VPNs seem to require trailing backslash, others don't accept it
  68. ENCDRIVE='C:\\'
  69. ;;
  70. esac
  71. # Timestamp in the format expected by GlobalProtect server
  72. NOW=$(date +'%m/%d/%Y %H:%M:%S')
  73. DAY=$(date +'%d')
  74. MONTH=$(date +'%m')
  75. YEAR=$(date +'%Y')
  76. cat <<EOF
  77. <?xml version="1.0" encoding="UTF-8"?>
  78. <hip-report name="hip-report">
  79. <md5-sum>$MD5</md5-sum>
  80. <user-name>$USER</user-name>
  81. <domain>$DOMAIN</domain>
  82. <host-name>$COMPUTER</host-name>
  83. <host-id>$HOSTID</host-id>
  84. <ip-address>$IP</ip-address>
  85. <ipv6-address>$IPV6</ipv6-address>
  86. <generate-time>$NOW</generate-time>
  87. <hip-report-version>4</hip-report-version>
  88. <categories>
  89. <entry name="host-info">
  90. <client-version>$CLIENT_VERSION</client-version>
  91. <os>$OS</os>
  92. <os-vendor>$OS_VENDOR</os-vendor>
  93. <domain>$DOMAIN.internal</domain>
  94. <host-name>$COMPUTER</host-name>
  95. <host-id>$HOSTID</host-id>
  96. <network-interface>
  97. <entry name="$NETWORK_INTERFACE_NAME">
  98. <description>$NETWORK_INTERFACE_DESCRIPTION</description>
  99. <mac-address>01-02-03-00-00-01</mac-address>
  100. <ip-address>
  101. <entry name="$IP"/>
  102. </ip-address>
  103. <ipv6-address>
  104. <entry name="$IPV6"/>
  105. </ipv6-address>
  106. </entry>
  107. </network-interface>
  108. </entry>
  109. EOF
  110. case $CLIENTOS in
  111. Linux)
  112. ;;
  113. *) cat <<EOF
  114. <entry name="antivirus">
  115. <list>
  116. <entry>
  117. <ProductInfo>
  118. <Prod name="McAfee VirusScan Enterprise" version="8.8.0.1804" defver="8682.0" prodType="1" engver="5900.7806" osType="1" vendor="McAfee, Inc." dateday="$DAY" dateyear="$YEAR" datemon="$MONTH">
  119. </Prod>
  120. <real-time-protection>yes</real-time-protection>
  121. <last-full-scan-time>$NOW</last-full-scan-time>
  122. </ProductInfo>
  123. </entry>
  124. <entry>
  125. <ProductInfo>
  126. <Prod name="Windows Defender" version="4.11.15063.332" defver="1.245.683.0" prodType="1" engver="1.1.13804.0" osType="1" vendor="Microsoft Corp." dateday="$DAY" dateyear="$YEAR" datemon="$MONTH">
  127. </Prod>
  128. <real-time-protection>no</real-time-protection>
  129. <last-full-scan-time>n/a</last-full-scan-time>
  130. </ProductInfo>
  131. </entry>
  132. </list>
  133. </entry>
  134. EOF
  135. ;;
  136. esac
  137. case $CLIENTOS in
  138. Linux) cat <<EOF
  139. <entry name="anti-malware">
  140. <list/>
  141. </entry>
  142. EOF
  143. ;;
  144. *) cat <<EOF
  145. <entry name="anti-spyware">
  146. <list>
  147. <entry>
  148. <ProductInfo>
  149. <Prod name="McAfee VirusScan Enterprise" version="8.8.0.1804" defver="8682.0" prodType="2" engver="5900.7806" osType="1" vendor="McAfee, Inc." dateday="$DAY" dateyear="$YEAR" datemon="$MONTH">
  150. </Prod>
  151. <real-time-protection>yes</real-time-protection>
  152. <last-full-scan-time>$NOW</last-full-scan-time>
  153. </ProductInfo>
  154. </entry>
  155. <entry>
  156. <ProductInfo>
  157. <Prod name="Windows Defender" version="4.11.15063.332" defver="1.245.683.0" prodType="2" engver="1.1.13804.0" osType="1" vendor="Microsoft Corp." dateday="$DAY" dateyear="$YEAR" datemon="$MONTH">
  158. </Prod>
  159. <real-time-protection>no</real-time-protection>
  160. <last-full-scan-time>n/a</last-full-scan-time>
  161. </ProductInfo>
  162. </entry>
  163. </list>
  164. </entry>
  165. EOF
  166. ;;
  167. esac
  168. case $CLIENTOS in
  169. Linux) cat <<EOF
  170. <entry name="disk-backup">
  171. <list/>
  172. </entry>
  173. EOF
  174. ;;
  175. *) cat <<EOF
  176. <entry name="disk-backup">
  177. <list>
  178. <entry>
  179. <ProductInfo>
  180. <Prod name="Windows Backup and Restore" version="10.0.15063.0" vendor="Microsoft Corp.">
  181. </Prod>
  182. <last-backup-time>n/a</last-backup-time>
  183. </ProductInfo>
  184. </entry>
  185. </list>
  186. </entry>
  187. EOF
  188. ;;
  189. esac
  190. case $CLIENTOS in
  191. Linux) cat <<EOF
  192. <entry name="disk-encryption">
  193. <list>
  194. <entry>
  195. <ProductInfo>
  196. <Prod name="cryptsetup" version="2.3.3" vendor="GitLab Inc.">
  197. </Prod>
  198. <drives>
  199. <entry>
  200. <drive-name>/</drive-name>
  201. <enc-state>encrypted</enc-state>
  202. </entry>
  203. </drives>
  204. </ProductInfo>
  205. </entry>
  206. </list>
  207. </entry>
  208. EOF
  209. ;;
  210. *) cat <<EOF
  211. <entry name="disk-encryption">
  212. <list>
  213. <entry>
  214. <ProductInfo>
  215. <Prod name="Windows Drive Encryption" version="10.0.15063.0" vendor="Microsoft Corp.">
  216. </Prod>
  217. <drives>
  218. <entry>
  219. <drive-name>$ENCDRIVE</drive-name>
  220. <enc-state>full</enc-state>
  221. </entry>
  222. </drives>
  223. </ProductInfo>
  224. </entry>
  225. </list>
  226. </entry>
  227. EOF
  228. ;;
  229. esac
  230. case $CLIENTOS in
  231. Linux) cat <<EOF
  232. <entry name="firewall">
  233. <list>
  234. <entry>
  235. <ProductInfo>
  236. <Prod name="IPTables" version="1.8.4" vendor="IPTables">
  237. </Prod>
  238. <is-enabled>no</is-enabled>
  239. </ProductInfo>
  240. </entry>
  241. <entry>
  242. <ProductInfo>
  243. <Prod name="nftables" version="0.9.3" vendor="The Netfilter Project">
  244. </Prod>
  245. <is-enabled>n/a</is-enabled>
  246. </ProductInfo>
  247. </entry>
  248. </list>
  249. </entry>
  250. EOF
  251. ;;
  252. *) cat <<EOF
  253. <entry name="firewall">
  254. <list>
  255. <entry>
  256. <ProductInfo>
  257. <Prod name="Microsoft Windows Firewall" version="10.0" vendor="Microsoft Corp.">
  258. </Prod>
  259. <is-enabled>yes</is-enabled>
  260. </ProductInfo>
  261. </entry>
  262. </list>
  263. </entry>
  264. EOF
  265. ;;
  266. esac
  267. case $CLIENTOS in
  268. Linux) cat <<EOF
  269. <entry name="patch-management">
  270. <list>
  271. <entry>
  272. <ProductInfo>
  273. <Prod name="Dandified Yum" version="4.2.23" vendor="Red Hat, Inc.">
  274. </Prod>
  275. <is-enabled>yes</is-enabled>
  276. </ProductInfo>
  277. </entry>
  278. </list>
  279. <missing-patches/>
  280. </entry>
  281. EOF
  282. ;;
  283. *) cat <<EOF
  284. <entry name="patch-management">
  285. <list>
  286. <entry>
  287. <ProductInfo>
  288. <Prod name="McAfee ePolicy Orchestrator Agent" version="5.0.5.658" vendor="McAfee, Inc.">
  289. </Prod>
  290. <is-enabled>yes</is-enabled>
  291. </ProductInfo>
  292. </entry>
  293. <entry>
  294. <ProductInfo>
  295. <Prod name="Microsoft Windows Update Agent" version="10.0.15063.0" vendor="Microsoft Corp.">
  296. </Prod>
  297. <is-enabled>yes</is-enabled>
  298. </ProductInfo>
  299. </entry>
  300. </list>
  301. <missing-patches/>
  302. </entry>
  303. EOF
  304. ;;
  305. esac
  306. cat <<EOF
  307. <entry name="data-loss-prevention">
  308. <list/>
  309. </entry>
  310. </categories>
  311. </hip-report>
  312. EOF