Skip to content

Commit

Permalink
chore: pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
thehappydinoa committed May 1, 2022
1 parent a821349 commit 7294d90
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ repos:
rev: v2.32.0
hooks:
- id: pyupgrade
args:
- "--py37"
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
Expand Down
3 changes: 0 additions & 3 deletions fsociety/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .cli import main as cli

__all__ = ["cli"]
2 changes: 0 additions & 2 deletions fsociety/cli.py → fsociety/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=exec-used,broad-except,inconsistent-return-statements,invalid-name,trailing-whitespace

import argparse
import platform
Expand Down
2 changes: 1 addition & 1 deletion fsociety/core/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class InvalidHost(Exception):

def get_hosts() -> List[str]:
try:
with open(full_path, "r") as hostfile:
with open(full_path) as hostfile:
return [host.strip() for host in hostfile]
except FileNotFoundError:
return list()
Expand Down
3 changes: 1 addition & 2 deletions fsociety/core/menu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=unused-import,broad-except,inconsistent-return-statements
import os
import shutil
from typing import Iterable
Expand Down Expand Up @@ -103,7 +102,7 @@ def tools_cli(name, tools, links=True):
if selected_tool not in tools_dict.keys():
if selected_tool in BACK_COMMANDS:
return
if selected_tool is "exit":
if selected_tool == "exit":
raise KeyboardInterrupt
console.print("Invalid Command", style="bold yellow")
return tools_cli(name, tools, links)
Expand Down
37 changes: 18 additions & 19 deletions fsociety/core/repo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=too-many-branches,line-too-long
import os
from abc import ABCMeta, abstractmethod
from shutil import rmtree, which
Expand All @@ -18,7 +17,7 @@
def print_pip_deps(packages: Union[str, Iterable[str]]) -> None:
requirements = []
if isinstance(packages, str) and os.path.exists(packages):
with open(packages, "r") as requirements_file:
with open(packages) as requirements_file:
for line in requirements_file:
if line.strip():
requirements.append(line)
Expand Down Expand Up @@ -54,7 +53,7 @@ def __init__(self) -> None:
self.task: Optional[TaskID] = None

def update(
self, opcode, count: int, max_value: int, msg: Optional[str] = None
self, opcode, count: int, max_value: int, msg: Optional[str] = None
) -> None:
opcode_strs = {
self.COUNTING: "Counting",
Expand Down Expand Up @@ -93,10 +92,10 @@ def update(

class GitHubRepo(metaclass=ABCMeta):
def __init__(
self,
path: str = "fsociety-team/fsociety",
install: Union[str, Dict[str, Union[str, List[str]]]] = "pip install -e .",
description=None,
self,
path: str = "fsociety-team/fsociety",
install: Union[str, Dict[str, Union[str, List[str]]]] = "pip install -e .",
description=None,
) -> None:
self.path = path
self.name = self.path.split("/")[-1]
Expand Down Expand Up @@ -125,7 +124,7 @@ def clone(self, overwrite: bool = False) -> str:

def install(self, no_confirm: bool = False, clone: bool = True) -> None:
if no_confirm or not confirm(
f"\nDo you want to install https://github.com/{self.path}?"
f"\nDo you want to install https://github.com/{self.path}?"
):
print("Cancelled")
return
Expand All @@ -141,7 +140,7 @@ def install(self, no_confirm: bool = False, clone: bool = True) -> None:
target_os = config.get("fsociety", "os")

if isinstance(install, dict):
if "pip" in install.keys():
if "pip" in install:
packages = install.get("pip")
message = "" # avoid unset issues
if isinstance(packages, list):
Expand All @@ -160,29 +159,29 @@ def install(self, no_confirm: bool = False, clone: bool = True) -> None:
if not confirm(message):
raise InstallError("User Cancelled")

elif "go" in install.keys() and which("go"):
elif "go" in install and which("go"):
command = install.get("go")

elif "binary" in install.keys():
elif "binary" in install:
bin_url = install.get("binary")
if which("curl"):
command = f"curl -L -o {self.full_path}/{self.name} -s {bin_url}"
command = (
f"curl -L -o {self.full_path}/{self.name} -s {bin_url}"
)
elif which("wget"):
command = f"wget -q -O {self.full_path}/{self.name} {bin_url}"
else:
raise InstallError("Supported download tools missing")
command = f"mkdir {self.full_path} && {command} && chmod +x {self.full_path}/{self.name}"
elif (
target_os == "macos"
and "brew" in install.keys()
and which("brew")
):
elif target_os == "macos" and "brew" in install and which("brew"):
brew_opts = install.get("brew")
command = f"brew {brew_opts}"
elif target_os in install.keys() and target_os in self.scriptable_os:
elif target_os in install and target_os in self.scriptable_os:
command = str(install[target_os])
else:
raise InstallError(f"Platform not supported, missing {', '.join(install.keys())}")
raise InstallError(
f"Platform not supported, missing {', '.join(install.keys())}"
)
else:
command = install

Expand Down
2 changes: 1 addition & 1 deletion fsociety/core/usernames.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def get_usernames() -> List[str]:
try:
with open(full_path, "r") as usernamefile:
with open(full_path) as usernamefile:
return [username.strip() for username in usernamefile]
except FileNotFoundError:
return list()
Expand Down
1 change: 0 additions & 1 deletion fsociety/core/utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=invalid-name,line-too-long
import os
from abc import ABCMeta
from base64 import b64decode
Expand Down
2 changes: 1 addition & 1 deletion fsociety/information_gathering/sqlmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self):
def run(self):
os.chdir(self.full_path)
user_url = input("\nEnter a url to scan: ").strip()
user_args = str()
user_args = ""
if confirm("\nDo you want to add any extra args?"):
os.system("python3 sqlmap.py --help")
user_args = input("\nEnter any extra args: ").strip()
Expand Down
1 change: 0 additions & 1 deletion fsociety/networking/bettercap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=line-too-long
import os
from shutil import which

Expand Down
3 changes: 1 addition & 2 deletions fsociety/networking/nmap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=line-too-long
import os
from shutil import which

Expand Down Expand Up @@ -31,7 +30,7 @@ def __init__(self):
install={
"arch": "sudo pacman -Sy nmap",
"brew": "install nmap",
"linux": "sudo apt-get install nmap"
"linux": "sudo apt-get install nmap",
},
description="the Network Mapper",
)
Expand Down
44 changes: 21 additions & 23 deletions fsociety/passwords/traitor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import os
from fsociety.core.repo import GitHubRepo
from fsociety.core.menu import set_readline
from shutil import which

premade_args = {
"any": "-a"
}
arch_map = {
"x86_64": "amd64",
"i386": "386"
}
from fsociety.core.menu import set_readline
from fsociety.core.repo import GitHubRepo

premade_args = {"any": "-a"}
arch_map = {"x86_64": "amd64", "i386": "386"}


class TraitorRepo(GitHubRepo):
def __init__(self):
Expand All @@ -19,38 +16,39 @@ def __init__(self):
self.arch = ""
self.version = "v0.0.14"
super().__init__(
path='liamg/traitor',
install={
"binary": ""
},
description='Automatic Linux privesc via exploitation of low-hanging fruit',
path="liamg/traitor",
install={"binary": ""},
description="Automatic Linux privesc via exploitation of low-hanging fruit",
)

def installed(self):
return which(f"{self.full_path}/{self.name}")

def install(self) -> None:
def install(self, no_confirm: bool = False, clone: bool = False):
artifact = f"https.*/traitor-{self.arch}"
url = f"https://api.github.com/repos/liamg/traitor/releases/latest"
url = "https://api.github.com/repos/liamg/traitor/releases/latest"
if which("curl"):
command = f"curl -s {url} | grep -wo '{artifact}'"
elif which("wget"):
command = f"wget -qO - {url} | grep -wo '{artifact}'"

self.install_options['binary'] = os.popen(command).read().strip('\n')
return super().install(clone=False)
self.install_options["binary"] = os.popen(command).read().strip("\n")
return super().install(no_confirm, clone)

def run(self) -> int:
longest_key = max([len(key) for key in premade_args]) + 2
longest_key = max(len(key) for key in premade_args) + 2
print("\nName".ljust(longest_key) + " | Args")
for name, args in premade_args.items():
print(f"{name.ljust(longest_key)}: {args.format()}")
set_readline(premade_args.keys())
selected = input("\nMake a selection: ")
if selected and selected in premade_args.keys():
args = premade_args.get(selected)
return os.system(f"{self.full_path}/{self.name} {args}")
elif selected and selected not in premade_args.keys(): # allow passing custom specific exploits
if selected and selected in premade_args:
return os.system(
f"{self.full_path}/{self.name} {premade_args.get(selected)}"
)
elif (
selected and selected not in premade_args.keys()
): # allow passing custom specific exploits
return os.system(f"{self.full_path}/{self.name} -e {selected}")
return self.run()

Expand Down
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import io
import os
import sys

Expand Down Expand Up @@ -31,7 +29,7 @@
exec(f.read(), pkg_vars)

try:
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
with open(os.path.join(here, "README.md"), encoding="utf-8") as f:
long_description = "\n" + f.read()
except FileNotFoundError:
long_description = DESCRIPTION
Expand All @@ -50,7 +48,7 @@ class TagCommand(Command):

@staticmethod
def status(s):
print("\033[1m{}\033[0m".format(s))
print(f"\033[1m{s}\033[0m")

def initialize_options(self):
pass
Expand Down Expand Up @@ -79,7 +77,7 @@ def run(self):
project_urls=PROJECT_URLS,
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
entry_points={
"console_scripts": ["fsociety=fsociety:cli"],
"console_scripts": ["fsociety=fsociety.__main__:main"],
},
install_requires=get_requirements("requirements.txt"),
extras_require={"dev": get_requirements("requirements-dev.txt")},
Expand Down

0 comments on commit 7294d90

Please sign in to comment.