Skip to content

Improved Ctrl + c behavior#1231

Open
T1erno wants to merge 1 commit into
Pennyw0rth:mainfrom
T1erno:fix-ctrl+c
Open

Improved Ctrl + c behavior#1231
T1erno wants to merge 1 commit into
Pennyw0rth:mainfrom
T1erno:fix-ctrl+c

Conversation

@T1erno
Copy link
Copy Markdown
Contributor

@T1erno T1erno commented May 5, 2026

Description

Please include a summary of the change and which issue is fixed, or what the enhancement does.
List any dependencies that are required for this change.

If you have used AI in any form, please state the tool you used (e.g. Claude Code, Cursor, Amp) along with the extent that the work was AI-assisted. See the project's AI policy for more details: https://github.com/Pennyw0rth/NetExec/blob/main/AI_POLICY.md

In this version, we use os._exit(0) to stop execution. It is a "Hard Kill" that ends the process without waiting for the threads to finish

When using asyncio.run_in_executor, the main thread is not "working" on the scan, but rather is monitoring the event loop. This allows the CTRL+C signal to be processed instantly rather than waiting for a network socket to respond.

Type of change

Insert an "x" inside the brackets for relevant items (do not delete options)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Deprecation of feature or functionality
  • This change requires a documentation update
  • This requires a third party update (such as Impacket, Dploot, lsassy, etc)
  • This PR was created with the assistance of AI (list what type of assistance, tool(s)/model(s) in the description)

Setup guide for the review

Please provide guidance on what setup is needed to test the introduced changes, such as your locally running machine Python version & OS, as well as the target(s) you tested against, including software versions.
In particular:

  • Bug Fix: Please provide a short description on how to trigger the bug, to make the bug reproducable for the reviewer.

  • Added Feature/Enhancement: Please specify what setup is needed in order to test the changes, such as:

    • Is additional software needed?
    • GPO changes required?
    • Specific registry settings that need to be changed?

    You can test it by scaning any /24 or segment on any protocol. Tested on Linux and Windows

    Related: (Win Binary) Ctr + Z/C/X doesn't work #61

Screenshots (if appropriate):

Screenshots are always nice to have and can give a visual representation of the change.
If appropriate, include before and after screenshot(s) to show which results are to be expected.

https://github.com/user-attachments/assets/1929d2ba-abd5-4b8c-810f-01fb23355a00
https://github.com/user-attachments/assets/bbf1fe46-6094-4461-84f7-3f0b7b5c796d

Checklist:

Insert an "x" inside the brackets for completed and relevant items (do not delete options)

  • I have ran Ruff against my changes (poetry: poetry run ruff check ., use --fix to automatically fix what it can)
  • I have added or updated the tests/e2e_commands.txt file if necessary (new modules or features are required to be added to the e2e tests)
  • If reliant on changes of third party dependencies, such as Impacket, dploot, lsassy, etc, I have linked the relevant PRs in those projects
  • I have linked relevant sources that describes the added technique (blog posts, documentation, etc)
  • I have performed a self-review of my own code (not an AI review)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (PR here: https://github.com/Pennyw0rth/NetExec-Wiki)

Note: There are other 2 issues when running ruff not related to my changes

@0xAnk
Copy link
Copy Markdown

0xAnk commented May 6, 2026

Much needed as default is really slow! Should be merged.

@NeffIsBack
Copy link
Copy Markdown
Member

Much needed as default is really slow! Should be merged.

Yep definitely!

Thanks for the PR! I'll look into this soon.

@NeffIsBack NeffIsBack added the bug-fix This Pull Request fixes a bug label May 6, 2026
@NeffIsBack
Copy link
Copy Markdown
Member

Hi, so I looked a bit deeper into it. Basically this solution still does not really exit the child threads gracefully, but just immediately aborts everything with the call to os._exit(). This has the advantage that we don't have to press CTRL+C multiple times, but it still doesn't give the chance to the proto objects (and therefore sqlite db etc.) to shutdown properly.

Let's go forward with this for now, so we at least have a way forcefully shutdown everything without that we need to press CTRL+C multiple times. I don't think all the changes the changes to the Threadpool stuff etc., or am I missing something? If not, please remove everything that isn't necessary for the exit signal.

Please also fix the Pull request description (remove the prefilled text like Please provide guidance on what setup... etc., these are just for guidance what belongs in that section).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants