Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project #3

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Python interpreted files
*.pyc

# Generated CA files
src/ca/ca.cer
src/ca/ca.key

# The saved traffic and log
db/*
src/mallory.log
214 changes: 32 additions & 182 deletions mallory_install.sh
Original file line number Diff line number Diff line change
@@ -1,183 +1,33 @@
#!/bin/bash
# ----------------------------------------------------------------
# This script updates a basic installation of Ubuntu (10.10 or 11.04)
# to the latest package revs, and installs the packages required
# to run the current (1.0) version of the Mallory tool.
# ----------------------------------------------------------------
# Copyright 2011 - Intrepidus Group
# ----------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------

export UPDATE_DIR=${HOME}/.mallory/update
export UPDATE_LOG=${UPDATE_DIR}/update.log

# -----------------------------------------------------------------
# functions
# -----------------------------------------------------------------
function print_header {
echo "+--------------------------------------------------------+"
echo "| MALLORY INSTALL/UPDATE SCRIPT |"
echo "+--------------------------------------------------------+"
}

function phase0 {
# create the update directory if it doesn't exist
[[ ! -d ${UPDATE_DIR} ]] && mkdir -p ${UPDATE_DIR}
print_header
echo "| Before running this script, please ensure that you've |"
echo "| configured a network interface and that the internet |"
echo "| is reachable by this virtual machine. |"
echo "+--------------------------------------------------------+"
echo "| Once you have done this (or if you already had) simply |"
echo "| rerun this script to continue the update |"
echo "+--------------------------------------------------------+"
echo "phase1" > ${UPDATE_DIR}/.next_phase
exit 0
}

function phase1 {
print_header
echo "beginning Mallory installation"
echo "updating apt package list"
sudo apt-get update |tee ${UPDATE_LOG}
echo ""

echo "upgrading OS to latest versions of installed packages"
sudo apt-get upgrade -y |tee -a ${UPDATE_LOG}

echo "installing Mallory dependencies"
sudo apt-get -y install build-essential mercurial libnetfilter-conntrack-dev libnetfilter-conntrack3 |tee -a ${UPDATE_LOG}
if [ ! -f /usr/lib/netfilter_conntrack.so.1 ]; then
sudo ln -s /usr/lib/libnetfilter_conntrack.so /usr/lib/libnetfilter_conntrack.so.1
fi
sudo apt-get -y install python-pip python-m2crypto python-qt4 pyro-gui python-netfilter python-pyasn1 |tee -a ${UPDATE_LOG}
sudo apt-get -y install python-paramiko python-twisted-web python-qt4-sql libqt4-sql-sqlite sqlite3 |tee -a ${UPDATE_LOG}
sudo easy_install pynetfilter_conntrack
echo ""

echo "enter directory you'd like Mallory to be installed to"
read -p "(default: ${HOME}/mallory)" mallorydir

if [ "$mallorydir" == "" ]; then
mallorydir="${HOME}/mallory";
fi

echo ${mallorydir} > ${UPDATE_DIR}/installdir
echo "retrieving current mallory source from bitbucket"
/usr/bin/hg clone https://bitbucket.org/IntrepidusGroup/mallory ${mallorydir}/current

echo "phase2" > ${UPDATE_DIR}/.next_phase
phase2
}


function phase2 {
print_header
echo "Mallory installation completed"
echo "To use mallory:"
echo "Open a new terminal window, cd to ${mallorydir}/current/src, then run:"
echo " sudo python ./mallory.py"
echo ""
echo "To run the mallory GUI:"
echo "Open a new terminal window cd to ${mallorydir}/current/src and run:"
echo " sudo chown $USER mallory.log"
echo " where $USER is the user you are logged in as. Then run:"
echo " python ./launchgui.py"
echo "Have fun!"
read -n1 -p "press any key to continue..."

echo "update" > ${UPDATE_DIR}/.next_phase
exit 0
}

function update {
print_header
echo "Starting Mallory Update"

if [ ! -d ${UPDATE_DIR} ]; then
echo "mallory update directory not found, quitting"
exit 1
fi

if [ ! -f ${UPDATE_DIR}/installdir ]; then
echo "mallory installation path not found"
exit 1
fi

export mallorydir=`cat ${UPDATE_DIR}/installdir`

if [ ! -d ${mallorydir} ]; then
echo "mallory installation directory doesn't exist"
exit 1
fi

echo "moving current install to archive"
if [[ -d ${mallorydir}/archive ]]; then
rm -rf ${mallorydir}/archive/*
else
mkdir ${mallorydir}/archive
fi

# Check for current and move it
# NOTE: we use 'cp -R; rm' instead of 'mv' here
# to avoid 'Directory not empty' errors
if [[ -d ${mallorydir}/current ]]; then
cp -R ${mallorydir}/current/* ${mallorydir}/archive/
fi
rm -rf ${mallorydir}/current

echo "retrieving current mallory source from bitbucket"
/usr/bin/hg clone https://bitbucket.org/IntrepidusGroup/mallory ${mallorydir}/current

echo "update" > ${UPDATE_DIR}/.next_phase
exit 0
}


# -----------------------------------------------------------------
# scriptybits
# -----------------------------------------------------------------

if [[ -f ${UPDATE_DIR}/.next_phase ]]; then
case `cat ${UPDATE_DIR}/.next_phase` in
phase0)
phase0
;;

phase1)
phase1
;;

phase2)
phase2
;;

update)
update
;;

phase4)
echo "phase4: profit!"
exit 0
;;

*)
echo "unknown update status, attempting update"
update
;;
esac
else
phase0
fi
echo -e "Latest supported Debian-based releases are Ubuntu 18.04 (Bionic) or Debian 10 (Buster).\nOnly Python 2 is supported.\nThis script assumes the use of apt package manager.\nIt is recommended to install mallory in a virtual machine.\nThis script was tested on ubuntu; there may be a variance in package names between distributions."
echo
echo "The script will now install/update dependencies using apt and pip. (safe to rerun)"
read -p "Press any key to continue, or ctrl+c to exit: " -n 1 -r
echo

set -e
set -x
sudo apt-get update

sudo apt-get install build-essential libnetfilter-conntrack-dev git python-pip python-m2crypto python-qt4 pyro-gui python-netfilter python-pyasn1 python-pil python-ipy python-paramiko python-twisted-web python-qt4-sql libqt4-sql-sqlite sqlite3 python --no-install-recommends

sudo -H pip2 install pynetfilter_conntrack
set +x

echo
echo 'Installation complete.'
echo
echo "If you haven't already, install the Mallory repo by running in a directory of your choosing:"
echo
echo " /usr/bin/git clone https://github.com/Tokarak/mallory"
echo
echo 'In the repo, src/mallory.py has the core functionality of mallory. src/launchgui.py can launch the gui WHILE src/mallory.py is already running.'
echo 'It is recommended to run the gui on your virtual machine using ssh with X11 forwarding (ssh -X ...) instead of installing a bulky desktop. To enable X11forwarding on your VM:'
echo " sudo apt install xauth"
echo 'Search "X11Forwarding" online to learn more.'
echo
echo 'Notice: if you get a "cannot open shared object file" error on running the script, please see:'
echo 'https://web.archive.org/web/20131007182424/http://intrepidusgroup.com/insight/2013/07/getting-mallory-to-run-in-modern-versions-of-ubuntu/'
echo "Script end."
echo
exit 0
2 changes: 1 addition & 1 deletion src/Pyro/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def bindToURI(self,URI):
raise ConnectionDeniedError('invalid response')
except socket.error:
Log.msg('PYROAdapter','connection failed to URI',str(URI))
raise ProtocolError('connection failed')
raise ProtocolError('Could not connect to mallory instance.')
finally:
self.lock.release()

Expand Down
7 changes: 4 additions & 3 deletions src/config_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ def save(self):
"%s -p tcp -m tcp --to-ports 20755") % interface)
cmds.append( ("iptables -t nat -A PREROUTING -j REDIRECT -i "
"%s -p udp -m udp --to-ports 20755") % interface)


print cmds
for cmd in cmds:
subprocess.call(cmd, shell=True)
subprocess.call(cmd, shell=True) # Better to fail explicitly on error

print cmds

def __str__(self):
return ("ifs:%s, mitm_ifs:%s, outbound_ifs:%s"
% (self.interfaces, self.mitm_interfaces,
Expand Down
12 changes: 5 additions & 7 deletions src/gui/ProtocolsGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,11 @@ def data(self, index, role):
return str(proto.serverPort)

if index.column() == PROTO_DEBUG:
debuggable = spacing + "No" + spacing

if proto.__class__ == "TcpProtocol":
debuggable = spacing + "Yes" + spacing

return debuggable

if isinstance( proto, TcpProtocol ):
return spacing + "Yes" + spacing
else:
return spacing + "No" + spacing

return QtCore.QVariant()

# Editing Data (Not Needed)
Expand Down
10 changes: 5 additions & 5 deletions src/gui/guimain.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def check_for_de(self):

eventcnt = 0
while True:
try:
# try:
eventlist = self.remote_debugger.getdebugq()

# Currently only handling one selection
Expand Down Expand Up @@ -241,10 +241,10 @@ def check_for_de(self):
#self.curdebugevent = next_unsent
self.send_cur_de(next_unsent)

except:
print "[*] MalloryGui: check_for_de: exception in de check loop"
print sys.exc_info()
traceback.print_exc()
# except:
# print "[*] MalloryGui: check_for_de: exception in de check loop"
# print sys.exc_info()
# traceback.print_exc()

class StreamListDelegate(QtGui.QItemDelegate):
def __init__(self, parent, model):
Expand Down
22 changes: 15 additions & 7 deletions src/mallory.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@
try:
# These protocols have dependencies and may not be safe to import
from protocol import sslproto, http, ssh, https
from plugin_managers import http_plugin_manager
except ImportError:
print "ImportError: Trouble importing protocols with dependencies. " \
except ImportError, e:
print 'ImportError : "%s"' % e
print "Trouble importing protocols with dependencies. " \
"Proceeding with minimal protocol support."
print "For support verify PIL (python-imaging) is installed"

try:
from plugin_managers import http_plugin_manager
except ImportError, e:
print 'ImportError : "%s"' % e
print "Could not import http_plugin_manager. " \
"Proceeding without support support."

# Config object is global. Buyer beware.
config = config.Config()
Expand Down Expand Up @@ -509,14 +516,15 @@ def main(self):
opts = CmdLineOpts()
mallory = Mallory(opts)


mallory.add_plugin_manager(http_plugin_manager.HttpPluginManager())
if 'http_plugin_manager' in dir():
mallory.log.info("Loading http_plugin_manager...")
mallory.add_plugin_manager(http_plugin_manager.HttpPluginManager())

# Pull in the protocol configured on the command line for use with the
# no-transparent option when the proxy is not being used transparently
if opts.options.proto:
import protocol
print "Proto is %s" % (opts.options.proto)
mallory.log.info("Proto is %s" % (opts.options.proto))

modulename,protoname = opts.options.proto.split(".")

Expand All @@ -528,7 +536,7 @@ def main(self):
"for port %d" \
% (protoinstance, protoinstance.serverPort))
except:
print "Invalid protocol specified at command line"
mallory.log.warning("Invalid protocol specified at command line")


mallory.main()
10 changes: 5 additions & 5 deletions src/plugin_managers/plugin/image_flip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config
import Image
from PIL import Image
import StringIO
from base import Base

Expand All @@ -20,11 +20,11 @@ def do (self, **kwargs):
pass
kwargs['data'] = response
return kwargs

def flip_image(self, imagein):
outstr = ""
outfile = StringIO.StringIO(outstr)
img = Image.open(StringIO.StringIO(imagein))
out = img.transpose(Image.ROTATE_180)
img = Image.open(StringIO.StringIO(imagein))
out = img.transpose(Image.ROTATE_180)
out.save(outfile, img.format)
return outfile.getvalue()
return outfile.getvalue()
12 changes: 6 additions & 6 deletions src/plugin_managers/plugin/image_invert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config
import Image
import ImageChops
from PIL import Image
from PIL import ImageChops
import StringIO
from base import Base

Expand All @@ -21,11 +21,11 @@ def do (self, **kwargs):
pass
kwargs['data'] = response
return kwargs

def invert_image(self, imagein):
outstr = ""
outfile = StringIO.StringIO(outstr)
img = Image.open(StringIO.StringIO(imagein))
out = ImageChops.invert(img)
img = Image.open(StringIO.StringIO(imagein))
out = ImageChops.invert(img)
out.save(outfile, img.format)
return outfile.getvalue()
return outfile.getvalue()
Loading