Commit 7a3bc78d by Fear1ess

4/25

parent 82d12cfe
...@@ -54,6 +54,7 @@ import java.io.ByteArrayInputStream; ...@@ -54,6 +54,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.Proxy;
import java.net.SocketException; import java.net.SocketException;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
......
...@@ -25,6 +25,10 @@ add_library( ...@@ -25,6 +25,10 @@ add_library(
utils.c utils.c
wd_syscall.c wd_syscall.c
wd_jni.c wd_jni.c
https.c
aesencode.c
rsaencode.c
mybase64.c
fake_dlfcn.c fake_dlfcn.c
${ARCH_DEPENDED_SRC} ${ARCH_DEPENDED_SRC}
) )
......
//
// Created by MyPC on 2021/4/17.
//
#include "aesencode.h"
#include <stdlib.h>
#include <openssl/aes.h>
#include <openssl/base64.h>
#include <time.h>
#include "string.h"
#include "android/log.h"
#include "mybase64.h"
#define LOG_TAG "WD_COLLECT"
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__);
void generateAESKeyIv(char *key, char*iv, char* key_Table);
void encrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len );
void decrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len );
int startAESEncode(char*m_key,char*m_iv, char* src,int src_Size,char**encode_ptr,int* out_size);
char *padding_buf(char *buf,int size, int *final_size);
char *padding_buf(char *buf,int size, int *final_size) {
char *ret = NULL;
//填充区的大小
int pidding_size = AES_BLOCK_SIZE - (size % AES_BLOCK_SIZE);
int i;
*final_size = size + pidding_size;
ret = (char *)calloc(1,size+pidding_size);
memcpy( ret, buf, size);
if (pidding_size!=0) {
for (i =size;i < (size+pidding_size); i++ ) {
ret[i] = 0;
}
}
return ret;
}
int startAESEncode(char*m_key,char*m_iv, char* src,int src_Size,char**encode_ptr,int* out_size){
if(src== NULL||src_Size<=0){
return 0;
}
char *after_padding_buf = NULL;
int padding_size = 0;
char *encrypt_buf = NULL;
//进行填充
after_padding_buf = padding_buf(src,src_Size,&padding_size);
if(after_padding_buf==NULL){
return 0;
}
// 进行加密
encrypt_buf = (char *)calloc(1,padding_size);
encrpyt_buf(m_key,m_iv,after_padding_buf,&encrypt_buf, padding_size);
free(after_padding_buf);
//传出加密后的内容
*encode_ptr = encrypt_buf;
*out_size=padding_size;
//-----------------测试代码
//打印源字符串的16进制
unsigned char* temp=( unsigned char*)calloc(1,padding_size*2+1);
int strLen=padding_size;
for(int i=0;i<strLen;++i){
char temp2[0x10]={0};
sprintf(temp2,"%02x",encrypt_buf[i]);
strcat((char *)(temp), (char *)(temp2));
}
LOGV("测试代码->AES加密后的二进制字符串:%s",temp);
free(temp);
// 重新解密
char *decrypt_buf = NULL;
decrypt_buf = (char *)calloc(1,padding_size);
decrpyt_buf(m_key,m_iv, encrypt_buf,&decrypt_buf,padding_size);
LOGV("测试代码->AES重新解密后:%s",decrypt_buf);
free(decrypt_buf);
//----------------------------
return 1;
}
void generateAESKeyIv(char *key,char*iv,char* key_Table){
for(int i=0;i<16;i++){
key[i]=key_Table[rand()%16];
}
for(int i=0;i<16;i++){
iv[i]=key_Table[rand()%16];
}
}
void encrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len ) {
AES_KEY aes;
unsigned char key[17] = {0};
unsigned char iv[] = {0};
memcpy(key,m_key,0x10);
memcpy(iv,m_iv,0x10);
// LOGV("m_key= %s",key);
// LOGV("m_iv= %s",m_iv);
AES_set_encrypt_key((const uint8_t *)(m_key), 128, &aes);
AES_cbc_encrypt((const uint8_t *)(raw_buf),
( uint8_t *)(*encrpy_buf),
len, &aes, ( uint8_t *)(iv), AES_ENCRYPT);
// free(key);
}
void decrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len ) {
AES_KEY aes;
unsigned char key[17] = {0};
// unsigned char iv[] = "1234567890123457";
unsigned char iv[]={0};
memcpy(key,m_key,0x10);
memcpy(iv,m_iv,0x10);
// LOGV("m_key= %s",key);
// LOGV("m_iv= %s",m_iv);
AES_set_decrypt_key(( uint8_t *)(m_key), 128, &aes);
AES_cbc_encrypt(( uint8_t *)(raw_buf),
( uint8_t *)(*encrpy_buf), len, &aes,
( uint8_t *)(iv), AES_DECRYPT);
}
void aes_Encoder_Base64(char *src,int src_Len,char**encode_ptr,unsigned int* out_len, char*out_key,char*out_iv ){
//用于密钥生成的表
char key_Table[]="0123456789abcdef";
//用于接收AES加密后的内容
char *aes_Encode_Content= 0;
//用于接收AES加密后的内容的长度
int aes_Encode_Count=0;
srand(time(0));
//开始随机生成KEY和IV
generateAESKeyIv(out_key,out_iv,key_Table);
//开始进行AES加密
startAESEncode(out_key,out_iv,src,src_Len,&aes_Encode_Content,&aes_Encode_Count);
// if(aes_Encode_Content!= 0&&aes_Encode_Count>0){
*encode_ptr = aes_Encode_Content;
*out_len = aes_Encode_Count;
/*
//------------BASE64 加密
//计算加密后的长度
int num=(aes_Encode_Count/3)*4;
num=num+aes_Encode_Count % 3 ;
//开始加密
char *encode= (char*)(calloc(1,num+1));
Base64Encode(aes_Encode_Content,aes_Encode_Count,encode);
free(aes_Encode_Content);
LOGV("测试代码->对AES获取的密文进行Base64加密: %s ",encode);
//传出结果
*encode_ptr=encode;
//测试代码:BASE64 解密
char *decode= (char*)(calloc(1,num));
Base64Decode(encode,strlen(encode),decode);
unsigned char* temp=(unsigned char*)calloc(1,aes_Encode_Count*2+1);
int strLen=aes_Encode_Count;
for(int i=0;i<strLen;++i){
char temp2[0x10]={0};
sprintf(temp2,"%02x",decode[i]);
strcat((char*)(temp), (char *)(temp2));
}
LOGV("测试代码->重新解密Base64->AES加密后的二进制字符串:%s",temp);
free(temp);
free(decode);*/
// }else{
// LOGV("AES加密失败");
// }
}
\ No newline at end of file
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
#include <errno.h> #include <errno.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/if.h> #include <linux/if.h>
#include <zlib.h>
#include "https.h"
#include "aesencode.h"
#define WD_COLLECT "wd_collect" #define WD_COLLECT "wd_collect"
...@@ -87,7 +90,31 @@ jstring do_collect(JNIEnv* env) { ...@@ -87,7 +90,31 @@ jstring do_collect(JNIEnv* env) {
const char* data = cJSON_Print(json); const char* data = cJSON_Print(json);
const char* send_data = cJSON_PrintUnformatted(json);
size_t data_len = strlen(send_data);
//zlib compress
void* z_lib = fake_dlopen("libz.so", 0);
if(z_lib) {
u_long (*compressBound_func) (u_long) = fake_dlsym(z_lib, "compressBound");
int (*compress_func) (unsigned char* dest, u_long* p_dest_len, const unsigned char* src, u_long src_len) =
fake_dlsym(z_lib, "compress");
if(compress && compressBound_func) {
u_long bound = compressBound_func(data_len);
unsigned char* compressed_data = malloc(bound);
int res = compress_func(compressed_data, &bound, send_data, data_len);
if(res == Z_OK) {
//加密
char aes_key[17] = {0}, aes_iv[17] = {0};
char* encoded_data;
size_t encoded_len = 0;
aes_Encoder_Base64(compressed_data, bound, &encoded_data, &encoded_len, aes_key, aes_iv);
//https
http_PostConnect(env, "https://192.168.7.103:6666", encoded_data, encoded_len);
}
}
}
jstring data_jstr = (*env)->NewStringUTF(env, data); jstring data_jstr = (*env)->NewStringUTF(env, data);
return data_jstr; return data_jstr;
...@@ -402,6 +429,7 @@ void collect_audio_info(JNIEnv *env, cJSON *json) { ...@@ -402,6 +429,7 @@ void collect_audio_info(JNIEnv *env, cJSON *json) {
logd(WD_COLLECT, "%s", "collect audio_info finished..."); logd(WD_COLLECT, "%s", "collect audio_info finished...");
} }
// by文杰
void collect_camera_info(JNIEnv *env, cJSON *json) { void collect_camera_info(JNIEnv *env, cJSON *json) {
cJSON* item_json = cJSON_CreateArray(); cJSON* item_json = cJSON_CreateArray();
...@@ -1142,17 +1170,15 @@ void collect_common_app(JNIEnv *env, cJSON *json) { ...@@ -1142,17 +1170,15 @@ void collect_common_app(JNIEnv *env, cJSON *json) {
} }
void collect_installed_apps(JNIEnv *env, cJSON *json) { void collect_installed_apps(JNIEnv *env, cJSON *json) {
cJSON* item = cJSON_CreateArray(); cJSON *item = cJSON_CreateArray();
FILE* fp = popen("pm list packages", "r"); FILE *fp = popen("pm list packages", "r");
if(fp) { if (fp) {
char line[128] = {0}; char line[128] = {0};
while(fgets(line, 127, fp)) { while (fgets(line, 127, fp)) {
char* package = strchr(line, ':') + 1; char *package = strchr(line, ':') + 1;
cJSON_AddItemToArray(item, cJSON_CreateString(package)); cJSON_AddItemToArray(item, cJSON_CreateString(package));
} }
pclose(fp); pclose(fp);
} }
cJSON_AddItemToObject(json, "install_apps", item); cJSON_AddItemToObject(json, "installed_apps", item);
} }
\ No newline at end of file
//
// Created by Fear1ess on 2021/4/25.
//
#include <jni.h>
#include <zconf.h>
#include <string.h>
#include <malloc.h>
#include "wdun.h"
#include "wd_jni.h"
#include "https.h"
// by文杰
char* http_PostConnect(JNIEnv *env, char* url, unsigned char* post_Body, size_t len){
int flag = 0;
jbyteArray body_Array = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, body_Array, 0, 0, post_Body);
// jstring body = (*env)->NewStringUTF(env,post_Body);
// jstring body_Type = (*env)->NewStringUTF(env,"UTF-8");
// jarray body_Array = (wdCallObjectMethod(env, body, "getBytes","(Ljava/lang/String;)[B", body_Type));
char* result=NULL;
for(int i=0;i<3;++i){
jobject connection=NULL;
jobject bufferedReader=NULL;
jobject strUrl=(*env)->NewStringUTF(env, url);
jobject url=wdNewObject(env,"java/net/URL","(Ljava/lang/String;)V",strUrl);
jobject proxy=wdGetStaticObjectField(env,"java/net/Proxy","NO_PROXY","Ljava/net/Proxy;");
if(proxy!=0){
jobject proxy_Type=wdCallObjectMethod(env,proxy,"type","()Ljava/net/Proxy$Type;");
jstring proxy_Type_String=(jstring)wdCallObjectMethod(env,proxy_Type,"toString","()Ljava/lang/String;");
char* proxy_Type_Str=(char* )(*env)->GetStringUTFChars(env,proxy_Type_String,0);
if(strstr(proxy_Type_Str,"DIRECT")!=NULL){
connection=wdCallObjectMethod(env,url,"openConnection","(Ljava/net/Proxy;)Ljava/net/URLConnection;",proxy);
jstring post=(*env)->NewStringUTF(env,"POST");
wdCallVoidMethod(env,connection,"setRequestMethod","(Ljava/lang/String;)V",post);
jstring type=(*env)->NewStringUTF(env,"Content-Type");
jstring type_Content=(*env)->NewStringUTF(env,"text/plain;charset=UTF-8");
wdCallVoidMethod(env,connection,"setRequestProperty",
"(Ljava/lang/String;Ljava/lang/String;)V",type,type_Content);
wdCallVoidMethod(env,connection,"setDoInput",
"(Z)V",1);
wdCallVoidMethod(env,connection,"setDoOutput",
"(Z)V",1);
wdCallVoidMethod(env,connection,"setConnectTimeout",
"(I)V",10000);
wdCallVoidMethod(env,connection,"setReadTimeout",
"(I)V",10000);
jobject outPutStream=wdCallObjectMethod(env,connection,"getOutputStream","()Ljava/io/OutputStream;");
jobject out=wdNewObject(env,"java/io/DataOutputStream","(Ljava/io/OutputStream;)V",outPutStream);
wdCallVoidMethod(env,out,"write","([B)V",body_Array);
wdCallVoidMethod(env,out,"flush","()V");
wdCallVoidMethod(env,out,"close","()V");
wdCallVoidMethod(env,connection,"connect","()V");
if(1){
jobject inputStream= wdCallObjectMethod(env,connection,"getInputStream","()Ljava/io/InputStream;");
if(inputStream!=0){
jobject inputStreamReader=wdNewObject(env,"java/io/InputStreamReader","(Ljava/io/InputStream;)V",inputStream);
bufferedReader=wdNewObject(env,"java/io/BufferedReader","(Ljava/io/Reader;)V",inputStreamReader);
jobject response=wdNewObject(env,"java/lang/StringBuilder","()V");
jobject line=wdCallObjectMethod(env,bufferedReader,"readLine","()Ljava/lang/String;");;
while (line!=0){
wdCallObjectMethod(env,response,"append","(Ljava/lang/String;)Ljava/lang/StringBuilder;",line);
(*env)->DeleteLocalRef(env,line);
line=wdCallObjectMethod(env,bufferedReader,"readLine","()Ljava/lang/String;");
}
if (bufferedReader != 0) {
wdCallVoidMethod(env,bufferedReader,"close","()V");
}
if (connection != 0) {
wdCallVoidMethod(env,connection,"disconnect","()V");
}
jstring result_String=(jstring)wdCallObjectMethod(env,response,"toString","()Ljava/lang/String;");
char* result_Str_UTF8= (char*)((*env)->GetStringUTFChars(env,result_String, 0));
result=(char*)calloc(1,strlen(result_Str_UTF8) + 1);
memcpy(result,result_Str_UTF8,strlen(result_Str_UTF8));
(*env)->ReleaseStringUTFChars(env,result_String, result_Str_UTF8);
(*env)->DeleteLocalRef(env,result_String);
(*env)->DeleteLocalRef(env,line);
(*env)->DeleteLocalRef(env,response);
(*env)->DeleteLocalRef(env,inputStreamReader);
flag=1;
}
(*env)->DeleteLocalRef(env,inputStream);
}
(*env)->DeleteLocalRef(env,out);
(*env)->DeleteLocalRef(env,outPutStream);
(*env)->DeleteLocalRef(env,type_Content);
(*env)->DeleteLocalRef(env,type);
(*env)->DeleteLocalRef(env,post);
}else{
//proxy被修改
}
(*env)->ReleaseStringUTFChars(env,proxy_Type_String, proxy_Type_Str);
(*env)->DeleteLocalRef(env,proxy_Type);
(*env)->DeleteLocalRef(env,proxy_Type_String);
}
(*env)->DeleteLocalRef(env,proxy);
(*env)->DeleteLocalRef(env,url);
(*env)->DeleteLocalRef(env,strUrl);
(*env)->DeleteLocalRef(env,bufferedReader);
(*env)->DeleteLocalRef(env,connection);
if(flag == 1){
break;
}else{
sleep(1);
}
}
(*env)->DeleteLocalRef(env, body_Array);
return result;
}
\ No newline at end of file
//
// Created by MyPC on 2021/4/17.
//
#ifndef MYTESTACC_AESENCODE_H
#define MYTESTACC_AESENCODE_H
void aes_Encoder_Base64(char *src,int src_Len,char** encode_ptr,unsigned int* out_len,char*out_key,char*out_iv );
#endif //MYTESTACC_AESENCODE_H
//
// Created by Fear1ess on 2021/4/25.
//
#ifndef REYUNSDK_HTTPS_H
#define REYUNSDK_HTTPS_H
#include <jni.h>
char* http_PostConnect(JNIEnv *env, char* url, unsigned char* post_Body, size_t len);
#endif //REYUNSDK_HTTPS_H
//
// Created by MyPC on 2021/4/17.
//
#ifndef MYTESTACC_MYBASE64_H
#define MYTESTACC_MYBASE64_H
int Base64Decode(const char *encoded, int encoded_length, char *decoded);
int Base64Encode(const char *src, int src_length, char *encoded);
#endif //MYTESTACC_MYBASE64_H
//
// Created by MyPC on 2021/4/17.
//
#ifndef MYTESTACC_RSAENCODE_H
#define MYTESTACC_RSAENCODE_H
#include "string.h"
void testWriteRSA2PEM();
void rsa_Encoder_Base64(char *src, int src_len, char** out);
#endif //MYTESTACC_RSAENCODE_H
//
// Created by MyPC on 2021/4/17.
//
#include <openssl/base64.h>
int Base64Encode(const char *src, int src_length, char *encoded){
return EVP_EncodeBlock((unsigned char*)encoded, (const unsigned char*)src, src_length);
}
int Base64Decode(const char *encoded, int encoded_length, char *decoded) {
return EVP_DecodeBlock((unsigned char*)decoded, (const unsigned char*)encoded, encoded_length);
}
\ No newline at end of file
...@@ -40,26 +40,7 @@ public class WdMain { ...@@ -40,26 +40,7 @@ public class WdMain {
} }
public void wdRegisterSensor(Context context, SensorManager sm, Sensor sensor) { public void wdRegisterSensor(Context context, SensorManager sm, Sensor sensor) {
sm.registerListener(new SensorEventListener() { sm.registerListener(new WdSensorEventListener(context, sm), sensor, Sensor.REPORTING_MODE_ON_CHANGE);
@Override
public void onSensorChanged(SensorEvent event) {
float[] fArr = event.values;
event.sensor.getType();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fArr.length; i++) {
sb.append(fArr[i] + "");
sb.append(" , ");
}
Log.d(TAG, "onSensorChanged: " + event.sensor.getType() + " --> " + sb.toString());
// onSensorChangedNative(event);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sensor, Sensor.REPORTING_MODE_ON_CHANGE);
} }
public void wdRegisterSensors(Context context) { public void wdRegisterSensors(Context context) {
...@@ -115,9 +96,6 @@ public class WdMain { ...@@ -115,9 +96,6 @@ public class WdMain {
System.loadLibrary("wdun"); System.loadLibrary("wdun");
initNative(context); initNative(context);
//todo 监控传感器数据变化
//todo 监控手机信号强度变化
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
tm.listen(new PhoneStateListener() { tm.listen(new PhoneStateListener() {
@Override @Override
......
package com.reyun.wandun;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;
public class WdSensorEventListener implements SensorEventListener {
private SensorManager mSensorManager;
private Context mContext;
public WdSensorEventListener(Context context, SensorManager sm) {
mSensorManager = sm;
mContext = context;
}
@Override
public void onSensorChanged(SensorEvent event) {
float[] fArr = event.values;
event.sensor.getType();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fArr.length; i++) {
sb.append(fArr[i] + "");
sb.append(" , ");
}
Log.d("WdSdk", "onSensorChanged: " + event.sensor.getType() + " --> " + sb.toString());
// onSensorChangedNative(event);
mSensorManager.unregisterListener(this);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment