-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f5e6339
Showing
9 changed files
with
898 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Drew Alleman | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Dystopia | ||
Low to medium Ubuntu Core honeypot coded in Python. | ||
![preview](/media/preview.PNG) | ||
# Features | ||
* Optional Login Prompt | ||
* Logs commands used and IP addresses | ||
* Customize MOTD, Port, Hostname and how many clients can connect at once (default is unlimited) | ||
* Save and load config | ||
* Add support to a plethora of commands | ||
|
||
# Todo | ||
* Packet Capture | ||
* Better Logging | ||
* Add more commands (Push towards being a ubuntu core IoT honeypot) | ||
* Service | ||
* Geolocation | ||
* Email Alerts | ||
* Insights such as charts & graphs | ||
* Add Default Configurations | ||
* Optimize / Fix Code | ||
|
||
|
||
# Command Line Arguments // Usage | ||
``` | ||
usage: dystopia.py [-h] [--port PORT] [--motd MOTD] [--max MAX] [--username USERNAME] [--password PASSWORD] | ||
[--hostname HOSTNAME] [--localhost] [--save SAVE] [--load LOAD] | ||
Dystopia | A python honeypot. | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
--port PORT, -P PORT specify a port to bind to | ||
--motd MOTD, -m MOTD specify the message of the day | ||
--max MAX, -M MAX max number of clients allowed to be connected at once. | ||
--username USERNAME, -u USERNAME | ||
username for fake login prompt and the user for the honeypot session | ||
--password PASSWORD, -p PASSWORD | ||
password for fake login prompt | ||
--hostname HOSTNAME, -H HOSTNAME | ||
hostname of the honeypot | ||
--localhost, -L host honeypot on localhost | ||
--save SAVE, -s SAVE save config to a json file | ||
--load LOAD, -l LOAD load a config file | ||
``` | ||
# How to add Support for More Commands | ||
You can add support to new commands by editing the file "commands.json". The format is command:output <br> | ||
for eg <br> | ||
```json | ||
{ | ||
"dog":"Dog command activated!" | ||
} | ||
``` | ||
![example](/media/dog.png) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import json | ||
import socket | ||
import logging | ||
from colorama import Fore | ||
from datetime import datetime | ||
|
||
logging.basicConfig(filename="dystopia.log", encoding="utf-8", level=logging.INFO, format="%(asctime)s:%(message)s") | ||
|
||
class DisplayStatistics: | ||
def __init__(self): | ||
self.stats = readJsonFile("stats.json") | ||
self.ips = [] | ||
for ip, stat in self.stats.items(): | ||
self.ips.append(ip) | ||
|
||
def getTopConnector(self): | ||
timesConnected = [] | ||
for ip in self.ips: | ||
timesConnected.append(self.stats[ip]["Times Connected"]) | ||
maxTimesConnected = max(timesConnected) | ||
index = timesConnected.index(maxTimesConnected) | ||
if maxTimesConnected == 0: | ||
return ("N/A", "N/A") | ||
return (self.ips[index], maxTimesConnected) | ||
|
||
def getMostLoginAttempts(self): | ||
failedLogins = [] | ||
for ip in self.ips: | ||
failedLogins.append(self.stats[ip]["Failed Logins"]) | ||
topAttacker = max(failedLogins) | ||
index = failedLogins.index(topAttacker) | ||
if topAttacker == 0: | ||
return ("N/A", "N/A") | ||
return (self.ips[index], topAttacker) | ||
|
||
|
||
def printBanner(): | ||
display = DisplayStatistics() | ||
topLogin = DisplayStatistics.getMostLoginAttempts(display) | ||
topConnector = DisplayStatistics.getTopConnector(display) | ||
bannerArt = ("""{2} | ||
:::::::-. .-:. ::-. .::::::.:::::::::::: ... ::::::::::. ::: :::. | ||
;;, `';,';;. ;;;;';;;` `;;;;;;;;''''.;;;;;;;. `;;;```.;;;;;; ;;`;; | ||
`[[ [[ '[[,[[[' '[==/[[[[, [[ ,[[ \\[[,`]]nnn]]' [[[ ,[[ '[[, | ||
$$, $$ c$$" ''' $ $$ $$$, $$$ $$$"" $$$c$$$cc$$$c | ||
888_,o8P' ,8P"` 88b dP 88, "888,_ _,88P 888o 888 888 888, | ||
MMMMP"` mM" "YMmMY" MMM "YMMMMMP" YMMMb MMM YMM ""` | ||
{3}[--]{1} {0}https://github.com/Drew-Alleman/dystopia | ||
{3}[--]{1} Top Connector: {0}{4} ({5}) | ||
{3}[--]{1} Most Login Attempts: {0}{6} ({7}){1} | ||
""".format( | ||
Fore.RED, Fore.WHITE, Fore.LIGHTBLUE_EX, Fore.YELLOW, topConnector[0], topConnector[1],topLogin[0], topLogin[1] | ||
) | ||
) | ||
print(bannerArt) | ||
|
||
|
||
def getTime(): | ||
now = datetime.now() # Get time | ||
prettyTime = now.strftime("[%H:%M:%S] ") # Format time | ||
return prettyTime | ||
|
||
|
||
def printMessage(message): | ||
cTime = getTime() | ||
print(Fore.GREEN + cTime + Fore.WHITE + message) | ||
logging.info(message) | ||
|
||
|
||
def printError(message): | ||
cTime = getTime() | ||
print(Fore.RED + cTime + Fore.WHITE + message) | ||
logging.error(message) | ||
|
||
|
||
def printWarning(message): | ||
cTime = getTime() | ||
print(Fore.YELLOW + cTime + Fore.WHITE + message) | ||
logging.warning(message) | ||
|
||
|
||
def getIP(): | ||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
sock.connect(("8.8.8.8", 80)) | ||
ipaddress = sock.getsockname()[0] | ||
sock.close() | ||
return ipaddress | ||
|
||
|
||
def writeJsonToFile(jsonData, fileName): | ||
if fileName.endswith(".json") == False: | ||
fileName = fileName + ".json" | ||
with open(fileName, "a+") as outFile: | ||
data = json.load(fileName) | ||
outFile.seek(0) | ||
data.update(jsonData) | ||
|
||
|
||
def isDataValid(data): | ||
if data is None or len(data) == 0: | ||
return False | ||
return True | ||
|
||
|
||
def writeToBlacklist(clientIPAddress): | ||
with open("blacklist.txt", "a+") as f: | ||
ips = f.readlines() | ||
ips = [ip.strip() for ip in ips] | ||
if clientIPAddress not in ips: | ||
f.write(clientIPAddress) | ||
|
||
|
||
def readJsonFile(fileName): | ||
if fileName is None: | ||
printError("file was not found!") | ||
try: | ||
with open(fileName, "r") as outFile: | ||
data = json.load(outFile) | ||
return data | ||
except FileNotFoundError: | ||
printError("file: '{}' was not found.".format(fileName)) | ||
quit() | ||
|
||
|
||
def yn(message): | ||
try: | ||
prompt = Fore.GREEN + " y" + Fore.WHITE + "/" + Fore.RED + "n" + Fore.WHITE + ": " | ||
yes = ["y", "Y","YES", "yes"] | ||
no = ["n", "N","NO", "no"] | ||
choice = input(Fore.YELLOW + "[?] " + Fore.WHITE + message + prompt) | ||
if choice in yes: | ||
return True | ||
elif choice in no: | ||
return False | ||
else: | ||
printError(choice + " ??") | ||
quit() | ||
except KeyboardInterrupt: | ||
quit() | ||
|
||
|
||
def formatString(s): | ||
s = s.decode().strip() | ||
if s.endswith("\x00"): | ||
s = s[:-2] | ||
return s |
Oops, something went wrong.