From 0128b5bbc7b7be1eec0df3816823815925ac8678 Mon Sep 17 00:00:00 2001 From: Hack Hunt Date: Mon, 18 Jan 2021 07:01:30 -0500 Subject: [PATCH] v1.0 Basic Honeypot --- README.md | 48 +++++++++++++++++++++++ honeypot.py | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 4 ++ 3 files changed, 159 insertions(+) create mode 100644 README.md create mode 100755 honeypot.py create mode 100755 setup.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..08109c7 --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +## Honeypot + +- A honeypot is a computer security mechanism set to detect, deflect, or, in some manner, counteract +attempts at unauthorized use of information systems. +- It attracts Cyber Attacks by mimicking as a target for the attacker. +- Also, used as a distraction for hackers from the real target. +- The Program generates a log file containing attacker's IP, Port and Time of +when conncetion was made. + +### Supports Platform: +Linux, Debain + +### How to use: +- Convert the setup.sh into executable + > **chmod 755 setup.sh** +- Run setup.sh + > **./setup.sh** +- Run the Python Script with root privileges. + > **sudo python3 honeypot.py** + + +### Available Arguments: +- **-h or --help:** *Displays all the available options.* +- **-ip or --host-ip**: *Specify the IPv4 Address of the Host.* +- **-d or --tarp-data:** *If someone tries to connect to the port specified this data will be sent.* +- **-p or --port:** *Specify port number to create Honeypot on.* + + +### Color: + +- **Green:** Successful. +- **Yellow:** Notifications. +- **Blue:** Activities. +- **Red:** Unsuccessful or Errors. + +### Programming Language: Python 3 and above + +### Licensed: GNU General Public License, version 3 + +### Developer Information: +- **Website:** https://www.hackhunt.in/ +- **Contact:** hh.hackunt@gmail.com +- **LinkedIn:** https://www.linkedin.com/company/hackhunt +- **Youtube:** [@hackhunt](https://youtube.com/hackhunt) +- **Instagram:** [@hh.hackhunt](https://www.instagram.com/hh.hackhunt/) +- **Facebook:** [@hh.hackhunt](https://www.facebook.com/hh.hackhunt/) +- **Twitter:** [hh_hackhunt](https://twitter.com/hh_hackhunt/) +- **Patreon:** [@hackhunt](https://www.patreon.com/hackhunt) diff --git a/honeypot.py b/honeypot.py new file mode 100755 index 0000000..1715e55 --- /dev/null +++ b/honeypot.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 + +import os +import sys +import socket +from termcolor import colored +import time +import argparse + +LOG_FILE = open('log.txt', 'at') + + +def log_data(client, data=''): + global LOG_FILE + + write_data = "Time: {0}\nIP: {1}\nPort: {2}\nData: {3}\n{4}\n\n".format(time.ctime(), + client[0], client[1], + data, "=" * 50) + LOG_FILE.write(write_data) + + +def start_honeypot(data, ip, port): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.bind((ip, port)) + sock.listen(1000) + + while True: + incoming_sock, address = sock.accept() + if address: + print(colored("[+] REQUEST INCOMING: {0}:{1}".format(address[0], address[1]), "blue")) + + try: + incoming_sock.send(data.encode('ascii')) + data = incoming_sock.recv(1024) + data = data.decode('ascii') + incoming_sock.close() + except socket.error as e: + print(colored("[-] Error! Message: {0}".format(e), "red")) + log_data(address) + else: + log_data(address, data) + + +def get_cmd_line_arguments(): + parser = argparse.ArgumentParser(prog="Honeypoty", + usage="%(prog)s [options]\n\t[-d | --trap-data] trap_data" + "\n\t[-ip | --host-ip] ipv4 address" + "\n\t[-p | --port] port_number", + formatter_class=argparse.RawDescriptionHelpFormatter, + description=""">>> | Honeypot v1.0 by Hack Hunt | <<< + ------------------------------""") + + parser._optionals.title = "Optional Argument" + + required_arguments = parser.add_argument_group("Required Argument") + + required_arguments.add_argument('-d', '--trap-data', + dest='data', + metavar="", + help='If someone tries to connect to the port specified this data will be sent', + required=True) + + required_arguments.add_argument('-ip, --host-ip', + dest='ip', + metavar="", + help='Specify the IPv4 Address of the Host', + required=True) + + required_arguments.add_argument('-p', '--port', + dest='port', + metavar="", + type=int, + help='Specify port number to create Honeypot on', + required=True) + + return parser.parse_args() + + +def main(): + args = get_cmd_line_arguments() + data = args.data + ip = args.ip + port = args.port + + try: + os.system("clear") + print(colored("[+] Initializing Honeypot v1.0...\n", 'green')) + print(colored("[*] To Quit press Keyboard Interruption Keys.", 'yellow')) + print(colored("[*] Loading...\n", 'yellow')) + + start_honeypot(data, ip, port) + + except KeyboardInterrupt: + print(colored("\n[+] Exiting...", "green")) + sys.exit(0) + + except BaseException as e: + print(colored("\n[-] Error: {0}".format(e), 'red')) + sys.exit(1) + + finally: + LOG_FILE.close() + + +################################################################## +if __name__ == '__main__': + main() diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..008f7a7 --- /dev/null +++ b/setup.sh @@ -0,0 +1,4 @@ +sudo apt install net-tools -y +sudo apt install python3-pip -y +sudo pip3 install termcolor +sudo pip3 install argparse