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

Implement ignore feature #322

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Conversation

mendelgusmao
Copy link

@mendelgusmao mendelgusmao commented Oct 9, 2024

Just a small contribution for wifite2: option to ignore targets on the fly.

Summary by Sourcery

Implement an 'ignore' feature to allow users to skip specific targets during attacks and manage ignored targets. Enhance the display functionality to show both cracked and ignored targets, improving user control and visibility over attack results.

New Features:

  • Introduce an 'ignore' feature that allows users to ignore specific targets during attacks, enhancing the flexibility of target management.

Enhancements:

  • Add functionality to display ignored targets alongside cracked targets, providing users with more comprehensive result visibility.

Copy link

sourcery-ai bot commented Oct 9, 2024

Reviewer's Guide by Sourcery

This pull request implements an "ignore" feature for wifite2, allowing users to ignore targets on the fly during scanning and attacks. The changes include modifications to handle ignored targets, display them, and provide user options to ignore targets during attacks.

Sequence diagram for ignoring a target during an attack

sequenceDiagram
    actor User
    participant AttackAll
    participant CrackResult
    User->>AttackAll: Initiate attack
    AttackAll->>User: Prompt for action
    User->>AttackAll: Choose 'Ignore'
    AttackAll->>CrackResult: ignore_target(target)
    CrackResult->>CrackResultIgnored: Create ignored target
    CrackResultIgnored->>CrackResultIgnored: Save ignored target
    CrackResultIgnored-->>CrackResult: Return to AttackAll
    CrackResult-->>AttackAll: Return to User
    AttackAll-->>User: Continue with next target
Loading

Class diagram for the new ignore feature

classDiagram
    class CrackResult {
        +save()
        +display(result_type)
        +load_all()
        +load_ignored_bssids(ignore_cracked)
        +load(json)
        +ignore_target(target)
    }
    class CrackResultIgnored {
        +bssid
        +essid
        +result_type
        +dump()
        +print_single_line(longest_essid)
        +to_dict()
    }
    CrackResult <|-- CrackResultIgnored
    class Answer {
        <<enumeration>>
        +Skip
        +ExitOrReturn
        +Continue
        +Ignore
    }
Loading

File-Level Changes

Change Details Files
Implement ignore feature for targets
  • Add functionality to save and load ignored targets
  • Modify the display method to show both cracked and ignored targets
  • Implement a new CrackResultIgnored class to handle ignored targets
  • Update the user interface to allow ignoring targets during attacks
wifite/model/result.py
wifite/attack/all.py
wifite/model/ignored_result.py
Update configuration and command-line arguments
  • Add new configuration option for showing ignored targets
  • Implement command-line argument to display ignored targets
  • Update argument parsing to handle the new ignore-related options
wifite/config.py
wifite/__main__.py
wifite/args.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @mendelgusmao - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider refactoring the CrackResult class to separate concerns. The class is taking on too many responsibilities with the new ignore feature.
  • Improve consistency in naming conventions and code style, particularly for the new Answer enum and throughout the new ignored_result.py file.
  • Enhance error handling and consider performance optimizations, especially in the ignore_target and load_ignored_bssids methods.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +19 to +23
def __init__(self, bssid, essid):
self.result_type = 'IGN'
self.bssid = bssid
self.essid = essid
super(CrackResultIgnored, self).__init__()
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider adding validation for bssid and essid parameters in the constructor

It might be beneficial to add some basic validation for the bssid and essid parameters in the constructor. This could include checking for correct format of BSSID and ensuring that ESSID is not empty or too long.

    def __init__(self, bssid, essid):
        if not self._is_valid_bssid(bssid):
            raise ValueError("Invalid BSSID format")
        if not essid or len(essid) > 32:
            raise ValueError("ESSID must not be empty and not exceed 32 characters")
        self.result_type = 'IGN'
        self.bssid = bssid
        self.essid = essid
        super(CrackResultIgnored, self).__init__()

% (name, len(saved_results)))

@classmethod
def display(cls):
""" Show cracked targets from cracked file """
def display(cls, result_type):
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the 'display' method into smaller, more focused methods.

The display method has indeed become more complex with the addition of the result_type parameter and conditional logic. To improve readability and maintainability, consider refactoring this method into smaller, more focused methods:

  1. Extract the loading and filtering logic into a separate method:
def get_filtered_results(cls, result_type):
    targets = cls.load_all()
    if result_type == 'cracked':
        return [item for item in targets if item.get('type') != 'IGN']
    else:
        return [item for item in targets if item.get('type') == 'IGN']
  1. Simplify the display method by using the new get_filtered_results method:
@classmethod
def display(cls, result_type):
    name = cls.cracked_file
    if not os.path.exists(name):
        Color.pl('{!} {O}file {C}%s{O} not found{W}' % name)
        return

    filtered_results = cls.get_filtered_results(result_type)
    if len(filtered_results) == 0:
        Color.pl('{!} {R}no results found in {O}%s{W}' % name)
        return

    Color.pl('\n{+} Displaying {G}%d{W} %s target(s) from {C}%s{W}\n' % (
        len(filtered_results), 'cracked' if result_type == 'cracked' else 'ignored', cls.cracked_file))

    results = sorted([cls.load(item) for item in filtered_results], key=lambda x: x.date, reverse=True)
    cls.print_results_table(results, result_type == 'cracked')
  1. Create a new method for printing the results table:
@classmethod
def print_results_table(cls, results, show_key):
    longest_essid = max(len(result.essid or 'ESSID') for result in results)
    cls.print_table_header(longest_essid, show_key)
    for result in results:
        result.print_single_line(longest_essid)
    Color.pl('')

@classmethod
def print_table_header(cls, longest_essid, show_key):
    # ... (existing header printing code) ...

These changes separate concerns, making each method more focused and easier to understand. The display method now orchestrates the overall process, while smaller methods handle specific tasks. This approach improves readability and makes future modifications easier.

@kimocoder
Copy link
Owner

You have a conflict, resolve this first and I'll merge 🥇

@kimocoder kimocoder merged commit adaa3ff into kimocoder:master Oct 30, 2024
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants