Skip to content

Commit

Permalink
add:返回包注入
Browse files Browse the repository at this point in the history
fix:mitm换了更高效的实现方式,现在https抓包更快了
fix:mbp;littleproxy,netty版本升级
  • Loading branch information
darkal committed Jun 2, 2017
1 parent 4872c75 commit 488b719
Show file tree
Hide file tree
Showing 207 changed files with 2,018 additions and 17,031 deletions.
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,50 @@ Content内容如果为JSON将会自动格式化显示<br>
![image](https://www.darkal.cn/imgd.php?src=/2016/09/230686663947787928.jpg&width=350)<br>
分享功能将抓包生成的所有数据包打包为har文件并压缩为zip,支持分享到微信、QQ等<br><br>

2. 环境切换<br>
2. 返回包注入<br>
支持修改流量返回包(该版本暂时只支持http的修改)<br>
![image](https://www.darkal.cn/imgd.php?src=/2016/09/WechatIMG180.jpeg&width=350)
![image](https://www.darkal.cn/imgd.php?src=/2016/09/WechatIMG181.jpeg&width=350)<br><br>

3. 环境切换<br>
支持切换模拟为微信、手Q,默认为普通浏览器。<br>
![image](https://www.darkal.cn/imgd.php?src=/2016/09/WechatIMG81.jpeg&width=350)<br><br>

3. 多样性输入:导航、地址栏、扫一扫、schema呼起<br>
4. 多样性输入:导航、地址栏、扫一扫、schema呼起<br>
支持地址栏直接输入地址,扫扫描二维码,以及schema呼起app并打开目标页面。<br>
schema的协议格式为:jdhttpmonitor://webview?param={'url'='http://www.darkal.cn'}<br><br>

4. Host配置<br>
5. Host配置<br>
可以配置各域名的host<br>
![image](https://www.darkal.cn/imgd.php?src=/2016/09/WechatIMG79.jpeg&width=350&t=1)<br><br>


5. 查看console.log日志<br>
6. 查看console.log日志<br>
![image](https://www.darkal.cn/imgd.php?src=/2016/09/WechatIMG82.jpeg&width=350)<br><br>


6. 网络工具<br>
7. 网络工具<br>
目前AndroidHttpCapture集成了常见的网络工具,如dns,ping,以及设备信息<br>
![image](https://www.darkal.cn/imgd.php?src=/2016/09/621495078826.jpg&width=350)<br><br>

7. 设置系统代理,监听其他app请求包<br>
8. 设置系统代理,监听其他app请求包<br>
当将用户手机的代理服务器设置为127.0.0.1:8888时,可以对其他app(例如微信)的HTTP数据进行抓包<br>
(此时AndroidHttpCapture就是一个手机上的fiddler)<br>
![image](https://www.darkal.cn/imgd.php?src=/2016/09/WechatIMG80.jpeg&width=350)<br><br>

### Q & A<br>
1. 分享的http包如何查看和分析?<br>
   分享的文件解压后为.har文件,可以通过fiddler方式或者在线工具进行分析。<br>
Fiddler方式需要先将包导到电脑上,然后使用fiddler导入该包:Import Sessions->Select Import Format ->HTTPArchive ->选择包,即可<br>
在线工具外网:http://h5.darkal.cn/har/ 只需要将包拖入此工具即可分析<br><br>


### 已知BUG<br>
1. 信任所有的服务器证书不做校验<br>
2. 开启返回包注入功能后,https返回的部分页面存在 err_CONTENT_LENGTH_MISMATCH 错误<br>

#### 如果觉得工具好用的话请多多star以及Pull requests<br>支持我喝杯咖啡请扫描下面的二维码,谢谢(ง •̀_•́)ง<br>
![image](http://h5.darkal.cn/har/guide/img/code.jpg)<br><br>

### 致谢<br>
AndroidHttpCapture基于Netty、browsermob-proxy来实现核心抓包的功能<br>
Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.<br>
Expand All @@ -58,8 +70,7 @@ https://github.com/netty/netty<br>

A free utility to help web developers watch and manipulate network traffic from their AJAX applications.<br>
https://github.com/lightbody/browsermob-proxy<br>
修改了多处browsermob-proxy的源码适配Android系统<br>
#### 目前遗留了一个Bug:信任所有的服务器证书不做校验<br><br>
修改了多处browsermob-proxy的源码适配Android系统<br><br>

MIT License<br>
Copyright (c) 2016 AndroidHttpCapture
Expand Down
15 changes: 9 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId "cn.darkal.networkdiagnosis"
minSdkVersion 14
targetSdkVersion 22
versionCode 25
versionName "2.4.26"
versionCode 30
versionName "3.1.30"
// Enabling multidex support.
multiDexEnabled true
resConfigs "zh"
Expand Down Expand Up @@ -76,10 +76,11 @@ dependencies {
compile 'com.android.support:support-annotations:24.2.1'
compile 'com.android.support:multidex:1.0.1'
// littleproxy及其依赖
compile('net.lightbody.bmp:littleproxy:1.1.0-beta-bmp-13') {
compile('net.lightbody.bmp:littleproxy:1.1.0-beta-bmp-16') {
exclude group: 'io.netty'
}
compile 'net.sf.qualitycheck:quality-check:1.3'

compile group: 'org.apache.directory.studio', name: 'org.apache.commons.io', version: '2.4'
compile 'javax.annotation:jsr250-api:1.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.6'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.6'
Expand All @@ -92,10 +93,12 @@ dependencies {
compile 'com.google.jimfs:jimfs:1.1'
compile 'com.jcraft:jzlib:1.1.3'
// 日志处理
compile 'org.slf4j:slf4j-api:1.7.21'
// compile 'org.slf4j:slf4j-api:1.7.21'
compile 'org.slf4j:slf4j-log4j12:1.7.21'

// compile 'org.slf4j:jcl-over-slf4j:1.7.21'
// 启用Netty的日志输出(调试用)
// compile 'com.noveogroup.android:android-logger:1.3.5'
// compile 'com.noveogroup.android:android-logger:1.3.5'
// 文件上传插件
compile 'net.gotev:uploadservice:3.0.3'
// Bugly上报
Expand Down
Binary file renamed app/libs/netty-android.jar → app/libs/netty-all-android-4.0.44.Final.jar
100644 → 100755
Binary file not shown.
29 changes: 15 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<uses-permission android:name="android.permission.READ_LOGS" />

<application
android:name="cn.darkal.networkdiagnosis.SysApplication"
android:name=".SysApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<!-- 配置APP渠道号 -->
Expand All @@ -31,15 +31,17 @@
android:value="Github" />

<activity
android:name="cn.darkal.networkdiagnosis.Activity.MainActivity"
android:name=".Activity.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateHidden">
<meta-data android:name="android.app.searchable"
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />

<intent-filter>
<action android:name="android.intent.action.VIEW" />

Expand All @@ -64,20 +66,20 @@
android:screenOrientation="portrait" />

<service
android:name="cn.darkal.networkdiagnosis.MyVpnService"
android:name=".MyVpnService"
android:permission="android.permission.BIND_VPN_SERVICE">
<intent-filter>
<action android:name="android.net.VpnService" />
</intent-filter>
</service>

<activity
android:name="cn.darkal.networkdiagnosis.Activity.SettingsActivity"
android:name=".Activity.SettingsActivity"
android:label="@string/title_activity_settings" />

<!-- 引用xml策略声明 -->
<receiver
android:name="cn.darkal.networkdiagnosis.Receiver.MyAdminReceiver"
android:name=".Receiver.MyAdminReceiver"
android:description="@string/app_name"
android:label="@string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
Expand All @@ -91,16 +93,15 @@
</receiver>

<activity
android:name="cn.darkal.networkdiagnosis.Activity.HarDetailActivity"
android:theme="@style/AppTheme.NoActionBar"/>

android:name=".Activity.HarDetailActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="cn.darkal.networkdiagnosis.Activity.JsonPreviewActivity"
android:theme="@style/AppTheme.NoActionBar"/>

android:name=".Activity.JsonPreviewActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:theme="@android:style/Theme.Translucent" />
<activity android:name=".Activity.ChangeFilterActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package cn.darkal.networkdiagnosis.Activity;

import android.content.DialogInterface;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.darkal.networkdiagnosis.Adapter.ContentFilterAdapter;
import cn.darkal.networkdiagnosis.Bean.ResponseFilterRule;
import cn.darkal.networkdiagnosis.R;
import cn.darkal.networkdiagnosis.SysApplication;
import cn.darkal.networkdiagnosis.Utils.DeviceUtils;
import cn.darkal.networkdiagnosis.Utils.SharedPreferenceUtils;

public class ChangeFilterActivity extends AppCompatActivity {
@BindView(R.id.activity_change_filter)
public RelativeLayout relativeLayout;

@BindView(R.id.lv_filter)
public ListView listView;

@BindView(R.id.fab_add)
public FloatingActionButton floatingActionButton;

ContentFilterAdapter contentFilterAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_filter);
ButterKnife.bind(this);
setupActionBar();

List<ResponseFilterRule> ruleList = ((SysApplication)getApplication()).ruleList;

contentFilterAdapter = new ContentFilterAdapter(this,ruleList);
listView.setAdapter(contentFilterAdapter);

floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(null);
}
});
}

/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
private void setupActionBar() {
setTitle("返回包注入");
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

public void showDialog(final ResponseFilterRule responseFilterRule){
AlertDialog.Builder builder = new AlertDialog.Builder(ChangeFilterActivity.this);

View textEntryView = LayoutInflater.from(ChangeFilterActivity.this).inflate(R.layout.alert_resp_filter, null);
final EditText urlEditText = (EditText) textEntryView.findViewById(R.id.et_origin_url);
final EditText regexEditText = (EditText) textEntryView.findViewById(R.id.et_regex);
final EditText contentEditText = (EditText) textEntryView.findViewById(R.id.et_replace_result);
if(responseFilterRule!=null){
urlEditText.setText(responseFilterRule.getUrl());
regexEditText.setText(responseFilterRule.getReplaceRegex());
contentEditText.setText(responseFilterRule.getReplaceContent());
builder.setTitle("修改注入项");
}else{
builder.setTitle("新增注入项");
}

builder.setCancelable(true);
builder.setView(textEntryView);
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(responseFilterRule!=null){
responseFilterRule.setUrl(urlEditText.getText().toString());
responseFilterRule.setReplaceRegex(regexEditText.getText().toString());
responseFilterRule.setReplaceContent(contentEditText.getText().toString());
}else {
if(urlEditText.getText().length()>0 && regexEditText.getText().length()>0
&& contentEditText.getText().length()>0) {
ResponseFilterRule responseFilterRule = new ResponseFilterRule();
responseFilterRule.setUrl(urlEditText.getText().toString());
responseFilterRule.setReplaceRegex(regexEditText.getText().toString());
responseFilterRule.setReplaceContent(contentEditText.getText().toString());
((SysApplication) getApplication()).ruleList.add(responseFilterRule);
}
}
contentFilterAdapter.notifyDataSetChanged();
}
});
builder.setNegativeButton("取消",null);
builder.show();
}

@Override
protected void onStop() {
SharedPreferenceUtils.save(getApplicationContext(),
"response_filter",((SysApplication) getApplication()).ruleList);
super.onStop();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Loading

0 comments on commit 488b719

Please sign in to comment.