From 3e92f0c9645f8d842508c49d6a81f6e94c604c89 Mon Sep 17 00:00:00 2001 From: Caleb Stewart Date: Tue, 15 Jun 2021 15:59:33 -0400 Subject: [PATCH] Fixed linux.enumerate.system.network when using old ip Older versions of `ip` do not support the `-c=never` argument (or colors at all for that matter). Also, verified isort results, which made some other modifications. --- CHANGELOG.md | 26 +++++++++ pwncat/commands/download.py | 6 +- pwncat/commands/help.py | 2 +- pwncat/commands/upload.py | 7 +-- pwncat/modules/linux/enumerate/file/suid.py | 4 +- .../modules/linux/enumerate/software/cron.py | 1 - .../modules/linux/enumerate/system/network.py | 57 ++++++++++--------- .../modules/linux/enumerate/system/process.py | 1 - .../linux/enumerate/system/services.py | 1 - pwncat/platform/linux.py | 2 - 10 files changed, 61 insertions(+), 46 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c4d0fed --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,26 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +The Changelog starts with v0.4.1, because we did not keep one before that, +and simply didn't have the time to go back and retroactively create one. + +## [Unreleased] + +- Fixed `linux.enumerate.system.network` to work with old and new style `ip`. +- Fixed `ChannelFile.recvinto` which will no longer raise `BlockingIOError` (#126, #131) +- Fixed sessions command with invalid session ID (#130) +- Fixed zsh shell prompt color syntax (#130) + +## [0.4.1] - 2021-06-14 +### Added +- Differentiate prompt syntax for standard bash, zsh and sh (#126) +- Added `-c=never` to `ip` command in `linux.enumerate.system.network` + (#126) +- Updated Dockerfile to properly build post-v0.4.0 releases (#125) +- Added check for `nologin` shell to stop pwncat from accidentally + closing the session (#116) +- Resolved all flake8 errors (#123) +- Improved EOF handling for Linux file-writes (#117) diff --git a/pwncat/commands/download.py b/pwncat/commands/download.py index d927424..2f75f01 100644 --- a/pwncat/commands/download.py +++ b/pwncat/commands/download.py @@ -14,11 +14,7 @@ from rich.progress import ( import pwncat from pwncat import util from pwncat.util import console -from pwncat.commands import ( - Complete, - Parameter, - CommandDefinition, -) +from pwncat.commands import Complete, Parameter, CommandDefinition class Command(CommandDefinition): diff --git a/pwncat/commands/help.py b/pwncat/commands/help.py index a0fd437..781ba45 100644 --- a/pwncat/commands/help.py +++ b/pwncat/commands/help.py @@ -6,7 +6,7 @@ from rich.table import Table, Column import pwncat from pwncat.util import console -from pwncat.commands import CommandDefinition, Complete, Parameter +from pwncat.commands import Complete, Parameter, CommandDefinition class Command(CommandDefinition): diff --git a/pwncat/commands/upload.py b/pwncat/commands/upload.py index 78e8a81..95cb0b8 100644 --- a/pwncat/commands/upload.py +++ b/pwncat/commands/upload.py @@ -12,12 +12,7 @@ from rich.progress import ( ) import pwncat -from pwncat.util import ( - console, - copyfileobj, - human_readable_size, - human_readable_delta, -) +from pwncat.util import console, copyfileobj, human_readable_size, human_readable_delta from pwncat.commands import Complete, Parameter, CommandDefinition diff --git a/pwncat/modules/linux/enumerate/file/suid.py b/pwncat/modules/linux/enumerate/file/suid.py index f4ed0ef..1d0c018 100644 --- a/pwncat/modules/linux/enumerate/file/suid.py +++ b/pwncat/modules/linux/enumerate/file/suid.py @@ -5,9 +5,7 @@ import rich.markup import pwncat from pwncat.db import Fact -from pwncat.facts.ability import ( - build_gtfo_ability, -) +from pwncat.facts.ability import build_gtfo_ability from pwncat.platform.linux import Linux from pwncat.modules.enumerate import Schedule, EnumerateModule diff --git a/pwncat/modules/linux/enumerate/software/cron.py b/pwncat/modules/linux/enumerate/software/cron.py index 9b6a4e6..090299c 100644 --- a/pwncat/modules/linux/enumerate/software/cron.py +++ b/pwncat/modules/linux/enumerate/software/cron.py @@ -2,7 +2,6 @@ import os import re - from pwncat.db import Fact from pwncat.modules import Status from pwncat.subprocess import CalledProcessError diff --git a/pwncat/modules/linux/enumerate/system/network.py b/pwncat/modules/linux/enumerate/system/network.py index 20a1405..f31ee04 100644 --- a/pwncat/modules/linux/enumerate/system/network.py +++ b/pwncat/modules/linux/enumerate/system/network.py @@ -3,6 +3,7 @@ import rich.markup from pwncat.db import Fact +from pwncat.subprocess import CalledProcessError from pwncat.platform.linux import Linux from pwncat.modules.enumerate import Schedule, EnumerateModule @@ -32,32 +33,36 @@ class Module(EnumerateModule): try: output = session.platform.run( - ["ip", "-c=never", "addr"], capture_output=True, text=True + ["ip", "-c=never", "addr"], capture_output=True, text=True, check=True ) - if output.stdout: - output = ( - line - for line in output.stdout.replace("\r\n", "\n").split("\n") - if line + except CalledProcessError: + try: + output = session.platform.run( + ["ip", "addr"], capture_output=True, text=True, check=True ) - - interface = None - - for line in output: - if not line.startswith(" "): - interface = line.split(":")[1].strip() - continue - - if interface is None: - # This shouldn't happen. The first line should be an interface - # definition, but just in case - continue - - line = line.strip() - if line.startswith("inet"): - address = line.split(" ")[1] - yield InterfaceData(self.name, interface, address) - - return + except CalledProcessError: + return except FileNotFoundError: - pass + return + + if output.stdout: + output = ( + line for line in output.stdout.replace("\r\n", "\n").split("\n") if line + ) + + interface = None + + for line in output: + if not line.startswith(" "): + interface = line.split(":")[1].strip() + continue + + if interface is None: + # This shouldn't happen. The first line should be an interface + # definition, but just in case + continue + + line = line.strip() + if line.startswith("inet"): + address = line.split(" ")[1] + yield InterfaceData(self.name, interface, address) diff --git a/pwncat/modules/linux/enumerate/system/process.py b/pwncat/modules/linux/enumerate/system/process.py index 5fab15e..eb7b9c5 100644 --- a/pwncat/modules/linux/enumerate/system/process.py +++ b/pwncat/modules/linux/enumerate/system/process.py @@ -2,7 +2,6 @@ import shlex from typing import List - from pwncat.db import Fact from pwncat.platform.linux import Linux from pwncat.modules.enumerate import Schedule, EnumerateModule diff --git a/pwncat/modules/linux/enumerate/system/services.py b/pwncat/modules/linux/enumerate/system/services.py index 922c766..f316d5d 100644 --- a/pwncat/modules/linux/enumerate/system/services.py +++ b/pwncat/modules/linux/enumerate/system/services.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import subprocess - from pwncat.db import Fact from pwncat.util import Init from pwncat.platform.linux import Linux diff --git a/pwncat/platform/linux.py b/pwncat/platform/linux.py index bad4ed3..621f675 100644 --- a/pwncat/platform/linux.py +++ b/pwncat/platform/linux.py @@ -1041,8 +1041,6 @@ class Linux(Platform): command += f" 2>{stderr}" elif stderr == pwncat.subprocess.DEVNULL: command += " 2>/dev/null" - elif stderr == pwncat.subprocess.PIPE: - command += " 2>&1" if isinstance(stdin, str): command += f" 0<{stdin}"