NetExec icon indicating copy to clipboard operation
NetExec copied to clipboard

Create SMB gpos module, implement get-folder command, and add some module helper functions

Open Marshall-Hallenbeck opened this issue 1 year ago • 28 comments

Module for SMB to list and download all GPOs. Can turn off the download functionality with DOWNLOAD=False

get_gpos module: image

--get-folder feature: image

Marshall-Hallenbeck avatar May 21 '24 19:05 Marshall-Hallenbeck

Would it be possible to detect a folder on a remote system? Than we could just integrate it into the existing get commands

NeffIsBack avatar Jun 14 '24 20:06 NeffIsBack

Would it be possible to detect a folder on a remote system? Than we could just integrate it into the existing get commands

Well the current get-file command references a file, so what would we change it to? I think having them separate makes more sense.

Marshall-Hallenbeck avatar Jun 14 '24 20:06 Marshall-Hallenbeck

Would it be possible to detect a folder on a remote system? Than we could just integrate it into the existing get commands

Well the current get-file command references a file, so what would we change it to? I think having them separate makes more sense.

Hmm yeah i was thinking about moving --get-file/--put-file maybe to --get/--put anyway and add some sort of deprecation warning for the old function. But of course that would only make sense if it is possible to do a smart download/upload. Thoughts?

NeffIsBack avatar Jun 15 '24 00:06 NeffIsBack

just using the verbs "get" and "put" doesn't make it clear what you are getting or putting, so it's sorta confusing, and honestly, changing all that code to just make it a single call sounds like a huge pain in the ass that I'm not interested in doing lol

Marshall-Hallenbeck avatar Jun 15 '24 14:06 Marshall-Hallenbeck

just using the verbs "get" and "put" doesn't make it clear what you are getting or putting, so it's sorta confusing, and honestly, changing all that code to just make it a single call sounds like a huge pain in the ass that I'm not interested in doing lol

I mean we are on SMB, imo its pretty clear what you are trying to achieve. But if it cant be changed by a fairly simple check or try&except call its fine i guess. I just try to limit the amount of options the smb protocol has, there are already a lot (too much imo)

NeffIsBack avatar Jun 18 '24 15:06 NeffIsBack

I mean we are on SMB, imo its pretty clear what you are trying to achieve

Well I disagree with that... we have numerous options to get things such as users, groups, disks, computers, etc all under the SMB protocol.

Marshall-Hallenbeck avatar Jun 18 '24 15:06 Marshall-Hallenbeck

I mean we are on SMB, imo its pretty clear what you are trying to achieve

Well I disagree with that... we have numerous options to get things such as users, groups, disks, computers, etc all under the SMB protocol.

That is true but it is still listed in the Options for put and get remote files. Also the options have descriptions & we have a wiki. Imo that should be enough, but if its not possible it doesnt matter anyway :D

NeffIsBack avatar Jun 22 '24 00:06 NeffIsBack

why the heck did i/it close it lol

NeffIsBack avatar Jun 22 '24 22:06 NeffIsBack

Also imo "recursive" download should always the default for folders, but that's just my opinion, thoughts?

Yeah that makes sense, but how many levels recursive?

Marshall-Hallenbeck avatar Feb 07 '25 17:02 Marshall-Hallenbeck

Also imo "recursive" download should always the default for folders, but that's just my opinion, thoughts?

Yeah that makes sense, but how many levels recursive?

My intuition would always be, that --get-folder would get the folder and all its contents. So i guess indefinitely (until the OS rejects files because of no space lol). Similar to i would copy&paste it in the file explorer

NeffIsBack avatar Feb 07 '25 17:02 NeffIsBack

Somehow also subfolders of the specified folder were not downloaded. E.g. here the folders "Machine" and "User" are missing image

NeffIsBack avatar Mar 18 '25 17:03 NeffIsBack

@NeffIsBack ugh I'm stupid, I literally just had two args switched. Pushing a commit now with that fix plus more debugging for the future.

Marshall-Hallenbeck avatar May 30 '25 16:05 Marshall-Hallenbeck

@NeffIsBack ugh I'm stupid, I literally just had two args switched. Pushing a commit now with that fix plus more debugging for the future.

Happens 😄 gonna test next week

My intuition would always be, that --get-folder would get the folder and all its contents. So i guess indefinitely (until the OS rejects files because of no space lol). Similar to i would copy&paste it in the file explorer

@Marshall-Hallenbeck fine for you if we set the default to a very high value, maybe something like 1000? Then you can still query one recursion level if you don't want to have all content, but the default still downloads the entire folder

NeffIsBack avatar May 30 '25 17:05 NeffIsBack

My intuition would always be, that --get-folder would get the folder and all its contents. So i guess indefinitely (until the OS rejects files because of no space lol). Similar to i would copy&paste it in the file explorer

@Marshall-Hallenbeck fine for you if we set the default to a very high value, maybe something like 1000? Then you can still query one recursion level if you don't want to have all content, but the default still downloads the entire folder

Right now there is no limit, it just downloads the entire folder. I could add in a limiter though.

Marshall-Hallenbeck avatar May 30 '25 18:05 Marshall-Hallenbeck

My intuition would always be, that --get-folder would get the folder and all its contents. So i guess indefinitely (until the OS rejects files because of no space lol). Similar to i would copy&paste it in the file explorer

@Marshall-Hallenbeck fine for you if we set the default to a very high value, maybe something like 1000? Then you can still query one recursion level if you don't want to have all content, but the default still downloads the entire folder

Right now there is no limit, it just downloads the entire folder. I could add in a limiter though.

For me it still only work with --recursive toggled on. Can we do it the other way around? Adding --non-recursive to disable recursion?

NeffIsBack avatar Jun 03 '25 09:06 NeffIsBack

There is still something weird going on: image

  1. It doesn't download all folders in the folder
  2. I still have the path i specified in the folder structure

NeffIsBack avatar Jun 03 '25 09:06 NeffIsBack

Looks like "2." is due to the specification of the path with forward slashes, but as impacket/nxc accepts it we should probably just escape/normalize them before creating the download path: image

NeffIsBack avatar Jun 03 '25 09:06 NeffIsBack

To "1.":

  • subsubfolder3 might be skipped because it is empty? However imo when we download a folder i would expect to fully have its structure downloaded
  • subsubfolder2 only has a folder inside and this one is empty, so that is maybe why it is skipped...? Not sure about this one though, but imo also all empty folders should be downloaded

image

NeffIsBack avatar Jun 03 '25 09:06 NeffIsBack

Yeah it doesn't download empty folders because... what's the point? I guess I can add that in if you think it's a good idea... What's the use of having empty folders downloaded by default?

Marshall-Hallenbeck avatar Jun 03 '25 13:06 Marshall-Hallenbeck

Yeah it doesn't download empty folders because... what's the point? I guess I can add that in if you think it's a good idea... What's the use of having empty folders downloaded by default?

Honestly, I would be super confused if half of the content of a folder would be missing, even if empty. Also there can still be information with folders, such as naming schemes etc. As a user I would expect the content to match exactly the content of the folder on the share (similar to mv/cp on Linux)

NeffIsBack avatar Jun 03 '25 14:06 NeffIsBack

Okay, I can update it. Do you think doing something like displaying [EMPTY] when downloading it would be helpful? My concern is people downloading a big file structure that's empty and just being like "this is all useless!" lol

Marshall-Hallenbeck avatar Jun 03 '25 14:06 Marshall-Hallenbeck

Okay, I can update it. Do you think doing something like displaying [EMPTY] when downloading it would be helpful? My concern is people downloading a big file structure that's empty and just being like "this is all useless!" lol

So imo downloading the folder should have the exact same outcome as connecting to the share via UI(file manager) and then copy&pasting it to your file system. If the content is then "useful" is imo up to the user.

I can think of several examples where even having an empty folder gives you useful information. E.g. you could have an upload folder or something similar with folders for each month, but what if in one month no uploads happen? Maybe someone has deleted the contents, nothing was uploaded, who knows. However, imo the existence of the folder still shows that at least the application didn't break. (just a braod, weird example but my point was that having a folder still provides information)

NeffIsBack avatar Jun 09 '25 21:06 NeffIsBack

There is still something weird going on: image

  1. It doesn't download all folders in the folder

Basically i don't want users to experience the same confusion as me, where i would expect subfolders to be in my downloaded folder and suddenly stuff is missing :D

NeffIsBack avatar Jun 09 '25 21:06 NeffIsBack

@NeffIsBack Please re-review! I've made it SMB only for now due to the annoyance of creating NXC cross-protocol objects. That might be my next fun refactor lol

Marshall-Hallenbeck avatar Jul 30 '25 15:07 Marshall-Hallenbeck

@Marshall-Hallenbeck there is still the bug with the forward slashes and therefore adding the remote path to the local structure: image Possibly missing path sanitation before creating the local folder structure?

Can you also set the recursive flag default to true? Was quite surprised about my empty folder when executing the command :D image

NeffIsBack avatar Aug 02 '25 17:08 NeffIsBack

@NeffIsBack Okay, cleaned up those recommendations. Ended up removing the AttributeError catch because it was just extra useless code.

Marshall-Hallenbeck avatar Aug 13 '25 18:08 Marshall-Hallenbeck

OK in my ADD nature I refactored this to do more GPO stuff, so I think I'll use this for everything-GPO related. I plan on having it automatically find insecure GPOs and add in SharpGPOAbuse-type attacks as well. For now I think it's in a decent place though...

Marshall-Hallenbeck avatar Aug 16 '25 12:08 Marshall-Hallenbeck

Hmm for some reason it seems that the gpt.ini files are not properly receiving their display names, but in LDAP they are displayed (I've moved this from LDAP + SMB to pure SMB for now).

Marshall-Hallenbeck avatar Aug 17 '25 15:08 Marshall-Hallenbeck