diff --git a/README.md b/README.md index 3f625ffd..62281c22 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,11 @@ pip install venv python3 -m venv pupyvenv source pupyvenv/bin/activate pip install -r requirements.txt - -python3 -m pupy.cli.pupysh +``` +run pupysh from the dev install : +``` +source pupyenv/bin/activate +python3 -m pupy.cli ``` ## Description diff --git a/pupy/pupylib/PupyClient.py b/pupy/pupylib/PupyClient.py index 5d42c7fb..4dfbf533 100644 --- a/pupy/pupylib/PupyClient.py +++ b/pupy/pupylib/PupyClient.py @@ -77,10 +77,7 @@ class PupyClient(object): # alias self.conn = self.desc['conn'] - self.is3to2 = ( - self.conn.remote_version[0] == 2 and - sys.version_info.major == 3 - ) + self.is3to2 = (self.conn.remote_version[0] == 2 and sys.version_info.major == 3) self.target = dependencies.Target( self.conn.remote_version, diff --git a/pupy/pupylib/PupyClientInitializer.py b/pupy/pupylib/PupyClientInitializer.py index bc336288..46622abd 100644 --- a/pupy/pupylib/PupyClientInitializer.py +++ b/pupy/pupylib/PupyClientInitializer.py @@ -10,12 +10,10 @@ import getpass import uuid import sys import os -import locale import logging import socket import pupy.agent as pupy -import encodings def _as_unicode(x): @@ -448,12 +446,12 @@ def get_uuid(): try: uacLevel = getUACLevel() - except Exception as e: + except Exception: uacLevel = "?" try: integrity_level = get_integrity_level() - except Exception as e: + except Exception: integrity_level = "?" try: diff --git a/pupy/pupylib/PupyCmd.py b/pupy/pupylib/PupyCmd.py index 43ee195e..79006625 100644 --- a/pupy/pupylib/PupyCmd.py +++ b/pupy/pupylib/PupyCmd.py @@ -59,7 +59,7 @@ from .PupyModule import ( from .PupyCompleter import CompletionContext from .PupyVersion import BANNER, UPSTREAM, DISCLAIMER from .PupyOutput import ( - Text, Line, Color, Title, NewLine, Info, + Line, Color, Title, NewLine, Info, ServiceInfo, Warn, Error, Success, Indent ) @@ -538,7 +538,7 @@ class PupyCmd(cmd.Cmd): if cmd is None: return self.default(line) self.lastcmd = line - if line == 'EOF' : + if line == 'EOF': self.lastcmd = '' if cmd == '': return self.default(line) diff --git a/pupy/pupylib/PupyCompleter.py b/pupy/pupylib/PupyCompleter.py index d894afeb..a0702e96 100644 --- a/pupy/pupylib/PupyCompleter.py +++ b/pupy/pupylib/PupyCompleter.py @@ -166,9 +166,7 @@ def module_name_completer(module, args, text, context): clients_filter=context.handler.default_filter) ) - return [ - module for module in modules if module.startswith(text) or not(text) - ] + return [module for module in modules if module.startswith(text) or not text] def module_args_completer(module, args, text, context): diff --git a/pupy/pupylib/PupyServer.py b/pupy/pupylib/PupyServer.py index 2daedc4d..da57e1f2 100644 --- a/pupy/pupylib/PupyServer.py +++ b/pupy/pupylib/PupyServer.py @@ -47,6 +47,7 @@ if sys.version_info.major > 2: from itertools import filterfalse basestring = str + long = int else: from itertools import ifilterfalse as filterfalse diff --git a/pupy/pupylib/PupyWeb.py b/pupy/pupylib/PupyWeb.py index c7e744fc..d9f00fcb 100644 --- a/pupy/pupylib/PupyWeb.py +++ b/pupy/pupylib/PupyWeb.py @@ -304,26 +304,14 @@ class PupyWebServer(object): def get_random_path_at_webroot(self): while True: - filename = ''.join( - random.choice( - string.ascii_uppercase + - string.ascii_lowercase + - string.digits - ) for _ in xrange(10) - ) + filename = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in xrange(10)) filepath = path.join(self.root, filename) if not path.isfile(filepath): return filepath, filename def random_path(self): - return '/' + ''.join( - random.choice( - string.ascii_uppercase + - string.ascii_lowercase + - string.digits - ) for _ in xrange(10) - ) + return '/' + ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in xrange(10)) def register_mapping(self, name): name = self.random_path() diff --git a/pupy/pupylib/__init__.py b/pupy/pupylib/__init__.py index 0c9f3ed4..3f639fe0 100644 --- a/pupy/pupylib/__init__.py +++ b/pupy/pupylib/__init__.py @@ -11,7 +11,6 @@ __all__ = [ import os import sys import platform -import re ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) HOST_SYSTEM = platform.system() @@ -49,4 +48,3 @@ if not getattr(sys, '__from_build_library_zip_compiler__', False): from .PupyModule import PupyModule from .PupyClient import PupyClient from .PupyServer import PupyServer - diff --git a/pupy/pupylib/payloads/dependencies.py b/pupy/pupylib/payloads/dependencies.py index e108450c..d7d9a210 100644 --- a/pupy/pupylib/payloads/dependencies.py +++ b/pupy/pupylib/payloads/dependencies.py @@ -359,8 +359,7 @@ def get_py_encoding(content): return line = lines[0] - if not (line.startswith(b'#') and - b'coding:' in line): + if not (line.startswith(b'#') and b'coding:' in line): return idx = line.find(b'coding:') + 7 @@ -845,13 +844,13 @@ def add_missing_init(target, modules): f=pathname+"/__init__.pyo" if f not in modules and f not in toadd and f[:-1] not in modules: logger.debug("adding missing {}".format(f)) - toadd[f] = pupycompile("", pathname , target=target.pyver) + toadd[f] = pupycompile("", pathname, target=target.pyver) modules.update(toadd) def bundle(target): if not target.os or not target.arch: return None - + bundle_name = '{}-{}-{}{}.zip'.format( target.os, target.arch, target.pymaj, target.pymin ) diff --git a/pupy/pupylib/utils/credentials.py b/pupy/pupylib/utils/credentials.py index afec3228..48ebb50e 100644 --- a/pupy/pupylib/utils/credentials.py +++ b/pupy/pupylib/utils/credentials.py @@ -5,7 +5,6 @@ from __future__ import print_function import os import json -import codecs from pupy.network.lib.convcompat import ( ExtendedJsonEncoder, ExtendedJsonDecoder, diff --git a/pupy/pupylib/utils/downloader.py b/pupy/pupylib/utils/downloader.py new file mode 100644 index 00000000..4a2a98ab --- /dev/null +++ b/pupy/pupylib/utils/downloader.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- coding: UTF8 -*- + +import requests +import shutil +import os +from tqdm.auto import tqdm +# make an HTTP request within a context manager +with requests.get("https://www.example.com/file.txt", stream=True) as r: + # check header to get content length, in bytes + total_length = int(r.headers.get("Content-Length")) + # implement progress bar via tqdm + with tqdm.wrapattr(r.raw, "read", total=total_length, desc="")as raw: + # save the output to a file + with open(f"{os.path.basename(r.url)}", 'wb')as output: + shutil.copyfileobj(raw, output) diff --git a/pupy/pupylib/utils/term.py b/pupy/pupylib/utils/term.py index 7f7730ac..abdd1815 100644 --- a/pupy/pupylib/utils/term.py +++ b/pupy/pupylib/utils/term.py @@ -13,7 +13,6 @@ import struct import platform import re import locale -import codecs import fcntl import termios @@ -660,10 +659,7 @@ def as_term_bytes(text, width=0): for line in hexdump.dumpgen(content): if text.colorize: # Change to something HexdumpLexer knows - lines.append( - line[:8] + ' ' + line[9:60] + '|' + - line[60:] + '|' - ) + lines.append(line[:8] + ' ' + line[9:60] + '|' + line[60:] + '|') else: lines.append(line) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..f55c1e06 --- /dev/null +++ b/tox.ini @@ -0,0 +1,56 @@ +[flake8] +# This style things should be fixed with time. +# They should be ungnored one-by-one and fixed. + +# E722 -- Should be fixed somehow + +# W606 - Rpyc (at least old) incompatible with Python3.7 + +# !!! DO NOT ADD ANY NEW EXCEPTION HERE !!! + +ignore = E722, + E501,E402, + E241,E221,E211,E222,E225,E226,E227,E272,E231, + E251,E265,E302,E225,E305,E303, + E228,E127,E128,E129,E502,E271,E261,E261,E262, + E122,E123,E124,E125,E126,E131,E121,E226,E266,E242, + E731,W606 + + +per-file-ignores = + # X509 standard names are short + pupylib/PupyCredentials.py: E741 + + # FIXME: add proper __all__ statement + packages/windows/all/pupwinutils/hookfuncs.py: F401 + network/lib/__init__.py: F401 + network/lib/transports/cryptoutils/pyaes/__init__.py: F401 + + # Large stolen file + packages/windows/all/wmi.py: E111 + + # Legacy formatting + network/lib/transports/cryptoutils/pyaes/aes.py: E201,E202,E222,W504 + + # False positive + packages/all/fsutils.py: F811 + +exclude = + conf + crypto + data + external + library_patches + output + payload_templates + proxy + webstatic + packages/patches + # deprecated + network/lib/streams/PupyAsyncStream.py + # symlinks (travis workaround) + packages/linux/all/lazagne + packages/linux/all/mimipy.py + packages/linux/all/beroot + packages/windows/all/beroot + packages/windows/all/lazagne