Skip to content

Commit

Permalink
Added discord plaintext and binary encode/decods. Added Reddit plaint…
Browse files Browse the repository at this point in the history
…ext encode/decode
  • Loading branch information
gracelombardi committed Oct 18, 2022
1 parent dada343 commit 76c9eba
Show file tree
Hide file tree
Showing 12 changed files with 682 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ For the Facebook covert channels a facebook_config.py file is needed that contai
For the Reddit covert channels a reddit_config.py file is needed that contains the following:

```python
api_key = "Example API Key"
api_secret = "Example API Secret"
client_id = "Example Client ID"
client_secret = "Example Client Secret"
user_agent = "script by /lombardig"
redirect_uri = "http://localhost:8080"
refresh_token = "Example Refresh Token"
```

### Binary Covert Channel
Expand All @@ -60,8 +63,7 @@ api_secret = "Example API Secret"
For the Discord covert channels a discord_config.py file is needed that contains the following:

```python
client_id = "Example Client ID"
client_secret = "Example Client Secret"
token = "Example Token"
```

### Binary Covert Channel
Expand Down
66 changes: 66 additions & 0 deletions discord_decode_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
CSEC 791 MS Project
Grace Lombardi
Discord Covert Channel
Decode Binary
"""
import re
import discord
from discord.ext import commands

import discord_config


intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix='!', intents=intents)


@client.event
async def on_ready():
"""
Returns a message when there is a successful connection.
"""
print('We have logged in as {0.user}'.format(client))


@client.event
async def on_message(message):
"""
Waits for a message that says "history" then checks for thumbs up or thumbs down and decodes
the message.
"""
history = []
if message.author == client.user:
return
if message.content.startswith('history'):
channel = discord.utils.get(message.guild.text_channels, name="general")
messages = channel.history(limit=500)
async for message in messages:
if not message.attachments:
thumbsup = [x for x in message.reactions if
str(x.emoji) == '👍'] # replace the emoji with the one you want
thumbsdown = [x for x in message.reactions if
str(x.emoji) == '👎'] # replace the emoji with the one you want
if thumbsup:
history.append('1')
if thumbsdown:
history.append('0')
mes = []
binary = ''.join(history)
history = re.findall('........', binary)
for i in history:
mes.append(chr(int(i, 2)))
decoded_message = ''.join(mes)
print("Message Successfully Decoded: ", decoded_message)


def main():
"""
This is the main decoding function.
"""
client.run(discord_config.token)


if __name__ == '__main__':
main()
71 changes: 71 additions & 0 deletions discord_decode_plaintext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
CSEC 791 MS Project
Grace Lombardi
Discord Covert Channel
Decode Plaintext
"""
import discord

import discord_config

word_list = []
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)


@client.event
async def on_ready():
"""
Returns a message when there is a successful connection.
"""
print('We have logged in as {0.user}'.format(client))


@client.event
async def on_message(message: discord.Message):
"""
Waits for a message that says "history" then checks for words from the military alphabet and
decodes the message.
"""
history = []
hidden_message = []
mil_alphabet = {'a': 'alpha', 'b': 'bravo', 'c': 'charlie', 'd': 'delta', 'e': 'echo',
'f': 'foxtrot', 'g': 'golf', 'h': 'hotel', 'i': 'india', 'j': 'juliet',
'k': 'kilo', 'l': 'lima', 'm': 'mike', 'n': 'november', 'o': 'oscar',
'p': 'papa', 'q': 'quebec', 'r': 'romeo', 's': 'sierra', 't': 'tango',
'u': 'uniform', 'v': 'victor', 'w': 'whiskey', 'x': 'xray', 'y': 'yankee',
'z': 'zulu'}
if message.author == client.user:
return
if message.content.startswith('history'):

channel = discord.utils.get(message.guild.text_channels, name="general")
messages = channel.history(limit=500)
async for message in messages:
if not message.attachments:
if message.author == client.user:
history.append(message.content)
if history[0] == 'Boom!':
for i in history[1:]:
if i == 'Boom!':
break
hidden_message.append(i)
unhidden_message = []
for letter in hidden_message:
for key, value in mil_alphabet.items():
if letter == value:
unhidden_message.append(key)
unhidden_message = ''.join(unhidden_message)
print("Message Successfully Decoded: ", unhidden_message[::-1])


def main():
"""
This is the main decoding function.
"""
client.run(discord_config.token)


if __name__ == '__main__':
main()
87 changes: 87 additions & 0 deletions discord_encode_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""
CSEC 791 MS Project
Grace Lombardi
Discord Covert Channel
Encode Binary
"""
import discord
from discord.ext import commands

import discord_config


intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix='!', intents=intents)


@client.event
async def on_ready():
"""
Returns a message when there is a successful connection.
"""
print('We have logged in as {0.user}'.format(client))


@client.event
async def on_message(message):
"""
Waits for a message that says "message" then removes all reactions then adds thumbs up or
thumbs down to signify binary.
"""
mes = get_message_input()
binary = convert_to_binary(mes)
print(binary)
if message.author == client.user:
return
if message.content.startswith('message'):
channel = discord.utils.get(message.guild.text_channels, name="general")
messages = channel.history(limit=500)
async for message in messages:
for reaction in message.reactions:
await message.clear_reaction(reaction)
limit = len(binary)
messages = channel.history(limit=limit)
binary = list(binary)
message_length = len(binary)
ind_num = 0
while ind_num < (message_length - 1):
async for message in messages:
binary_number = binary[ind_num]
if binary_number == '0':
print('dislike')
await message.add_reaction('👎')
if binary_number == '1':
print('like')
await message.add_reaction('👍')
ind_num += 1


def get_message_input():
"""
This function prompts the user for a message to encode and then returns a list of all characters
in the message.
"""
message = input("Enter the message to encode: ")
message = message.replace(" ", "")
chars = list(message.lower())
return chars


def convert_to_binary(chars):
"""
This function coverts every character in the list to their binary equivalent.
"""
binary = ''.join(format(ord(char), '08b') for char in chars)
return binary


def main():
"""
This is the main encoding function.
"""
client.run(discord_config.token)


if __name__ == '__main__':
main()
69 changes: 69 additions & 0 deletions discord_encode_plaintext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
CSEC 791 MS Project
Grace Lombardi
Discord Covert Channel
Encode Plaintext
"""
import discord

import discord_config

word_list = []
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)


@client.event
async def on_ready():
"""
Returns a message when there is a successful connection.
"""
print('We have logged in as {0.user}'.format(client))


@client.event
async def on_message(message):
"""
Waits for a message that says "hello" then sends words from the military alphabet to send the
message.
"""
if message.author == client.user:
return

if message.content.startswith('hello'):
for i in word_list:
await message.channel.send(i)
await message.channel.send("Boom!")


def get_message_input():
"""
This function prompts the user for a message to encode and then returns a list of all characters
in the message.
"""
message = input("Enter the message to encode: ")
message = message.replace(" ", "")
chars = list(message.lower())
return chars


def main():
"""
This is the main encoding function.
"""
mil_alphabet = {'a': 'alpha', 'b': 'bravo', 'c': 'charlie', 'd': 'delta', 'e': 'echo',
'f': 'foxtrot', 'g': 'golf', 'h': 'hotel', 'i': 'india', 'j': 'juliet',
'k': 'kilo', 'l': 'lima', 'm': 'mike', 'n': 'november', 'o': 'oscar',
'p': 'papa', 'q': 'quebec', 'r': 'romeo', 's': 'sierra', 't': 'tango',
'u': 'uniform', 'v': 'victor', 'w': 'whiskey', 'x': 'xray', 'y': 'yankee',
'z': 'zulu'}
message = get_message_input()
for i in message:
letter = mil_alphabet[i]
word_list.append(letter)
client.run(discord_config.token)


if __name__ == '__main__':
main()
19 changes: 19 additions & 0 deletions facebook_encode_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import facebook

token = {''}
graph = facebook.GraphAPI(token)
page_ids = []
myID = graph.request('/me?fields=id')
posts = graph.get_object(id=myID['id'], fields='posts.fields(object_id)')
post_ids = []
for post in posts:
post_ids.append(posts[post])
print(post_ids)
i = 0
while i < len(post_ids):
likes = graph.get_object(id=post_ids[i], fields='likes')
i += 1
print(likes)

likes = graph.put_like(object_id=str(post_ids[0]))
print(likes)
45 changes: 45 additions & 0 deletions reddit_decode_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
CSEC 791 MS Project
Grace Lombardi
Reddit Covert Channel
Decode Binary
"""

import praw
import reddit_config


def authenticate():
"""
This function authenticates to the reddit api.
"""
reddit = praw.Reddit(client_id=reddit_config.client_id,
client_secret=reddit_config.client_secret,
user_agent=reddit_config.user_agent,
redirect_uri=reddit_config.redirect_uri,
refresh_token=reddit_config.refresh_token)
return reddit


def main():
"""
This is the main decoding function.
"""
reddit = authenticate()
comment_ids = []
binary = []
for comment in reddit.redditor('lombardig').comments.new(limit=None):
comment_ids.append(comment.id)
for comment_id in comment_ids:
comment = reddit.comment(comment_id)
if comment.score == 1:
binary.append('0')
if comment.score == 2:
binary.append('1')
binary = ''.join(binary)
message = chr(int(binary, 2))
print("Message Successfully Decoded: ", message)


if __name__ == '__main__':
main()
Loading

0 comments on commit 76c9eba

Please sign in to comment.