|
| 1 | +# Configuration: |
| 2 | +We configured RaspberryPi to enable ssh service on boot and automatically connect to a wifi router to get an ip address |
| 3 | + |
| 4 | + |
| 5 | +## Stage 1: |
| 6 | +we used raspberry pi, inbuilt wifi interface (wlan0) to connect to the router/Personal Hostpot and attain IP address. |
| 7 | +After the connection, the packets will be processed and actions are preformed according to some firewall rules. |
| 8 | +constraint: If a port scan happens on the any machine over the network, the psad service will alert the root user on raspberry pi and redirects the attacker to the HoneyPot. |
| 9 | + |
| 10 | +**psad.conf** |
| 11 | +```psad |
| 12 | +ENABLE_AUTO_IDS Y; |
| 13 | +ENABLE_AUTO_IDS_EMAILS N; |
| 14 | +IPT_SYSLOG_FILE /var/log/syslog; |
| 15 | +EXPECT_TCP_OPTIONS Y; |
| 16 | +EXPECT_TCP_FLAGS Y; |
| 17 | +AUTO_IDS_DANGER_LEVEL 3; |
| 18 | +AUTO_BLOCKING_SCRIPT /etc/psad/redirect_to_honeypot.sh; |
| 19 | +
|
| 20 | +``` |
| 21 | +**redirect script** |
| 22 | +```redirect_to_honeypot.sh |
| 23 | +#!/bin/bash |
| 24 | + |
| 25 | +# Get the attacker's IP from PSAD |
| 26 | +ATTACKER_IP=$1 |
| 27 | + |
| 28 | +# Redirect the attacker's HTTP traffic to the honeypot (port 80) |
| 29 | +iptables -t nat -A PREROUTING -s $ATTACKER_IP -p tcp --dport 80 -j DNAT --to-destination 192.168.1.200 |
| 30 | + |
| 31 | +# Log the redirection |
| 32 | +echo "$(date) - Redirected $ATTACKER_IP to honeypot" >> /var/log/honeypot_redirect.log |
| 33 | +``` |
| 34 | +**IPTables config** |
| 35 | +```iptables |
| 36 | +# Flush existing rules |
| 37 | +sudo iptables -F |
| 38 | +sudo iptables -t nat -F |
| 39 | +
|
| 40 | +# Allow forwarding from Raspberry Pi to the network |
| 41 | +sudo iptables -A FORWARD -i eth0 -o eth0 -j ACCEPT |
| 42 | +
|
| 43 | +# Default NAT for regular traffic (forward to actual server) |
| 44 | +sudo iptables -t nat -A PREROUTING -d 192.168.1.100 -j DNAT --to-destination 192.168.1.100 |
| 45 | +
|
| 46 | +# Redirect traffic from the attacker (X.X.X.X) to the honeypot |
| 47 | +sudo iptables -t nat -A PREROUTING -s X.X.X.X -p tcp --dport 80 -j DNAT --to-destination 192.168.1.200 |
| 48 | +
|
| 49 | +# Allow masquerading for outbound traffic |
| 50 | +sudo iptables -t nat -A POSTROUTING -j MASQUERADE |
| 51 | +
|
| 52 | +``` |
| 53 | + |
| 54 | +## Stage 2: |
| 55 | +We created a virtual wifi interface (wlan0_ap) that acts as a Access Point to the machines under stage 2 |
| 56 | +Supported modes for raspberry pi 3 B+ |
| 57 | +```bash |
| 58 | +Supported interface modes: |
| 59 | + * IBSS |
| 60 | + * managed |
| 61 | + * AP |
| 62 | + * AP/VLAN |
| 63 | + * monitor |
| 64 | + * mesh point |
| 65 | +``` |
| 66 | + |
| 67 | +At this point of time, we are good with connection hardware. |
| 68 | +To achive DHCP for allocation of IP address, we used dnsmasq and host apd service |
| 69 | +- **dnsmasq**: allocates an ip address for the network [DHCP server] |
| 70 | +```dnsmasq |
| 71 | +interface=wlan0_ap |
| 72 | +dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h |
| 73 | +
|
| 74 | +domain-needed |
| 75 | +bogus-priv |
| 76 | +dhcp-option=3,192.168.4.1 |
| 77 | +dhcp-option=6,192.168.4.1 |
| 78 | +``` |
| 79 | + |
| 80 | +- **Hostapd**: used to configure the virtual wifi interface as access point. |
| 81 | +```Hostapd |
| 82 | +interface=wlan0_ap |
| 83 | +driver=nl80211 |
| 84 | +ssid=RaspberryPi3 |
| 85 | +hw_mode=g |
| 86 | +channel=6 |
| 87 | +wmm_enabled=0 |
| 88 | +auth_algs=1 |
| 89 | +#wpa=2 |
| 90 | +#wpa_passphrase=12345678 |
| 91 | +#wpa_key_mgmt=WPA-PSK |
| 92 | +#rsn_pairwise=CCMP |
| 93 | +``` |
| 94 | +## Stage 3 |
| 95 | +At stage 3, we used 2 virtual machines running web servers which are mirrors to each other but the purpose is different. |
| 96 | +One webserver collects all the sensor data from the legit user and sends it through the raspberry pi to the webserver that is hosted on the **vm1** |
| 97 | + |
| 98 | +if any attacker trys a port over the network, the psad service on raspberrypi detects the attack and redirect the user to **honeypot** that is on **vm2** |
| 99 | + |
| 100 | +both the **vms** are connected using the bridged adapter for direct communication. |
0 commit comments