A quick tutorial about how to configure a WPA2-PSK Access point by hand, and forward traffic between the wired nic and Wifi card. Very basic, but it does work.
This requires a Kali / Debian machine, and a network card able to run AP mode, and of course a client to test with. Time is ten-15 minuttes.

So ok. Let's jump right in. Let's assume you have a Kali / Debian box, and a spare Wifi card around, and wan't to see if you can build a software AP.
This tutorial is based on there being DHCP from a router, we won't be dealing with setting up DHCP and DNS on the machine running the AP, we'll get back to that in a more advanced tutorial.

First of, we have to check if NetworkManager is running, and if it is' kill it / stop it, because it will trip us up, trying to configure the network cards for us. There's a couple of ways to do that, here's the easy one.

ps aux | grep NetworkManager

Another way is using systemctl, like so.

systemctl status NetworkManager
● NetworkManager.service - Network Manager
     Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendo>
     Active: inactive (dead) since Sat 2020-04-18 15:52:41 CEST; 1h 6min ago
       Docs: man:NetworkManager(8)
    Process: 1228 ExecStart=/usr/sbin/NetworkManager --no-daemon (code=exited, >
   Main PID: 1228 (code=exited, status=0/SUCCESS)

If you see "inactive", that's good. If you see "active" that's bad. Stop it with

service NetworkManager stop

A quick note here. You might loose internet connection and DNS resolving because of stopping network-manager. So how do we get it back ? Let's take a sidestep for a minute here, and talk about setting up connections by hand, so we have basic internet and DNS running.

 What we need to setup DNS is making sure there are servers in /etc/resolv.conf, so look in that, using the cat command. If there isn't any content in it, setup a couple of servers.

echo 'namerserver 8.8.8.8' > /etc/resolv.conf
echo 'nameserver 8.8.4.4' >> /etc/resolv.conf

That takes care of DNS. Next we configure eth0 with an address.

ifconfig 192.168.0.10 netmask 255.255.255.0 eth0

The last thing we need is setting up the default route to the internet. Let's do that.

route add default gateway 192.168.0.1 eth0

 

That should do it. Now we know how to configure a network card, let's move on.

We need to setup a service called hostapd. It's the software that will provide the AP function itself, so we won't get anywhere without it. Luckily for us, it's not that hard. Here's my config used for testing.

cat /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
bridge=br0
ssid=testnet
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Lameass_password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

More of less, all you have to change is "interface", "driver", "ssid', and "wpa_passphrase". In this config it creates a bridge called br0, a network called testnet, with My_Lameass_password as the password.

When that's done. We start the hostapd service with

#start hostapd

service hostapd start

#Check it's running

ps aux | grep hostapd

Next we need to make a bridge. Remember we setup eth0 by hand ? We need it to be added to the br0 bridge, so let's do that.

brctl addif br0 eth0

Next we need DHCP to assign an address to our bridge / setup the bridge in hand. the method's the same as for a normal interface, using ifconfig / dhclient, so by now you should be able to do that on your own :)

Next, we need to have a look at the routing tables, and enable forwarding in the kernel, and then we're almost done.

#check routing

route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    0      0        0 br0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 br0

#If no route set, set it.

add -net 0.0.0.0. gw ip_of_router dev br0

# OR 

route add default gw ip_of_router

# Delete old route

del -net 0.0.0.0 gw ip_of_router

Last we setup forwarding in the kernel

echo '1' > /proc/sys/net/ipv4/ip_forward

TADAAA. That should be it. Try to see if you can log onto the network, get an address and go online. If not, try setting up the client with a static IP, get it on the AP, and see if that works. This should be all there's to it.

This method should be useable no matter if your access is a modem, wifi, or whatever. Just remember that using NetworkManager is out of the question, as it will interfere. So modem would be by hand, using something as vwdial, wifi with another wifi card, using wpa_supplicant or whatever the network requires.
And yes, do try for the fun of it, to start Wireshark and run it on the bridge interface :) That should allow you to see online traffic as long as it's not encrypted, or better still, try bettercap, running on the bridge interface :)

If you want / need DNS function on the AP, it can be added with dnsmasq.Here's a basic conf file.

cat /etc/dnsmasq.conf
# disables dnsmasq reading any other files like /etc/resolv.conf for nameservers
no-resolv
# Interface to bind to
interface=br0
#Specify starting_range,end_range,lease_time
dhcp-range=192.168.0.200,192.168.0.240,12h
# dns addresses to send to the clients
server=8.8.8.8
server=192.168.0.100



Happy surfing :)

You have no rights to post comments