Unverified Commit 7df27d83 authored by Modark's avatar Modark Committed by GitHub
Browse files

Feat/rich UI menu lovely (#567)

parent c43f290d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ jobs:
          cache: 'pip'
      - run: pip install --upgrade pip
      - run: pwd && ls -hal
      - run: sudo ./install.sh 1
      - run: sudo ./install.py 1
      - run: pwd && ls -hal
      # Typing "1" will allow us to manually enter the filepath to hackingtool.
      # Provide the filepath ${HOME}/work/hackingtool/hackingtool
+6 −6
Original line number Diff line number Diff line
@@ -204,11 +204,11 @@
- [Crivo](https://github.com/GMDSantana/crivo)


![](https://github.com/Z4nzu/hackingtool/blob/master/images/A00.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A0.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A1.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A2.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A4.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/AA.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/AAA.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/AAAA.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/AAAAA.png)

## Installation For Linux <img src="https://konpa.github.io/devicon/devicon.git/icons/linux/linux-original.svg" alt="linux" width="25" height="25"/></p><p align="center">

@@ -233,7 +233,7 @@

## Step : 4 Run hackingtool
    
    sudo bash install.sh
    sudo python install.py

## Step : 5 For installing tools in directory

+6 −6
Original line number Diff line number Diff line
@@ -23,11 +23,11 @@

# Hackingtool Menu 🧰

![](https://github.com/Z4nzu/hackingtool/blob/master/images/A00.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A0.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A1.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A2.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A4.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/A.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/AA.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/AAA.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/AAAA.png)
![](https://github.com/Z4nzu/hackingtool/blob/master/images/AAAAA.png)

## Installation guide for Linux <img src="https://konpa.github.io/devicon/devicon.git/icons/linux/linux-original.svg" alt="linux" width="25" height="25"/></p><p align="center">

@@ -41,7 +41,7 @@
    
    sudo pip3 install -r requirements.txt
    
    bash install.sh
    python install.py
    
    sudo hackingtool

+75 −59
Original line number Diff line number Diff line
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich import box
from rich.traceback import install
from rich.theme import Theme

import os
import sys
import webbrowser
from platform import system
from traceback import print_exc
from typing import Callable
from typing import List
from typing import Tuple
from typing import Callable, List, Tuple

# Enable rich tracebacks
install()
_theme = Theme({"purple": "#7B61FF"})
console = Console(theme=_theme)


def clear_screen():
@@ -24,57 +34,57 @@ def validate_input(ip, val_range):


class HackingTool(object):
    # About the HackingTool
    TITLE: str = ""  # used to show info in the menu
    TITLE: str = ""
    DESCRIPTION: str = ""

    INSTALL_COMMANDS: List[str] = []
    INSTALLATION_DIR: str = ""

    UNINSTALL_COMMANDS: List[str] = []

    RUN_COMMANDS: List[str] = []

    OPTIONS: List[Tuple[str, Callable]] = []

    PROJECT_URL: str = ""

    def __init__(self, options = None, installable: bool = True,
                 runnable: bool = True):
    def __init__(self, options=None, installable=True, runnable=True):
        options = options or []
        if isinstance(options, list):
            self.OPTIONS = []
            if installable:
                self.OPTIONS.append(('Install', self.install))
                self.OPTIONS.append(("Install", self.install))
            if runnable:
                self.OPTIONS.append(('Run', self.run))
                self.OPTIONS.append(("Run", self.run))
            self.OPTIONS.extend(options)
        else:
            raise Exception(
                "options must be a list of (option_name, option_fn) tuples")
            raise Exception("options must be a list of (option_name, option_fn) tuples")

    def show_info(self):
        desc = self.DESCRIPTION
        desc = f"[cyan]{self.DESCRIPTION}[/cyan]"
        if self.PROJECT_URL:
            desc += '\n\t[*] '
            desc += self.PROJECT_URL
        os.system(f'echo "{desc}"|boxes -d boy | lolcat')
            desc += f"\n[green]🔗 {self.PROJECT_URL}[/green]"
        console.print(Panel(desc, title=f"[bold purple]{self.TITLE}[/bold purple]", border_style="purple", box=box.DOUBLE))

    def show_options(self, parent=None):
        clear_screen()
        self.show_info()

        table = Table(title="Options", box=box.SIMPLE_HEAVY)
        table.add_column("No.", style="bold cyan", justify="center")
        table.add_column("Action", style="bold yellow")

        for index, option in enumerate(self.OPTIONS):
            print(f"[{index + 1}] {option[0]}")
            table.add_row(str(index + 1), option[0])

        if self.PROJECT_URL:
            print(f"[{98}] Open project page")
        print(f"[{99}] Back to {parent.TITLE if parent is not None else 'Exit'}")
        option_index = input("Select an option : ").strip()
            table.add_row("98", "Open Project Page")
        table.add_row("99", f"Back to {parent.TITLE if parent else 'Exit'}")

        console.print(table)

        option_index = input("\n[?] Select an option: ").strip()
        try:
            option_index = int(option_index)
            if option_index - 1 in range(len(self.OPTIONS)):
                ret_code = self.OPTIONS[option_index - 1][1]()
                if ret_code != 99:
                    input("\n\nPress ENTER to continue:").strip()
                    input("\nPress [Enter] to continue...")
            elif option_index == 98:
                self.show_project_page()
            elif option_index == 99:
@@ -82,95 +92,101 @@ class HackingTool(object):
                    sys.exit()
                return 99
        except (TypeError, ValueError):
            print("Please enter a valid option")
            input("\n\nPress ENTER to continue:").strip()
            console.print("[red]⚠ Please enter a valid option.[/red]")
            input("\nPress [Enter] to continue...")
        except Exception:
            print_exc()
            input("\n\nPress ENTER to continue:").strip()
            console.print_exception(show_locals=True)
            input("\nPress [Enter] to continue...")
        return self.show_options(parent=parent)

    def before_install(self):
        pass
    def before_install(self): pass

    def install(self):
        self.before_install()
        if isinstance(self.INSTALL_COMMANDS, (list, tuple)):
            for INSTALL_COMMAND in self.INSTALL_COMMANDS:
                console.print(f"[yellow]→ {INSTALL_COMMAND}[/yellow]")
                os.system(INSTALL_COMMAND)
            self.after_install()

    def after_install(self):
        print("Successfully installed!")
        console.print("[green]✔ Successfully installed![/green]")

    def before_uninstall(self) -> bool:
        """ Ask for confirmation from the user and return """
        return True

    def uninstall(self):
        if self.before_uninstall():
            if isinstance(self.UNINSTALL_COMMANDS, (list, tuple)):
                for UNINSTALL_COMMAND in self.UNINSTALL_COMMANDS:
                    console.print(f"[red]→ {UNINSTALL_COMMAND}[/red]")
                    os.system(UNINSTALL_COMMAND)
            self.after_uninstall()

    def after_uninstall(self):
        pass
    def after_uninstall(self): pass

    def before_run(self):
        pass
    def before_run(self): pass

    def run(self):
        self.before_run()
        if isinstance(self.RUN_COMMANDS, (list, tuple)):
            for RUN_COMMAND in self.RUN_COMMANDS:
                console.print(f"[cyan]⚙ Running:[/cyan] [bold]{RUN_COMMAND}[/bold]")
                os.system(RUN_COMMAND)
            self.after_run()

    def after_run(self):
        pass
    def after_run(self): pass

    def is_installed(self, dir_to_check=None):
        print("Unimplemented: DO NOT USE")
        console.print("[yellow]⚠ Unimplemented: DO NOT USE[/yellow]")
        return "?"

    def show_project_page(self):
        console.print(f"[blue]🌐 Opening project page: {self.PROJECT_URL}[/blue]")
        webbrowser.open_new_tab(self.PROJECT_URL)


class HackingToolsCollection(object):
    TITLE: str = ""  # used to show info in the menu
    TITLE: str = ""
    DESCRIPTION: str = ""
    TOOLS = []  # type: List[Any[HackingTool, HackingToolsCollection]]
    TOOLS: List = []

    def __init__(self):
        pass

    def show_info(self):
        os.system("figlet -f standard -c {} | lolcat".format(self.TITLE))
        # os.system(f'echo "{self.DESCRIPTION}"|boxes -d boy | lolcat')
        # print(self.DESCRIPTION)
        console.rule(f"[bold purple]{self.TITLE}[/bold purple]", style="purple")
        console.print(f"[italic cyan]{self.DESCRIPTION}[/italic cyan]\n")

    def show_options(self, parent=None):
        clear_screen()
        self.show_info()

        table = Table(title="Available Tools", box=box.MINIMAL_DOUBLE_HEAD)
        table.add_column("No.", justify="center", style="bold cyan")
        table.add_column("Tool Name", style="bold yellow")

        for index, tool in enumerate(self.TOOLS):
            print(f"[{index} {tool.TITLE}")
        print(f"[{99}] Back to {parent.TITLE if parent is not None else 'Exit'}")
        tool_index = input("Choose a tool to proceed: ").strip()
            table.add_row(str(index), tool.TITLE)

        table.add_row("99", f"Back to {parent.TITLE if parent else 'Exit'}")
        console.print(table)

        tool_index = input("\n[?] Choose a tool: ").strip()
        try:
            tool_index = int(tool_index)
            if tool_index in range(len(self.TOOLS)):
                ret_code = self.TOOLS[tool_index].show_options(parent=self)
                if ret_code != 99:
                    input("\n\nPress ENTER to continue:").strip()
                    input("\nPress [Enter] to continue...")
            elif tool_index == 99:
                if parent is None:
                    sys.exit()
                return 99
        except (TypeError, ValueError):
            print("Please enter a valid option")
            input("\n\nPress ENTER to continue:").strip()
            console.print("[red]⚠ Please enter a valid option.[/red]")
            input("\nPress [Enter] to continue...")
        except Exception:
            print_exc()
            input("\n\nPress ENTER to continue:").strip()
            console.print_exception(show_locals=True)
            input("\nPress [Enter] to continue...")
        return self.show_options(parent=parent)
+8 −1
Original line number Diff line number Diff line
# coding=utf-8
import re

from rich.console import Console
from rich.theme import Theme

from core import HackingTool
from core import HackingToolsCollection
from hackingtool import all_tools

_theme = Theme({"purple": "#7B61FF"})
console = Console(theme=_theme)


def sanitize_anchor(s):
    return re.sub(r"\W", "-", s.lower())
Loading