# Ad-Hoc Scan a Specific Asset in Nexpose Enterprise Plug-In

**URL:** <https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925>\
**Category:** Plugins\
**Tags:** nexpose\_enterprise\
**Created:** [May 18, 2020, 8:35pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925 "2020-05-18T20:35:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![brandon\_mcclure](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/brandon_mcclure/32/182_2.png) [@brandon\_mcclure](https://discuss.rapid7.com/u/brandon_mcclure)\
**Post date:** [May 18, 2020, 8:35pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/1 "2020-05-18T20:35:31Z")

</div>

If I’m reading the Nexpose Enterprise Plug-In documentation right, the “Scan a Site” Action only allows you to scan a predefined site by site\_name.  
I’m trying to do an Ad-Hoc scan of a specific Asset in a Site and don’t see that as an option.  
I know that I can do this via a REST by passing a string array of hosts with a templateId and name.  
Is there an Action in the Plug-In that I’m missing? If not could this functionality be added?

---

<div class="post-metadata">

**Author:** ![philipp\_behmer](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/philipp_behmer/32/183_2.png) [@philipp\_behmer](https://discuss.rapid7.com/u/philipp_behmer)\
**Post date:** [May 19, 2020, 2:45pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/2 "2020-05-19T14:45:18Z")

</div>

Looks like the assets to include could be easily added by just sending them in the body of the request:  
[https://help.rapid7.com/insightvm/en-us/api/index.html#operation/startScan](https://help.rapid7.com/insightvm/en-us/api/index.html#operation/startScan)

The request isn’t using the body at the moment:

> <https://github.com/rapid7/insightconnect-plugins/blob/master/rapid7_insightvm/komand_rapid7_insightvm/actions/scan/action.py#L22>

But I think it could be easily added as the request function already supports a JSON payload for the body:

> <https://github.com/rapid7/insightconnect-plugins/blob/master/rapid7_insightvm/komand_rapid7_insightvm/util/resource_helper.py#L85>

With this change it would be possible to also define engine, scan name and scan template.

---

<div class="post-metadata">

**Author:** ![brandon\_mcclure](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/brandon_mcclure/32/182_2.png) [@brandon\_mcclure](https://discuss.rapid7.com/u/brandon_mcclure)\
**Post date:** [May 19, 2020, 3:07pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/3 "2020-05-19T15:07:37Z")

</div>

yes, that is exactly what I’m doing via the REST API

Passing the body like this  
`{ "engineId": int, "hosts": ["string"], "name": "string", "templateId": "string" }`

I would just prefer to use an action on the Nexpose Enterprise Plug-In verses making a REST call

---

<div class="post-metadata">

**Author:** ![philipp\_behmer](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/philipp_behmer/32/183_2.png) [@philipp\_behmer](https://discuss.rapid7.com/u/philipp_behmer)\
**Post date:** [May 19, 2020, 4:08pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/4 "2020-05-19T16:08:37Z")

</div>

I implemented this functionality quickly for the hosts.

> <https://github.com/rapid7/insightconnect-plugins/pull/493>

Feel free to add the other parameters and send in a pull request.  
This functionality is available as soon as the pull request is merged.  
Then you need to update your IVM plugin in ICON and your workflow.

---

<div class="post-metadata">

**Author:** ![brandon\_mcclure](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/brandon_mcclure/32/182_2.png) [@brandon\_mcclure](https://discuss.rapid7.com/u/brandon_mcclure)\
**Post date:** [May 19, 2020, 4:40pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/5 "2020-05-19T16:40:39Z")

</div>

Thanks, I’ll keep an eye out for it and le you know.  
I didn’t see this Plug-In in the community repo on GitHub

---

<div class="post-metadata">

**Author:** ![philipp\_behmer](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/philipp_behmer/32/183_2.png) [@philipp\_behmer](https://discuss.rapid7.com/u/philipp_behmer)\
**Post date:** [May 19, 2020, 6:45pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/6 "2020-05-19T18:45:10Z")

</div>

@brandon_mcclure the new version was just released 🎉

---

<div class="post-metadata">

**Author:** ![brandon\_mcclure](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/brandon_mcclure/32/182_2.png) [@brandon\_mcclure](https://discuss.rapid7.com/u/brandon_mcclure)\
**Post date:** [May 22, 2020, 10:17pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/7 "2020-05-22T22:17:27Z")

</div>

So I got this working as a test, but I’m not sure about the pull request, I started filling it but wasn’t sure I was doing it right. Any way you can help me with that?  
The change was pretty minimal, I just used what you did and added a few more.  
I did run through the tests playing with different values for these and they all passed.  
In the plugin.spec.yaml I did this

```
scan:
    title: Scan
    description: Start a scan on a site
    input:
      site_id:
        title: Site ID
        description: ID of the site to scan
        type: string
        example: 1
        required: true
      name:
        title: Scan Name
        description: The Scan Name, leaving blank will use "API Scan - " + UTC Timestamp
        type: string
        example: "Full Audit Ad-Hoc Scan from API"
        required: false
      hosts:
        title: Hosts
        description: The hosts that should be included in the scan, leaving blank will scan all
        type: "[]string"
        example: ["192.0.2.3", "192.0.2.10-192.0.2.20", "ADSRV.local"]
        required: false
      template_id:
        title: Template Id
        description: The ID of the Scan Template that should use, leaving blank will use the default Scan Template
        type: string
        example: "full-audit-without-web-spider"
        required: false
      engine_id:
        title: Engine Id
        description: The ID of the Scan Engine that should use, leaving blank will use the default Scan Engine
        type: string
        example: 4
        required: false
```

then in the scan action I modified it to this:

```
site_id = params.get("site_id")
        name = params.get("name")
        hosts = params.get("hosts")
        template_id = params.get("template_id")
        engine_id = params.get("engine_id")
        endpoint = endpoints.Scan.site_scans(self.connection.console_url,site_id)
        self.logger.info("Using %s ..." % endpoint)
        if name or hosts or template_id or engine_id:
            payload = {}
            if name:
                payload["name"] = name
            if hosts:
                payload["hosts"] = hosts
            if template_id:
                payload["templateId"] = template_id
            if engine_id:
                payload["engineId"] = engine_id
            response = resource_helper.resource_request(endpoint=endpoint, method='post', payload=payload)
        else:
            response = resource_helper.resource_request(endpoint=endpoint, method='post')
```

---

<div class="post-metadata">

**Author:** ![philipp\_behmer](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/philipp_behmer/32/183_2.png) [@philipp\_behmer](https://discuss.rapid7.com/u/philipp_behmer)\
**Post date:** [May 25, 2020, 11:56am UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/8 "2020-05-25T11:56:15Z")

</div>

Hi Brandon!  
I only noticed that the engineId is an integer (you defined it as string):  
[https://help.rapid7.com/insightvm/en-us/api/index.html#operation/startScan](https://help.rapid7.com/insightvm/en-us/api/index.html#operation/startScan)

Everything else looks fine for me.  
Before you do the pull request don’t forget to also increase the version number and add a line to the changelog in the help file.

But the ICON team will also review your changes in the pull request.

---

<div class="post-metadata">

**Author:** ![brandon\_mcclure](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/brandon_mcclure/32/182_2.png) [@brandon\_mcclure](https://discuss.rapid7.com/u/brandon_mcclure)\
**Post date:** [May 25, 2020, 4:32pm UTC](https://discuss.rapid7.com/t/ad-hoc-scan-a-specific-asset-in-nexpose-enterprise-plug-in/925/9 "2020-05-25T16:32:19Z")

</div>

I saw that, but switched it to a string because the scan\_id was defined as a string, but maybe that is because it is being used in the URL and not the body.  
I’ll give the pull request a shot, I did one for the workflows, the plugins just had different requirements that I wasn’t sure about.
