Secure77

Techblog and Security

Python TCP Server

Scripts / Tools

Python TCP Server

Github Project: https://github.com/secure-77/PythonTCPServer

Features

  • easy to extend
  • YAML configuration
  • Implement commands or scripts via configuration
  • simple authentication
  • simple brute force protection
  • server logging
  • client timeout
  • dynamic help (list commands from config)
  • passthrough command output to client

Requirements

Python
pyyaml

(tested with python 3.9 and pyyaml 5.1)

Configuration

Just adjust the config.yaml, make sure the port is open in your firewall

In the commands section of the file you can simply add commands that the server will provide and run

call: the program or script which will be called
arg: comma seperated list of arguments

Security

The login token is the current date in format „dd.mm.yyyy“ (not very save, in production you should replace that part of code).

Make sure to restrict the edit permissions of the configuration file, otherwise the server functionality could be extend to run any command from remote.

The brute force protection will only set a sleep time, in production maybe this should extend with client disconnection and ip blocking.

Usage

you can use ncat (https://nmap.org/ncat/) or telenet to connect to your tcp server (from mobile device you can use tmux with ncat) or write your own frontend client or app.

to start the server just run the tcpServer.py, on windows if you want to run it as service just use https://nssm.cc/usage

Example

Sources

https://pymotw.com/3/socket/tcp.html

https://hackersandslackers.com/simplify-your-python-projects-configuration/

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert