Post

Hotspot wifi + vpn + tor + pirate

Debian ,nginx ,php ,VPN ,HotSpot ,Wifi ,PirateBox

Hotspot wifi + vpn + tor + pirate

Réalisation d’une “boîte” hotspot wifi + vpn + tor + pirate avec une carte olimex A20-OlinuxIno-Micro

Carte olimex A20-OlinuxIno-Micro

Documentation olimex

alt text

alt text

Installation Debian Jessie sur carte olimex A20-OLinuXino-MICRO

Matériel

  • Carte olimex A20-OLinuXino-MICRO
  • Bloc Alimentation 10V 1A
  • Dongle Wifi/USB RT5370
  • Carte micro SD min 4GO
  • SSD 60GB
  • Batterie Li-ion 3.7v 5000mAh

SDcard

SDcard créer avec les paquets debian armhf
Index of /debian/dists/stretch/main/installer-armhf/current/images/netboot/SD-card-images/

Connexion liaison série

Utilisation module USB/Série /dev/ttyUSB0 et minicom
Insertion carte SD et mise sous tension A20-OlinuxIno-Micro
Installation :

  • Europe/France
  • Partionnement
    • Disque ssd en LVM : vg-ssd ,lv-root ext4 10G /, lv-home ext4 30G /home, lv-swap 2G et lv-data 100G
    • SDcard /boot ext2 512M

Passage en super utilisateur

1
su

On désinstalle apache

1
apt-get purge apache2*   #connman hostapd avahi-daemon bind9-host

Mise à niveau

1
apt update && apt upgrade

Les points de montage

1
mount
1
2
3
...
/dev/mmcblk0p1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
...

Version linux et debian

Linux arm 4.9.34-armv7-lpae-x4 #1 SMP Thu Jun 29 10:03:16 CEST 2017 armv7l GNU/Linux
Debian 9.0 stretch

Utiliser le SSD /dev/sda
On efface la table des partitions

1
dd if=/dev/zero of=/dev/sda bs=1M count=10

Créer une partition /dev/sda1 par fdisk (8 à 15 Go)
fdisk /dev/sda ,o ,n ,p ,1 ,2048 ,+15G,w
Formater ext4

1
mkfs.ext4 -L stretch /dev/sda1

Copier tout le contenu de la SDcard sur le SSD

1
mount /dev/sda1 /mnt  # montage du disque SSD

Créer un fichier d’exclusion

1
nano exclude.txt
1
2
3
4
5
6
7
8
dev/*
proc/*
sys/*
tmp/*
run/*
mnt/*
media/*
lost+found

Lancer la copie

1
rsync -av --exclude-from exclude.txt / /mnt

La SDcard ne sera utilisée que pour le boot , modifier pour un démarrage sur le SSD

1
nano /boot/extlinux/extlinux.conf  # remplacer root=/dev/mmcblk0p1 par root=/dev/sda1

Suppression de connman

1
apt-get purge connman

Interface réseau (on a supprimé connman)

1
nano /mnt/etc/network/interfaces
1
2
3
4
5
6
7
8
9
10
11
12
13
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
    auto eth0
    allow-hotplug eth0
    iface eth0 inet dhcp

    iface eth0 inet6 auto

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Démontage

1
umount /mnt

Redémarrer

1
reboot

Vérifier par mount le point de montage sur /dev/sda1 après redémarrage

1
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)

Relever adresse ip pour connexion SSH :

1
ip addr # 192.168.0.43

Créer un groupe et utilisateur

1
2
3
sudo groupadd oli
sudo useradd -m -g oli -c 'oli olibox' -s /bin/bash oli
sudo passwd oli

Modifier sudoers pour accès sudo sans mot de passe à l’utilisateur oli

1
echo "oli     ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

Paraméter SSH
Pas de connexion root PermitRootLogin no dans fichier /etc/ssh/sshd_config
Installer libpam-systemd (session SSH ne se termine pas correctement lors d’un “reboot” à distance) : apt install libpam-systemd
Relancer le service ssh : systemctl restart ssh
Se connecter depuis un poste du réseau : ssh debian@192.168.0.43

Les pilotes dongle wifi RT5370 cont installés (firmware-ralink)
Outils curl ,tmux, lsof, tree, iw

1
sudo apt -y install  curl tmux lsof tree

host hostname

1
2
3
4
sudo nano /etc/hosts
       127.0.1.1	xatyuezal.xyz	olibox
sudo nano /etc/hostname
       olibox

locales

1
sudo dpkg-reconfigure locales
1
2
3
Generating locales (this might take a while)...
  fr_FR.UTF-8... done
Generation complete.

tzdata

1
sudo dpkg-reconfigure tzdata
1
2
3
Current default time zone: 'Europe/Paris'
Local time is now:      Mon Jan  2 20:48:30 CET 2017.
Universal Time is now:  Mon Jan  2 19:48:30 UTC 2017.

Renommer l’interface réseau wlxxx en wlan0
Le dongle concerné

1
2
3
4
lsusb
Bus 001 Device 002: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

ip link
1
2
3: wlx000f541324b5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0f:54:13:24:b5 brd ff:ff:ff:ff:ff:ff

Créer une nouvelle règle udev

1
sudo nano /etc/udev/rules.d/70-netnames.rules

Ajouter

1
2
# identify device by MAC address
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:0f:54:13:24:b5", NAME="wlan0"

Cette opération nécessite un reboot, on retire puis on réinsère le dongle USB Wifi
On lance ip link pour vérifier si wlan0

1
2
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0f:54:13:24:b5 brd ff:ff:ff:ff:ff:ff

nginx compilé + php5 + mysql

nginx compilé + php5/7

1
[nginx compilé + php (procédures)](post_url 2017-06-29-Serveur-web-nginx-PHP7 %})

Créer un dossier pour les configurations nginx

1
sudo mkdir -p /etc/nginx/conf.d/xatyuezal.xyz.d

mysql

1
sudo apt install mysql-server php5-mysqlnd  # mysql49 (debian jessie)  

mariadb

1
2
sudo apt install mariadb-server             # mysql49 (debian stretch)
sudo mysqladmin -u root password 'votre-nouveau-mot-de-passe'

Hotspot Wifi + DHCP

Installation d’un point d’accès Wifi avec dhcp pour fournir des adresses ip aux clients wifi

les interfaces réseau

1
ip link
1
2
3
4
5
6
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 02:c2:09:40:f2:2b brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 7c:dd:90:5f:68:7b brd ff:ff:ff:ff:ff:ff

HotSpot Wifi (lien original “Hot-Spot Wifi”)

On passe en mode su

1
sudo -s

Installer hostapd

1
apt install hostapd

Configurer HostApd , éditer ou créer le fichier hostapd.conf

1
nano /etc/hostapd/hostapd.conf 
1
2
3
4
5
6
7
8
9
10
11
12
13
interface=wlan0
driver=nl80211
ssid=HotSpotYan
hw_mode=g
channel=5
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=4dGB4q2dYm
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Modifier le fichier /etc/default/hostapd

1
2
3
nano /etc/default/hostapd

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Installons le serveur DHCP, isc-dhcp-server

1
apt install isc-dhcp-server

Editer /etc/dhcp/dhcpd.conf, paramètres du serveur DHCP -ce qui permet des connexions wifi pour obtenir automatiquement les adresses IP, DNS, etc.

1
  nano /etc/dhcp/dhcpd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# have support for DDNS.)
ddns-update-style none;


default-lease-time 600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

subnet 10.10.10.0 netmask 255.255.255.0 {
range 10.10.10.10 10.10.10.50;
option broadcast-address 10.10.10.255;
option routers 10.10.10.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 208.67.222.222,208.67.222.220;
}

Editer

1
nano /etc/default/isc-dhcp-server

Modifier la dernière ligne du fichier qui contient INTERFACES pour y ajouter le port wifi , wlan0

1
INTERFACES="wlan0"

wlan0
Nous allons configurer la connexion wlan0 pour être statique

1
nano /etc/network/interfaces

Supprimer tout ce qui fait référence aux anciens paramètres de configuration de wlan0, nous allons les changer
Ajouter en fin de fichier

1
2
3
4
allow-hotplug wlan0  
iface wlan0 inet static  
    address 10.10.10.1
    netmask 255.255.255.0

Activer et définir une adresse statique wifi dans une autre plage privée d’adresse 10.10.10

1
2
ip link set dev wlan0 up
        RTNETLINK answers: Operation not possible due to RF-kill

Pour corriger l’erreur

1
2
3
apt install rfkill
rfkill unblock all
ip link set dev wlan0 up

On définit l’IP de wlan0 manuellement pour éviter de relancer le service

1
ip addr add 10.10.10.1/24 dev wlan0

Configuration NAT (Network Address Translation)
NAT est une technique qui permet à plusieurs périphériques d’utiliser une seule connexion à Internet.
Linux prend en charge NAT en utilisant Netfilter (également connu sous le nom iptables) et est assez facile à configurer.

Tout d’abord, activez le redirection IP dans le noyau:

1
2
sysctl net.ipv4.ip_forward=1 
sysctl net.ipv6.conf.all.forwarding=1

Pour le configurer automatiquement au démarrage, modifiez le fichier /etc/sysctl.conf et décommenter les lignes suivantes:

1
2
3
4
# enable packet forwarding for IPv4
net.ipv4.ip_forward=1
# enable packet forwarding for IPv6
net.ipv6.conf.all.forwarding=1

Les règles

1
2
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Le hotspot wifi a accès à internet

Multi SSID

Pour paramétrer le point d’accès Wifi avec plusieurs SSID ,il faut modifier l’adresse MAC du périphérique réseau wlan (Multiple SSIDs with hostapd)
L’adresse mac doit se terminer par un 0
Pour éviter tout conflit , l’adresse mac débutera par 02 (‘locally administered’)
Relever l’adresse mac de l’interface wlan

1
2
ifconfig wlan0 | grep -o "HWaddr ..:..:..:..:..:.."
HWaddr 7c:dd:90:5f:68:7b

On va la modifier en 02:dd:90:5f:68:70

1
2
3
ifconfig wlan0 down                      # désactiver wlan0
ifconfig wlan0 hw ether 02:dd:90:5f:68:70
ifconfig wlan0 up                        # réactiver wlan0

Modifier la configuration hostapd en spécifiant l’adresse mac et en ajoutant les nouveaux SSID

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
interface=wlan0
bssid=02:dd:90:5f:68:70
driver=nl80211
ssid=HotSpotYan
hw_mode=g
channel=5
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=4dGB4q2dYm
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

bss=wlan0_0
ssid=PirateYan

bss=wlan0_1
ssid=VpnYan

bss=wlan0_2
ssid=TorYan

Redémarrer le service

1
service hostapd restart

Les nouveaux interfaces réseau avec leur SSID viennent s’ajouter

1
ip link
1
2
3
4
5
6
7
8
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 02:dd:90:5f:68:70 brd ff:ff:ff:ff:ff:ff
4: wlan0_0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 02:dd:90:5f:68:71 brd ff:ff:ff:ff:ff:ff
5: wlan0_1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 02:dd:90:5f:68:72 brd ff:ff:ff:ff:ff:ff
6: wlan0_2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 02:dd:90:5f:68:73 brd ff:ff:ff:ff:ff:ff

Attribuer des adresses privées aux interfaces wlan0_x dans /etc/network/interfaces ,ajouter en fin de fichier

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
allow-hotplug wlan0  
iface wlan0 inet static  
    address 10.10.10.1
    netmask 255.255.255.0
    pre-up ifconfig wlan0 hw ether 02:dd:90:5f:68:70

allow-hotplug wlan0_0
iface wlan0_0 inet static
    address 10.10.10.2
    netmask 255.255.255.0

allow-hotplug wlan0_1
iface wlan0_1 inet static
    address 10.10.10.3
    netmask 255.255.255.0

allow-hotplug wlan0_2
iface wlan0_2 inet static
    address 10.10.10.4
    netmask 255.255.255.0

PirateBox

En mode su , se rendre sous /var/www et cloner php-piratebox

1
2
3
cd /var/www
git clone https://github.com/jvaubourg/php-piratebox.git
mv php-piratebox piratebox # renommer le dossier

Clients wlan0 accès internet via eth0 , règles iptables

1
2
iptables -w -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -w -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Le fichier de configuration nginx

1
nano /etc/nginx/conf.d/xatyuezal.xyz.d/piratebox.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Max file size
client_max_body_size 10G;

# OPTIONAL
location /public/uploads/ {

  # OPTIONAL: use a public/uploads/ folder located elsewhere
  # WITH: $options['base_uploads'] = '/var/spool/piratebox/public/uploads/'
  root /var/spool/piratebox/;

  # OPTIONAL: force download for all files
  add_header Content-Type "application/octet-stream";
  add_header Content-Disposition "attachment; filename=$1";
}

# OPTIONAL
location /public/chat/ {

  # OPTIONAL: use a public/chat/ folder located elsewhere
  # WITH: $options['base_chat'] = '/var/spool/piratebox/public/chat/'
  root /var/spool/piratebox/;

  # OPTIONAL: deny direct access to the chat log
  deny all;
  return 403;
}

# PHP
location ~ \.php {
  include /etc/nginx/fastcgi_params;

  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_pass unix:/var/run/php5-fpm.sock;

  # 10 minutes max for uploading a file
  fastcgi_send_timeout 600;
}

# OPTIONAL: use fancy urls
# WITH: $options['fancyurls'] = true
location @piratebox {

  # WITH: $options['base_uri'] = '/foobar/'
  rewrite ^/foobar/(.*)$ /foobar/?/get&dir=$1;
}

location / {
  index index.html index.php;

  # OPTIONAL: use fancy urls
  try_files $uri $uri/ @piratebox;
}

Pour inclure la configuration

1
nano /etc/nginx/conf.d/default.conf	
1
2
3
4
5
6
7
8
9
10
11
12
server {
    listen 80;
    listen [::]:80;
    server_name _;
    root /var/www/piratebox/;

    include conf.d/xatyuezal.xyz.d/*.conf;	

    access_log /var/log/nginx/xatyuezal.xyz-access.log;
    error_log /var/log/nginx/xatyuezal.xyz-error.log;

}

Taille des fichiers

1
nano /etc/php5/fpm/php.ini
1
2
3
4
5
6
; Max file size
upload_max_filesize = 10G
post_max_size = 10M

; 10 minutes max for uploading a file
max_execution_time = 600

Permissions

1
2
chown www-data: /var/www/piratebox/public/uploads/
chown www-data: /var/www/piratebox/public/chat/

OpenVpn

On installe openvpn

1
sudo apt install openvpn

On se base sur un fichier de configuration client généré lors de l’installation dur serveur openvpn
IMPORTANT : fonctionnement ipv4 (proto udp) , ipv6 ? (proto udp6) non fonctionnel sur les clients android
Aperçu du fichier clientvpn.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
client
proto udp
remote xoyize.xyz 1194
dev tun
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
auth SHA256
cipher AES-128-CBC
tls-client
tls-version-min 1.2
tls-cipher TLS-DHE-RSA-WITH-AES-128-GCM-SHA256
#setenv opt block-outside-dns
verb 3
<ca>
[...]
</ca>
<cert>
[...]
</cert>
<key>
[...]
</key>
key-direction 1
<tls-auth>
[...]
</tls-auth>
status /var/log/openvpn-client.status
log-append /var/log/openvpn-client.log

Pour utiliser le fichier de conf /etc/openvpn/clientvpn.conf lors du démarrage du service d’OpenVPN.

1
2
systemctl start openvpn@clientvpn.service
sleep 10        # attendre 10 secondes (création tun)

On regarde quel interface de tunneling

1
2
ip link |grep tun    # tun0  
8: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 100

Ecrire les règles iptables ipv4 :

1
2
3
4
5
6
7
8
# Règles vpn clients wlan et eth
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE -m comment --comment "Utiliser IP VPN pour eth0"  
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE -m comment --comment "Utiliser IP VPN pour tun0"  
iptables -A FORWARD -s 192.168.0.0/24 -i eth0 -o tun0 -m conntrack --ctstate NEW -j ACCEPT -m comment --comment "Autoriser uniquement le trafic des clients eth0 vers tun0"  

iptables -A FORWARD -s 10.10.10.0/24 -i wlan0 -o eth0 -m conntrack --ctstate NEW -j REJECT -m comment --comment "Bloquer le trafic des clients vers eth0"  
iptables -A FORWARD -s 10.10.10.0/24 -i wlan0 -o tun0 -m conntrack --ctstate NEW -j ACCEPT -m comment --comment "Autoriser uniquement le trafic des clients wlan0 vers tun0" 

Sauvegardez les pour le prochain redémarrage :

1
iptables-save > /etc/iptables.ipv4.nat

Le contenu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Generated by iptables-save v1.4.21 on Mon Jan  2 13:39:15 2017
*nat
:PREROUTING ACCEPT [337:26891]
:INPUT ACCEPT [22:6613]
:OUTPUT ACCEPT [96:6454]
:POSTROUTING ACCEPT [4:192]
-A POSTROUTING -o eth0 -m comment --comment "Utiliser IP VPN pour eth0" -j MASQUERADE
-A POSTROUTING -o tun0 -m comment --comment "Utiliser IP VPN pour tun0" -j MASQUERADE
COMMIT
# Completed on Mon Jan  2 13:39:15 2017
# Generated by iptables-save v1.4.21 on Mon Jan  2 13:39:15 2017
*filter
:INPUT ACCEPT [2617:1377921]
:FORWARD ACCEPT [2859:1302577]
:OUTPUT ACCEPT [576417:915698122]
-A FORWARD -s 192.168.0.0/24 -i eth0 -o tun0 -m conntrack --ctstate NEW -m comment --comment "Autoriser uniquement le trafic des clients eth0 vers tun0" -j ACCEPT
-A FORWARD -s 10.10.10.0/24 -i wlan0 -o eth0 -m conntrack --ctstate NEW -m comment --comment "Bloquer le trafic des clients vers eth0" -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -s 10.10.10.0/24 -i wlan0 -o tun0 -m conntrack --ctstate NEW -m comment --comment "Autoriser uniquement le trafic des clients wlan0 vers tun0" -j ACCEPT
COMMIT
# Completed on Mon Jan  2 13:39:15 2017

Pour les charger à chaque reboot :

1
echo "up iptables-restore < /etc/iptables.ipv4.nat" >> /etc/network/interfaces
Cet article est sous licence CC BY 4.0 par l'auteur.