IMCAFS

Home

safe development of raspberry sect (1)

Posted by barello at 2020-02-24
all

Author: Yale

Details of original contribution: great reward | Hetian original contribution waiting for you!

Recently, I am preparing my work and preparing to participate in this year's national college students information security competition. My work is mainly developed based on raspberry school. What I want to do cannot be disclosed for the time being, but after the competition, I will send out all the development processes of my work.

What is raspberry pie?

Raspberry pie was developed by raspberry PI foundation, a charity registered in the UK, with Eben Upton / E Upton as the project leader. In March 2012, Eben epton, the University of Cambridge, UK, officially launched the world's smallest desktop computer, also known as the card computer, which is only the size of a credit card, but has all the basic functions of the computer. This is the raspberry PI computer board, translated as "raspberry pie" in Chinese.

Based on the needs of the project, it is necessary to be able to monitor the traffic of other devices in the same LAN. The previous scheme is to install nmap, tcpdump, arpspoof, dhcpd, etc. on the raspberry pie, to do a man in the middle attack by ARP Spoofing or dhcpspoof, and to sniff and monitor the traffic by forwarding the traffic of other devices from the raspberry pie. But later, considering that the performance of raspberry pie itself is not very strong, and there are other tasks to be done in the project. If you carry out ARP attacks or DHCP for a long time, you should eat the performance, so you decide to use raspberry pie as a router.

In the initial stage, we want to realize the function that the terminal device can connect to the Internet through the hot spots of raspberry pie, and we can monitor the traffic by installing tcpdump, tshark and other software on raspberry pie.

At this time, there are two solutions: one is to install several software on raspbian system of raspbian school to make a soft AP, and the other is to brush the Lede (derived from openwrt) system to make a pure router. The second plan was rejected because it almost wasted the powerful performance of raspberry pie. If I just brush a Lede, and what I want to do later may not work on Lede, so I chose the first plan. This leads to the following.

0x01

Do router, this thing has not done before, online tutorials are basically to teach you how to brush the router system. But I had to go to Google to see how raspberry pie makes routers. There are about four versions of installation methods found in English, and two in Chinese (both of the first four versions are translated, but not translated completely, and the format is wrong, which makes me miserable).

In three days, I tried every one of them, and finally made it. I stepped on many pits, brushed the system countless times, and loved my 32g SD card~~

In order to make it easier for those who are interested to do it, I will explain the tools, steps, etc., as well as the pits and precautions I stepped on as much as possible in the following. (marked with red pen)

0x02

Raspberry pie 3B+

SD card

Card reader

Reticle

Power cord

SDCard Formatted

Win32_Disk_Imager

2017-11-29-raspbian-stretch.img

0x03 start operation formally next

First, insert the SD card into the card reader, insert the card reader into the notebook, then open the SD card formatted, select the SD card we inserted in the selectcard, and click the format in the lower right corner to format it

Next, open win32disk imager

In the imagefile, select the image to burn (2017-11-29-raspbian-stretch.img), and in the device, select the device to burn

Click wirte and it will start to burn automatically

After the burn, you will find that the original 32g SD card is only 20MB ~ ~ don't panic, that means the burn is successful

Open the folder, create a text document named SSH in it, and leave the content blank (delete the suffix of. Txt)

Next, pop up the SD card from the computer, and insert the SD card into the card slot of raspberry pie.

0x04

Connect the power cord to raspberry pie and turn on the power.

At the same time, connect the Ethernet port of raspberry pie with the Ethernet port of the computer (the computer is connected to the Internet through wireless mode)

Open network and Sharing Center

Click change adapter settings

Check the WLAN right-click to open the attribute

Check the corresponding box as shown in the figure to enable Internet sharing

Then open CMD, input ipconfig, first look at the situation of each interface, in fact, we should pay attention to the IP of Ethernet

As shown in the figure above, Ethernet is 192.168.137.1

Next, enter ARP – a

It can be seen that there are several addresses of the same network segment in 192.168.137.1 (this screenshot is repeated after my router is made, so the bridging I made on the router and the IP connecting the terminal device of the router are all on it, so there will be multiple IP addresses. If I install the steps in my article, there should be only one address except 192.168.137.255. Remember Live in this address and open the xshell connection. Here I assume the address of raspberry pie is 192.168.137.159)

Open xshll as shown in the figure

(the reason why you created a new SSH file in the folder after burning the system is to enable the SSH function of raspbian, because raspbian does not enable SSH by default.)

Click OK to start the connection

The following interface will appear

The default username of raspberry pie is pi

Input password. Raspberry is the default Raspberry

You can see that the connection is successful

Then we have completed the work of system construction in the early stage

0x05

After the installation of raspberry pie, input the following commands in the terminal directly to change the source (the reason for changing the source is known to all, so we can tell)

Sudo-s

echo-e "deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretchmain contrib non-free rpi \n deb-srchttp://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contribnon-free rpi" > /etc/apt/sources.list

echo -e "deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/stretch main ui" > /etc/apt/sources.list.d/raspi.list

Exit

Then type sudoapt get quote

Get a list of recent packages; the list contains some package information, such as whether the package has been updated

Enter sudoapt get upgrade

Download the updated package locally and install it

Next, install the two important software used this time

Hostapd and dnsmasq

Enter the following command to install sudoapt get install hostapd

sudoapt-get install dnsmasq

Hostapd is used to create wireless hotspot, that is to say, it can send WiFi signal, but can our terminal connect to WiFi and get online? Of course, our terminal also needs to be assigned a suitable IP address, which is basically contracted by the DHCP service today, so we need to use dnsmasq to configure the DHCP service and DNS service.

The address of a LAN formed by a wireless router is basically 192.168. X.x, which is similar to that of every manufacturer. Basically, it is 192.168.1.1 and so on. Let's assign 192.168.0.10 to WLAN 0 (the X here can be specified arbitrarily, of course, it must be between 1 and 255)

We need to open it on xshell

Four lines at the end of the last input of the file

The first two lines indicate that the IP of WLAN 0 is 192.168.0.10

The two lines of the back door are prepared for the subsequent bridging work

The use of nano will not be introduced. Ctrl + O, then Ctrl + X

Or you can save it with Ctrl + X and enter y to exit

0x06

After assigning the static IP to raspberry pie, we need to configure the two aforementioned software: one is responsible for creating AP, and the other is responsible for DHCP. First, we need to configure the software for creating AP, namely hostapd

(in this experiment, the bridging method is used. Among the resources recommended by 0X11, there are also those that do not use the bridging method to build. You can refer to and compare them by yourself. However, no matter how the traffic is finally forwarded, no matter what software is installed, the functions of creating AP and managing DHCP are indispensable.)

Terminal inputs are as follows:

This file does not exist by default. We need to create it ourselves

Enter the following:

Note the last two lines. SSID can be changed to the WiFi name you want, and wpa_passphrase can be changed to WiFi password (note that it must be 8-bit or above, otherwise there will be problems when starting the hostapd service later ~ ~ the same as most router settings, in order to reduce the difficulty and risk of being brutally cracked)

Save and exit in a common way

Next, we need to add the corresponding path to the file created just now in hostapd

input

Note the content of the middle daemon? Conf

Modify it as shown in the figure above (note that in the original document, there is a "before" daemon "conf", which means notes, which must be removed during modification)

The content in quotation marks is the path of the file we edited earlier

Save and exit

0x07

At this time, start hostapd and you should be able to see the WiFi signal

Enter servicehostapd start to start

When I open the WiFi service on windows, I can see the created AP

Piwifi is the name of the WiFi we created. At this time, you can enter the correct password to access it, but you can't access it in the morning because it's not assigned to the appropriate IP address

Let's solve this problem next

0x08

The configuration file of dnsmasq is too cumbersome. We don't need to use it. To make it convenient, we need to change the name and save it first

Enter the following command

Then recreate a profile and edit it:

Yes, you're right. It only takes two lines

In this way, only 30-11 = 19 terminals can access our raspberry pie. The value here can be set according to the specification

Save and exit

0x09

After the traffic comes, we need to forward the traffic

Remove the comment in front of net. IPv4. IP ﹐ forward = 1 in the middle of the file

Pictured

Of course, you can also add this sentence directly at the end of the file to save and exit

0x10

After the traffic forwarding is set, we need to additionally set the inbound and outbound rules of iptabels

sudoiptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Then save the newly added rule

sudosh -c "iptables-save > /etc/iptables.ipv4.nat"

In order to use raspberry pie after restarting, we will edit the following file

Add a line to exit0

In the configuration file of hostapd, did you notice this line

The second line indicates bridging

It means that we need a bridging software to get through the traffic of WLAN 0 and eth0

Enter the following command to install the relevant software

Sudo apt-get install bridge-utils

Then create a new interface named BR0

Sudobrctl addbr br0

Then connect eth0 to BR0

Sudobrctl addif br0 eth0

Then go to the configuration file of the interface to set the corresponding settings

Open profile

Add the following at the end of the file:

Save and exit

After restart, it can be used as a wireless router.

So far, the router has been built. Compared with the routers on the market, the playability and expansibility are the biggest highlights. In the next article, we will build the security of raspberry pie and develop the extended functions on this basis.

0X11

Now by the way, install tcpdump to see if you can see the traffic of the devices connected to the raspberry router

First, access the hot spot piwifi of raspberry pie on the Mac, and then ifconfig checks the address

And then type in the raspberry pie

You can see the traffic

The specific application of this project is waiting for my second article~~

0x12

This production is mainly based on software implementation, so the big guys have their own plans, in addition to the above plans. There are also the following options:

When ISC DHCP server is used with hostapd, there are many files that need to be modified, and the iptables rules that need to be added are also cumbersome (Reference: https://www.maketecheasier.com/set-up-raspberry-pi-as-wireless-access-point /)

This article is built with hostapd + udhcpd, which can be used for reference learning (https://elinux.org/rpi-wireless-hotspot)

This article is also built with hostapd + dhsmasq. You can refer to the comparative study (Reference: https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd /)

Can't you enjoy it? 2017 dry cargo essence of the year, please click "essence" 2017 annual online safety dry cargo collection.

Don't forget to contribute!!!   

The official account of the day is open to original contributions!!!

We have good technical original articles.

Welcome to email: [email protected];

Hetianhui will give 100-500 yuan of contribution fee according to the time limit, novelty, writing, practicality and other aspects of the article.

If you have talent, please contribute!

Great reward | Hetian's original contribution waiting for you! (click for details)