-
Notifications
You must be signed in to change notification settings - Fork 256
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
[FIX #133] Various exception handler fixes for stability #138
Conversation
@Mitul16 if you're interested, want to give this a go and see if it fixes the uncaught exceptions you were seeing before? It seems to fix the ones I could reproduce, but I'm curious to see from your perspective. Thanks! |
The recv method did not used to handle an empty result properly. It now raises a ChannelClosed exception properly. Also, odly, the `Manager.find_session_by_channel` method had never been implemented.
It doesn't look like the fix is in action, please do let me know. I would like to test it for sure. |
Sorry for the back and forth. There was a couple cases I missed from your report in the issue. I believe the last push covers all the bases, and I'd really appreciate your feedback now 😄 |
I think the following issue comes under current Issue - If I remember correctly, there was once a check in the module
60 access = pwncat.victim.access(args.destination)
61 if Access.DIRECTORY in access:
62 args.destination = os.path.join(
63 args.destination, os.path.basename(args.source)
64 )
65 elif Access.PARENT_EXIST not in access:
66 console.log(
67 f"[cyan]{args.destination}[/cyan]: no such file or directory"
68 )
69 return
|
Also fixed a tangential problem which arose regarding the group enumerations which caused a recursive call the enumerate groups from within the group enumeration.
Yes, that used to be a thing, and was removed because I thought the |
Well, now it is breezing 😀 I have tested the following for an invalidated session :
None of the above renders the There is one little issue, I tried to upload |
Socket-based channels now raise ChannelClosed if no connection is active and a recv/send method is called. Also, the close method no longer raises an exception if the channel is not active. It is silently ignored as a NOOP.
Cool, I was able to replicate that pretty easily. The problem was that the |
@calebstewart I have a doubt, why have you used In 35 def __init__(self, ch, msg="generic channel failure"):
36 super().__init__(msg)
37 self.channel = ch Even in the classes extending the super class def __init__(self, ch):
super().__init__(ch, CORRESPONDING_ERROR_MESSAGE) The places where you have |
There is a missing argument to the ChannelError constructor - ch (channel). Because of this, many explicitly passed error messages are simply rejected. There is a minor typo correction as well, 'writiers' -> 'writers'.
Regarding my last comment, I have added a commit to the branch issue-133-uncaught-channelerror |
This change was not committed, possibly due to the use of testing directory
You're correct. That appears to be a typo, which would eventually cause an exception as the channel reference is used to cleanup disconnected channels on exception. |
I had not seen it. I went and found it. You can create a pull request if you'd like. I will say I don't agree with catching the ChannelError in |
On second thought, I can just merge your changes into my branch. There's no need for a formal pull request. It's all working toward the same goal anyway. |
Ah! You are back. I was testing # In `pwncat` terminal prompt, password is `bandit0`
connect ssh://bandit0@bandit.labs.overthewire.org:2220 You may find that |
Moreover, I wasn't sure upto how many parent layers (methods) to bring the error, I did find |
That was a bug in the exception handler that slipped through the cracks for a long time. Good catch. Should be fixed in this branch now. Also, I'm pretty sure we're on different time zones 🤣
Totally understand your logic, but I would say the In any case, I'll get your changes merged in a moment. |
…' into issue-133-uncaught-channelerror
This is the reason I didn't create a PR because of the way I have implemented this |
Not a big deal. I have your fork added as a separate remote to my local clone, so I can easily merge your branch, then make the one slight modification and push back here. I'd prefer that, so that your contributions aren't lost in the git history. 👍 I've done that, and we should be good at this point at least with the exception problems we've found so far. Hopefully there aren't any more. 😭 |
Are you still seeing any spurious or weird exception issues or working on anything related to this PR? If not, I will merge this branch back into master. |
Yes, I did find one but it is not related to connections but file I/O instead
56 if identity is not None:
57 # Make sure the provided identity file is good to use
58 if not os.path.exists(identity):
59 raise ChannelError(self, f"identity file `{identity}` not found!")
60 elif os.access(identity, os.R_OK):
61 raise ChannelError(self, f"cannot read identity file `{identity}`") Unfortunately there are a little more, but these are not related to |
The back command was super simple fix, so I went ahead and just fixed that. It was raising the wrong exception type. Regarding the SSH stuff, I'm going to say that should be a different issue. The whole setup process for SSH channels should be changing soon (see #122 and #91), and that exception doesn't actually break anything. It's just not a pleasant message for an actual exceptional condition. Plus this PR is getting pretty hefty as it is. lol |
No problem. If/when you are comfortable that the exception issues are fixed, please mark this PR as reviewed, and then I'll merge. This and #140 are the two things I'd like to get merged before dropping v0.4.3. They're big fixes that should be ideally released ASAP. Thanks again for your help on this! These two issues have been huge steps forward in the stability of pwncat. 😄 |
Just a quick question, how are you trying to catch the I went ahead to test my modifications - two new exceptions raised in 48 try:
49 client = socket.create_connection((host, port))
50 except socket.gaierror:
51 raise ChannelError(self, "invalid host provided")
52 except ConnectionRefusedError:
53 raise ChannelError(self, "connection refused, check your port")
|
Whatever calls For the |
Yes, because it is being executed from
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have reviewed all the changes except pwncat/manager.py
.
There are a lot of modifications and I have not tested each and every little change.
Everything looks fine to me, I will try to fuzz pwncat/manager.py
There's no easy way to classify all the exception handling fixes implemented in this branch, so I'm just going with this...
|
Exception handling in the output thread was cleaned up and had Windows platform raise the RawModeExit exception to trigger an exit when interactive end marker was observed.
…wart/pwncat into issue-133-uncaught-channelerror
Myself and @JohnHammond have been testing this all evening, and think it's ready for merging. I'm going to go ahead and merge this in as I feel like random bug fixes are getting tossed in (e.g. I just fixed a Windows problem that is only loosely related). The pull request is diverging more than I'd like. If there's more problems, feel free to open another issue and we'll work through it. |
Description of Changes
Fixes #133.
Added better exception handling in
Manager.interactive
which should now withstand dropped sessions.Major Changes Implemented:
Pre-Merge Tasks
python-black
isort
flake8
on repo, and fixed any new problems w/ modified filespytest
test cases[Unreleased]
)For issues with pre-merge tasks, see CONTRIBUTING.md