Adb: How to setup dns servers? - android

I need to configure network on an android automotive though the usb0 interface in static ip so I configured the network like that:
ifconfig usb0 192.168.1.137
ifconfig usb0 down
iptables --flush
iptables -A OUTPUT -o usb0 -p all -j ACCEPT
iptables -A INPUT -o usb0 -p all -j ACCEPT
ifconfig usb0 up
ip route add default via 192.168.1.1
and with that I can ping my devices in LAN and also 8.8.8.8 who respond in ping but I cannot for example ping google.com because of an DNS issue (I think). I found setprop net.dns1 8.8.8.8 on internet but that does not work. Also I don't have a /system/etc/resolv.conf. So if you have any idea tell me. Thanks.

Related

How to change frida server port in android?

By default, the frida-server in android, after installing, runs on port 27042 (127.0.0.1:27042). How can I change this port number to something else like 567 (127.0.0.1:567)? Is there any way?
Since Frida version 6.2.6, you can connect to specific IP/port like this :
# connect to specific IP/port
$ frida-trace -H ip:port -i "open*"
Sample :
$ frida-trace -H 192.168.1.1:1234 -i "open*"
Set Frida-Server on Host to all interfaces and non-default port
frida-server -l 0.0.0.0:19999 &
Call Frida-Server from Host
frida-ps -ai -H 192.168.0.38:19999
frida-server -l 127.0.0.1:567 &
where the interface address and port number are as you specified.
You can also use the all-interfaces IP address 0.0.0.0
frida-server -l 0.0.0.0:567 &
and then it will listen on port 567 on all interfaces, including 127.0.0.1

RPI3 PIXEL Jessie - usb0 interface

Greetings to everyone!
I have a project on RPI but I have 1 problem.
Project description: RPI (server, connected to LAN DHCP with internet access) + Android Tablet (connects on USB0 static interface on RPI via USB Tethering).
Android App: Made an android APP to connect to server and manage RPI as client via sockets and ajax requests.
Problem: I have made five examples of same thing with 5 tablets and 5 RPI-i and USB0 is being seen by LAN Router and the problem is that I want nobody from LAN (not even another tablet) can connect to USB0 but that tablet connected to RPI with USB Tethering. Now how 5 devices is connected to LAN sometimes happens that tablet from RPI1 connects via LAN to RPI2 beacuse USB0 can be seen on LAN.
I want that USB0 is not seen on LAN but can give internet to tablet via eth0.
Currently I'm giving USB0 internet like this:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE && sudo iptables -A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT && sudo iptables -A FORWARD -i usb0 -o eth0 -j ACCEPT
I would really be glad if somebody could help me I'm not so good in configuring network interfaces
Check out this project. parts of it are probably quite useful for you.
https://github.com/samyk/poisontap/blob/master/pi_startup.sh

Bash Scripting, Android, forward a specific port incoming on tun0 to wlan0 to Local PC

I have this script running on boot (as root) on my phone and cycling on a timer to make my wifi hotspot send data through a PIA VPN(tun0). PIA will assign a single port allowed to be used for port forwarding and I now want to forward that assigned port to a tethered PC which is connected to the wifi hotspot (wlan0). The PC's local IP address is 192.168.1.252 (hotspot assigned) and the port number is 40212 (PIA assigned). Is there a way to add that routing to this script?
Additional Info:
$ netcfg
wlan0 UP 192.168.1.1/24
lo UP 127.0.0.1/8
tun0 UP 10.100.1.6/30
rmnet UP xx.xxx.xxx.xxx/xx #Didn't want phone's external(?) IP online.
Script:
while sleep 30; do
iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -j MASQUERADE
iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 8.8.8.8
ip rule add from 192.168.1.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.1.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61

Reverse tethering of several Android devices via USB

I'm trying to setup a testing environment for my android app where the separate devices need an Internet connection, but don't have wireless capabilities.
So I decided on using usb reverse tethering. My host machine is running Ubuntu. I already managed to setup reverse tethering for one device, the connection is working and I can ping google.com from this device's adb shell.
When I connect a second device, the first tethering stops working.
Both devices have the same IP adress configured on their internal usb0 interface.
Here's what I have so far:
Port forwarding on host is activated
echo 1 > /proc/sys/net/ipv4/ip_forward
Iptables rule on host to route traffic:
iptables -t nat -A POSTROUTING -s 169.254.255.2/24 -j MASQUERADE
Plugin first device:
ifconfig shows the device on usb0 # ip 169.254.255.2/30
On first device (with adb shell)
> route add default gw 169.254.255.2 dev usb0
> setprop net.dns1 8.8.8.8
> ping google.com --> is giving results
Plugin second device
ifconfig shows this device on usb1 # ip 169.254.255.2/30
On second device
Add gw, set DNS like above
Now the second device can ping google.com, but the first one not.
When I change the internal IP or the IPs assigned to the hosts usb0, usb1 interfaces I am not able to connect to the devices via adb anymore.
I suspect this to be a networking problem, rather than a problem with ADB? Any Ideas?
After a lot of googling and trial and error I finally found the solution for my particular setup.
What I did in the end, and what I missed in my first attempts, was to put each connected usb device into a separate subnet (see this answer on serverfault).
To put it clearly, the setup is now like following:
iptables contains the following rule
iptables -t nat -A POSTROUTING -j MASQUERADE
the host's usb0 and usb1 interface, now in separate subnets
usb0: inet addr:169.254.0.1 Bcast:169.254.15.255 Mask:255.255.240.0
usb1: inet addr:169.254.16.1 Bcast:169.254.31.255 Mask:255.255.240.0
internal usb0 iface of Android device connected on host's usb0:
- usb0 169.254.0.2/20
- default gw 169.254.0.1 (so the host's usb0 iface)
internal usb0 iface of Android device connected on host's usb1:
- usb0 169.254.16.2/20
- default gw 169.254.16.1 (so the host's usb1 iface)
That way I now have Internet access (after adb shell setprop net.dns1 8.8.8.8) from each android device connected to the usb interfaces on my host.
You need a linux system with root access, rooted android phone and usb cable.
Steps
Install adb and fastboot in your linux system.
sudo apt-get install android-tools-adb android-tools-fastboot
Connect your android phone to your PC via USB and enable USB tethering from the settings on your phone.
Open terminal in your PC and type the commands given below.
Find out the new network interface that was created on your PC.
ifconfig
Generally the new network interface will be usb0 or usb1. Let us consider usb0.
Now make some static IP address for this new interface usb0.
sudo ifconfig usb0 10.42.0.1 netmask 255.255.255.0
Now make this new interface usb0 as shared connection.
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
Now make some changes iptables firewall.
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
Now we have to enter some commands in the android phone. We can use either adb or directly typing the commands in the android phone through a terminal emulator installed in the phone. I am using the adb way.
Find the network interface in the android phone.
adb shell busybox ifconfig
Mine was rndis0.
Set the static IP, netmask and gateway.
adb shell ifconfig rndis0 10.42.0.2 netmask 255.255.255.0
adb shell route add default gw 10.42.0.1 dev rndis0
Verify Internet connectivity on your phone.
adb shell ping 8.8.8.8
If it is pinging, then the Internet in your mobile is working.
This Internet connection will not work with the apps like opera mini and paytm, but works well with whatsapp.

sniffing virtualbox traffic, host os linux mint

My host OS is: Linux Mint 15, my guest OS on virtualBox is: androVM.
What I want to do is take all http/s traffic from androVM and tunnel it though mitmproxy.
I am using the following, I usually connect to the internet via vpn (tun0).
The virtualbox is attached to the NAT, tun0 interface.
Here is the iptables script I am using, and yes I did install the cert on androVM via adb.
I am running the following bash script as follows:
#!/bin/sh
echo "Setting up IP tables"
echo "Resetting iptables rules"
iptables -t nat -F
echo "Now setting up ip forwarding rules"
sysctl -w net.ipv4.ip_forward=1
echo "Setting up the routing rules so all traffic from tun0(whatever interface) goes to mitmproxy"
iptables -t nat -A PREROUTING -i tun0 -p tcp --dport 443 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i tun0 -p tcp --dport 80 -j REDIRECT --to-port 8080
echo "Completed task"
$ sudo ./iptables.sh
$ sudo mitmproxy
What happens at this point is the androVM won't even access the internet, I have previously used this and it has worked, maybe something else is doing on, any hints, clues or guidance would be appreciated.
Thanks

Categories

Resources