Skip to content

Commit

Permalink
Merge pull request #17 from mushorg/black_formatting
Browse files Browse the repository at this point in the history
formatting with black
  • Loading branch information
glaslos authored Dec 8, 2021
2 parents 3efb9ce + be893cc commit 0c647a9
Show file tree
Hide file tree
Showing 16 changed files with 572 additions and 280 deletions.
4 changes: 2 additions & 2 deletions oschameleon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__title__ = 'oschameleon'
__version__ = '0.1.2'
__title__ = "oschameleon"
__version__ = "0.1.2"
74 changes: 57 additions & 17 deletions oschameleon/oschameleonRun.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'''
"""
Created on 01.12.2016
@author: manuel
'''
"""
import argparse
import gevent.monkey
import grp
Expand All @@ -22,19 +22,47 @@
class OSChameleon(object):
def __init__(self, template=None, template_directory=None, args=None):
if float(nfqueue.nfq_bindings_version()) < 0.6:
print("Found nfqueue version: {} but need at least 0.6, aborting.".format(nfqueue.nfq_bindings_version()))
print(
"Found nfqueue version: {} but need at least 0.6, aborting.".format(
nfqueue.nfq_bindings_version()
)
)
exit(1)
self.parser = argparse.ArgumentParser(description='OSChameleon sample usage')
self.parser.add_argument('--template', metavar='template/SIMATIC_300_PLC.txt', type=str, help='path to the nmap fingerprint template', default="template/SIMATIC_300_PLC.txt")
self.parser.add_argument('--server', metavar='IP', type=str, help='server ip for iptables', default='127.0.0.1')
self.parser.add_argument('--public_ip', metavar='IP', help='running in production with public ip', default=False)
self.parser.add_argument('--interface', metavar='eth0', help='network interface', default='eth0')
self.parser.add_argument('--debug', metavar='True/False', help='verbose debugging output', default=False)
self.parser = argparse.ArgumentParser(description="OSChameleon sample usage")
self.parser.add_argument(
"--template",
metavar="template/SIMATIC_300_PLC.txt",
type=str,
help="path to the nmap fingerprint template",
default="template/SIMATIC_300_PLC.txt",
)
self.parser.add_argument(
"--server",
metavar="IP",
type=str,
help="server ip for iptables",
default="127.0.0.1",
)
self.parser.add_argument(
"--public_ip",
metavar="IP",
help="running in production with public ip",
default=False,
)
self.parser.add_argument(
"--interface", metavar="eth0", help="network interface", default="eth0"
)
self.parser.add_argument(
"--debug",
metavar="True/False",
help="verbose debugging output",
default=False,
)
self.args = self.parser.parse_args()

gevent.monkey.patch_all()

if self.args.debug == 'True':
if self.args.debug == "True":
self.args.debug = True
else:
self.args.debug = False
Expand All @@ -49,18 +77,26 @@ def start(self):
self.drop_privileges()
except KeyboardInterrupt:
flush_tables()
print ("bye")
print("bye")

def root_process(self):
if self.args.debug:
print("Child: Running as {0}/{1}.".format(pwd.getpwuid(os.getuid())[0], grp.getgrgid(os.getgid())[0]))
print(
"Child: Running as {0}/{1}.".format(
pwd.getpwuid(os.getuid())[0], grp.getgrgid(os.getgid())[0]
)
)
data = OSFuscation.run(self.args.debug, self.args.template, self.args.server)
if self.args.debug:
print('OSFuscation return value', data)
print("OSFuscation return value", data)

def drop_privileges(self, uid_name='nobody', gid_name='nogroup'):
def drop_privileges(self, uid_name="nobody", gid_name="nogroup"):
if self.args.debug:
print("Init: Running as {0}/{1}.".format(pwd.getpwuid(os.getuid())[0], grp.getgrgid(os.getgid())[0]))
print(
"Init: Running as {0}/{1}.".format(
pwd.getpwuid(os.getuid())[0], grp.getgrgid(os.getgid())[0]
)
)
wanted_uid = pwd.getpwnam(uid_name)[2]
wanted_gid = grp.getgrnam(gid_name)[2]

Expand All @@ -81,7 +117,11 @@ def drop_privileges(self, uid_name='nobody', gid_name='nogroup'):
new_uid_name = pwd.getpwuid(os.getuid())[0]
new_gid_name = grp.getgrgid(os.getgid())[0]
if self.args.debug:
print("Parent: Privileges dropped, running as {0}/{1}.".format(new_uid_name, new_gid_name))
print(
"Parent: Privileges dropped, running as {0}/{1}.".format(
new_uid_name, new_gid_name
)
)
while True:
try:
gevent.sleep(1)
Expand All @@ -90,6 +130,6 @@ def drop_privileges(self, uid_name='nobody', gid_name='nogroup'):
break


if __name__ == '__main__':
if __name__ == "__main__":
p = OSChameleon()
p.start()
8 changes: 4 additions & 4 deletions oschameleon/osfuscation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def run(cls, debug=False, template_path='', server_ip=None):
os_pattern = get_os_pattern(template_path, debug)

if debug:
print '*' * 30
print os_pattern
print '*' * 30
print('*' * 30)
print(os_pattern)
print('*' * 30)

# Flush the IP tables first
flush_tables()
Expand All @@ -148,7 +148,7 @@ def run(cls, debug=False, template_path='', server_ip=None):
q.unbind(socket.AF_INET)
q.close()
flush_tables()
print 'Exiting...'
print('Exiting...')


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 0c647a9

Please sign in to comment.