Debian 10 - GnuDIP Dynamic DNS ============================== ******************************************************************************** ## TCP Implementation with tinydns ******************************************************************************** Public domain ******************************************************************************** ### Server: /opt/gnudip/gnudip-passwd.txt # To create hashed passwords : echo -n PASSWORD | md5sum # # Hashed-password Domain Name 25f9e794323b453885f5181f1b624d0b example.com machine01 6ebe76c9fb411be97b3b0d48b791a7c9 example.com ftp ******************************************************************************** ### Server: /opt/gnudip/gnudip-server.sh #!/bin/bash PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" CWD=$(dirname $(readlink -f $0)) MYPID=$$ ################################################################################ # Configuration RECORDS="$CWD/records" LOGGER="logger -t gnudip-server[$MYPID]" HPASSFILE="$CWD/gnudip-passwd.txt" TTL=60 # Message format USER:HPASS:DOMAIN:RCODE:IPADDR # USER+DOMAIN:128 HPASS:32 RCODE:1 IPADDR:15 Colons:4 MAXMSGLEN=180 READTMOUT=3 ################################################################################ # Read and sanitize client IP # xinetd supplies client IP CLIENTIP=$(echo $REMOTE_HOST) IPSW=1 if [[ $CLIENTIP =~ ^[0-9]{1,3}(\.[0-9]{1,3}){2}\.[0-9]{1,3}$ ]]; then IP=($(echo $CLIENTIP | sed -e 's,\., ,g')) [[ ${IP[0]} -le 255 && ${IP[1]} -le 255 && ${IP[2]} -le 255 && ${IP[3]} -le 255 ]] IPSW=$? fi if [ "$IPSW" == "1" ]; then echo "Client IP address is not valid" | $LOGGER echo 1 exit fi echo "Got new connection from $CLIENTIP" | $LOGGER ################################################################################ # Generate and send salt SALT=$(tr -dc A-Za-z0-9 > "$RECORDS/$DOMAIN-$MYPID" echo "Login OK: $RECORD" | $LOGGER echo 0 exit ******************************************************************************** ### Server: /opt/gnudip/gnudip-apply.sh #!/bin/bash PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" CWD=$(dirname $(readlink -f $0)) RECORDS="$CWD/records" DOMAINSDIR="/opt/tinydns-scripts/domains" RESTART="/opt/tinydns-scripts/create-data-file.sh" TINYDNS="1.2.3.4" if [ ! -d "$RECORDS" ]; then mkdir -p $RECORDS chown nobody:nogroup $RECORDS fi N=$(ls $RECORDS | wc -l) if [ "$N" == "0" ] ;then exit fi RSTSW=0 for F in $(find $RECORDS -type f); do RECORD=$(cat $F | head -n1) PREFIX=$(echo $RECORD | cut -d: -f1) NAME=${PREFIX:1} DOMAIN=$(echo $NAME | sed -e 's/^[^\.]*\.//g') IP=$(echo $RECORD | cut -d: -f2) echo $PREFIX echo $NAME echo $IP N=$(dnsq a $NAME $TINYDNS | egrep "^answer: $NAME " | egrep -c " $IP$") if [ "$N" != "0" ]; then continue fi RSTSW=1 sed -i "/^$PREFIX:/d" "$DOMAINSDIR/$DOMAIN" echo $RECORD >> "$DOMAINSDIR/$DOMAIN" rm $F done [ "$RSTSW" == "1" ] && $RESTART ******************************************************************************** ### Server: /opt/gnudip/gnudip-apply-loop.sh #!/bin/bash # # Start inside screen : # env SCREENDIR="/var/run/screen/S-root/" screen -dmS GNUDIP /opt/gnudip/gnudip-apply-loop.sh # PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" CWD=$(dirname $(readlink -f $0)) APPLY="$CWD/gnudip-apply.sh" SLEEP=5 while :;do $APPLY sleep $SLEEP done ******************************************************************************** ### Server: Add to /etc/services gnudip 3495/tcp ******************************************************************************** ### Server: /etc/xinetd.d/gnudip service gnudip { disable = no flags = IPv4 socket_type = stream protocol = tcp wait = no user = nobody server = /opt/gnudip/gnudip-server.sh bind = 0.0.0.0 } ******************************************************************************** ### Server: /etc/rc.local env SCREENDIR="/var/run/screen/S-root/" screen -dmS GNUDIP /opt/gnudip/gnudip-apply-loop.sh ******************************************************************************** ### Client: /root/scripts/gnudip-client.sh #!/bin/bash # # Usage : # ncat ddns.topdns.ir 3495 -e gnudip-client.sh # PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" MYPID=$$ LOGGER="logger -t gnudip-client[$MYPID]" USER="machine01" PASS="123456789" DOMAIN="example.com" read SALT echo "Salt: $SALT" | $LOGGER REQ="$USER:$(echo -n "$(echo -n "$PASS" | md5sum | sed 's, .*,,').$SALT" | md5sum | sed 's, .*,,'):$DOMAIN:2" echo "$REQ" | $LOGGER echo "$REQ" read RESP echo "Response $RESP" | $LOGGER ******************************************************************************** ### Client: /etc/crontab * * * * * root /usr/bin/ncat ddns.topdns.ir 3495 -e /root/scripts/gnudip-client.sh &> /dev/null ******************************************************************************** ### Links http://gnudip2.sourceforge.net/ http://gnudip2.sourceforge.net/gnudip-www/ http://gnudip2.sourceforge.net/gnudip-www/latest/gnudip/html/protocol.html http://gnudip2.sourceforge.net/gnudip-www/latest/gnudip/html/protocol_sample.txt http://gnudip2.sourceforge.net/gnudip-www/latest/gnudip/html/client/UNIX/ http://gnudip2.sourceforge.net/gnudip-www/latest/maintenance_commands.html http://gnudip2.sourceforge.net/gnudip-www/latest/remote.html http://gnudip2.sourceforge.net/gnudip-www/latest/INSTALL.html http://gnudip2.sourceforge.net/gnudip-www/latest/BACKEND.html http://gnudip2.sourceforge.net/gnudip-www/latest/TODO.html http://gnudip2.sourceforge.net/gnudip-www/gnudip-2.3.5-www.tar.gz http://up.nl.eu.org/projects/gnudip.html https://github.com/rodajc/gnudiphttp/ https://fossies.org/linux/misc/dns/old/gnudip-2.3.5.tar.gz/ ******************************************************************************** _BY: Pejman Moghadam_ _TAG: gnudip, xinetd, ddns, dns, tinydns_ _DATE: 2021-06-02 07:07:36_