Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
ae3043b1de
|
|||
b17e6c9353
|
|||
aef87bed4a
|
|||
4a09411676
|
|||
0822b9407c
|
|||
032b2facaf
|
|||
b02757dae0 | |||
47483e641a | |||
0f73da0295 | |||
93a88fc322 | |||
f5aa131048 | |||
03635184ae | |||
43bac5ed2c | |||
b6e8815bbc |
44
README.md
44
README.md
@ -1,23 +1,53 @@
|
|||||||
# ding
|
# ding
|
||||||
## What is ding?
|
## What is ding?
|
||||||
ding is a client-server thing written in python. Its aim is to execute a set of commands remotely which can be set in the server's config file.
|
ding is a client-server thing written in python3. Its aim is to execute a set of commands remotely. The commands can be set in the server's config file.
|
||||||
|
|
||||||
|
|
||||||
## How does it work?
|
## How does it work?
|
||||||
The server awaits commands sent by the client. A command must be defined in the server's config file, else the server won't do anything.
|
The server will wait for a command to be sent by a client. If the command is present within the server's config file it will then execute the command, else nothing will happen.
|
||||||
|
|
||||||
|
|
||||||
## What about ding's security?
|
## What about ding's security?
|
||||||
The authentication is done by an SSL Client Certificate signed by an (own generated) Certificate Authority. The scripts for generating a CA and signing a Server/Client Certificate are also in here to make it (relatively) easy. [ You need only to press enter in the most cases, type in some certificate information and entering a previously defined CA password. ]
|
The authentication is done via a SSL Client Certificate signed by an (self generated) Certificate Authority. The scripts for generating a CA and signing the Server/Client Certificates are also included to make it (relatively) easy. [ This involves typing in a few certificate details and entering a previously defined CA password. ]
|
||||||
|
|
||||||
|
|
||||||
|
## Pic or didn't happen
|
||||||
|

|
||||||
|
[Can't read a thing?](https://raw.githubusercontent.com/Bandie/ding/master/img/dingScreenshot.png)
|
||||||
|
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
* Install python3 on your target computers.
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
In all steps please read carefully what the certification generate scripts want from you. The certificate information needn't to be true at all and can be random. They only need to be different from each other.
|
At every step please read carefully what the generate certificates scripts want from you. The information on the certificates doesn't need to be true and can be totally random. They only need to be different from one another.
|
||||||
|
|
||||||
|
Step 1 to 3 can only be run on UNIX or GNU/Linux.
|
||||||
|
|
||||||
1. Run `./1_generateCA.sh` to generate a CA.
|
1. Run `./1_generateCA.sh` to generate a CA.
|
||||||
2. Run `./2_generateServCert.sh` to generate a signed Server Certificate.
|
2. Run `./2_generateServCert.sh` to generate a signed Server Certificate.
|
||||||
3. Run `./3_generateClientCert.sh` to generate a signed Client Certificate.
|
3. Run `./3_generateClientCert.sh` to generate a signed Client Certificate.
|
||||||
4. Move `ding_client`, `ding_client.cfg`, `ding_client.crt`, `ding_client.key` and `CA.crt` to the computer which should be able to send commands to the server.
|
4. Move `ding_client`, `ding_client.cfg`, `ding_client.crt`, `ding_client.key` and `CA.crt` to the computer which should be able to send commands to the server.
|
||||||
5. Do some configuration on the server and client (ding\_server.cfg, ding\_client.cfg).
|
* UNIX or GNU/Linux: Also move `ding_client.cfg` to that computer.
|
||||||
6. Start the server using `./ding_server`. You may want to put this in a tmux session ([Ctrl+B, D] ;) ).
|
* Windows: Also move `ding_client.win.cfg` to that computer.
|
||||||
7. Try out the client using `./ding_client <command>`.
|
5. Do some configuration on the server and client (`ding_server.cfg`, `ding_client.cfg` or `ding_server.win.cfg`, `ding_client.win.cfg` on Windows).
|
||||||
|
6. Start the server using `./ding_server` or `python .\ding_server` on Windows. (You may want to put this in a tmux session. [Ctrl+B, D] ;) ).
|
||||||
|
7. Try out the client using `./ding_client <command>` òr `python .\ding_client <command>` on Windows.
|
||||||
|
|
||||||
|
|
||||||
|
## Optional: Cleartext password with timeout
|
||||||
|
If you want to be sure that this power won't be abused by bad people using your computer, you may want to add a password (saved in cleartext).
|
||||||
|
The password will be sent inside the TLS connection.
|
||||||
|
|
||||||
|
### Warning! Beware of the shell history!
|
||||||
|
You might want to do something like `$ history -c` after sending the password via the client or play around with bash's HISTCONTROL variable.
|
||||||
|
|
||||||
|
### How to enable the password
|
||||||
|
|
||||||
|
1. Open your `ding_server.cfg` or `ding_server.win.cfg`.
|
||||||
|
2. Set `pw_on=true`.
|
||||||
|
3. Set a password, like `password=abc def`.
|
||||||
|
4. Set a password timeout: `pwtimeout=10` for 10 seconds.
|
||||||
|
|
||||||
|
If you have a password with special characters as in spaces and the like, you may want to use quotation marks around your password. `./ding_client "abc def"` or `python .\ding_client "abc def"` on Windows.
|
||||||
|
27
ding_client
27
ding_client
@ -3,12 +3,20 @@
|
|||||||
# Author: Bandie Canis
|
# Author: Bandie Canis
|
||||||
# License: 2-Clause BSD License
|
# License: 2-Clause BSD License
|
||||||
|
|
||||||
import sys, ssl, socket
|
import sys, ssl, socket, os
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
CONFIG = "ding_client.cfg"
|
|
||||||
|
global exitcode
|
||||||
|
exitcode = 1
|
||||||
|
|
||||||
def readConfig():
|
def readConfig():
|
||||||
|
|
||||||
|
if(os.name == 'nt'):
|
||||||
|
CONFIG = "ding_client.win.cfg"
|
||||||
|
else:
|
||||||
|
CONFIG = "ding_client.cfg"
|
||||||
|
|
||||||
cfg = configparser.SafeConfigParser()
|
cfg = configparser.SafeConfigParser()
|
||||||
try:
|
try:
|
||||||
cfg.read(CONFIG)
|
cfg.read(CONFIG)
|
||||||
@ -28,8 +36,6 @@ def readConfig():
|
|||||||
|
|
||||||
def send(conn, cmd):
|
def send(conn, cmd):
|
||||||
|
|
||||||
global exitcode
|
|
||||||
|
|
||||||
conn.connect((host, port))
|
conn.connect((host, port))
|
||||||
buf = conn.recv(1024)
|
buf = conn.recv(1024)
|
||||||
if(buf == b"OK 1337\n"):
|
if(buf == b"OK 1337\n"):
|
||||||
@ -38,11 +44,17 @@ def send(conn, cmd):
|
|||||||
if(buf == b"OK CMD"):
|
if(buf == b"OK CMD"):
|
||||||
exitcode = 0
|
exitcode = 0
|
||||||
elif(buf == b"ERR NO_CMD"):
|
elif(buf == b"ERR NO_CMD"):
|
||||||
print("Error. Server said: The command doesn't exist/isn't set.", file=sys.stderr)
|
print("Error. Server said: The command isn't set on the server.", file=sys.stderr)
|
||||||
exitcode = 1
|
exitcode = 1
|
||||||
elif(buf == b"ERR CMD_ERR"):
|
elif(buf == b"ERR CMD_ERR"):
|
||||||
print("Error. Server said: The command doesn't work because the file doesn't exist on the server.")
|
print("Error. Server said: The command doesn't work because the file doesn't exist on the server.")
|
||||||
exitcode = 2
|
exitcode = 2
|
||||||
|
elif(buf == b"ERR PW"):
|
||||||
|
print("Error. Password required. The password was wrong.")
|
||||||
|
exitcode = 4
|
||||||
|
elif(b"OK PW" in buf):
|
||||||
|
bufr=str(buf.decode('utf-8'))
|
||||||
|
print("Password accepted. Timeout:", bufr.replace("OK PW ",""), "seconds.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
conn.sendall(b"NO.")
|
conn.sendall(b"NO.")
|
||||||
@ -63,7 +75,10 @@ def main():
|
|||||||
print("Please check your paths in the config file. (Have you forgotten to generate the Certificates?)", sep="", file=sys.stderr)
|
print("Please check your paths in the config file. (Have you forgotten to generate the Certificates?)", sep="", file=sys.stderr)
|
||||||
quit(2)
|
quit(2)
|
||||||
|
|
||||||
conn = context.wrap_socket(socket.socket())
|
if(":" in host):
|
||||||
|
conn = context.wrap_socket(socket.socket(family=socket.AF_INET6))
|
||||||
|
else:
|
||||||
|
conn = context.wrap_socket(socket.socket(family=socket.AF_INET))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
10
ding_client.win.cfg
Normal file
10
ding_client.win.cfg
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[Client]
|
||||||
|
host=localhost
|
||||||
|
port=13573
|
||||||
|
|
||||||
|
|
||||||
|
cafile=CA.crt
|
||||||
|
#Client Certificate/key signed by the CA above
|
||||||
|
certfile=ding_client.crt
|
||||||
|
keyfile=ding_client.key
|
||||||
|
|
63
ding_server
63
ding_server
@ -3,19 +3,27 @@
|
|||||||
# Author: Bandie Canis
|
# Author: Bandie Canis
|
||||||
# License: 2-Clause BSD license
|
# License: 2-Clause BSD license
|
||||||
|
|
||||||
import ssl, socket, subprocess, time
|
import ssl, socket, subprocess, time, os
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
CONFIG = "ding_server.cfg"
|
|
||||||
|
|
||||||
def getTimestamp():
|
def getTimestamp():
|
||||||
t = "[" + time.strftime("%Y-%m-%d %H:%M:%S") + "]"
|
t = "[" + time.strftime("%Y-%m-%d %H:%M:%S") + "]"
|
||||||
return t
|
return t
|
||||||
|
|
||||||
def execFromConfig(option):
|
def execFromConfig(option, pw=False):
|
||||||
cfg = configparser.SafeConfigParser()
|
cfg = configparser.SafeConfigParser()
|
||||||
cfg.read(CONFIG)
|
cfg.read(CONFIG)
|
||||||
|
|
||||||
|
if(pw):
|
||||||
|
if(option == password):
|
||||||
|
return 4
|
||||||
|
else:
|
||||||
|
return 5
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = cfg.get("Commands", option).replace("\"", "").replace("\'", "")
|
cmd = cfg.get("Commands", option).replace("\"", "").replace("\'", "")
|
||||||
cmd = cmd.split(" ")
|
cmd = cmd.split(" ")
|
||||||
@ -34,7 +42,6 @@ def execFromConfig(option):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
newsocket, fromaddr = bindsocket.accept()
|
newsocket, fromaddr = bindsocket.accept()
|
||||||
try:
|
try:
|
||||||
@ -44,10 +51,16 @@ def main():
|
|||||||
|
|
||||||
con_loop = True
|
con_loop = True
|
||||||
while con_loop:
|
while con_loop:
|
||||||
|
global tmppw_on, pw_on, pwtimeout
|
||||||
|
if('timeout' in locals() and timeout<time.time()):
|
||||||
|
del timeout
|
||||||
|
tmppw_on=pw_on
|
||||||
|
print(getTimestamp(), "Locked.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
buf = connstream.recv(1024)
|
buf = connstream.recv(1024)
|
||||||
if not buf: break
|
if not buf: break
|
||||||
buf = buf.decode("utf-8").upper()
|
buf = buf.decode("utf-8")
|
||||||
except ssl.SSLEOFError:
|
except ssl.SSLEOFError:
|
||||||
print(getTimestamp(), "SSL-EOF-Error.")
|
print(getTimestamp(), "SSL-EOF-Error.")
|
||||||
con_loop = False
|
con_loop = False
|
||||||
@ -55,8 +68,22 @@ def main():
|
|||||||
print(getTimestamp(), "Connection reset.")
|
print(getTimestamp(), "Connection reset.")
|
||||||
serve()
|
serve()
|
||||||
|
|
||||||
print(getTimestamp(), " ", fromaddr[0], ": ", buf, sep="")
|
|
||||||
|
|
||||||
|
|
||||||
|
if(tmppw_on):
|
||||||
|
retval = execFromConfig(buf, True)
|
||||||
|
if(retval == 5):
|
||||||
|
print(getTimestamp(), " ", fromaddr[0], ": Wrong Password.", sep="")
|
||||||
|
connstream.send(b"ERR PW")
|
||||||
|
if(retval == 4):
|
||||||
|
print(getTimestamp(), " ", fromaddr[0], ": Unlocked for ", pwtimeout, "sec.", sep="")
|
||||||
|
pwokstr = "OK PW " + str(pwtimeout)
|
||||||
|
connstream.send(bytes(pwokstr, "utf-8"))
|
||||||
|
timeout=time.time() + pwtimeout
|
||||||
|
tmppw_on = False
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(getTimestamp(), " ", fromaddr[0], ": ", buf, sep="")
|
||||||
retval = execFromConfig(buf)
|
retval = execFromConfig(buf)
|
||||||
if(retval == 0):
|
if(retval == 0):
|
||||||
connstream.send(b"OK CMD")
|
connstream.send(b"OK CMD")
|
||||||
@ -74,7 +101,12 @@ def main():
|
|||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
|
||||||
global host, port, cafile, certfile, keyfile, context, bindsocket
|
global CONFIG, host, port, cafile, certfile, keyfile, pw_on, password, pwtimeout, tmppw_on, context, bindsocket
|
||||||
|
|
||||||
|
if(os.name == 'nt'):
|
||||||
|
CONFIG = "ding_server.win.cfg"
|
||||||
|
else:
|
||||||
|
CONFIG = "ding_server.cfg"
|
||||||
|
|
||||||
cfg = configparser.SafeConfigParser()
|
cfg = configparser.SafeConfigParser()
|
||||||
cfg.read(CONFIG)
|
cfg.read(CONFIG)
|
||||||
@ -85,6 +117,14 @@ def init():
|
|||||||
cafile=cfg.get("Security", "cafile").replace("\"","").replace("\'","")
|
cafile=cfg.get("Security", "cafile").replace("\"","").replace("\'","")
|
||||||
certfile=cfg.get("Security", "certfile").replace("\"","").replace("\'","")
|
certfile=cfg.get("Security", "certfile").replace("\"","").replace("\'","")
|
||||||
keyfile=cfg.get("Security", "keyfile").replace("\"","").replace("\'","")
|
keyfile=cfg.get("Security", "keyfile").replace("\"","").replace("\'","")
|
||||||
|
pw_on=cfg.get("Security", "pw_on").replace("\"","").replace("\'","")
|
||||||
|
password=cfg.get("Security", "password").replace("\"","").replace("\'","")
|
||||||
|
pwtimeout=int(cfg.get("Security", "pwtimeout").replace("\"","").replace("\'",""))
|
||||||
|
if(pw_on.upper() == "TRUE"):
|
||||||
|
pw_on = True
|
||||||
|
else:
|
||||||
|
pw_on = False
|
||||||
|
tmppw_on=pw_on
|
||||||
except configparser.NoOptionError as e:
|
except configparser.NoOptionError as e:
|
||||||
print("Error in configuration file:", e)
|
print("Error in configuration file:", e)
|
||||||
quit(1)
|
quit(1)
|
||||||
@ -102,7 +142,10 @@ def init():
|
|||||||
quit(2)
|
quit(2)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bindsocket = socket.socket()
|
if(":" in host):
|
||||||
|
bindsocket = socket.socket(family=socket.AF_INET6)
|
||||||
|
else:
|
||||||
|
bindsocket = socket.socket(family=socket.AF_INET)
|
||||||
bindsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
bindsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
bindsocket.bind((host, port))
|
bindsocket.bind((host, port))
|
||||||
bindsocket.listen(5)
|
bindsocket.listen(5)
|
||||||
@ -114,13 +157,17 @@ def init():
|
|||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
print("Running ding server on ", host, ":", port,
|
print("Running ding server on ", host, ":", port,
|
||||||
|
"\nConfig: ", CONFIG,
|
||||||
"\nCAFile: ", cafile,
|
"\nCAFile: ", cafile,
|
||||||
"\nCertfile: ", certfile,
|
"\nCertfile: ", certfile,
|
||||||
"\nKeyfile: ", keyfile,
|
"\nKeyfile: ", keyfile,
|
||||||
|
"\nPassword lock: ", pw_on,
|
||||||
|
"\nPassword timeout: ", pwtimeout,
|
||||||
"\n===========",
|
"\n===========",
|
||||||
sep="")
|
sep="")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(__name__ == "__main__"):
|
if(__name__ == "__main__"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -12,6 +12,21 @@ certfile=ding_server.crt
|
|||||||
# Server's private key
|
# Server's private key
|
||||||
keyfile=ding_server.key
|
keyfile=ding_server.key
|
||||||
|
|
||||||
|
## Optional cleartext password
|
||||||
|
# To unlock the commands you need to send the password before sending the command.
|
||||||
|
# Example:
|
||||||
|
# $ ./ding_client "My password"
|
||||||
|
# $ ./ding_client lock
|
||||||
|
|
||||||
|
# Password on? (true/false)
|
||||||
|
pw_on=false
|
||||||
|
|
||||||
|
# Password (if you use spaces or other stuff you need to embrace the password in quotation marks, like ./ding_client "abc def"
|
||||||
|
password=abc def
|
||||||
|
|
||||||
|
# Password timeout in seconds
|
||||||
|
pwtimeout=10
|
||||||
|
|
||||||
|
|
||||||
[Commands]
|
[Commands]
|
||||||
# Syntax:
|
# Syntax:
|
||||||
|
41
ding_server.win.cfg
Normal file
41
ding_server.win.cfg
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
[Server]
|
||||||
|
host=localhost
|
||||||
|
port=13573
|
||||||
|
|
||||||
|
[Security]
|
||||||
|
# Certificate of the OWN CA
|
||||||
|
cafile=CA.crt
|
||||||
|
|
||||||
|
# Server's certificate [signed by the CA above]
|
||||||
|
certfile=ding_server.crt
|
||||||
|
|
||||||
|
# Server's private key
|
||||||
|
keyfile=ding_server.key
|
||||||
|
|
||||||
|
## Optional cleartext password
|
||||||
|
# To unlock the commands you need to send the password before sending the command.
|
||||||
|
# Example:
|
||||||
|
# python .\ding_client "My password"
|
||||||
|
# python .\ding_client lock
|
||||||
|
|
||||||
|
# Password on? (true/false)
|
||||||
|
pw_on=false
|
||||||
|
|
||||||
|
# The password.
|
||||||
|
# If you have a password with special characters as in spaces and the like, you may want to use quotation marks around your password: python .\ding_client "abc def"
|
||||||
|
password=abc def
|
||||||
|
|
||||||
|
# Password timeout in seconds
|
||||||
|
pwtimeout=10
|
||||||
|
|
||||||
|
|
||||||
|
[Commands]
|
||||||
|
# Syntax:
|
||||||
|
# SERVER_COMMAND: Command --which --should_be --executed
|
||||||
|
#
|
||||||
|
# For cmd.exe:
|
||||||
|
# a_cmd_command: C:\Windows\System32\cmd.exe /C <Your cmd commands here>
|
||||||
|
#
|
||||||
|
# For powershell:
|
||||||
|
# a_ps_command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe <Powershell commands here>
|
||||||
|
lock: C:\Windows\System32\rundll32.exe user32.dll,LockWorkStation
|
BIN
img/dingScreenshot.png
Normal file
BIN
img/dingScreenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 102 KiB |
Reference in New Issue
Block a user