Skip to content

Commit

Permalink
Merge pull request #122 from devRawnie/menu_driven
Browse files Browse the repository at this point in the history
Started making menu driven program
  • Loading branch information
avinashkranjan authored Apr 16, 2021
2 parents 420bfb9 + 5bf840f commit d81f496
Show file tree
Hide file tree
Showing 5 changed files with 403 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test.py
__pycache__/
env/**
.vscode/**
2 changes: 1 addition & 1 deletion Discovering-Subdomains/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
pass
except KeyboardInterrupt:
# if the user does ctrl+c
print(Hello user, you have pressed ctrl+c, so terminating!)
print("Hello user, you have pressed ctrl+c, so terminating!")
sys.exit()
else:
print("[+] Discovered subdomain:", url)
Expand Down
35 changes: 35 additions & 0 deletions MENU-DRIVEN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Running the menu driven program

python3 main.py

## Adding new scripts to the Menu Driven Program

1. Open the _scripts.py_ file.

2. Create a new object inside the __SCRIPTS__ object with the following attributes

"Name of the Script": {
"path_to_directory": "./relative_path_to_the_scripts_folder",
"program_name": "name_of_the_script_file.py",
"cli_args_required": True|False,
# If 'cli_args_required' is set to True, create the "arguments" key.

"arguments": {
"argument_name": {
"description" : "Descrition of the argument",
"optional": True|False,
"store_only": True|False
# if no value is to be passed with the argument name
"positional": True|False
# Set to True if name of the argument is not to be included in the program's name.
},
}
}

### Scripts which were not included in the menu driven program

1. SniffAir: The __setup.sh__ file is not included in the code directory.

2. SQL Injection: The script has no interface built-in in order to interact with it using command line.

3. Target-Lib: The script has no interface built-in in order to interact with it using command line.
78 changes: 78 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import sys
from os import chdir, listdir, getcwd
from os.path import abspath

from scripts import SCRIPTS


def print_menu():
# Convert all the available choices to a list
keys = [*SCRIPTS]

# Add option to exit from the menu
keys.append("Exit")

# Print all the available choices
count = 1
for key in keys:
print("{}. {}".format(count, key))
count += 1

choice = int(input("\nEnter your choice: "))

# Check for invalid input
while choice < 0 or choice > len(keys):
print("\nError: Invalid Choice")
return print_menu()

return keys[choice-1]


def main():
choice = print_menu()
print()
if choice == "Exit":
exit(0)

script_object = SCRIPTS[choice]
if "cli_args_required" in script_object:
if script_object["cli_args_required"]:
if "arguments" not in script_object:
print("Error: Name of command line arguments not passed in setup file")
exit(0)
else:
print("Enter the value for argument(s).")
args = script_object["arguments"]
for arg_key in args.keys():
arg_obj = args[arg_key]
if arg_obj["optional"]:
val = input(f'* {arg_obj["description"]} (Press Enter to skip)- ')
if "store_only" in arg_obj:
if len(val) > 0:
sys.argv.append(arg_key)
else:
if len(val) > 0:
if "positional" not in arg_obj:
sys.argv.append(arg_key)
sys.argv.append(val)
else:
val = input(f'* {arg_obj["description"]} - ')
if "store_only" in arg_obj:
sys.argv.append(arg_key)
elif "positional" not in arg_obj:
sys.argv.append(arg_key)
sys.argv.append(val)

sys.path.append(abspath(script_object["path_to_directory"]))
chdir(script_object["path_to_directory"])

with open(script_object["program_name"], 'r') as file:
exec(file.read(), globals(), globals())

if __name__ == '__main__':
# try:
# main()
# except Exception as e:
# print("An exception occurred: ")
# print(str(e))
main()
Loading

0 comments on commit d81f496

Please sign in to comment.