-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmessageGenerator.py
107 lines (76 loc) · 2.76 KB
/
messageGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Message Generator script to make it easier to use the marco attack via gr-pke
import math # needed for hex to bin conversion
import socket # needed for udp socket
import sys # needed for udp socket
from threading import Thread # needed for multithreading
import time # needed for auto mode
class MessageGen:
"""
Class that handles custom PKE message generation
"""
def __init__(self, ipAddr, portNum):
"""
Initalization Message
Args:
ipAddr (string): The IP Address to transmit the message to
portNum (int): The port number to send the message to
"""
# Creates the UDP socket
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Holds the server address
self.serverAddress = (str(ipAddr), int(portNum))
def sendMsg(self, message):
"""
Generates and transmits the message
Args:
message (str): The PKE message in hex
"""
print(f'Sending: {str(message)}')
self.socket.sendto(message.encode(), self.serverAddress)
def decodeMsg(self, message):
"""
Decodes the hex string into binary with all leading zeros
Args:
message (str): The hex string to decode
"""
# Code to convert hex to binary
res = "{0:08b}".format(int(message, 16))
# Print the resultant string
print ("Resultant transmission should be", str(res))
def autoThread(self):
"""
Thread that auto transmits the wakeup message
"""
message = "FFEABA000000FFEABA000000FFEABA"
while True:
try:
self.sendMsg(message)
self.decodeMsg(message)
time.sleep(0.2)
except KeyboardInterrupt:
print("\nKeyboard interrupt detected, shuting down")
sys.exit(1)
break
def manThread(self):
"""
Thread that lets the user manually enter a message to send
"""
while True:
try:
message = input("\nEnter the hex message to transmit: ")
self.sendMsg(message)
self.decodeMsg(message)
except KeyboardInterrupt:
print("\nKeyboard interrupt detected, shuting down")
sys.exit(1)
break
if __name__ == "__main__":
print("Starting PKE Message generator")
ipAddr = input('Enter target IP Address: ')
portNum = input('Enter target port number: ')
runMode = input('Enter 1 for auto mode, andything else for manual:')
messageGen = MessageGen(ipAddr, portNum)
if runMode == '1':
messageGen.autoThread()
else:
messageGen.manThread()