携程旅行app数据采集

携程旅行app数据采集

目标:通过协议方式采集携程旅行app 酒店客房价格及酒店静态资料

jadx反编译

在这里插入图片描述

抓包分析

通过charles或FD发现无法正常抓包,通过wireshark抓包得知采用的是基于TCP的私有协议。

经过大量分析得出结论:SOTPConnection 中负责通讯请求,


private boolean sendRequest(j jVar) throws Exception {
    
    
        if (ASMUtils.getInterface("b009009091d7678cf389322a73af7974", 5) != null) {
    
    
            return ((Boolean) ASMUtils.getInterface("b009009091d7678cf389322a73af7974", 5).accessFunc(5, new Object[]{
    
    jVar}, this)).booleanValue();
        }
        long currentTimeMillis = System.currentTimeMillis();
        try {
    
    
            jVar.b(jVar.G() + 1);
            jVar.a.add("4");
            Executors.buildRequest(jVar);
            currentTimeMillis = System.currentTimeMillis();
            if (checkTaskCancel(jVar)) {
    
    
                finishTask(jVar);
            }
            if (jVar.K()) {
    
    
                if (this.socket != null) {
    
    
                    byte[] y = jVar.y();
                    OutputStream outputStream = this.socket.getOutputStream();
                    outputStream.write(y);
                    outputStream.flush();
                    jVar.a.add(Constants.VIA_REPORT_TYPE_SHARE_TO_QZONE);
                    jVar.j(System.currentTimeMillis());
                    jVar.e(System.currentTimeMillis() - currentTimeMillis);
                    jVar.l(System.currentTimeMillis());
                    return true;
                }
            }
            jVar.j(System.currentTimeMillis());
            jVar.e(System.currentTimeMillis() - currentTimeMillis);
            jVar.l(System.currentTimeMillis());
            return false;
        } catch (Exception e) {
    
    
            throw e;
        } catch (Throwable th) {
    
    
            jVar.j(System.currentTimeMillis());
            jVar.e(System.currentTimeMillis() - currentTimeMillis);
            jVar.l(System.currentTimeMillis());
        }
    }

通过自定义抓包工具,从此处获取请求与响应的数据包。

请求与响应解码

通过调试分析得知,ProcoltolHandle 负责序列化与反序列化,具体逆向过程不细表。
不同版块的序列化方式不一样,在下面这个类中定义了整个app涉及的序列化方式

public enum CommEncodingType {
    
    
    None,
    Normal,
    UTF8,
    PB,
    Json,
    SotpPB,
    SotpJson,
    PBSotp,
    PBJson,
    JsonSotp,
    JsonPB,
    GraphQL
}

通讯协议整体比较复杂,涉及Gzip压缩、aes加密以及自定义请求头,需要大量时间精力还原。

加解密逆向分析

涉及的加解密在EncodeUtil中实现,

    public native byte[] cd(byte[] bArr, int i);

    public native byte[] ce(byte[] bArr, int i);

是本地方法实现的,通过以下代码

static {
    
    
        try {
    
    
            System.loadLibrary("ctripenc");
        } catch (Throwable th) {
    
    
            if (!classVerify) {
    
    
                th.printStackTrace();
                System.loadLibrary("ctripenc");
            }
        }
    }

可得知,是在ctripenc so文件中实现,打开lib/armeabi 可看到

在这里插入图片描述
需要将cd、ce方法还原出来。

编写调用客户端测试

 public static void testHotelRoomListRequest(int hotelID, String checkInDate, String checkOutDate) throws Exception {
    
    
        RequestDataBean requestDataBean = buildHotelRoomListRequest(hotelID,checkInDate,checkOutDate);
        byte[] totalData = requestDataBean.totelData;
        byte[] responseBodyData = send2ctrip(totalData);
        HotelRoomListResponse hotelRoomListResponse = new HotelRoomListResponse();
        ProtobufIOUtil.mergeFrom(responseBodyData, hotelRoomListResponse, HotelRoomListResponse.getSchema());
        System.out.println(JSON.toJSONString(hotelRoomListResponse));
    }

写一个main方法执行一下即可获取到价格列表

在这里插入图片描述

价格列表的json内容比较大,下面摘取价格部分内容作展示

"priceInfoList": [
        {
    
    
          "avgPrice": "224",
          "avgPriceAfterDiscount": "224",
          "avgPriceAfterDiscountIncludeTax": "224",
          "avgPriceIncludeTax": "224",
          "avgTax": "0",
          "cashBackAvgAmount": "0",
          "cashBackTotalAmount": "0",
          "currencyCode": "RMB",
          "primeDiscount": "0",
          "totalDays": 1,
          "totalPrice": "224",
          "totalPriceAfterDiscount": "224",
          "totalPriceAfterDiscountIncludeTax": "224",
          "totalPriceIncludeTax": "224",
          "totalTax": "0"
        }
      ]

猜你喜欢

转载自blog.csdn.net/super19911115/article/details/120049453