Skip to content

Instantly share code, notes, and snippets.

@Cdaprod
Created February 24, 2024 21:42
Show Gist options
  • Save Cdaprod/0176552a2156bc036352d7e2ff6c23ef to your computer and use it in GitHub Desktop.
Save Cdaprod/0176552a2156bc036352d7e2ff6c23ef to your computer and use it in GitHub Desktop.
This guide and script provide a foundational approach to integrating iOS Shortcuts with web services for security analysis, enhancing your ability to quickly assess the safety of URLs on the fly.

Creating an iOS Shortcuts workflow that integrates with the VirusTotal API to test URLs directly from the Share Sheet involves a series of steps. This workflow will capture URLs shared via the Share Sheet, submit them to the VirusTotal API for safety analysis, and then display the analysis results to you. Below is a guide on setting up this workflow, including the necessary scripts to publish this as a gist or integrate it into your iOS device's Shortcuts app.

Preparing Your Environment:

  1. Obtain a VirusTotal API Key:

    • Sign up for a free account at VirusTotal.
    • Navigate to your profile settings to find your API key.
  2. Ensure You Have the Shortcuts App Installed:

    • The Shortcuts app is available by default on iOS devices. Update it to the latest version for the best experience.

Creating the Shortcut:

  1. Open the Shortcuts App and tap on the "+" icon to create a new shortcut.
  2. Name Your Shortcut: For example, "Check URL Safety".
  3. Configure Share Sheet Input:
    • Enable the Share Sheet trigger and select "URLs" as the accepted input type.
  4. Add Actions to Capture and Process the URL:
    • Get URLs from Input: To capture URLs shared via the Share Sheet.
    • URL Action: Enter the VirusTotal API endpoint: https://www.virustotal.com/api/v3/urls.
    • Get Contents of URL Action: Set the method to "POST". In "Headers", add "x-apikey" and your VirusTotal API key. In "Request Body", set to "Form" and add a key "url" with the value set to the URL variable captured from the Share Sheet.
  5. Parse and Display the API Response:
    • Get Dictionary from Input: To parse the JSON response from the API.
    • Show Result: Customize this action to display the desired information from the analysis results, using parts of the parsed dictionary.

Example Script for Publishing as a Gist:

Below is a hypothetical script that outlines how you might format the shortcut actions for publication or sharing. Since direct execution of this script is not possible without the iOS Shortcuts app context, use it as a reference for setting up your shortcut:

# iOS Shortcut for Checking URL Safety with VirusTotal
# Note: This is a conceptual representation for documentation purposes.

1. Action: Get URLs from Input
   - Accepts URLs from Share Sheet

2. Action: URL
   - URL: https://www.virustotal.com/api/v3/urls

3. Action: Get Contents of URL
   - Method: POST
   - Headers:
     - Key: x-apikey
     - Value: <Your VirusTotal API Key>
   - Request Body (Form):
     - Key: url
     - Value: <URL from Share Sheet>

4. Action: Get Dictionary from Input
   - Parse the JSON response from VirusTotal

5. Action: Show Result
   - Display the safety analysis results

Using Your Shortcut:

  • With the shortcut set up, you can test URLs by sharing them to the Shortcuts app via the Share Sheet and selecting your "Check URL Safety" shortcut. The results will provide insight into the safety of the URL based on VirusTotal's analysis.

Final Notes:

  • Adjustments may be needed based on the specific JSON response structure from VirusTotal.
  • Ensure you respect the API rate limits imposed by VirusTotal, especially if using a free account.

This guide and script provide a foundational approach to integrating iOS Shortcuts with web services for security analysis, enhancing your ability to quickly assess the safety of URLs on the fly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment