Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib
- from functools import partial
- from scapy.layers.inet import IP, UDP
- from scapy.layers.l2 import Ether
- from scapy.packet import Raw
- from scapy.sendrecv import sniff, sendp
- import re
- import datetime
- KEY_PATTERN = r"0(\d\d)(.+)?$"
- LOCATION_DATA_PATTERN = r"^location data \d{1,2}\/10: (.+)$"
- ALIEN_IP = "54.71.128.194"
- LOCATIONS_NUMBER = 10
- ASCII_a = 97
- LETTERS = 26
- AIRPORT = "nevada25.84"
- def main():
- print("Sniffing...")
- full_location = [] # Building full location list
- sniff(lfilter=is_alien_packet, prn=partial(print_decrypted_alien_packet, full_location))
- def is_alien_packet(packet):
- """
- Checks if the given packet one of the "ALIENS" packets
- @param packet: the packet to check
- @return: true/false
- """
- return IP in packet and (packet[IP].src == ALIEN_IP or packet[IP].dst == ALIEN_IP)
- def print_decrypted_alien_packet(full_location, packet):
- """
- Prints the data of the given packet
- @param full_location: building full location list
- @param packet: the packet which contains the data to print
- """
- data = packet[Raw].load.decode()
- decrypted = decrypt(data)
- if "location data" in decrypted:
- location_data = re.search(LOCATION_DATA_PATTERN, decrypted).group(1)
- full_location.append(location_data) # Builds the full location, everytime assigns the list by 10 chars
- if len(full_location) == LOCATIONS_NUMBER:
- full_location_md5 = hashlib.md5(''.join(map(str, full_location)).encode()).hexdigest()
- # Hashes MD5 the 100 char location buffer and assigns into the packet data
- ready = f"FLY000location_md5={full_location_md5},airport={AIRPORT},time=15:52,lane=earth.jup," \
- f"vehicle=2554,fly"
- pkt = Ether() / IP(dst=ALIEN_IP) / UDP(dport=packet[UDP].sport, sport=packet[UDP].dport) / Raw(load=ready)
- # Builds the new packet with all parameters
- sendp(pkt, verbose=0) # Sends the packet (without output)
- if packet[IP].src == ALIEN_IP: # ALIEN -> PC
- print(f"|{datetime.datetime.now().strftime('%H:%M:%S')}| << {decrypted}")
- else:
- print(f"|{datetime.datetime.now().strftime('%H:%M:%S')}| >> {decrypted}")
- def decrypt(data):
- """
- Finds automatically the key and decrypts the given data
- @param data: DATA (full data key+data)
- @return: the DECRYPTED str
- """
- matches = re.search(KEY_PATTERN, data)
- key = int(matches.group(1)) # Getting key from the data
- input_str = xstr(matches.group(2)).lower() # Data (without the key) and lower()
- builder = ""
- for num, ch in enumerate(input_str):
- if not ch.isalpha() or num % 2 != 0:
- builder += ch
- else:
- builder += str(chr((ord(ch) - ASCII_a - key) % LETTERS + ASCII_a))
- num += 1
- return builder
- def xstr(s):
- """
- if str equals to None it replaces it with blank str (to avoid issues)
- @param s: str
- @return: new str (if None ->> '' else [nothing changed])
- """
- return '' if s is None else str(s)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement