Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PuTTY module and fix WinSCP #249

Merged
merged 13 commits into from May 16, 2024
Merged

Add PuTTY module and fix WinSCP #249

merged 13 commits into from May 16, 2024

Conversation

NeffIsBack
Copy link
Contributor

@NeffIsBack NeffIsBack commented Apr 5, 2024

This PR contains:

  • A new module to query for saved private keys in PuTTY
  • Also add detection for saved proxy credentials in PuTTY
  • Fixes a critical bug in winscp
  • Overall improves code from winscp

PuTTY example:
image

Before, if a certain registry was not found by winscp it crashed internally, skipping credential extraction for a user with existing credentials. Before and after:
image
image

@NeffIsBack NeffIsBack added bug-fix This Pull Request fixes a bug new module labels Apr 5, 2024
@Marshall-Hallenbeck
Copy link
Collaborator

Very weird issue. If I run this against hosts 1 at a time, it works fine, but if I run against 2 hosts at the same time, for some reason the dce object is None?

image

@NeffIsBack
Copy link
Contributor Author

NeffIsBack commented Apr 6, 2024

Okay i think my intuition was right: We have an instantiation problem. When we load a module multiple times it highly likely loads THE SAME module. This means objects that are set as class attributes (here self.rrp) will be the same objects across all targets. Therefore when the first object finishes rrp the same is applicable to all other modules. This is probably true for protocols as well (weird, that this didn't cause more errors).
image

Solution: Either create an rrp object and pass it down the functions or fix the loading process

EDIT: This does not apply to the context and connection as these are passed into the login method on runtime (and are created seperately).

EDIT2: The last assignment overwrite all other objects in other modules!!!
image
image

@NeffIsBack
Copy link
Contributor Author

NeffIsBack commented Apr 6, 2024

For now i updated the module to not use an object on itself, but to pass it through the functions. We should definitely fix the load process though imo

@NeffIsBack
Copy link
Contributor Author

Fortunately not applicable to the protocol (that would anyway have caused a lot of issues in the first place)
image

@mpgn
Copy link
Collaborator

mpgn commented Apr 6, 2024

Excellent finding as always @NeffIsBack 😃

@NeffIsBack
Copy link
Contributor Author

NeffIsBack commented Apr 6, 2024

A colleague pointed out, that you can store proxy username&password with PuTTY which are stored in the registry in plaintext. Added detection for that as well

@mpgn mpgn added this to the v1.2.0 milestone Apr 10, 2024
mpgn
mpgn previously approved these changes Apr 10, 2024
@Marshall-Hallenbeck Marshall-Hallenbeck changed the title Add PuTTY module Add PuTTY module and fix WinSCP May 12, 2024
@NeffIsBack
Copy link
Contributor Author

@Marshall-Hallenbeck for testing set the proxy creds:
image

As well as a path to a saved priv key file:
image

And save it as a session:
image

@Marshall-Hallenbeck
Copy link
Collaborator

Installing necessary requirements to test this now

@Marshall-Hallenbeck
Copy link
Collaborator

@NeffIsBack just tested this and it works great, I just had a concern with the file name that it saves the file in.

It doesn't include a timestamp/hash in the filename so keys will over-write each other if they are named the same. I think it'd be useful to make sure they aren't being overwritten in situations where a user might have different keys with the same keyname on different hosts (such as id_rsa) or in the rare case they change the key and you redownload it.

@Marshall-Hallenbeck
Copy link
Collaborator

Also, it looks like the proxy creds aren't stored anywhere, just printed to the screen?

@NeffIsBack
Copy link
Contributor Author

@NeffIsBack just tested this and it works great, I just had a concern with the file name that it saves the file in.

It doesn't include a timestamp/hash in the filename so keys will over-write each other if they are named the same. I think it'd be useful to make sure they aren't being overwritten in situations where a user might have different keys with the same keyname on different hosts (such as id_rsa) or in the rare case they change the key and you redownload it.

Indeed a valid concern! I'll change that real quick.

@NeffIsBack
Copy link
Contributor Author

Also, it looks like the proxy creds aren't stored anywhere, just printed to the screen?

Hmm yes, i didn't want to add them to the db as they might not be AD credentials, but arbitrary ones. Also we have no garantuee they work, like a valid login or an AD dump of some kind (although they probably will). That's why i didn't add them.

@NeffIsBack
Copy link
Contributor Author

Changed:
image

mpgn
mpgn previously approved these changes May 15, 2024
@Marshall-Hallenbeck
Copy link
Collaborator

Also, it looks like the proxy creds aren't stored anywhere, just printed to the screen?

Hmm yes, i didn't want to add them to the db as they might not be AD credentials, but arbitrary ones. Also we have no garantuee they work, like a valid login or an AD dump of some kind (although they probably will). That's why i didn't add them.

Can you save them to a file in the PuTTY directory?

@Marshall-Hallenbeck
Copy link
Collaborator

Marshall-Hallenbeck commented May 15, 2024

@NeffIsBack with the new modules folder, we have two places where nxc & modules are logging (.nxc/logs/ and now .nxc/modules/$name).

I'm working on another PR to normalize module logging, but should we break up logs and module data output? i.e. .nxc/modules/$name/ would be data like SAM/SYSTEM, Putty keys, etc and .nxc/logs/ is for generic additional logging? There's also date folders in the logs folder for wcc, which is referenced in #256

If you want I can come up with a normalized way to handle all this and we can just merge what's here and I'll update it later.

@mpgn
Copy link
Collaborator

mpgn commented May 15, 2024

@NeffIsBack with the new modules folder, we have two places where nxc & modules are logging (.nxc/logs/ and now .nxc/modules/$name).

I'm working on another PR to normalize module logging, but should we break up logs and module data output? i.e. .nxc/modules/$name/ would be data like SAM/SYSTEM, Putty keys, etc and .nxc/logs/ is for generic additional logging? There's also date folders in the logs folder for wcc, which is referenced in #256

If you want I can come up with a normalized way to handle all this and we can just merge what's here and I'll update it later.

For core option it's not very logical to move them to a module folder imo

@NeffIsBack
Copy link
Contributor Author

Also, it looks like the proxy creds aren't stored anywhere, just printed to the screen?

Hmm yes, i didn't want to add them to the db as they might not be AD credentials, but arbitrary ones. Also we have no garantuee they work, like a valid login or an AD dump of some kind (although they probably will). That's why i didn't add them.

Can you save them to a file in the PuTTY directory?

Done:
image

Copy link
Collaborator

@Marshall-Hallenbeck Marshall-Hallenbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, LGTM. I'll make the logging changes in another PR per what we discussed in PMs.

@Marshall-Hallenbeck Marshall-Hallenbeck merged commit e3baadb into main May 16, 2024
6 checks passed
@Marshall-Hallenbeck Marshall-Hallenbeck deleted the neff-putty branch May 16, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix This Pull Request fixes a bug new module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants