nei*_*eif 12
我最近一直在使用pysmb进行网络共享枚举,并发现找到好的/完整的例子并不容易.我会把你推荐给我用pysmb枚举smb共享的小脚本:https://github.com/n3if/scripts/tree/master/smb_enumerator
为了完整起见,我也在这里发布了完成连接和枚举的代码片段:
from smb import SMBConnection
try:
conn = SMBConnection(username,password,'name',system_name,domain,use_ntlm_v2=True,
sign_options=SMBConnection.SIGN_WHEN_SUPPORTED,
is_direct_tcp=True)
connected = conn.connect(system_name,445)
try:
Response = conn.listShares(timeout=30) # obtain a list of shares
print('Shares on: ' + system_name)
for i in range(len(Response)): # iterate through the list of shares
print(" Share[",i,"] =", Response[i].name)
try:
# list the files on each share
Response2 = conn.listPath(Response[i].name,'/',timeout=30)
print(' Files on: ' + system_name + '/' + " Share[",i,"] =",
Response[i].name)
for i in range(len(Response2)):
print(" File[",i,"] =", Response2[i].filename)
except:
print('### can not access the resource')
except:
print('### can not list shares')
except:
print('### can not access the system')
Run Code Online (Sandbox Code Playgroud)
小智 7
SMBConnection类允许您以阻塞模式访问远程Samba服务器上的文件.
要检索远程服务器上共享文件夹中的文件列表,
from smb.SMBConnection import SMBConnection
conn = SMBConnection(userid, password, client_machine_name, remote_machine_name, use_ntlm_v2 = True)
conn.connect(server_ip, 139)
filelist = conn.listPath('shared_folder_name', '/')
Run Code Online (Sandbox Code Playgroud)
返回的文件列表将是SharedFile实例列表.
可以tests/SMBConnectionTests在pysmb源包中的文件夹中找到更多示例.
| 归档时间: |
|
| 查看次数: |
22554 次 |
| 最近记录: |