mirror of https://github.com/n1nj4sec/pupy.git
Generate DNSCNC state from config
This commit is contained in:
parent
80cd99db71
commit
30ad7c1a2a
|
@ -15,6 +15,7 @@ httpd = false
|
|||
|
||||
#dnscnc = localhost:5454 starts the DNS cnc listener on the port 5454.
|
||||
dnscnc = false
|
||||
recursor = false
|
||||
|
||||
# allow requests to services like ifconfig.co to automatically retrieve public IP
|
||||
allow_requests_to_external_services = false
|
||||
|
|
|
@ -6,7 +6,7 @@ from network.lib.picocmd.picocmd import *
|
|||
from Queue import Queue
|
||||
|
||||
from pupylib.PupyConfig import PupyConfig
|
||||
from pupylib.utils.network import get_listener_ip
|
||||
from pupylib.utils.network import get_listener_ip, get_listener_port
|
||||
|
||||
import requests
|
||||
import netifaces
|
||||
|
@ -57,26 +57,42 @@ class PupyDnsCommandServerHandler(DnsCommandServerHandler):
|
|||
|
||||
class PupyDnsCnc(object):
|
||||
def __init__(
|
||||
self, domain, igd=None, connect_host=None,
|
||||
recursor='8.8.8.8', port=5353, listen='0.0.0.0',
|
||||
self, igd=None, connect_host=None,
|
||||
recursor=None,
|
||||
connect_transport='ssl', connect_port=443,
|
||||
config=None, credentials=None
|
||||
):
|
||||
|
||||
credentials = credentials or Credentials()
|
||||
config = config or PupyConfig()
|
||||
|
||||
self.config = config
|
||||
|
||||
connect_host = connect_host or config.getip('pupyd', 'address')
|
||||
|
||||
self.credentials = credentials
|
||||
self.igd = igd
|
||||
self.transport = connect_transport or config.get('pupyd', 'transport')
|
||||
self.port = int(connect_port or config.getint('pupyd', 'port'))
|
||||
self.host = connect_host if connect_host else get_listener_ip(
|
||||
external=True, config=config, igd=igd
|
||||
)
|
||||
if self.host:
|
||||
self.host = [ str(self.host) ]
|
||||
|
||||
fdqn = self.config.get('pupyd', 'dnscnc').split(':')
|
||||
domain = fdqn[0]
|
||||
if len(fdqn) > 1:
|
||||
port = int(fdqn[1])
|
||||
else:
|
||||
port = 53
|
||||
|
||||
listen = str(config.get('pupyd', 'address') or '0.0.0.0')
|
||||
prefer_external = config.getboolean('gen', 'external')
|
||||
|
||||
self.host = [
|
||||
str(get_listener_ip(
|
||||
external=prefer_external,
|
||||
config=config,
|
||||
igd=igd
|
||||
))
|
||||
]
|
||||
self.port = get_listener_port(config, external=prefer_external)
|
||||
self.transport = config.get('pupyd', 'transport')
|
||||
|
||||
recursor = config.get('pupyd', 'recursor')
|
||||
if recursor and recursor.lower() in ('no', 'false', 'stop', 'n', 'disable'):
|
||||
recursor = None
|
||||
|
||||
self.dns_domain = domain
|
||||
self.dns_port = port
|
||||
|
@ -95,8 +111,8 @@ class PupyDnsCnc(object):
|
|||
)
|
||||
|
||||
if self.igd and self.igd.available:
|
||||
self.igd.AddPortMapping(int(port), 'UDP', 53)
|
||||
self.igd.AddPortMapping(int(port), 'TCP', 53)
|
||||
self.igd.AddPortMapping(53, 'UDP', int(port))
|
||||
self.igd.AddPortMapping(53, 'TCP', int(port))
|
||||
|
||||
self.server.start()
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ from . import PupyClient
|
|||
import os.path
|
||||
|
||||
class PupyServer(threading.Thread):
|
||||
def __init__(self, config):
|
||||
def __init__(self, config, credentials):
|
||||
super(PupyServer, self).__init__()
|
||||
self.daemon = True
|
||||
self.server = None
|
||||
|
@ -61,6 +61,8 @@ class PupyServer(threading.Thread):
|
|||
self._current_id_lock = threading.Lock()
|
||||
|
||||
self.config = config or PupyConfig()
|
||||
self.credentials = credentials or PupyCredentials()
|
||||
|
||||
self.port = self.config.getint('pupyd', 'port')
|
||||
self.address = self.config.getip('pupyd', 'address') or ''
|
||||
|
||||
|
@ -108,12 +110,9 @@ class PupyServer(threading.Thread):
|
|||
dnsport = 5454
|
||||
|
||||
self.dnscnc = PupyDnsCnc(
|
||||
fdqn,
|
||||
igd=self.igd,
|
||||
port=dnsport,
|
||||
connect_port=self.port,
|
||||
connect_transport=self.transport,
|
||||
config=self.config
|
||||
config=self.config,
|
||||
credentials=self.credentials
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -81,8 +81,7 @@ if __name__=="__main__":
|
|||
PupyCredentials.ENCRYPTOR = None
|
||||
|
||||
# Try to initialize credentials before CMD loop
|
||||
PupyCredentials.Credentials()
|
||||
|
||||
credentials = PupyCredentials.Credentials()
|
||||
config = PupyConfig()
|
||||
|
||||
if args.port:
|
||||
|
@ -94,8 +93,7 @@ if __name__=="__main__":
|
|||
if args.transport_args:
|
||||
config.set('pupyd', 'transport_args', args.transport_args, cmd=True)
|
||||
|
||||
pupyServer = PupyServer(config)
|
||||
|
||||
pupyServer = PupyServer(config, credentials)
|
||||
pupycmd = PupyCmdLoop(pupyServer)
|
||||
|
||||
pupyServer.start()
|
||||
|
|
Loading…
Reference in New Issue