3

I have a webserver that is running on my pc. I am developing an android app that is tested on AVD emulator. The emulator uses IP address 10.0.2.2 to access localhost on the hosting machine. That way, everything works well.

However, what I would like to do is install Wireshark on my PC and capture the network traffic between Android app and Web Server on my PC.

This can't be done when using address 10.0.2.2, you need to use the IP of your Web Server insted.(Web server is only in local, it doen't have public IP).

The problem is that in our network, all the PCs have a local address from the 10.x.x.x range. So, when trying to connect to my PCs local IP that is 10.a.b.c, the connection fails because the Emulator also uses that same address space.

What would be the easiest way to solve this?

Changing my PCs local IP is not an option.

Edit: I found a way to change the subnet that the emulator is using. I found out that Android uses quemu. After reading this, I started the emulator from the command line with this command:

emulator @Nexus_5X_API_25 -qemu -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9

The eumlator starts but I get the following Warning: Warning: netdev mynet0 has no peer

And when I check the IP of the Android device using adb shell, I see that the device IP is still 10.0.2.15, so it still uses 10.0.2.x address space, not 192.168.x.x as I expected.

I found this note in the quemu documentation, but couldn't find what are the other parameters that need to be added to the command: Note - if you specify any networking options on the command line (via -net or -netdev) then QEMU will require you to provide options sufficient to define and connect up both parts. (Forgetting to specify the backend or the network device will give a warning message such as "Warning: netdev mynet0 has no peer", "Warning: vlan 0 is not connected to host network" or "Warning: vlan 0 with no nics"; the VM will then boot but will not have functioning networking.)

EDIT2: I changed the command to look like this and now there is no warning: @Nexus_5X_API_25 -debug init -qemu -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9 -device virtio-net-pci,netdev=mynet0

However, it's still not working and that is beacause emulator.exe fails to override netdev command of qemu and appends it to the end instead, so the network settings stay the same.

Here is the generated QEMU option list:

emulator: argv[00] = "C:\Users\nikola\AppData\Local\Android\sdk\emulator/qemu/windows-x86_64/qemu-system-i386.exe"
emulator: argv[01] = "-dns-server"
emulator: argv[02] = "xx.xx.xx.xx,xx.xx.xx.xx,xx.xx.xx.xx,xx.xx.xx.xx"
emulator: argv[03] = "-serial"
emulator: argv[04] = "null"
emulator: argv[05] = "-cpu"
emulator: argv[06] = "android32"
emulator: argv[07] = "-enable-hax"
emulator: argv[08] = "-smp"
emulator: argv[09] = "cores=2"
emulator: argv[10] = "-m"
emulator: argv[11] = "1536"
emulator: argv[12] = "-lcd-density"
emulator: argv[13] = "420"
emulator: argv[14] = "-kernel"
emulator: argv[15] = "C:\Users\xxx\AppData\Local\Android\sdk/system-images\android-25\google_apis\x86\/kernel-ranchu"
emulator: argv[16] = "-initrd"
emulator: argv[17] = "C:\Users\xxx\AppData\Local\Android\sdk/system-images\android-25\google_apis\x86\/ramdisk.img"
emulator: argv[18] = "-object"
emulator: argv[19] = "iothread,id=disk-iothread"
emulator: argv[20] = "-drive"
emulator: argv[21] = "if=none,overlap-check=none,cache=unsafe,index=0,id=system,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd\system.img.qcow2,read-only"
emulator: argv[22] = "-device"
emulator: argv[23] = "virtio-blk-pci,drive=system,iothread=disk-iothread,modern-pio-notify"
emulator: argv[24] = "-drive"
emulator: argv[25] = "if=none,overlap-check=none,cache=unsafe,index=1,id=cache,file=C:\Users\nikola\.android\avd\Nexus_5X_API_25.avd/cache.img.qcow2,l2-cache-size=1048576"
emulator: argv[26] = "-device"
emulator: argv[27] = "virtio-blk-pci,drive=cache,iothread=disk-iothread,modern-pio-notify"
emulator: argv[28] = "-drive"
emulator: argv[29] = "if=none,overlap-check=none,cache=unsafe,index=2,id=userdata,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/userdata-qemu.img.qcow2,l2-cache-size=1048576"
emulator: argv[30] = "-device"
emulator: argv[31] = "virtio-blk-pci,drive=userdata,iothread=disk-iothread,modern-pio-notify"
emulator: argv[32] = "-drive"
emulator: argv[33] = "if=none,overlap-check=none,cache=unsafe,index=3,id=sdcard,file=C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/sdcard.img.qcow2,l2-cache-size=1048576"
emulator: argv[34] = "-device"
emulator: argv[35] = "virtio-blk-pci,drive=sdcard,iothread=disk-iothread,modern-pio-notify"
emulator: argv[36] = "-netdev"
emulator: argv[37] = "user,id=mynet"
emulator: argv[38] = "-device"
emulator: argv[39] = "virtio-net-pci,netdev=mynet"
emulator: argv[40] = "-netdev"
emulator: argv[41] = "user,id=mynet2,net=10.0.3.0/24"
emulator: argv[42] = "-device"
emulator: argv[43] = "virtio-net-pci,netdev=mynet2"
emulator: argv[44] = "-show-cursor"
emulator: argv[45] = "-L"
emulator: argv[46] = "C:\Users\xxx\AppData\Local\Android\sdk\emulator/lib/pc-bios"
emulator: argv[47] = "-soundhw"
emulator: argv[48] = "hda"
emulator: argv[49] = "-vga"
emulator: argv[50] = "none"
emulator: argv[51] = "-netdev"
emulator: argv[52] = "user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9"
emulator: argv[53] = "-device"
emulator: argv[54] = "virtio-net-pci,netdev=mynet0"
emulator: argv[55] = "-append"
emulator: argv[56] = "qemu=1 androidboot.hardware=ranchu clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=1 ndns=4"
emulator: argv[57] = "-android-hw"
emulator: argv[58] = "C:\Users\xxx\.android\avd\Nexus_5X_API_25.avd/hardware-qemu.ini"

I replaced all the sensitive data with xxx

iehrlich
  • 3,524
  • 4
  • 30
  • 42
user3362334
  • 1,441
  • 1
  • 15
  • 36
  • found here something that might be useful for you! http://stackoverflow.com/questions/9555403/capturing-mobile-phone-traffic-on-wireshark – Queky Mar 24 '17 at 09:38
  • Thank for the link. I already read that. However, The methods suggested concentrate on phisical Android devices, not emulators. And almost all of the suggestions requires WiFi – user3362334 Mar 24 '17 at 09:47

1 Answers1

0

You could use something like this using the redir tool:

redir --laddr=10.xx.xx.xx --lport=5555 --caddr=127.0.0.1 --cport=5555 redir --laddr=10.xx.xx.xx --lport=5555 --caddr=127.0.0.1 --cport=5555 redir --laddr=10.xx.xx.xx --lport=5037 --caddr=127.0.0.1 --cport=5037

ApriOri
  • 2,498
  • 27
  • 43