Skip to content

Commit 6acf52c

Browse files
committed
Merge pull request #17 from bwall/redirectport_and_dynamic_modules
redirect_port and dynamic attack module loading
2 parents c2d882c + af50c12 commit 6acf52c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/modules/attacks/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
__all__ = ["beef_hook", "pemod", "replacer"]
1+
from os.path import basename, dirname, abspath
2+
from glob import glob
3+
4+
__all__ = [i for i in (basename(f)[:-3] for f in glob(dirname(abspath(__file__))+"/*.py")) if i != "__init__" and i != "attack"]
5+
__all__ = [v for v in __all__ if not v == "__init__"]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from attack import Attack
2+
import util
3+
from zoption import Zoption
4+
5+
6+
class redirect_port(Attack):
7+
def __init__(self):
8+
super(redirect_port, self).__init__("redirect_port")
9+
self.iptable = "iptables -t nat -A PREROUTING -p tcp --dport {0} -j REDIRECT --to-port {1}"
10+
self.config.update({"source_port": Zoption(type="int", value=80, required=True, display="Source port"),
11+
"dest_port": Zoption(type="int", value=8080, required=True, display="Destination port")})
12+
self.config.update({})
13+
self.running = False
14+
self.info = """
15+
Redirects inbound TCP traffic on source port to destination port on localhost
16+
"""
17+
18+
def modip(self, enable=True):
19+
"""
20+
Enable or disable the iptable rule
21+
"""
22+
to_exec = self.iptable.format(self.config['source_port'].value, self.config['dest_port'].value)
23+
if enable:
24+
util.init_app(to_exec)
25+
else:
26+
util.init_app(to_exec.replace('-A', '-D'))
27+
28+
def initialize(self):
29+
util.Msg("Starting redirect_port...")
30+
31+
self.modip()
32+
33+
self.running = True
34+
35+
util.Msg("Redirection to from TCP port {0} to {1}...")
36+
37+
return True
38+
39+
def shutdown(self):
40+
util.Msg("Shutting down RedirectPort...")
41+
self.modip(False)
42+
43+
def session_view(self):
44+
"""
45+
Return information about the redirections
46+
"""
47+
return "Redirect from {0} to {1}".format(self.config['source_port'].value, self.config['dest_port'].value)

0 commit comments

Comments
 (0)