-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to hook 'BSD socket' with fishhook tool? #1
Comments
Test on the real phone. Not simulator |
@0x4d4746h I'm not sure, according to some person's tests, the library fishhook of Facebook,Can't hook function of BSD socket like |
And I will confirm in the future whether it is true, thanks @0x4d4746h |
@0x4d4746h I have tested in the machine and simulator, we can hook the |
@aozhimin I am able to hook send() but not connect(). Can pls you confirm? |
@vzrao I'm sure it's ok. I don't know where your problem is. |
@aozhimin Is it possible to share the related .h and .m files? If not, where are these hook_xxx functions defined, in AppDelegate.m or some other individual file? Thanks! |
@vzrao I'm so sorry see your reply now. In fact, you can declare these
|
@aozhimin thank you for replying. I am still not able to see connect() got hooked. my code is to download some pictures like below: NSURLSessionDataTask *imageTask = [session dataTaskWithRequest:request completionHandler:
send() and recvmsg() were hooked/observed. Since these functions use the same header <sys/socket.h> as connect(), they should be in the same library. will connect() happen every time there is network/http request? I doubt connect() is not called at all in my case. But NSURLSessionDataTask eventually will use BSD functions, right? Thanks! |
@vzrao According to my test, when use the NSURLSession API to make HTTP requests, the BSD socket functions will eventually be called, such as
and here is the code for hook method of BSD socket:
The following is the output of the Xcode console:
The following screenshot is from Charles: The IP address The following is a backtrace info:
|
@aozhimin Thank you Zhimin. Are you testing connect() on real device? I was able to see connect() get hooked on emulator but not on real iPhone. what kind of device you test on? Mine is an iPhone 6s with iOS 10.3.3(14G60). I just copied and pasted your code into main.m and ViewController.m (viewDidLoad) with minimum modification: ViewController.m
**main.m //int main(int argc, char * argv[]) { static int (*orig_connect)(int, const struct sockaddr *, socklen_t); static ssize_t (*orig_send)(int, const void *, size_t, int); int hook_connect(int socket, const struct sockaddr addr, socklen_t address_len) { ssize_t hook_send(int socket, const void * buffer, size_t length, int flags) { int main(int argc, char * argv[]) { |
@vzrao Yep, the above test was tested on the simulator, it is only part of the test. I also tested on the real machine. iPhone 5s with iOS 8.1.3. |
|
@vzrao There are some additional explanations. The following is the assembly code of
However, The following is in SE(10.3.2):
As you can see, unlike the iOS simulator, there isn't |
As for
and the output of NSLog statement is as follows:
|
@aozhimin Thank you Zhimin! The high level purpose is to let all the network traffic of specific apps to go through a proxy server (where bytes can be counted). We've looked at Network Extension but it requires managed devices (MDM). Any advice? Thanks! |
@vzrao |
Thank you Zhimin. We tried Personal VPN and all the traffic of our app did went through our proxy. But the problem is that if there are other apps running in background at the same time, those traffic will go through the proxy as well, which is not what we want. |
@vzrao |
Anybody succeed for connect() and send() methods?
The text was updated successfully, but these errors were encountered: