如何使用 python 连接到远程 OpenVas 扫描仪?

gad*_*hvi 3 python linux security ssh openvas

我正在探索 OpenVas 工具来满足项目需求,openVas 目前由 Greenbone 管理。当我尝试使用 python api 使用远程扫描仪时出现错误。

我完成了所有初始配置,设置了所需的 gui 帐户等,并且能够手动扫描所需的系统,但是当我尝试使用 Python Api 执行相同操作时,它不起作用。互联网上和手册中都没有任何示例来验证我的代码。我使用了 [ https://pypi.org/project/python-gvm/] api。

我写了简单的代码,但它不起作用..

from gvm.connections import SSHConnection
from gvm.protocols.latest import Gmp
from gvm.transforms import EtreeTransform
from gvm.xml import pretty_print

connection = SSHConnection(hostname='192.168.1.84',username='alex',password='alex@123')
gmp = Gmp(connection)
gmp.authenticate('admin', 'admin')

# Retrieve current GMP version
version = gmp.get_version()

# Prints the XML in beautiful form
pretty_print(version)

Run Code Online (Sandbox Code Playgroud)

我收到错误-

/usr/bin/python3.7 /home/punshi/PycharmProjects/nessus_api/openvas-greenbone.py
/usr/local/lib/python3.7/dist-packages/paramiko/kex_ecdh_nist.py:39: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
  m.add_string(self.Q_C.public_numbers().encode_point())
/usr/local/lib/python3.7/dist-packages/paramiko/kex_ecdh_nist.py:96: CryptographyDeprecationWarning: Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_point
  self.curve, Q_S_bytes
/usr/local/lib/python3.7/dist-packages/paramiko/kex_ecdh_nist.py:111: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
  hm.add_string(self.Q_C.public_numbers().encode_point())
Traceback (most recent call last):
  File "/home/punshi/PycharmProjects/nessus_api/openvas-greenbone.py", line 8, in <module>
    gmp.authenticate('admin', 'admin')
  File "/usr/local/lib/python3.7/dist-packages/gvm/protocols/gmpv7.py", line 211, in authenticate
    response = self._read()
  File "/usr/local/lib/python3.7/dist-packages/gvm/protocols/base.py", line 54, in _read
    return self._connection.read()
  File "/usr/local/lib/python3.7/dist-packages/gvm/connections.py", line 126, in read
    raise GvmError('Remote closed the connection')
gvm.errors.GvmError: Remote closed the connection

Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

我已经手动测试了 SSH 连接,因此问题要么出在我的代码上,要么出在其他代码上。

附加细节-

Ubuntu 16,
Greenbone Security Assistant 7.0.3 (gui)
Open Vas - 9.0.3
Run Code Online (Sandbox Code Playgroud)

小智 6

我有完全相同的问题,我用TLSConnection而不是解决了它SSHConnection。这是你的代码:

import gvm
from gvm.protocols.latest import Gmp
from gvm.transforms import EtreeTransform
from gvm.xml import pretty_print

connection =gvm.connections.TLSConnection(hostname='192.168.1.84')
gmp = Gmp(connection)
gmp.authenticate('admin', 'admin')

# Retrieve current GMP version
version = gmp.get_version()

# Prints the XML in beautiful form
pretty_print(version)
Run Code Online (Sandbox Code Playgroud)