0

I am using Nessus XML RPC to update a SharePoint site. I can add items to a list, but cannot update or delete. No error is returned.

Variables:

$strSharePointSite = "https://mysite/_vti_bin/lists.asmx?WSDL"
$strListName       = "{e26b73cd-2278-4656-be96-7aa366e7527a}"
$strViewName       = "{234c8a17-2df7-49b7-8d0c-aadbc6a171f0}"

Works:

function AddItem {
    Param
        (
            $objItem
        )

    Write-Debug "Add Item"
    Write-Debug ("Host: " + $objItem.Host)
    Write-Debug ("Plugin ID: " + $objItem.PluginID)

    $blnExploitAvailable = $objItem.ExploitAvailable

    if ($blnExploitAvailable -ne "true" -and $blnExploitAvailable -ne "false") { $blnExploitAvailable = "false" }

    $strXML = "<Method ID = '1' Cmd = 'New'>" +
              "<Field Name = 'Title'>" + (XMLEncode($objItem.Host)) + "</Field>" +
              "<Field Name = 'Severity'>" + (XMLEncode($objItem.Severity)) + "</Field>" +
              "<Field Name = 'Plugin_x0020_ID'>" + (XMLEncode($objItem.PluginID)) + "</Field>" +
              "<Field Name = 'Plugin_x0020_Name'>" + (XMLEncode($objItem.PluginName)) + "</Field>" +
              "<Field Name = 'Description'>" + (XMLEncode($objItem.Description)) + "</Field>" +
              "<Field Name = 'Solution'>" + (XMLEncode($objItem.Solution)) + "</Field>" +
              "<Field Name = 'Exploitable'>" + (XMLEncode($blnExploitAvailable)) + "</Field>" +
              "</Method>"

    $objXMLDoc   = New-Object System.Xml.XmlDocument
    $objXMLBatch = $objXMLDoc.CreateElement("Batch")

    $objXMLBatch.SetAttribute("OnError", "Continue")
    $objXMLBatch.SetAttribute("ListVersion", 1)
    $objXMLBatch.InnerXml = $strXML

    Write-Debug $strXML

    (New-WebServiceProxy -Uri $strSharePointSite -UseDefaultCredential).UpdateListItems($strListName, $objXMLBatch)

Does Not Work:

function UpdateItem {
    Param
        (
            $intID,
            $blnActive = $true
        )

    Write-Debug ("Update Item: " + $intID)
    Write-Debug ("Item Active: " + $blnActive)

    $strXML = "<Method ID = '1' Cmd = 'Update'>" + 
              "<Field Name = 'ID'>$intID</Field>"

    if ($blnActive -eq $true) {              
        $strXML += "<Field Name = 'Active'>1</Field>"
    } else {
        $strXML += "<Field Name = 'Active'>0</Field>"
    }

    $strXML += "</Method>"

    Write-Debug $strXML

    $objXMLDoc   = New-Object System.Xml.XmlDocument
    $objXMLBatch = $objXMLDoc.CreateElement("Batch")

    $objXMLBatch.SetAttribute("OnError", "Continue")
    $objXMLBatch.SetAttribute("ListVersion", 1)
    $objXMLBatch.SetAttribute("ViewName", $strViewName)
    $objXMLBatch.InnerText = $strXML

    (New-WebServiceProxy -Uri $strSharePointSite -UseDefaultCredential).UpdateListItems($strListName, $objXMLBatch)

I have tried several different settings. i.e using Alias Names for List and View names. Changing UpdateItem to Delete, True vs 1 and False vs 0, etc.

"Active" is a Yes/No field.

The View specified includes all fields, including ID.

I need a new set of eyes. I am 98% sure this should work.

0

Can't believe it. Needed to take a break and come back. Here was the problem:

$objXMLBatch.InnerText = $strXML

Should be:

$objXMLBatch.InnerXml = $strXML

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy