逆向美团电单车随意停放不收调度费的过程

共享单车不仅能解决居民出行“最后一公里”而且具有便捷、环保等优点,但是美团不如安安出行来的便捷,在本人所在的城市安安出行是能够在运营区域内随意停放不用收取额外的调度费用,而美团则是要收取10 ~ 50不等的调度费用,定点停放对于运营方确实是方便了运维但是停车点的不足导致用户使用起来不是很方便,就在前段时间本人被朋友邀请出去喝酒于是就使用了一下美团的共享电单车,但是目的地并没有停车点,于是换车就出现了下面的提示:
IMG_3315.jpg

此时我就在想,一次行程收费2元,再多交10元那么我为什么不叫出租车呢(而且还更舒适,吐槽美团电动车避震真的不行),于是我就使用了一款虚拟定位软件把我的定位修改到附近的停车点,然后点击还车,成功还车不需要多交10元。

第二日

喝完酒回家后第二天醒来,我就在想美团是否只是验证了手机定位来判断你是否在停车点内,于是带着验证的想法我就开始了逆向美团App

逆向全过程

首先我们从越狱手机上dump出文件

iproxy 2222 22
./dump.py 美团

成功dump出ipa文件后解压文件(ipa就是个压缩包)然后dump出头文件

class-dump -S -s -H Payload/imeituan.app -o ./Header

这时候我们就得到了27528个头文件,但是这个量太多了,不可能一个个看过去,得缩小范围,于是我使用Lookin打开分析美团电单车页面,找到该页面的VC为MBKHomeViewController


QQ20200818-024705@2x.png

于是我们打开头文件里名为MBKHomeViewController.h的文件查看


QQ20200818-024947@2x.png

在该头文件里发现一个很可疑属性
@property(retain, nonatomic) MBKMapManager *mapManager;

从这个英文命名来MBKMapManager看应该是管理地图的控制类,这时候大厂的优势就体现出来了,命名规范也方便了逆向... 咳咳咳,也算是副作用吧,于是我们跳进MBKMapManager这个类进去看看


QQ20200818-025233@2x.png

在这个类中我们依然发现了一个很可疑的函数

- (void)mt_mapView:(id)arg1 didSelectAnnotationView:(id)arg2;

因为我们在选择停车点的时候是要点击界面上的🅿️图标的,而Annotation翻译过来是“注解、批注”的意思,那么按照理解这个方法应该是点击了页面上的注解图标的,于是我们先来写个插件验证下,代码如下:

%hook MBKMapManager
- (void)mt_mapView:(id)arg1 didSelectAnnotationView:(id)arg2 {
    %orig;
    
    NSLog(@"iOSRE: mt_mapView: %@ didSelectAnnotationView: %@", [arg1 class], [arg2 class]);
}
%end

编译安装至手机后,重新打开美团App到电单车页面,然后点击一下地图上的🅿️图标,控制台输出了

iOSRE: mt_mapView: MTMapView didSelectAnnotationView: MBKGeoFencingAnnotationView

那么说明我们的判断正确,这个就是点击事件,而从输出来看第一个参数是MapView自身,第二个就是这个停车点的对象,于是我们跳进这个类看看


QQ20200818-025929@2x.png

但是这个类并没有太多内容,可能属性及方法都在父类,于是我们跳进他的父类看看


QQ20200818-030103@2x.png

很遗憾,这个父类并没有关于定位的任何相关属性或方法,于是我们再跳入这个类的父类看看
QQ20200818-030239@2x.png

很幸运,在这个类我们终于发现了一个比较可疑的属性,还记得我们刚才翻译过的“Annotation”单词么,说明这个属性很可能就是记录这个停车点位置的对象,于是我们跳进这个属性进去看看

@property(retain, nonatomic) id <MTAnnotation> annotation; // @dynamic annotation;

不过这个属性的类型为id <MTAnnotation>,从做了一年的iOS开发的我来思考,他很可能是个协议(Protocol),而且头文件里也有MTAnnotation-Protocol.h这个类,于是我们跳进去看看


QQ20200818-030731@2x.png

作为有着一年iOS开发经验的我来说,一看这个coordinate就是定位信息

@protocol MTAnnotation <NSObject>
@property(readonly, nonatomic) struct CLLocationCoordinate2D coordinate;

这已经非常的明显了,接下来我们梳理一下流程

拿到定位信息的流程

MBKHomeViewController -> mapManager -> -[mt_mapView:didSelectAnnotationView:]
-> 第二个参数MBKGeoFencingAnnotationView -> annotation -> coordinate

于是我们在刚才的插件上继续编写代码来进行验证,代码如下:

%hook MBKMapManager
- (void)mt_mapView:(id)arg1 didSelectAnnotationView:(id)arg2 {
    %orig;
    
    if ( [arg2 isKindOfClass:[%c(MBKGeoFencingAnnotationView) class] ]) {
        id annotation = [arg2 valueForKey:@"annotation"];
        NSLog(@"iOSRE: annotation: %@", annotation);
        id coor = [annotation valueForKey:@"coordinate"];
        NSLog(@"iOSRE: coor: %@ - %@", [coor class], coor);
    }
}
%end

然后编译安装到手机,重新打开美团App进入电单车页面并点击地图上🅿️图标,控制台输出了

iOSRE: annotation: <MBKGeoFencingAnnotation: 0x28156b3a0>
iOSRE: coor: NSConcreteValue - {length = 16, bytes = 0x99666b43860d3a4087bed79d6acd5d40}

看到这里,发现有点不对,按照我们刚才梳理的逻辑,这个coor应该是CLLocationCoordinate2D类型才对,但是从打印结果来看他是NSConcreteValue,这时候有点懵,按照class-dump导出的头文件来看他正常应该是CLLocationCoordinate2D类型才对,难道是class-dump导出错误或者是我们分析错误?

在查阅了大量资料以及询问其他iOS开发后,我发现他可能是NSKeyValueCoding,于是抱着死马当活马医的态度我打算进行尝试,毕竟我做iOS开发也没多久没太多经验,于是编写代码如下:

%hook MBKMapManager
- (void)mt_mapView:(id)arg1 didSelectAnnotationView:(id)arg2 {
    %orig;
    
    if ( [arg2 isKindOfClass:[%c(MBKGeoFencingAnnotationView) class] ]) {
        id annotation = [arg2 valueForKey:@"annotation"];
        NSLog(@"iOSRE: annotation: %@", annotation);
        id coor = [annotation valueForKey:@"coordinate"];
        NSLog(@"iOSRE: coor: %@ - %@", [coor class], coor);
        struct CLLocationCoordinate2D cll;
        [coor getValue:&cll];
        NSLog(@"iOSRE: arg2: cll: latitude: %f longitude: %f", cll.latitude, cll.longitude);
}
%end

再次编译安装到手机,运行美团App进入电单车页面点击地图上🅿️图标,控制台输出了

iOSRE: annotation: <MBKGeoFencingAnnotation: 0x28156b3a0>
iOSRE: coor: NSConcreteValue - {length = 16, bytes = 0x99666b43860d3a4087bed79d6acd5d40}
iOSRE: arg2: cll: latitude: 26.xxxxx longitude: 119.xxxxxx

oooooooooh!! 看到这最后一行输出,难道我们成功了么,于是我们改造代码如下:

%hook MBKMapManager
- (void)mt_mapView:(id)arg1 didSelectAnnotationView:(id)arg2 {
    %orig;
    
    if ( [arg2 isKindOfClass:[%c(MBKGeoFencingAnnotationView) class] ]) {
        id annotation = [arg2 valueForKey:@"annotation"];
        id coor = [annotation valueForKey:@"coordinate"];
        struct CLLocationCoordinate2D cll;
        [coor getValue:&cll];
        
        UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"当前选择位置" message:[NSString stringWithFormat:@"纬度: %f\n经度: %f\n\n建议/bug反馈QQ: 1451925/656469762", cll.longitude, cll.latitude] preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * setparking = [UIAlertAction actionWithTitle:@"设置为🅿️" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            lat = cll.latitude;
            lng = cll.longitude;
        }];
        UIAlertAction * unSetparking = [UIAlertAction actionWithTitle:@"取消🅿️" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            lat = 0;
            lng = 0;
        }];
        UIAlertAction * copy1 = [UIAlertAction actionWithTitle:@"复制纬度" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIPasteboard.generalPasteboard.string = [NSString stringWithFormat:@"%f", cll.latitude];
        }];
        UIAlertAction * copy2 = [UIAlertAction actionWithTitle:@"复制经度" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIPasteboard.generalPasteboard.string = [NSString stringWithFormat:@"%f", cll.longitude];
        }];
        UIAlertAction * cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:setparking];
        [alert addAction:unSetparking];
        [alert addAction:copy1];
        [alert addAction:copy2];
        [alert addAction:cancel];
        
        [UIApplication.sharedApplication.delegate.window.rootViewController presentViewController:alert animated:YES completion:nil];
    }
}
%end

再次编译安装到手机,此时点击地图上的🅿️图标,弹窗正常弹出来了


IMG_3318.JPG

此时点击“设置为🅿️”后,看见我们的定位确确实实改变到了点击的停车点位置,并且在出门实验后在一个不能还车的地点进行操作后还车,也确实不需要收取10元手续费; 到这里已经成功破解美团的停车点限制了,再次吐槽美团不严谨,仅仅只是验证手机定位。

Ps: 由于涉及内容过多,上述的代码均为部分代码,非完整代码,不过会逆向的应该能自己Copy一份书来。

最后插件下载地址: https://wwa.lanzous.com/iSYmgfqmxqh
(不保证该插件能使用多久,毕竟公开出来肯定就会被处理)

我是亚里亚,我的梦想是成为一个不秃头的安全工程师,那么下期见。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。