Skip to content

Commit

Permalink
add multi-file put, keeping compatibiltiy with old format (tuple) -
Browse files Browse the repository at this point in the history
  • Loading branch information
wumb0 committed Apr 28, 2024
1 parent 52d4511 commit 8fb9bc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions nxc/protocols/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,14 +1246,22 @@ def rid_brute(self, max_rid=None):
dce.disconnect()
return entries

def put_file(self):
self.logger.display(f"Copying {self.args.put_file[0]} to {self.args.put_file[1]}")
with open(self.args.put_file[0], "rb") as file:
def put_file_single(self, src, dst):
self.logger.display(f"Copying {src} to {dst}")
with open(src, "rb") as file:
try:
self.conn.putFile(self.args.share, self.args.put_file[1], file.read)
self.logger.success(f"Created file {self.args.put_file[0]} on \\\\{self.args.share}\\{self.args.put_file[1]}")
self.conn.putFile(self.args.share, dst, file.read)
self.logger.success(f"Created file {src} on \\\\{self.args.share}\\{dst}")
except Exception as e:
self.logger.fail(f"Error writing file to share {self.args.share}: {e}")

def put_file(self):
files = self.args.put_file
if isinstance(files, list):
for src, dest in files:
self.put_file_single(src, dest)
else:
self.put_file_single(*files)

def get_file(self):
share_name = self.args.share
Expand Down
2 changes: 1 addition & 1 deletion nxc/protocols/smb/proto_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def proto_args(parser, std_parser, module_parser):
sgroup.add_argument("--only-files", action="store_true", help="only spider files")

tgroup = smb_parser.add_argument_group("Files", "Options for put and get remote files")
tgroup.add_argument("--put-file", nargs=2, metavar="FILE", help="Put a local file into remote target, ex: whoami.txt \\\\Windows\\\\Temp\\\\whoami.txt")
tgroup.add_argument("--put-file", action="append", nargs=2, metavar="FILE", help="Put a local file into remote target, ex: whoami.txt \\\\Windows\\\\Temp\\\\whoami.txt")
tgroup.add_argument("--get-file", nargs=2, metavar="FILE", help="Get a remote file, ex: \\\\Windows\\\\Temp\\\\whoami.txt whoami.txt")
tgroup.add_argument("--append-host", action="store_true", help="append the host to the get-file filename")

Expand Down

0 comments on commit 8fb9bc0

Please sign in to comment.