Skip to content

Commit

Permalink
SMB - fix path concatenation (demisto#27604)
Browse files Browse the repository at this point in the history
* SMB - fix wrong path concatenation

* added RNs

* fixed RNs

* updated docker image

* Moved path creation to function

* Updated func

* updated RN

* removed yml rename
  • Loading branch information
darkushin authored and xsoar-bot committed Jul 26, 2023
1 parent 28eab53 commit abddcc9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
20 changes: 14 additions & 6 deletions Packs/SMB/Integrations/SMB_v2/SMB_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def handle_path(path):
return path.strip('\\/')


def create_share_path(hostname, path):
"""
Create a path to the shared folder according to the smbprotocol convention: '\\server\share'.
For reference see https://github.com/jborean93/smbprotocol/blob/master/examples/high-level/directory-management.py
"""
return fr'\\{hostname}\{path}'


class SMBClient:
def __init__(self, hostname, user, password, encrypt, port):
self.hostname = hostname
Expand Down Expand Up @@ -59,7 +67,7 @@ def test_module(client: SMBClient):
def smb_upload(client: SMBClient, args: dict):
hostname = args.get('hostname')
path = handle_path(args.get('file_path'))
path = os.path.join(hostname or client.hostname, path)
path = create_share_path(hostname or client.hostname, path)
username = args.get('username')
password = args.get('password')
entryID = args.get('entryID')
Expand Down Expand Up @@ -89,7 +97,7 @@ def smb_upload(client: SMBClient, args: dict):
def smb_download(client: SMBClient, args: dict):
hostname = args.get('hostname')
path = handle_path(args.get('file_path'))
path = os.path.join(hostname or client.hostname, path)
path = create_share_path(hostname or client.hostname, path)
username = args.get('username')
password = args.get('password')

Expand All @@ -104,7 +112,7 @@ def smb_download(client: SMBClient, args: dict):
def smb_remove_file(client: SMBClient, args: dict):
hostname = args.get('hostname')
path = handle_path(args.get('file_path'))
path = os.path.join(hostname or client.hostname, path)
path = create_share_path(hostname or client.hostname, path)
username = args.get('username')
password = args.get('password')

Expand All @@ -119,7 +127,7 @@ def list_dir(client: SMBClient, args: dict):
username = args.get('username')
password = args.get('password')
path = handle_path(args.get('path'))
path = os.path.join(hostname or client.hostname, path)
path = create_share_path(hostname or client.hostname, path)

client.create_session(hostname, username, password)
entries = list(scandir(path))
Expand Down Expand Up @@ -151,7 +159,7 @@ def smb_mkdir(client: SMBClient, args: dict):
username = args.get('username')
password = args.get('password')
path = handle_path(args.get('path'))
path = os.path.join(hostname or client.hostname, path)
path = create_share_path(hostname or client.hostname, path)

client.create_session(hostname, username, password)

Expand All @@ -165,7 +173,7 @@ def smb_rmdir(client: SMBClient, args: dict):
username = args.get('username')
password = args.get('password')
path = handle_path(args.get('path'))
path = os.path.join(hostname or client.hostname, path)
path = create_share_path(hostname or client.hostname, path)

client.create_session(hostname, username, password)
rmdir(path)
Expand Down
41 changes: 17 additions & 24 deletions Packs/SMB/Integrations/SMB_v2/SMB_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ configuration:
name: dc
type: 0
required: false
additionalinfo: The domain controller hostname. This is useful for environments
with DFS servers as it is used to identify the DFS domain information automatically.
additionalinfo: The domain controller hostname. This is useful for environments with DFS servers as it is used to identify the DFS domain information automatically.
- display: Username
name: credentials
type: 9
Expand Down Expand Up @@ -117,15 +116,15 @@ script:
description: The password to use for authentication. If empty, the password from the instance configuration is used.
description: Returns a list containing the names of the entries in the directory given by path.
outputs:
- contextPath: SMB.Path.SharedFolder
description: The full path of the shared folder.
type: String
- contextPath: SMB.Path.Files
description: List of files under the shared folder.
type: Unknown
- contextPath: SMB.Path.Directories
description: List of directories under the shared folder.
type: Unknown
- contextPath: SMB.Path.SharedFolder
description: The full path of the shared folder.
type: String
- contextPath: SMB.Path.Files
description: List of files under the shared folder.
type: Unknown
- contextPath: SMB.Path.Directories
description: List of directories under the shared folder.
type: Unknown
- name: smb-file-remove
arguments:
- name: file_path
Expand All @@ -135,11 +134,9 @@ script:
- name: hostname
description: Server IP address / hostname. If empty, the hostname from the instance configuration is used.
- name: username
description: The username to use when creating a new SMB session. If empty,
the username from the instance configuration is used.
description: The username to use when creating a new SMB session. If empty, the username from the instance configuration is used.
- name: password
description: The password to use for authentication. If empty, the password
from the instance configuration is used.
description: The password to use for authentication. If empty, the password from the instance configuration is used.
description: Removes a file from the server.
- name: smb-directory-create
arguments:
Expand All @@ -150,11 +147,9 @@ script:
- name: hostname
description: Server IP address / hostname. If empty, the hostname from the instance configuration is used.
- name: username
description: The username to use when creating a new SMB session. If empty,
the username from the instance configuration is used.
description: The username to use when creating a new SMB session. If empty, the username from the instance configuration is used.
- name: password
description: The password to use for authentication. If empty, the password
from the instance configuration is used.
description: The password to use for authentication. If empty, the password from the instance configuration is used.
description: Creates a new directory under the given path.
- name: smb-directory-remove
arguments:
Expand All @@ -165,13 +160,11 @@ script:
- name: hostname
description: Server IP address / hostname. If empty, the hostname from the instance configuration is used.
- name: username
description: The username to use when creating a new SMB session. If empty,
the username from the instance configuration is used.
description: The username to use when creating a new SMB session. If empty, the username from the instance configuration is used.
- name: password
description: The password to use for authentication. If empty, the password
from the instance configuration is used.
description: The password to use for authentication. If empty, the password from the instance configuration is used.
description: Removes a directory from the given path.
dockerimage: demisto/smbprotocol:1.0.0.46456
dockerimage: demisto/smbprotocol:1.0.0.63639
isfetch: false
runonce: false
script: '-'
Expand Down
7 changes: 7 additions & 0 deletions Packs/SMB/ReleaseNotes/2_0_16.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### Server Message Block (SMB) v2

- Fixed an issue where wrong path concatenation caused commands to fail.
- Updated the Docker image to: *demisto/smbprotocol:1.0.0.63639*.
2 changes: 1 addition & 1 deletion Packs/SMB/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Server Message Block (SMB)",
"description": "File exchange with an SMB server.",
"support": "xsoar",
"currentVersion": "2.0.15",
"currentVersion": "2.0.16",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit abddcc9

Please sign in to comment.