Lesson 6: Use Loops

Many security situations generate large quantities of data, often with additional information to supplement the parent data set. In such cases, you can use loop steps to thoroughly review vast quantities of information in a fraction of the time that it would take to review each data point manually.

In this lesson, you’ll build a simple loop step to process array input from previous steps. You will use the internal loop variable $item artifact step to the loop to process and display each iteration’s data.

Build a Loop Step

To create the loop:

  1. Click on the + icon after the “WhoisLookup” step.
  2. Select Loop for the step type, then click Continue.
  3. Name the loop “Show Individual Nameservers”, then make sure the Repeat Over tab in the “Input” section is underlined in blue.
  4. Select Whois Lookup.name_servers from the dropdown for the “Variable to repeat over” field. Then click Save Step and Enter Loop.
  5. The workflow builder now only shows the canvas for the loop, “Show Individual Nameservers.” Any steps you add here are only for the loop. Click the + sign to add a step.
  6. Select Artifact for the step type. Name the artifact “Show One Nameserver”.
  7. In the “Output format” field, click on the blue + sign in the lower-right corner, then select Show Individual Nameservers.$item. Then type a single space.
  8. After the space, copy and paste in is one of the nameservers for {{[Welcome Trigger].[domain]}}. into the “Output format” field.
  9. Click Preview, then click Add Artifact.
  10. Click on the blue Exit Loop Step button in the upper-right corner of the workflow builder, then test the workflow with the input rapid7.com.

When your test completes, the test job will include a few “Show One Nameserver” artifacts and one “Welcome Artifact.” Observe the behavior in each of these artifacts and the different data displayed in each one.

Congratulations! You created your first loop and created artifacts for each iteration of the loop. You also learned how to use the $item internal loop variable.

In computer programming, loops are sequences of instructions that repeat until an exit condition is reached. InsightConnect helps you set up these exit conditions with the two types of loops: “Repeat Over” and “Repeat Until.”

“Repeat Over” loops will iterate over the array variable you configure. This type of loop is limited to the number of items in the array, so the loop will iterate 10 times over an array variable with 10 items. “Repeat Until” loops don’t require specific loop input variables, and you can set the number of times the loop will iterate over the steps within the loop.

In this lesson, you used the loop to inspect every nameserver in the Whois “name servers” step output variable. Inside the loop, InsightConnect references the current item in the array variable with the $item variable. The value of $item changed with every iteration of the loop, and you see these different values in the “Show One Nameserver” artifacts.