hipreport-android.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/system/bin/sh
  2. # These values may need to be extracted from the official HIP report, if made-up values are not accepted.
  3. PLATFORM_VERSION="4.3"
  4. PLATFORM_NAME="Android-x86"
  5. HOSTID="deadbeef-dead-beef-dead-beefdeadbeef"
  6. # Read command line arguments into variables
  7. COOKIE=
  8. IP=
  9. IPV6=
  10. MD5=
  11. while [ "$1" ]; do
  12. if [ "$1" = "--cookie" ]; then shift; COOKIE="$1"; fi
  13. if [ "$1" = "--client-ip" ]; then shift; IP="$1"; fi
  14. if [ "$1" = "--client-ipv6" ]; then shift; IPV6="$1"; fi
  15. if [ "$1" = "--md5" ]; then shift; MD5="$1"; fi
  16. shift
  17. done
  18. if [ -z "$COOKIE" -o -z "$MD5" -o -z "$IP$IPV6" ]; then
  19. echo "Parameters --cookie, --md5, and --client-ip and/or --client-ipv6 are required" >&2
  20. exit 1;
  21. fi
  22. # Extract username and domain and computer from cookie
  23. USER=$(echo "$COOKIE" | sed -rn 's/(.+&|^)user=([^&]+)(&.+|$)/\2/p')
  24. DOMAIN=$(echo "$COOKIE" | sed -rn 's/(.+&|^)domain=([^&]+)(&.+|$)/\2/p')
  25. COMPUTER=$(echo "$COOKIE" | sed -rn 's/(.+&|^)computer=([^&]+)(&.+|$)/\2/p')
  26. # Timestamp in the format expected by GlobalProtect server
  27. NOW=$(date +'%m/%d/%Y %H:%M:%S')
  28. # WARNING: Replacing this with a here-doc (cat <<EOF) does not work
  29. # with Android's /system/bin/sh, likely due to an insufficient read
  30. # buffer size.
  31. echo '<hip-report name="hip-report">'
  32. echo " <md5-sum>$MD5</md5-sum>"
  33. echo " <user-name>$USER</user-name>"
  34. echo " <domain>$DOMAIN</domain>"
  35. echo " <host-name>$COMPUTER</host-name>"
  36. echo " <host-id>$HOSTID</host-id>"
  37. echo " <ip-address>$IP</ip-address>"
  38. echo " <ipv6-address>$IPV6</ipv6-address>"
  39. echo " <generate-time>$NOW</generate-time>"
  40. echo ' <categories>'
  41. echo ' <entry name="host-info">'
  42. echo ' <client-version>4.0.2-19</client-version>'
  43. echo " <os>$PLATFORM_NAME $PLATFORM_VERSION</os>"
  44. echo ' <os-vendor>Google</os-vendor>'
  45. echo " <domain>$DOMAIN.internal</domain>"
  46. echo " <host-name>$COMPUTER</host-name>"
  47. echo " <host-id>$HOSTID</host-id>"
  48. echo ' </entry>'
  49. echo ' </categories>'
  50. echo '</hip-report>'