bytedance / appshark

Appshark is a static taint analysis platform to scan vulnerabilities in an Android app.
Apache License 2.0
1.49k stars 165 forks source link

设置类型漏洞的检测问题 #47

Open firmianay opened 1 year ago

firmianay commented 1 year ago

有一类常规漏洞是设置上的错误,比如针对WebView的setJavaScriptEnabled(true)setWebContentsDebuggingEnabled(true)setAllowContentAccess(true)等。 试过APIMode,但不能对函数的参数做过滤;如果用SliceMode,将1传播到setJavaScriptEnabled,但是source不支持整数类型。 大佬能否给一个规则示例。

bdbubble commented 1 year ago

true 在 jimple 里就是数字 1,false 是 0。可以用ConstNumberMode

{
  "WebViewDebug": {
    "traceDepth" : 1,
    "ConstNumberMode": true,
    "targetNumberArr": [1],
    "sink": {
      "<android.webkit.WebView: void setWebContentsDebuggingEnabled(boolean)>": {
        "TaintCheck": ["p0"]
      }
    }
  }
}
firmianay commented 1 year ago

可以了,谢谢师傅!

firmianay commented 1 year ago

那如果参数是通过变量传入的呢,ConstNumberMode好像找不到这个入口

public class GConfig {
    public static boolean DEBUG = true;
  public static void prepareWebView(Context context) {
      if (mWebView == null) {
          WebView webView = new WebView(context.getApplicationContext());
          mWebView = webView;
          webView.getSettings().setJavaScriptEnabled(true);
          mWebView.getSettings().setDomStorageEnabled(true);
          if (Build.VERSION.SDK_INT >= 19) {
              WebView.setWebContentsDebuggingEnabled(GConfig.DEBUG);
          }
      }
      mWebView.clearHistory();
      mWebView.addJavascriptInterface(mContent, "_hybrid_circle_content");
      mWebView.loadUrl(NetworkConfig.getInstance().getCirclePageUrl());
  }
firmianay commented 1 year ago

还有个问题,这种设置通常是有默认值的,那如何判断没有调用某个方法,即默认为true

nkbai commented 1 year ago

这个调整一下traceDepth,不过不要太深了,会引起很多误报。 这个规则的本质是有哪些常量整数流到了函数的某个参数中。

nkbai commented 1 year ago

还有个问题,这种设置通常是有默认值的,那如何判断没有调用某个方法,即默认为true

如果是判断某个函数没有调用,这个appshark不好检测。

firmianay commented 1 year ago

还有个问题,这种设置通常是有默认值的,那如何判断没有调用某个方法,即默认为true

如果是判断某个函数没有调用,这个appshark不好检测。

我不了解这个函数签名具体是怎么匹配的,能不能在APIMode增加这个功能,先找到某个类名的所有函数,然后看是否包含特定函数

nkbai commented 1 year ago

你可以好好想想这个功能怎么设计,如果确实能描述清楚,可以增加这个单独的mode都是可以的。

firmianay commented 9 months ago

这个调整一下traceDepth,不过不要太深了,会引起很多误报。 这个规则的本质是有哪些常量整数流到了函数的某个参数中。

有时候感觉不太行,ConstString模式似乎是去jimple里匹配每一行是否有字符串,然后添加到constStringPatternMap缓存,但是像下面这种情况,只会把A处的表达式添加进去,B处的就被忽略了

        <com.example.loaddex.LiveLiterals$MainActivityKt: java.lang.String String$0$str$arg-0$call-$init$$val-file$fun-errorExample2dexKt$class-MainActivity> = "/sdcard/";  // A

    public final java.lang.String String$0$str$arg-0$call-$init$$val-file$fun-errorExample2dexKt$class-MainActivity()
    {
        com.example.loaddex.LiveLiterals$MainActivityKt r0;
        androidx.compose.runtime.State $r2, $r3;
        java.lang.String $r1;
        boolean $z0;

        r0 := @this: com.example.loaddex.LiveLiterals$MainActivityKt;

        $z0 = staticinvoke <androidx.compose.runtime.internal.LiveLiteralKt: boolean isLiveLiteralsEnabled()>();

        if $z0 != 0 goto label1;

        $r1 = <com.example.loaddex.LiveLiterals$MainActivityKt: java.lang.String String$0$str$arg-0$call-$init$$val-file$fun-errorExample2dexKt$class-MainActivity>;  // B

        return $r1;
nkbai commented 9 months ago

B处在做指针分析的时候不是会被关联起来么?

firmianay commented 9 months ago

在那几个log文件里都没有搜到errorExample2dexKt,在results.json里也没有