Skip to content

Commit

Permalink
v1.0 Basic Honeypot
Browse files Browse the repository at this point in the history
  • Loading branch information
Hack Hunt committed Jan 18, 2021
1 parent 55b9299 commit 0128b5b
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
107 changes: 107 additions & 0 deletions honeypot.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sudo apt install net-tools -y
sudo apt install python3-pip -y
sudo pip3 install termcolor
sudo pip3 install argparse

0 comments on commit 0128b5b

Please sign in to comment.