This is the 20th year of the 21st century. Technologies of all kinds are booming right now and are helping and assisting humans in almost every domain you can think of. At this rate of progress, it is almost impossible to even comprehend what the future holds.
But let us worry about the present for now. Unfortunately, there are people who misuse this great power of technologies for very inhumane and unethical reasons. They are commonly termed as "hackers".
Global cybercrime damages are predicted to cost up to US $6 Trillion By 2021. Since the start of the COVID-19 pandemic, WHO has reported a fivefold increase in cyber attacks. Every possible precaution needs to be taken to stay safe in the digital world. WiFi cracking and network attacks are some of the dangerous cyber attacks that are carried out by hackers. Did you know that if a hacker cracks your WiFi, he/she can access all the devices connected to that network?
So, I came up with this project to help you scan your networks so that you can monitor for suspicious devices connected on the network. Using the Bolt IoT module, you will get the output on your Telegram account. Without further ado.... let's get started!
Bolt WiFi Module & Cloud Setup :Create a Bolt Cloud account (if you don't have one) using the link given below. If you already have one, sign in directly.
https://cloud.boltiot.com/register/
Download the Bolt app [Android or Iphone], and setup the Bolt IoT WiFi module by simply following the instructions in the app. You can also refer to the link below for instructions.
https://docs.boltiot.com/docs/adding-a-new-device
- Now login to cloud.boltiot.com
- On the left hand Nav Bar, click on API.
- Click on Generate New API Key and click enable.
Copy and store this key somewhere safely. We will need it later.
Also store the device ID safely.
Telegram is a messaging app similar to Whatsapp. It can be installed on both Android and IOS.
1) Creating a Telegram Channel :-
- Sign Up/ Sign In to your Telegram Account.
- On the Home Screen, swipe from left to toggle Menu, and click on "New Channel".
- It will ask for a Name and Description(optional). You can Name it whatever you like. Enter everything and click on the tick.
2) Creating a Bot :-
- Go to the Telegram Home screen and search for "BotFather".
- Select the verified account as shown. Next, just type "/start" and send.
- Next, type "/newbot" and hit enter. It will ask for a Bot Name, so name the bot. Then it will ask for a username- give a unique username.
Congrats! You just created a bot on Telegram. It will give you a token. Store the token safely.
- Now click and open Channel Info. Click on Administrators and add your Bot. Grant all permissions to the Bot and click the tick.
Virtual Box is a software which will help you virtualize any Operating System of your Choice. Download Virtual Box for your OS from here.
I am recommending Ubuntu OS for this project, although almost any Debian based Linux distro would work. Watch this video to download and use Ubuntu OS on Virtual box.
Code :Open Virtual Box and start your virtual machine. Open Terminal.
- First let us create a folder/directory on the Desktop(for easy navigation) to save our programs. Use the following commands (you can name the folder as you wish, I have named mine as NetworkScanner).
- Go back to the terminal and change path to the created directory.
- Type the next command to open a python file. Using sudo may prompt you for the password. Enter your password and hit enter.
- Type/paste the following code in the editor. It is a configuration file to send the output to Telegram. Use the details that had to be stored safely.
bolt_api_key = "XXXX" # Your Bolt Cloud API Key
device_id = "XXXX" # Your device ID [BOLTXXXX where XXXX are some numbers]
telegram_chat_id = "@XXXX" # Channel name of Telegram channel. Paste after @ symbol.
telegram_bot_id = "botXXXX" # Bot Token ID of Telegram Bot. Paste after 'bot' text.
- To save the file, hit the following buttons in order :
[Ctrl+X] --> y --> Enter
- Create another python file using command " sudo nano file_name.py". Type/paste the following code in the editor :
import requests # to make HTTP requests
import json # library for handling JSON data
from boltiot import Bolt # importing Bolt from boltiot module
import conf # config file
mybolt = Bolt(conf.bolt_api_key, conf.device_id)
import scapy.all as sc # import scapy library
# Function to Scan the IP
def scan(ip):
arp_request = sc.ARP(pdst = ip)
broadcast = sc.Ether(dst = "ff:ff:ff:ff:ff:ff")
x = broadcast/arp_request
answered_list = sc.srp(x, timeout=1, verbose=False)[0]
targets_list = []
for element in answered_list:
targets_dict = {"ip":element[1].psrc, "mac":element[1].hwsrc}
targets_list.append(targets_dict)
return targets_list
# Function to Print the Output Result
def result(results_list):
print("IP\t\tMAC Address\n-------------------------------------")
for target in results_list:
print(target["ip"] + "\t" + target["mac"])
scan_target = input("Enter target IP:\n")
scan_result = scan(scan_target)
result(scan_result)
# Function to send output to Telegram
def telegram_message(message):
url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
data = {"chat_id": conf.telegram_chat_id, "text": message}
try:
response = requests.request("POST", url, params=data)
print("This is the Telegram URL")
print(url)
print("This is the Telegram response")
print(response.text)
telegram_data = json.loads(response.text)
return telegram_data["ok"]
except Exception as e:
print("An error occurred in sending the alert message via Telegram")
print(e)
return False
message = "These are the details of the devices connected on the network:\n" + str(scan_result)
telegram_status = telegram_message(message)
print("This is the telegram status:\n", telegram_status)
- To save the file, hit the following buttons in order :
[Ctrl+X] --> y --> Enter
Execution :Before running the code, open a new Terminal, type the following command and note down your network's Gateway IP address(your address may be different).
- Use "ls" command to list out all available files in the directory.
- Use the following command to run the program :
- Upon execution of program, you will be prompted with an input. Enter your Gateway IP as shown :
P.S. - to scan WiFi networks using virtual machines, you will need a Wireless Network Adapter. Once you connect the adapter, you can carry on with the same procedure.
Comments