Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added wifi spoofing #3

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified firmware/blank-settings.bin
Binary file not shown.
86 changes: 76 additions & 10 deletions flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from signal import signal, SIGINT
from serial.tools import hexlify_codec
from serial.tools.list_ports import comports

from scripts.helpers import MacGenerator
from pprint import pprint

try:
Expand All @@ -41,6 +41,7 @@

BRANCH = "stable"
FIRMWARE_DIR="./firmware"
MACPREFIX_DIR="./mac-prefixes"
FIRMWARE_URL = "https://raw.githubusercontent.com/O-MG/O.MG-Firmware/%BRANCH%"
MEMMAP_URL = "https://raw.githubusercontent.com/O-MG/WebFlasher/main/assets/memmap.json"

Expand Down Expand Up @@ -246,7 +247,7 @@ def omg_dependency_imports():
except:
if not os.path.exists('./scripts/'):
os.mkdir("./scripts/")
dependencies = ['flashapi.py', 'miniterm.py']
dependencies = ['flashapi.py', 'miniterm.py', 'helpers.py']
for dependency in dependencies:
file_path = "scripts/"+dependency
file_url = FIRMWARE_URL.replace("%BRANCH%",BRANCH) + "/scripts/" + dependency
Expand Down Expand Up @@ -280,7 +281,9 @@ def __init__(self):
self.WIFI_SSID = "O.MG"
self.WIFI_PASS = "12345678"
self.WIFI_MODE = "2"
self.WIFI_TYPE = "STATION"
self.WIFI_TYPE = "ACCESS POINT"
self.WIFI_MAC = ""
self.WIFI_DEVICE = ""
self.FILE_PAGE = "page.mpfs"
self.FILE_INIT = "esp_init_data_default_v08.bin"
self.FILE_ELF0 = "image.elf-0x00000.bin"
Expand Down Expand Up @@ -617,16 +620,19 @@ def omg_reset_settings():
print("Warning: Unable to reset " + FILE_INIT)


def omg_patch(_ssid, _pass, _mode, slotsize=4, percent=60):
def omg_patch(_ssid, _pass, _mode, slotsize=4, percent=60, _macaddress="", _devicename=""):
FILE_INIT = results.FILE_OFAT_INIT

init_cmd = "INIT;"
settings = {
"wifimode": _mode,
"wifissid": _ssid,
"wifikey": _pass,
"devicename": "omg"
}
if _devicename:
settings["devicename"] = _devicename
if _macaddress:
settings["wifimac"] = _macaddress
for config,value in settings.items():
init_cmd+="S:{KEY}{SEP}{VALUE};".format(SEP="=", KEY=config,VALUE=value)
# once booted we know more, this is a sane default for now
Expand All @@ -652,13 +658,12 @@ def omg_patch(_ssid, _pass, _mode, slotsize=4, percent=60):


def omg_input():
WIFI_MODE = ''
WIFI_MODE = results.WIFI_MODE
SANITIZED_SELECTION = False

while not SANITIZED_SELECTION:

try:
notemsg = "Hitting enter without an option will default to AP Mode with SSID: %s Pass: %s"%(results.WIFI_SSID,results.WIFI_PASS)
notemsg = "Hitting enter without an option will default to %s Mode with SSID: %s Pass: %s"%(results.WIFI_TYPE,results.WIFI_SSID,results.WIFI_PASS)
WIFI_MODE = input("\nSELECT WIFI MODE\n1: STATION - (Connect to existing network. 2.4GHz)\n2: ACCESS POINT - (Create SSID. IP: 192.168.4.1)\n[%s]\nWifi Configuration [Hit Enter to use Defaults]: "%notemsg)
if WIFI_MODE == '' or WIFI_MODE == '1' or WIFI_MODE == '2':
SANITIZED_SELECTION = True
Expand Down Expand Up @@ -702,6 +707,67 @@ def omg_input():
pass

results.WIFI_PASS = WIFI_PASS

WIFI_MAC = ""
SANITIZED_SELECTION = False

while not SANITIZED_SELECTION:
try:
MAC_MODE = input("\nSELECT MAC ADDRESS MODE\n1: ENTER - (Enter a specific mac address)\n2: MANUFACTURER - (Generate a random mac address by manufacturer)\n3: RANDOM - (Generate a random mac address)\n4: ACTUAL - (Use devices real mac address)\nMac Address Mode [Hit Enter to use Actual]: ")
mac_generator = MacGenerator()
match MAC_MODE:
case "1":
WIFI_MAC = input("ENTER WIFI MAC (6 octets): ")
case "2":
if not os.path.exists(MACPREFIX_DIR):
print("Valid MACPREFIX_DIR required for this option")
continue
else:
manufacturers = mac_generator.get_manufacturers(MACPREFIX_DIR)
for index, item in enumerate(manufacturers, start=1):
print(f"{index}: {item.capitalize()}")
user_input = input("Choose Manufacturer: ")
try:
index = int(user_input)
selected_manufacturer = manufacturers[index - 1]
manufacturers_prefixes = mac_generator.get_manufacturer_prefixes(selected_manufacturer)
WIFI_MAC = mac_generator.generate(manufacturers_prefixes)
except:
print("\nInvalid selection, try again")
continue

case "3":
WIFI_MAC = mac_generator.generate()
case other:
print("Using devices real mac address")
results.WIFI_MAC = ''
SANITIZED_SELECTION = True
continue

if mac_generator.valid_mac_address(WIFI_MAC):
results.WIFI_MAC = WIFI_MAC
print(f"Generated Mac Address: {WIFI_MAC}")
SANITIZED_SELECTION = True
else:
print("Invalid mac address, try again")
except:
pass

WIFI_DEVICE = ""
SANITIZED_SELECTION = False

while not SANITIZED_SELECTION:
try:
notemsg = f"[Hit Enter to use {f"'{results.WIFI_DEVICE}'" if results.WIFI_DEVICE != "" else "Actual"}] "
DEVICE_MODE = input(f"\nSELECT DEVICE NAME MODE\n1: ENTER - (Enter a device name)\n{notemsg}")
match DEVICE_MODE:
case "1":
WIFI_DEVICE = input(f"\nENTER DEVICE NAME: {notemsg}")
if WIFI_DEVICE:
results.WIFI_DEVICE = WIFI_DEVICE
except:
pass
SANITIZED_SELECTION = True

# enable to let user customize on plus an elite devices
# beta feature
Expand Down Expand Up @@ -791,10 +857,10 @@ def omg_runflash(pre_erase=False,skip_flash=False,skip_input=False,skip_reset=Fa
if not skip_flash:
if not skip_input:
omg_input()
omg_patch(results.WIFI_SSID, results.WIFI_PASS, results.WIFI_MODE, results.FLASH_SLOTS, results.FLASH_PAYLOAD_SIZE)
omg_patch(results.WIFI_SSID, results.WIFI_PASS, results.WIFI_MODE, results.FLASH_SLOTS, results.FLASH_PAYLOAD_SIZE, results.WIFI_MAC, results.WIFI_DEVICE)
omg_flashfw(mac,flash_size)
print("\n[ WIFI SETTINGS ]")
print("\n WIFI_SSID: {SSID}\n WIFI_PASS: {PASS}\n WIFI_MODE: {MODE}\n WIFI_TYPE: {TYPE}".format(SSID=results.WIFI_SSID, PASS=results.WIFI_PASS, MODE=results.WIFI_MODE, TYPE=results.WIFI_TYPE))
print("\n WIFI_SSID: {SSID}\n WIFI_PASS: {PASS}\n WIFI_MODE: {MODE}\n WIFI_TYPE: {TYPE}\n WIFI_MAC: {MAC}\n WIFI_DEVICE: {DEVICE}\n".format(SSID=results.WIFI_SSID, PASS=results.WIFI_PASS, MODE=results.WIFI_MODE, TYPE=results.WIFI_TYPE, MAC=results.WIFI_MAC, DEVICE=results.WIFI_DEVICE))
print("\n[ FIRMWARE USED ]")
print("\n INIT: {INIT}\n ELF0: {ELF0}\n ELF1: {ELF1}\n PAGE: {PAGE}".format(INIT=results.FILE_INIT, ELF0=results.FILE_ELF0, ELF1=results.FILE_ELF1, PAGE=results.FILE_PAGE))
if results.FLASH_SLOTS > 0:
Expand Down
50 changes: 50 additions & 0 deletions mac-prefixes/apple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
000393
000A27
000A95
000D93
001124
001451
0016CB
0017F2
0019E3
001B63
001CB3
001D4F
001E52
001EC2
001F5B
001FF3
0021E9
002241
002312
002332
00236C
003065
0050E4
080007
14109F
189EFC
20C9D0
444C0C
5C95AE
685B35
68967B
6C3E6D
705681
74E2F5
7CD1C3
804971
842999
848506
8C2DAA
8CFABA
98FE94
9C207B
A82066
B065BD
BC52B7
BC6778
C09F42
E0C97A
E0F5C6
F0DCE2
Empty file added mac-prefixes/google.txt
Empty file.
Empty file added mac-prefixes/logitech.txt
Empty file.
118 changes: 118 additions & 0 deletions scripts/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import os
import re
import random

class FileHelper:

@staticmethod
def read_file_to_list(file_path):
try:
with open(file_path, 'r') as file:
# Read the lines from the file and strip newline characters
lines = [line.strip() for line in file]
return lines
except FileNotFoundError:
print(f"The file {file_path} was not found.")
return []
except IOError:
print(f"An error occurred while reading the file {file_path}.")
return []

@staticmethod
def get_text_file_names(directory):
text_file_names = [os.path.splitext(f)[0] for f in os.listdir(directory) if f.endswith('.txt')]
return text_file_names

class MacGenerator:

def __init__(self, directory=""):
self.directory = directory
self.manufacturer = ''

def generate(self, mac_prefix=''):
required_octets = 3
if mac_prefix:
if isinstance(mac_prefix, list):
mac_prefix = random.choice(mac_prefix)
if not isinstance(mac_prefix, str) or not self.valid_mac_address(mac_prefix, True):
raise ValueError('Invalid mac prefix')
else:
required_octets = 6

generated_octets = ':'.join([f"{random.randint(0, 255):02x}" for _ in range(required_octets)])

if required_octets == 3:
mac_address = mac_prefix + ':' + generated_octets
else:
mac_address = generated_octets

if not self.valid_mac_address(mac_address):
raise ValueError('Invalid mac address')

return mac_address.upper()

def valid_mac_address(self, mac, affix=False):
mac_regex = {
'half': r'^([0-9A-Fa-f]{2}:){2}[0-9A-Fa-f]{2}$',
'full': r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
}
if affix:
valid = re.match(mac_regex['half'], mac)
else:
valid = re.match(mac_regex['full'], mac)
return valid

def get_manufacturer_prefixes(self, manufacturer, directory=""):
self._ensure_directory(directory)
try:
filePath = f"{self.directory}/{manufacturer}.txt"
mac_prefixes = FileHelper.read_file_to_list(filePath)
if len(mac_prefixes) < 1:
raise ValueError("Manufacturer prefix file empty")
except:
raise FileExistsError('Manufacturer prefix file not found')
return self.format_prefixes(mac_prefixes)

def _ensure_directory(self, directory=""):
if directory and not self.directory:
self.directory = directory
if not directory and not self.directory:
raise ValueError("Manufacturer prefix file not specified")

def get_manufacturers(self, directory=""):
self._ensure_directory(directory)
self.manufacturers = FileHelper.get_text_file_names(self.directory)
return self.manufacturers

def format_prefixes(self, mac_prefix_list):
formatted_mac_prefix_list = []
for mac_prefix in mac_prefix_list:
valid_prefix = self.valid_mac_address(mac_prefix, True)
if not valid_prefix:
formatted_mac_prefix = f"{mac_prefix[:2]}:{mac_prefix[2:4]}:{mac_prefix[4:]}"
elif valid_prefix:
formatted_mac_prefix = mac_prefix
else:
continue
formatted_mac_prefix_list.append(formatted_mac_prefix)
return formatted_mac_prefix_list

if __name__ == "__main__":
#run from root dir or change string if it fails for now

mac_generator = MacGenerator('./mac-prefixes')
manufacturers = mac_generator.get_manufacturers()
print("\n".join(manufacturers))
try:
manufacturer_prefixes = mac_generator.get_manufacturer_prefixes("apple")
mac_address = mac_generator.generate(manufacturer_prefixes)
print(f"Generated mac: {mac_address}")
except Exception as error:
print(f"An error occurred: {error}")

#print("Generated mac address:", mac_address)


#https://www.coffer.com/mac_find/
#chrome-extension://mbigbapnjcgaffohmbkdlecaccepngjd
#//tr[not(td[2][contains(., '('))])]/td[1]