1

Guys I'm using Kali Linux, I created a python script and everything is fine, but when I try to use a reserved port for this error:

PermissionError: [Errno 13] Permission denied

But when I use a higher port, 8080 for example, then it works, but I’m already logged in as root, and I’ve also given permission to my Python file with chmod + x script.py. The port I want to use is 443, can someone help me?

Edit:

My code:

import os
import sys                                        
import platform                                   
import time
import socket
import argparse                                   
                                          
HOST = "localhost"                                
PORT = 443
                                          
def main():                                        
 try:
  print(f"Starting honeypot ...")                   
  time.sleep(5)
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)                                               
  s.bind((HOST,PORT))
  while True:
   s.listen(5)
   conn,addr = s.accept()                            
   print(f"Honeypot has been visited by: {addr[0]}")                                                   
   print(f"Honeypot has been visited by: {addr[1]}")
   conn.sendall(b"I got you!\n")
 except KeyboardInterrupt:
  print("\nShutdown honeypot ...")

main()

Similar but unsolved questions that solve the problem https://askubuntu.com/questions/868590/ping-socket-permission-denied A similar question https://superuser.com/questions/922732/why-do-i-get-permission-denied-even-as-root Among others ...

The idea is to build a honeypot

Dakota
  • 42
  • 1
  • 9
  • Run it with sudo. I don't know kali specifically, but most (all?) Linux distros require super user privileges to bind to the lower ports. – Jared Smith Mar 02 '21 at 13:07
  • So ... the problem is that I'm already logged in as a super user and even if I run `sudo python3 script.py` – Dakota Mar 02 '21 at 13:22
  • "already logged in as a super user" does your shell prompt say `root@your-hostname`? You should not be getting permission denied if it does. – Jared Smith Mar 02 '21 at 13:25
  • Yes, root@localhost is displayed – Dakota Mar 02 '21 at 13:28
  • Hmm.... while this is not technically off-topic for stack overflow, you may get a better response on one of the more linux-y stacks like superuser or unix&linux or maybe infosec. Make sure you read their guidelines first to see if it's on topic there. – Jared Smith Mar 02 '21 at 13:31

0 Answers0