Android USB reverse tethering: How to fool the apps - android

USB reverse tethering = Cellphone gets network connection from PC via USB.
I know how to do USB reverse tethering except for one problem: Many Android apps will check network connection using the code below before doing any useful work:
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
The problem is that, when using USB reverse tethering, the above code will report no network connection. However, there IS a network connection (which is the USB reverse tethering itself), and ping, wget and all programs not doing this stupid check work well.
So the question is: How can I hack the system to let this network connection check return success (so that I can fool these apps)?
BTW. I use Cyanogenmod 7. And any solution specific to this MOD is also welcome.

If you are doing this much hacking I am assuming that you will probably have your device rooted. If so program a shell interface to send commands to the device shell with JNI and receive STDOUT. Use this interface to run a netcfg command that can be parsed into an array - this will give you all the details the API hides. It also allows you to override Androids device settings using the ipconfig command.
As far as using this to send and receive from your device - in my experience - you will have to probably compile a device specif module that can be loaded into the kernel at run time. Or just download the kernel from the manufacturer and compile the module into the kernel and then flash the phone with the new custom kernel.
Hope this helps.

To do this , you have to download ReverseTethering_3.19.zip file (Google it to find the link.)
Extract to your desired location.
Prerequisite: -
only rooted phones work.
USB debugging should be enabled.
Now connect your rooted android mobile to PC through USB cable.Wait for PC to recognize your mobile. Now open the extracted zip file and open AndroidTool.exe with admin rights.
Now click connect in the android tool.
Now it tries to connect and installs USB tunneling apk on your device.It also asks for super user rights . Grant it.
Finally after successfully establishing the connection, you will see.
https://drive.google.com/file/d/0B11p07T8VxhNNUdIM3gtTFR4N3M/view?usp=sharing
(Sorry, I cant upload image.)
Now you get the internet on your mobile and usb tunneling app is installed.But you can access only HTTP connections(i.e;) works only in chrome. Play store apps may not work.
So you have to fool apps and make it believe that either is mobile is connected to WiFi or mobile data . Only then apps work.
So you have to go to Tools menu in Android tool.
https://drive.google.com/file/d/0B11p07T8VxhNRXR3aTVUZUl1dVk/view?usp=sharing
Now install hack(optional).It installs Xposed framework and installs hack connectivity apk. Just follow the instructions , it is easy.
Hack connectivity makes the apps believe that mobile is connected to WiFi or mobile data depending on which type of hack u did after installing Hack connectivity. Finally after hacking ,it asks for reboot. After reboot , you can enjoy internet using USB reverse tethering on all apps.

Related

How to Monitor CPU/Memory/GPU Usage of an Android Device without Connecting it to a PC?

Based on my understanding of Android Monitor, an Android device needs to be connected to the machine that is running Android Studio in order to profile CPU/memory/GPU usage. Are there any methods that allow profiling an app without connecting it to the PC? For example, writing the debug info that is generated for Android Monitor in a file and process the file later?
My goal is to gather debugging information without connecting the Android device to a PC (either via a USB cable or over the network).
Your initial work with a device usually needs to be over USB. However, after that point, you can switch using adb over the network, using adb connect. Once you have adb connected over the network, everything works just as if you had connected it via USB, including full Android Studio access.
Bear in mind that:
Some devices do not need the initial USB connection, as they are designed to work with adb over the network "out of the box" (e.g., Fire TV)
I think that older devices may not support this, for some value of "older"
You cannot monitor it without an active debugging connection. That being said, debugging connection isn't limited to USB. You need some kind of connection, and that connection can be USB, but it can also be over the internet(refer How can I connect to Android with ADB over TCP?).
Some devices don't support this, some have a setting for it in developer settings, and using root you don't need a connection. For devices that support adb over the internet, but aren't rooted or have the setting in developer settings, you need to have a usb connection initially.

How to use 3G network when connected to a WiFi network with no internet access?

sometimes I have to connect my Nexus 5 to a WiFi network only to share some files with other devices, but this network does not have Internet access. I would like to use 3G for data connection while the phone is connected. Obviously I have root access. Is there any way to achieve this? (Not necessary a simple way)
My phone isn't rooted and I don't have a shell installed on it to test, but off the top of my head maybe this could help?
route -n - determine what routes are available
route add default gw <<ip address>> - replace with the gateway's IP address that you want to be the default. Make sure to run this command as root or with sudo.
I'm not familiar with Android shell access or the internals of how Android manages its networking. For all I know, the entire 3G Internet connection may shut down by default when you are on wifi. If all else fails, you could also consider a "mobile hotspot" app for your phone, and have the devices connect to you (as a bonus, they would have Internet access too).
More information on viewing default gateway with route command

I need to debug my Android app while not plugged into my computer

So, let me start off by saying that I am 'relatively' familiar and comfortable with making Android apps and using both LogCat and DDMS to debug.
That being said, I'm encountering more of a logistical issue than anything else right now - I am making a locative app, where the GPS is fuelling and controlling other methods in my Activity, and after a while, it is crashing.
Now, because it is locative, I am walking around to test it, in order to receive different GPS locations. Because of this, I am not connected to my computer at the time that it crashes, so have no way (that I know of) to read the stack trace, etc.
In my particular instance, I am navigating through a series of activities, and finally reach the penultimate screen in my app, and while I am running the application in my studio, it runs indefinitely without issue. It is only when I take the device outside that it crashes...
I am wondering if anyone has any tips or tricks with this issue - I'm sure give the prevalence of locative apps, it must have come up, but I cant seem to find the right search terms. It could be as simple as saving the LogCat to file, and/or the stackTrace, but I'm not sure that's the answer...
Thanks in advance.
If I got you right, this is what you are looking for:
https://play.google.com/store/apps/details?id=org.jtb.alogcat&hl=de
Edit: Also there are many more apps like this. You can just browse around in Google Play Store
You can debug the app without rooting your android, unlike the other responses. start off by plugging the android into your computer, then run adb devices to make sure the device is there. Then, run tcpip 5555 to change the android to tcp mode, which will allow debugging over wifi. Disconnect the android from the computer, and connect to it by typing adb 192.168.x.xxx, replacing the x's with your android's IP address. It should connect with no issues, as long as port 5555 is open, and both the android and your computer is on the same wifi.
Simple: Wireless ADB
One of the reason that I choose to run CyanogenMod on my testing devices is that it is a stripped down version of Android that has some additional developer tools, one of those being the ability to access the wireless portion of the ADB system.
As you are probably unaware, you are able to establish an ADB connection to your device over WiFi, however, if running a stock ROM, this requires root access, as it can be potentially harmful to your device, as Wireless ADB will work even over your cellular network, meaning that you could potentially receive apps from other insert carrier here's devices.
If you wish to run WirelessADB, here is a Play Store app that will help you to enable the feature on your device. Requires ROOT
It is as simple as connecting your device to your local WiFi network, (same one the development computer is connected to), enable Wireless ADB, and then running the following command on your computer:
adb connect 192.168.1.101
Replacing 192.168.1.101 with the IP address of your android device.
By establishing this connection, you can run everything just as you would if the device was plugged in via USB Cable.
I recommend ACRA (Application Crash Reports for Android ). It allows you to send crash reports to a number of different destinations. See https://github.com/ACRA/acra/wiki/BasicSetup

Usb tether and debug at the same time

I need network connection on my Android device to test apps. My notebook WiFi adapter is broken, so after 2 hours I've set connection via USB. But! Eclipse doesn't see the device when I start "Wired Tether" on it to get connection and I can't debug my apps.
Does anybody know how to solve this issue? Use USB tethering to get internet connection on phone and debug apps at the same time?
I don't know of a way to simultaneously use USB debugging and tethering. Here are some workarounds, though:
Get a USB wireless adapter for your computer (see http://www.amazon.com/gp/bestsellers/electronics/13983791/ref=pd_zg_hrsr_e_2_4_last). I don't know if buying one of these is an option for you in India.
Send your apk to your phone wirelessly for app installation (see Developing on android-based device via wireless) and then view the logcat directly on the phone for debugging (aLogcat seems to be popular, and allows you to send log files via, for example, email, so that you can open them on your computer to view them on a bigger screen)
I know these solutions involve some cost, effort, or inconvenience, but hopefully one will work for you.
EDIT:
As noted in answers from #shkschneider and #CodeShane, Internet sharing via Bluetooth is possible. CodeShane's answer mentions PdaNet (which apparently also allows for simultaneous USB tethering and debugging), and includes a link. Another solution is OpenGarden. These solutions provide access to the Internet for the computer via the phone. If the reverse is desired (and this is not entirely clear from the question), reverse tethering seems to be the answer (see the answer from #NickL).
Long story short: you can't. Android simply does not supports it (that is more because of the USB standard and tethering action than AOSP's fault).
So to go around the problem, you should either:
Get internet form another source
Maybe you could have ethernet connection?
Tether internet from your phone to your netbook in another way
You can't use wireless tether since your wifi adapter is broken, but maybe you could tether using bluetooth?
Debug your phone in another way
Maybe you could use an android application like aLogCat or similar?
But in the hand, sorry, you can't tether usb from phone to netbook while usb debugging from the netbook. Your success will depend on your ability to find an alternative solution.
I would like to point out that I am using PDANet for USB-tethered internet to type this reply while I am also debugging an android application on the same phone via Eclipse Juno. Not sure which side fixed this, but it is awesome!
As for why Eclipse isn't seeing your device, standard troubleshooting tips apply .. make sure to enable USB debugging and unknown sources/3rd party apps, try restarting, check usb drivers, update drivers/eclipse..
Device not detected in Eclipse when connected with USB cable
http://developer.android.com/tools/device.html
Eclipse not finding phone
PdaNet 3.5
Eclipse Juno Service Release 1; Build id: 20120920-0800
You can use bluetooth tethering to get internet connection and debug using USB.
Step 1. Turn off USB tethering
Step 2. Turn on Wireless USB Debugging
Connect to your device via USB
Enter "adb tcpip 5555"
Unplug your device
Look up your device's IP in the system settings
Enter "adb connect [ip address]:5555"
Step 3. Turn on USB tethering
Now you can use internet via USB cable and debug app in wireless mode
That's it!
Yes, its possible. There's a hack available at below links !
Source: HowToGeek , StackOverFlow
You can actually connect the adb to the phone via TCP. You may need a rooted phone for this to work, though
If I understand your question correctly, you want to tether your phone to the PC via USB, and use the (internet)connection of your PC + still get logcat output?
Then yes, this certainly is possible.Tethering is when your PC uses the internet of your phone, the other way around is called reverse tethering. Your device has to be rooted, then you can use this application for reverse tethering.
When you connect your phone to the computer via USB, you press 'connect' in the application. It then installs an app on your phone, which handles the reverse tethering connection. It works, I sometimes have to press 'check DNS' while it is connecting to make it working.. but it works! Also debugging via USB works the usual way.
First you need to debug your device using USB cable then type adb tcpip 5555 it will allow debugging via TCP/IP protocol.
After that turn on your USB tethering, now your computer get internet connection but lost the USB debugging.
Now you must know your phone IP address so you can debug via TCP/IP. You can use command arp -a in terminal and look at the gateway address.
The last is connect to your phone using adb connect yourphoneip:5555 for example adb connect 192.168.42.129:5555
Now you get debug and tether at the same time
You can use
WiFi Tethering - For Internet connection
Connect USB for adb.

Capturing mobile phone traffic on Wireshark

How can I capture mobile phone traffic on Wireshark?
Here are some suggestions:
For Android phones, any network: Root your phone, then install tcpdump on it. This app is a tcpdump wrapper that will install tcpdump and enable you to start captures using a GUI. Tip: You will need to make sure you supply the right interface name for the capture and this varies from one device to another, eg -i eth0 or -i tiwlan0 - or use -i any to log all interfaces
For Android 4.0+ phones: Android PCAP from Kismet uses the USB OTG interface to support packet capture without requiring root. I haven't tried this app, and there are some restrictions on the type of devices supported (see their page)
For Android phones: tPacketCapture uses the Android VPN service to intercept packets and capture them. I have used this app successfully, but it also seems to affect the performance with large traffic volumes (eg video streaming)
For IOS 5+ devices, any network: iOS 5 added a remote virtual interface (RVI) facility that lets you use Mac OS X packet trace programs to capture traces from an iOS device. See here for more details
For all phones, wi-fi only: Set up your Mac or PC as a wireless access point, then run wireshark on the computer.
For all phones, wi-fi only: Get a capture device that can sniff wi-fi. This has the advantage of giving you 802.11x headers as well, but you may miss some of the packets
Capture using a VPN server: Its fairly easy to set-up your own VPN server using OpenVPN. You can then route your traffic through your server by setting up the mobile device as a VPN client and capture the traffic on the server end.
In addition to rupello's excellent answer, a "dirty" but very effective trick:
For all phones, any (local) network: Set up your PC to Man-In-The-Middle your mobile device.
Use Ettercap to do ARP spoofing between your mobile device and your router, and all your mobile's traffic will appear in Wireshark. See this tutorial for set-up details
Another option which has not been suggested here is to run the app you want to monitor in the Android emulator from the Android SDK. You can then easily capture the traffic with wireshark on the same machine.
This was the easiest option for me.
Wireshark + OSX + iOS:
Great overview so far, but if you want specifics for Wireshark + OSX + iOS:
install Wireshark on your computer
connect iOS device to computer via USB cable
connect iOS device and computer to the same WiFi network
run this command in a OSX terminal window: rvictl -s x where x is the UDID of your iOS device. You can find the UDID of your iOS device via iTunes (make sure you are using the UDID and not the serial number).
goto Wireshark Capture->Options, a dialog box appears, click on the line rvi0 then press the Start button.
Now you will see all network traffic on the iOS device. It can be pretty overwhelming. A couple of pointers:
don't use iOS with a VPN, you don't be able to make sense of the encrypted traffic
use simple filters to focus on interesting traffic
ip.addr==204.144.14.134 views traffic with a source or destination address of 204.144.14.134
http views only http traffic
Here's a sample window depicting TCP traffic for for pdf download from 204.144.14.134:
For Android phone I used tPacketCapture:
https://play.google.com/store/apps/details?id=jp.co.taosoftware.android.packetcapture&hl=en
This app was a lifesaver I was debugging a problem with failure of SSL/TLS handshake on my Android app. Tried to setup ad hoc networking so I could use wireshark on my laptop. It did not work for me. This app quickly allowed me to capture network traffic, share it on my Google Drive so I could download on my laptop where I could examine it with Wireshark! Awesome and no root required!
Packet Capture Android app implements a VPN that logs all network traffic on the Android device. You don't need to setup any VPN/proxy server on your PC. Does not needs root. Supports SSL decryption which tPacketCapture does not. It also includes a good log viewer.
Preconditions: adb and wireshark is installed on your computer and you have a rooted android device.
Download tcpdump to ~/Downloads
adb push ~/Downloads/tcpdump /sdcard/
adb shell
su root
mv /sdcard/tcpdump /data/local/
cd /data/local/
chmod +x tcpdump
./tcpdump -vv -i any -s 0 -w /sdcard/dump.pcap
CTRL+C after you've captured enough packets.
exit
exit
adb pull /sdcard/dump.pcap ~/Downloads/
Now you can open the pcap file using Wireshark.
Install Fiddler on your PC and use it as a proxy on your Android device.
Source: http://www.cantoni.org/2013/11/06/capture-android-web-traffic-fiddler
Similarly to making your PC a wireless access point, but can be much easier, is using reverse tethering. If you happen to have an HTC phone they have a nice reverse-tethering option called "Internet pass-through", under the network/mobile network sharing settings. It routes all your traffic through your PC and you can just run Wireshark there.
Make your laptop a wifi hotspot for your phone (any) and connect it to internet. Sniff Traffic on your wifi interface using wireshark.
you will get to know a lot of anti privacy stuff!
As a Wireshark alternative/companion for Android, you can try my open source app PCAPdroid. On non-rooted devices, it uses the VPNService to capture the traffic with some limitations. On rooted devices, it works like a user-friendly tcpdump.
You can analyze connections and packets payload directly into the app, or export the traffic in PCAP format to analyze it on a PC with Wireshark. It has many other cool features, give it a try!
For Android, I previously used tPacketCapture but it didn't work well for an app streaming some video. I'm now using Shark. You need to be root to use it though.
It uses TCPDump (check the arguments you can pass) and creates a pcap file that can be read by Wireshark. The default arguments are usually good enough for me.
I had a similar problem that inspired me to develop an app that could help to capture traffic from an Android device. The app features SSH server that allows you to have traffic in Wireshark on the fly (sshdump wireshark component). As the app uses an OS feature called VPNService to capture traffic, it does not require the root access.
The app is in early Beta. If you have any issues/suggestions, do not hesitate to let me know.
Download From Play
Tutorial in which you could read additional details
For iOS Devices:
⦿ Open Terminal and simply write:
rvictl -s udid
it'll open an interface on Wireshark with a name, In my case its rvi0.
udid is iPhone's unique device id.
(How to find my iOS Device UDID)

Categories

Resources