软层漏洞扫描Python

2024-06-16 09:57:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用SoftLayer的Python库来运行自动漏洞扫描。不幸的是,我得到了以下例外:

SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception): Unable to create a new object of type SoftLayer_Network_Security_Scanner_Request_Nessus. Make sure the authentication method is correct.

我使用的代码如下所示。在

import SoftLayer

USERNAME=""    # I put valid value in here
APIKEY=""      # I put valid value in here
TARGET=""      # I put valid value in here

client = SoftLayer.create_client_from_env(
    username=USERNAME,
    api_key=APIKEY
)
""" ALTERNATE I TRIED ALSO FROM DOCUMENTATION:
client = SoftLayer.Client(
    username=USERNAME,
    api_key=APIKEY
)
"""
account = client['Account'].getObject()
scanner = client.call(
        "SoftLayer_Network_Security_Scanner_Request",
        "createObject", {
            "accountId": account.get('id'),
            "ipAddress": TARGET
})

Python库发送的HTTP请求如下所示:

^{pr2}$

收到的HTTP响应是:

HTTP/1.1 200 OK
Date: Thu, 09 Feb 2017 12:47:17 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Vary: Accept-Encoding
Connection: close
Content-Type: text/xml
Content-Length: 495

<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<fault>
 <value>
  <struct>
   <member>
    <name>faultCode</name>
    <value>
     <string>SoftLayer_Exception</string>
    </value>
   </member>
   <member>
    <name>faultString</name>
    <value>
     <string>Unable to create a new object of type SoftLayer_Network_Security_Scanner_Request_Nessus. Make sure the authentication method is correct.</string>
    </value>
   </member>
  </struct>
 </value>
</fault>
</methodResponse>

有人能帮我一下,看看代码,因为我不知道问题出在哪里。 你能不能也提供一个最低限度的权限清单,这是需要的工作?在

注意:我尝试启用所有可能的调试权限,但没有成功


Tags: nameinclientstringputvaluerequestcreate
2条回答

这看起来是API的一个问题,它不仅可以指定IP地址,还可以指定hardwareId(对于裸机服务器)或guestId(对于虚拟来宾服务器)

所以试试这个代码:

import SoftLayer

USERNAME="set me"    # I put valid value in here
APIKEY="set me"      # I put valid value in here
TARGET="set me"      # I put valid value in here

client = SoftLayer.create_client_from_env(
    username=USERNAME,
    api_key=APIKEY
)

account = client['Account'].getObject()
server = client['Virtual_Guest'].findByIpAddress(TARGET)
if (server) :
    request = {
            "accountId": account["id"],
            "guestId": server["id"]
    }
else:
    server = client['Hardware_Server'].findByIpAddress(TARGET)
    if (server):
        request = {
            "accountId": account["id"],
            "hardwareId": server["id"]
    }
    else:
        print ("server does not exist.")
        exit
scanner = client['Network_Security_Scanner_Request'].createObject(request)

我测试了Nelson的上述评论,它正在与guestId set for virtual systems合作。所以你必须提供accountId、guestId和ipAddress才能使其生效。我也将测试硬件,并期待同样的成功。如果没有,我会再次发帖

相关问题 更多 >