Skip to content

Commit

Permalink
Added redirect_port module and modified src/modules/attack/__init__.p…
Browse files Browse the repository at this point in the history
…y to load any modules in the attack dir
  • Loading branch information
bwall-slave committed Feb 24, 2015
1 parent 5a525fc commit af50c12
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/modules/attacks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
__all__ = ["beef_hook", "pemod", "replacer"]
from os.path import basename, dirname, abspath
from glob import glob

__all__ = [i for i in (basename(f)[:-3] for f in glob(dirname(abspath(__file__))+"/*.py")) if i != "__init__" and i != "attack"]
__all__ = [v for v in __all__ if not v == "__init__"]
47 changes: 47 additions & 0 deletions src/modules/attacks/redirect_port.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from attack import Attack
import util
from zoption import Zoption


class redirect_port(Attack):
def __init__(self):
super(redirect_port, self).__init__("redirect_port")
self.iptable = "iptables -t nat -A PREROUTING -p tcp --dport {0} -j REDIRECT --to-port {1}"
self.config.update({"source_port": Zoption(type="int", value=80, required=True, display="Source port"),
"dest_port": Zoption(type="int", value=8080, required=True, display="Destination port")})
self.config.update({})
self.running = False
self.info = """
Redirects inbound TCP traffic on source port to destination port on localhost
"""

def modip(self, enable=True):
"""
Enable or disable the iptable rule
"""
to_exec = self.iptable.format(self.config['source_port'].value, self.config['dest_port'].value)
if enable:
util.init_app(to_exec)
else:
util.init_app(to_exec.replace('-A', '-D'))

def initialize(self):
util.Msg("Starting redirect_port...")

self.modip()

self.running = True

util.Msg("Redirection to from TCP port {0} to {1}...")

return True

def shutdown(self):
util.Msg("Shutting down RedirectPort...")
self.modip(False)

def session_view(self):
"""
Return information about the redirections
"""
return "Redirect from {0} to {1}".format(self.config['source_port'].value, self.config['dest_port'].value)

0 comments on commit af50c12

Please sign in to comment.